|
| 1 | +import * as path from 'path'; |
| 2 | + |
| 3 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; |
| 4 | +import { setupTestTree } from '../common/setup.spec'; |
| 5 | + |
| 6 | +const version = '21.1.0'; |
| 7 | + |
| 8 | +describe(`Update to ${version}`, () => { |
| 9 | + let appTree: UnitTestTree; |
| 10 | + const schematicRunner = new SchematicTestRunner('ig-migrate', path.join(__dirname, '../migration-collection.json')); |
| 11 | + |
| 12 | + beforeEach(() => { |
| 13 | + appTree = setupTestTree(); |
| 14 | + }); |
| 15 | + |
| 16 | + const migrationName = 'migration-53'; |
| 17 | + |
| 18 | + it('should replace CSS custom properties prefix from --igx to --ig', async () => { |
| 19 | + appTree.create( |
| 20 | + `/testSrc/appPrefix/component/test.component.scss`, |
| 21 | +`.custom-avatar { |
| 22 | + --igx-avatar-background: var(--ig-primary-500); |
| 23 | +}` |
| 24 | + ); |
| 25 | + |
| 26 | + const tree = await schematicRunner |
| 27 | + .runSchematic(migrationName, {}, appTree); |
| 28 | + |
| 29 | + expect( |
| 30 | + tree.readContent('/testSrc/appPrefix/component/test.component.scss') |
| 31 | + ).toEqual( |
| 32 | +`.custom-avatar { |
| 33 | + --ig-avatar-background: var(--ig-primary-500); |
| 34 | +}` |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + it('should replace multiple --igx- occurrences in a single file', async () => { |
| 39 | + appTree.create( |
| 40 | + `/testSrc/appPrefix/component/multi.component.scss`, |
| 41 | +`.theme { |
| 42 | + --igx-surface-500: var(--igx-primary-500); |
| 43 | + color: var(--igx-secondary-200); |
| 44 | + background: var(--igx-surface-100); |
| 45 | +}` |
| 46 | + ); |
| 47 | + |
| 48 | + const tree = await schematicRunner |
| 49 | + .runSchematic(migrationName, {}, appTree); |
| 50 | + |
| 51 | + expect( |
| 52 | + tree.readContent('/testSrc/appPrefix/component/multi.component.scss') |
| 53 | + ).toEqual( |
| 54 | +`.theme { |
| 55 | + --ig-surface-500: var(--ig-primary-500); |
| 56 | + color: var(--ig-secondary-200); |
| 57 | + background: var(--ig-surface-100); |
| 58 | +}` |
| 59 | + ); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should leave files without --igx- unchanged', async () => { |
| 63 | + const original = `.card { |
| 64 | + --ig-primary-500: #000; |
| 65 | +}`; |
| 66 | + |
| 67 | + appTree.create( |
| 68 | + `/testSrc/appPrefix/component/no-change.component.scss`, |
| 69 | + original |
| 70 | + ); |
| 71 | + |
| 72 | + const tree = await schematicRunner |
| 73 | + .runSchematic(migrationName, {}, appTree); |
| 74 | + |
| 75 | + expect( |
| 76 | + tree.readContent('/testSrc/appPrefix/component/no-change.component.scss') |
| 77 | + ).toEqual(original); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should update --igx- inside :root and comments', async () => { |
| 81 | + appTree.create( |
| 82 | + `/testSrc/appPrefix/component/root.component.scss`, |
| 83 | +`:root { |
| 84 | + --igx-radius-factor: 1.25; |
| 85 | +} |
| 86 | +
|
| 87 | +// --igx-elevation-1 is used for cards |
| 88 | +.card { |
| 89 | + box-shadow: var(--igx-elevation-1); |
| 90 | +}` |
| 91 | + ); |
| 92 | + |
| 93 | + const tree = await schematicRunner |
| 94 | + .runSchematic(migrationName, {}, appTree); |
| 95 | + |
| 96 | + expect( |
| 97 | + tree.readContent('/testSrc/appPrefix/component/root.component.scss') |
| 98 | + ).toEqual( |
| 99 | +`:root { |
| 100 | + --ig-radius-factor: 1.25; |
| 101 | +} |
| 102 | +
|
| 103 | +// --ig-elevation-1 is used for cards |
| 104 | +.card { |
| 105 | + box-shadow: var(--ig-elevation-1); |
| 106 | +}` |
| 107 | + ); |
| 108 | + }); |
| 109 | +}); |
0 commit comments