|
| 1 | +import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing'; |
| 2 | +import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; |
| 3 | +import {createNewTestRunner, migrateComponents, TEMPLATE_FILE} from '../test-setup-helper'; |
| 4 | + |
| 5 | +describe('card template migrator', () => { |
| 6 | + let runner: SchematicTestRunner; |
| 7 | + let cliAppTree: UnitTestTree; |
| 8 | + |
| 9 | + async function runMigrationTest(oldFileContent: string, newFileContent: string) { |
| 10 | + cliAppTree.overwrite(TEMPLATE_FILE, oldFileContent); |
| 11 | + const tree = await migrateComponents(['card'], runner, cliAppTree); |
| 12 | + expect(tree.readContent(TEMPLATE_FILE)).toBe(newFileContent); |
| 13 | + } |
| 14 | + |
| 15 | + beforeEach(async () => { |
| 16 | + runner = createNewTestRunner(); |
| 17 | + cliAppTree = patchDevkitTreeToExposeTypeScript(await createTestApp(runner)); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should not update other elements', async () => { |
| 21 | + await runMigrationTest('<mat-button></mat-button>', '<mat-button></mat-button>'); |
| 22 | + }); |
| 23 | + |
| 24 | + it('should update single', async () => { |
| 25 | + await runMigrationTest('<mat-card></mat-card>', '<mat-card appearance="outlined"></mat-card>'); |
| 26 | + }); |
| 27 | + |
| 28 | + it('should update multiple same-line unnested', async () => { |
| 29 | + await runMigrationTest( |
| 30 | + '<mat-card></mat-card><mat-card></mat-card>', |
| 31 | + '<mat-card appearance="outlined"></mat-card><mat-card appearance="outlined"></mat-card>', |
| 32 | + ); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should update multiple same-line nested', async () => { |
| 36 | + await runMigrationTest( |
| 37 | + '<mat-card><mat-card></mat-card></mat-card>', |
| 38 | + '<mat-card appearance="outlined"><mat-card appearance="outlined"></mat-card></mat-card>', |
| 39 | + ); |
| 40 | + }); |
| 41 | + |
| 42 | + it('should update multiple same-line nested and unnested', async () => { |
| 43 | + await runMigrationTest( |
| 44 | + '<mat-card><mat-card></mat-card><mat-card></mat-card></mat-card>', |
| 45 | + '<mat-card appearance="outlined"><mat-card appearance="outlined"></mat-card><mat-card appearance="outlined"></mat-card></mat-card>', |
| 46 | + ); |
| 47 | + }); |
| 48 | + |
| 49 | + it('should update multiple multi-line unnested', async () => { |
| 50 | + await runMigrationTest( |
| 51 | + ` |
| 52 | + <mat-card></mat-card> |
| 53 | + <mat-card></mat-card> |
| 54 | + `, |
| 55 | + ` |
| 56 | + <mat-card appearance="outlined"></mat-card> |
| 57 | + <mat-card appearance="outlined"></mat-card> |
| 58 | + `, |
| 59 | + ); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should update multiple multi-line nested', async () => { |
| 63 | + await runMigrationTest( |
| 64 | + ` |
| 65 | + <mat-card> |
| 66 | + <mat-card></mat-card> |
| 67 | + </mat-card> |
| 68 | + `, |
| 69 | + ` |
| 70 | + <mat-card appearance="outlined"> |
| 71 | + <mat-card appearance="outlined"></mat-card> |
| 72 | + </mat-card> |
| 73 | + `, |
| 74 | + ); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should update multiple multi-line nested and unnested', async () => { |
| 78 | + await runMigrationTest( |
| 79 | + ` |
| 80 | + <mat-card> |
| 81 | + <mat-card></mat-card> |
| 82 | + <mat-card></mat-card> |
| 83 | + </mat-card> |
| 84 | + `, |
| 85 | + ` |
| 86 | + <mat-card appearance="outlined"> |
| 87 | + <mat-card appearance="outlined"></mat-card> |
| 88 | + <mat-card appearance="outlined"></mat-card> |
| 89 | + </mat-card> |
| 90 | + `, |
| 91 | + ); |
| 92 | + }); |
| 93 | +}); |
0 commit comments