|
| 1 | +import {createTestCaseSetup} from '@angular/cdk/schematics/testing'; |
| 2 | +import {MIGRATION_PATH} from '../../paths'; |
| 3 | + |
| 4 | +describe('V18 token renames', () => { |
| 5 | + async function setup(fileName: string, originalSource: string): Promise<string> { |
| 6 | + const filePath = `projects/cdk-testing/src/${fileName}`; |
| 7 | + const {runFixers, writeFile, appTree} = await createTestCaseSetup( |
| 8 | + 'migration-v18', |
| 9 | + MIGRATION_PATH, |
| 10 | + [], |
| 11 | + ); |
| 12 | + |
| 13 | + if (fileName.endsWith('.html')) { |
| 14 | + writeFile( |
| 15 | + 'projects/cdk-testing/src/comp.ts', |
| 16 | + [ |
| 17 | + `import {Component} from '@angular/core';`, |
| 18 | + `@Component({selector: 'comp', templateUrl: '${fileName}'})`, |
| 19 | + `export class Comp {}`, |
| 20 | + ].join('\n'), |
| 21 | + ); |
| 22 | + } else if (fileName.endsWith('.css') && fileName !== 'theme.css') { |
| 23 | + writeFile( |
| 24 | + 'projects/cdk-testing/src/comp.ts', |
| 25 | + [ |
| 26 | + `import {Component} from '@angular/core';`, |
| 27 | + `@Component({selector: 'comp', template: '', styleUrl: '${fileName}'})`, |
| 28 | + `export class Comp {}`, |
| 29 | + ].join('\n'), |
| 30 | + ); |
| 31 | + } |
| 32 | + |
| 33 | + writeFile(filePath, originalSource); |
| 34 | + await runFixers(); |
| 35 | + return appTree.readContent(filePath); |
| 36 | + } |
| 37 | + |
| 38 | + it('should migrate mdc-form-field tokens in theme css', async () => { |
| 39 | + const result = await setup( |
| 40 | + 'theme.scss', |
| 41 | + [ |
| 42 | + `body {`, |
| 43 | + ` --mdc-form-field-label-text-color: red;`, |
| 44 | + ` --mdc-form-field-label-text-font: Roboto;`, |
| 45 | + ` --mdc-form-field-label-text-size: 16px;`, |
| 46 | + ` --mdc-form-field-label-text-weight: bold;`, |
| 47 | + ` --mdc-form-field-label-text-tracking: 0;`, |
| 48 | + ` --mdc-form-field-label-text-line-height: 1.2;`, |
| 49 | + ` --mdc-form-field-label-text-color-custom: green;`, |
| 50 | + `}`, |
| 51 | + ].join('\n'), |
| 52 | + ); |
| 53 | + |
| 54 | + expect(result.split('\n')).toEqual([ |
| 55 | + `body {`, |
| 56 | + ` --mat-checkbox-label-text-color: red;`, |
| 57 | + ` --mat-checkbox-label-text-font: Roboto;`, |
| 58 | + ` --mat-checkbox-label-text-size: 16px;`, |
| 59 | + ` --mat-checkbox-label-text-weight: bold;`, |
| 60 | + ` --mat-checkbox-label-text-tracking: 0;`, |
| 61 | + ` --mat-checkbox-label-text-line-height: 1.2;`, |
| 62 | + ` --mdc-form-field-label-text-color-custom: green;`, |
| 63 | + `}`, |
| 64 | + ]); |
| 65 | + }); |
| 66 | + |
| 67 | + it('should migrate mdc-form-field tokens in component css', async () => { |
| 68 | + const result = await setup( |
| 69 | + 'some-comp.css', |
| 70 | + `:host {color: var(--mdc-form-field-label-text-color);}`, |
| 71 | + ); |
| 72 | + |
| 73 | + expect(result).toBe(`:host {color: var(--mat-checkbox-label-text-color);}`); |
| 74 | + }); |
| 75 | + |
| 76 | + it('should migrate mdc-form-field tokens in ts', async () => { |
| 77 | + const result = await setup( |
| 78 | + 'some-comp.ts', |
| 79 | + `const TEXT_COLOR_PROP = '--mdc-form-field-label-text-color';`, |
| 80 | + ); |
| 81 | + |
| 82 | + expect(result).toBe(`const TEXT_COLOR_PROP = '--mat-checkbox-label-text-color';`); |
| 83 | + }); |
| 84 | + |
| 85 | + it('should migrate mdc-form-field tokens in html', async () => { |
| 86 | + const result = await setup( |
| 87 | + 'some-comp.html', |
| 88 | + `<div style="--mdc-form-field-label-text-color: red;"><ng-content /></div>`, |
| 89 | + ); |
| 90 | + |
| 91 | + expect(result).toBe(`<div style="--mat-checkbox-label-text-color: red;"><ng-content /></div>`); |
| 92 | + }); |
| 93 | +}); |
0 commit comments