|
| 1 | +import * as path from 'path'; |
| 2 | + |
| 3 | +import { EmptyTree } from '@angular-devkit/schematics'; |
| 4 | +import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing'; |
| 5 | + |
| 6 | +const version = '15.0.11'; |
| 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 | + const configJson = { |
| 13 | + defaultProject: 'testProj', |
| 14 | + projects: { |
| 15 | + testProj: { |
| 16 | + root: '/', |
| 17 | + sourceRoot: '/testSrc' |
| 18 | + } |
| 19 | + }, |
| 20 | + schematics: { |
| 21 | + '@schematics/angular:component': { |
| 22 | + prefix: 'appPrefix' |
| 23 | + } |
| 24 | + } |
| 25 | + }; |
| 26 | + |
| 27 | + beforeEach(() => { |
| 28 | + appTree = new UnitTestTree(new EmptyTree()); |
| 29 | + appTree.create('/angular.json', JSON.stringify(configJson)); |
| 30 | + }); |
| 31 | + |
| 32 | + const migrationName = 'migration-28'; |
| 33 | + |
| 34 | + it('should replace CSS $grays parameters', async () => { |
| 35 | + appTree.create( |
| 36 | + `/testSrc/appPrefix/component/test.component.scss`, |
| 37 | +`$my-palette: palette( |
| 38 | + $primary: #09f, |
| 39 | + $secondary: #e41c77, |
| 40 | + $grays: #000 |
| 41 | +); |
| 42 | +$my-palette: palette( |
| 43 | + $primary: #09f, |
| 44 | + $secondary: #e41c77, |
| 45 | + $grays: #000123 |
| 46 | +);` |
| 47 | + ); |
| 48 | + |
| 49 | + const tree = await schematicRunner |
| 50 | + .runSchematicAsync(migrationName, {}, appTree) |
| 51 | + .toPromise(); |
| 52 | + |
| 53 | + expect( |
| 54 | + tree.readContent('/testSrc/appPrefix/component/test.component.scss') |
| 55 | + ).toEqual( |
| 56 | +`$my-palette: palette( |
| 57 | + $primary: #09f, |
| 58 | + $secondary: #e41c77, |
| 59 | + $gray: #000 |
| 60 | +); |
| 61 | +$my-palette: palette( |
| 62 | + $primary: #09f, |
| 63 | + $secondary: #e41c77, |
| 64 | + $gray: #000123 |
| 65 | +);` |
| 66 | + ); |
| 67 | + }); |
| 68 | + |
| 69 | + it('should replace CSS $grays parameters variations', async () => { |
| 70 | + appTree.create( |
| 71 | + `/testSrc/appPrefix/component/test.component.scss`, |
| 72 | +`$my-palette: palette( |
| 73 | + $grays: red, |
| 74 | + $grays: rgb(204, 102, 153), |
| 75 | + $grays: rgba(107, 113, 127, 0.8), |
| 76 | + $grays: hsl(228, 7%, 86%), |
| 77 | + $grays: hsla(20, 20%, 85%, 0.7), |
| 78 | +); |
| 79 | +$my-palette: palette( |
| 80 | + $grays: red, |
| 81 | + $grays: rgb(204, 102, 153), |
| 82 | + $grays: rgba(107, 113, 127, 0.8), |
| 83 | + $grays: hsl(228, 7%, 86%), |
| 84 | + $grays: hsla(20, 20%, 85%, 0.7), |
| 85 | +);` |
| 86 | + ); |
| 87 | + |
| 88 | + const tree = await schematicRunner |
| 89 | + .runSchematicAsync(migrationName, {}, appTree) |
| 90 | + .toPromise(); |
| 91 | + |
| 92 | + expect( |
| 93 | + tree.readContent('/testSrc/appPrefix/component/test.component.scss') |
| 94 | + ).toEqual( |
| 95 | +`$my-palette: palette( |
| 96 | + $gray: red, |
| 97 | + $gray: rgb(204, 102, 153), |
| 98 | + $gray: rgba(107, 113, 127, 0.8), |
| 99 | + $gray: hsl(228, 7%, 86%), |
| 100 | + $gray: hsla(20, 20%, 85%, 0.7), |
| 101 | +); |
| 102 | +$my-palette: palette( |
| 103 | + $gray: red, |
| 104 | + $gray: rgb(204, 102, 153), |
| 105 | + $gray: rgba(107, 113, 127, 0.8), |
| 106 | + $gray: hsl(228, 7%, 86%), |
| 107 | + $gray: hsla(20, 20%, 85%, 0.7), |
| 108 | +);` |
| 109 | + ); |
| 110 | + }); |
| 111 | + |
| 112 | + it('should NOT replace $grays as custom var', async () => { |
| 113 | + appTree.create( |
| 114 | + `/testSrc/appPrefix/component/test.component.scss`, |
| 115 | +`$grays: #FFFFFF;` |
| 116 | + ); |
| 117 | + |
| 118 | + const tree = await schematicRunner |
| 119 | + .runSchematicAsync(migrationName, {}, appTree) |
| 120 | + .toPromise(); |
| 121 | + |
| 122 | + expect( |
| 123 | + tree.readContent('/testSrc/appPrefix/component/test.component.scss') |
| 124 | + ).toEqual( |
| 125 | +`$grays: #FFFFFF;` |
| 126 | + ); |
| 127 | + }); |
| 128 | + |
| 129 | + it('should replace grays as value', async () => { |
| 130 | + appTree.create( |
| 131 | + `/testSrc/appPrefix/component/test.component.scss`, |
| 132 | +`.my-class { |
| 133 | + color: contrast-color($color: 'grays', $variant: 300); |
| 134 | +}` |
| 135 | + ); |
| 136 | + |
| 137 | + const tree = await schematicRunner |
| 138 | + .runSchematicAsync(migrationName, {}, appTree) |
| 139 | + .toPromise(); |
| 140 | + |
| 141 | + expect( |
| 142 | + tree.readContent('/testSrc/appPrefix/component/test.component.scss') |
| 143 | + ).toEqual( |
| 144 | +`.my-class { |
| 145 | + color: contrast-color($color: 'gray', $variant: 300); |
| 146 | +}` |
| 147 | + ); |
| 148 | + }); |
| 149 | + |
| 150 | + it('should replace .igx-typography with .ig-typography as style', async () => { |
| 151 | + appTree.create( |
| 152 | + `/testSrc/appPrefix/component/test.component.scss`, |
| 153 | +`.igx-typography { |
| 154 | + h1, h2, h3, h4, h5, h6, p, .igx-typography__body-1 { |
| 155 | + margin: 0; |
| 156 | + } |
| 157 | +}`); |
| 158 | + |
| 159 | + const tree = await schematicRunner |
| 160 | + .runSchematicAsync(migrationName, {}, appTree) |
| 161 | + .toPromise(); |
| 162 | + |
| 163 | + expect( |
| 164 | + tree.readContent('/testSrc/appPrefix/component/test.component.scss') |
| 165 | + ).toEqual( |
| 166 | +`.ig-typography { |
| 167 | + h1, h2, h3, h4, h5, h6, p, .ig-typography__body-1 { |
| 168 | + margin: 0; |
| 169 | + } |
| 170 | +}` |
| 171 | + ); |
| 172 | + }); |
| 173 | + |
| 174 | + it('should replace igx-typography & igx-scrollbar from template', async () => { |
| 175 | + appTree.create( |
| 176 | + `/testSrc/appPrefix/component/test.component.html`, |
| 177 | +`<body class="igx-typography igx-scrollbar"> |
| 178 | + <app-root></app-root> |
| 179 | +</body>` |
| 180 | + ); |
| 181 | + |
| 182 | + const tree = await schematicRunner |
| 183 | + .runSchematicAsync(migrationName, {}, appTree) |
| 184 | + .toPromise(); |
| 185 | + |
| 186 | + expect( |
| 187 | + tree.readContent('/testSrc/appPrefix/component/test.component.html') |
| 188 | + ).toEqual( |
| 189 | +`<body class="ig-typography ig-scrollbar"> |
| 190 | + <app-root></app-root> |
| 191 | +</body>` |
| 192 | + ); |
| 193 | + }); |
| 194 | +}); |
0 commit comments