|
| 1 | +import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing'; |
| 2 | +import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; |
| 3 | +import {createNewTestRunner, migrateComponents, THEME_FILE} from '../test-setup-helper'; |
| 4 | + |
| 5 | +describe('input styles', () => { |
| 6 | + let runner: SchematicTestRunner; |
| 7 | + let cliAppTree: UnitTestTree; |
| 8 | + |
| 9 | + async function runMigrationTest(oldFileContent: string, newFileContent: string) { |
| 10 | + cliAppTree.create(THEME_FILE, oldFileContent); |
| 11 | + const tree = await migrateComponents(['input'], runner, cliAppTree); |
| 12 | + expect(tree.readContent(THEME_FILE)).toBe(newFileContent); |
| 13 | + } |
| 14 | + |
| 15 | + beforeEach(async () => { |
| 16 | + runner = createNewTestRunner(); |
| 17 | + cliAppTree = patchDevkitTreeToExposeTypeScript(await createTestApp(runner)); |
| 18 | + }); |
| 19 | + |
| 20 | + describe('mixin migrations', () => { |
| 21 | + it('should replace the old theme with the new ones', async () => { |
| 22 | + await runMigrationTest( |
| 23 | + ` |
| 24 | + @use '@angular/material' as mat; |
| 25 | + $theme: (); |
| 26 | + @include mat.input-theme($theme); |
| 27 | + `, |
| 28 | + ` |
| 29 | + @use '@angular/material' as mat; |
| 30 | + $theme: (); |
| 31 | + @include mat.mdc-input-theme($theme); |
| 32 | + @include mat.mdc-input-typography($theme); |
| 33 | + `, |
| 34 | + ); |
| 35 | + }); |
| 36 | + |
| 37 | + it('should use the correct namespace', async () => { |
| 38 | + await runMigrationTest( |
| 39 | + ` |
| 40 | + @use '@angular/material' as arbitrary; |
| 41 | + $theme: (); |
| 42 | + @include arbitrary.input-theme($theme); |
| 43 | + `, |
| 44 | + ` |
| 45 | + @use '@angular/material' as arbitrary; |
| 46 | + $theme: (); |
| 47 | + @include arbitrary.mdc-input-theme($theme); |
| 48 | + @include arbitrary.mdc-input-typography($theme); |
| 49 | + `, |
| 50 | + ); |
| 51 | + }); |
| 52 | + |
| 53 | + it('should handle updating multiple themes', async () => { |
| 54 | + await runMigrationTest( |
| 55 | + ` |
| 56 | + @use '@angular/material' as mat; |
| 57 | + $light-theme: (); |
| 58 | + $dark-theme: (); |
| 59 | + @include mat.input-theme($light-theme); |
| 60 | + @include mat.input-theme($dark-theme); |
| 61 | + `, |
| 62 | + ` |
| 63 | + @use '@angular/material' as mat; |
| 64 | + $light-theme: (); |
| 65 | + $dark-theme: (); |
| 66 | + @include mat.mdc-input-theme($light-theme); |
| 67 | + @include mat.mdc-input-typography($light-theme); |
| 68 | + @include mat.mdc-input-theme($dark-theme); |
| 69 | + @include mat.mdc-input-typography($dark-theme); |
| 70 | + `, |
| 71 | + ); |
| 72 | + }); |
| 73 | + |
| 74 | + it('should add correct theme if all-component-themes mixin included', async () => { |
| 75 | + await runMigrationTest( |
| 76 | + ` |
| 77 | + @use '@angular/material' as mat; |
| 78 | + $theme: (); |
| 79 | + @include mat.all-component-themes($theme); |
| 80 | + `, |
| 81 | + ` |
| 82 | + @use '@angular/material' as mat; |
| 83 | + $theme: (); |
| 84 | + @include mat.all-component-themes($theme); |
| 85 | + @include mat.mdc-select-theme($theme); |
| 86 | + @include mat.mdc-select-typography($theme); |
| 87 | + @include mat.mdc-core-theme($theme); |
| 88 | + @include mat.mdc-core-typography($theme); |
| 89 | + @include mat.mdc-input-theme($theme); |
| 90 | + @include mat.mdc-input-typography($theme); |
| 91 | + @include mat.mdc-form-field-theme($theme); |
| 92 | + @include mat.mdc-form-field-typography($theme); |
| 93 | + @include mat.mdc-autocomplete-theme($theme); |
| 94 | + @include mat.mdc-autocomplete-typography($theme); |
| 95 | + `, |
| 96 | + ); |
| 97 | + }); |
| 98 | + |
| 99 | + it('should add multiple themes for multiple all-component-themes mixins', async () => { |
| 100 | + await runMigrationTest( |
| 101 | + ` |
| 102 | + @use '@angular/material' as mat; |
| 103 | + $light-theme: (); |
| 104 | + $dark-theme: (); |
| 105 | + @include mat.all-component-themes($light-theme); |
| 106 | + @include mat.all-component-themes($dark-theme); |
| 107 | + `, |
| 108 | + ` |
| 109 | + @use '@angular/material' as mat; |
| 110 | + $light-theme: (); |
| 111 | + $dark-theme: (); |
| 112 | + @include mat.all-component-themes($light-theme); |
| 113 | + @include mat.mdc-select-theme($light-theme); |
| 114 | + @include mat.mdc-select-typography($light-theme); |
| 115 | + @include mat.mdc-core-theme($light-theme); |
| 116 | + @include mat.mdc-core-typography($light-theme); |
| 117 | + @include mat.mdc-input-theme($light-theme); |
| 118 | + @include mat.mdc-input-typography($light-theme); |
| 119 | + @include mat.mdc-form-field-theme($light-theme); |
| 120 | + @include mat.mdc-form-field-typography($light-theme); |
| 121 | + @include mat.mdc-autocomplete-theme($light-theme); |
| 122 | + @include mat.mdc-autocomplete-typography($light-theme); |
| 123 | + @include mat.all-component-themes($dark-theme); |
| 124 | + @include mat.mdc-select-theme($dark-theme); |
| 125 | + @include mat.mdc-select-typography($dark-theme); |
| 126 | + @include mat.mdc-core-theme($dark-theme); |
| 127 | + @include mat.mdc-core-typography($dark-theme); |
| 128 | + @include mat.mdc-input-theme($dark-theme); |
| 129 | + @include mat.mdc-input-typography($dark-theme); |
| 130 | + @include mat.mdc-form-field-theme($dark-theme); |
| 131 | + @include mat.mdc-form-field-typography($dark-theme); |
| 132 | + @include mat.mdc-autocomplete-theme($dark-theme); |
| 133 | + @include mat.mdc-autocomplete-typography($dark-theme); |
| 134 | + `, |
| 135 | + ); |
| 136 | + }); |
| 137 | + |
| 138 | + it('should preserve whitespace', async () => { |
| 139 | + await runMigrationTest( |
| 140 | + ` |
| 141 | + @use '@angular/material' as mat; |
| 142 | + $theme: (); |
| 143 | +
|
| 144 | +
|
| 145 | + @include mat.input-theme($theme); |
| 146 | +
|
| 147 | +
|
| 148 | + `, |
| 149 | + ` |
| 150 | + @use '@angular/material' as mat; |
| 151 | + $theme: (); |
| 152 | +
|
| 153 | +
|
| 154 | + @include mat.mdc-input-theme($theme); |
| 155 | + @include mat.mdc-input-typography($theme); |
| 156 | +
|
| 157 | +
|
| 158 | + `, |
| 159 | + ); |
| 160 | + }); |
| 161 | + }); |
| 162 | + |
| 163 | + describe('selector migrations', () => { |
| 164 | + it('should update the legacy mat-input classname', async () => { |
| 165 | + await runMigrationTest( |
| 166 | + ` |
| 167 | + .mat-input-element { |
| 168 | + color: red; |
| 169 | + } |
| 170 | + `, |
| 171 | + ` |
| 172 | + .mat-mdc-input-element { |
| 173 | + color: red; |
| 174 | + } |
| 175 | + `, |
| 176 | + ); |
| 177 | + }); |
| 178 | + |
| 179 | + it('should update a legacy classname w/ multiple selectors', async () => { |
| 180 | + await runMigrationTest( |
| 181 | + ` |
| 182 | + .some-class.mat-input-element, .another-class { |
| 183 | + color: red; |
| 184 | + } |
| 185 | + `, |
| 186 | + ` |
| 187 | + .some-class.mat-mdc-input-element, .another-class { |
| 188 | + color: red; |
| 189 | + } |
| 190 | + `, |
| 191 | + ); |
| 192 | + }); |
| 193 | + |
| 194 | + it('should preserve the whitespace of multiple selectors', async () => { |
| 195 | + await runMigrationTest( |
| 196 | + ` |
| 197 | + .some-class, |
| 198 | + .mat-input-element, |
| 199 | + .another-class { color: red; } |
| 200 | + `, |
| 201 | + ` |
| 202 | + .some-class, |
| 203 | + .mat-mdc-input-element, |
| 204 | + .another-class { color: red; } |
| 205 | + `, |
| 206 | + ); |
| 207 | + }); |
| 208 | + |
| 209 | + it('should add comment for potentially deprecated selector', async () => { |
| 210 | + await runMigrationTest( |
| 211 | + ` |
| 212 | + .mat-input-server { |
| 213 | + color: red; |
| 214 | + } |
| 215 | + `, |
| 216 | + ` |
| 217 | + /* TODO: The following rule targets internal classes of input that may no longer apply for the MDC version. */ |
| 218 | +
|
| 219 | + .mat-input-server { |
| 220 | + color: red; |
| 221 | + } |
| 222 | + `, |
| 223 | + ); |
| 224 | + }); |
| 225 | + |
| 226 | + it('should add comment for potentially deprecated multi-line selector', async () => { |
| 227 | + await runMigrationTest( |
| 228 | + ` |
| 229 | + .some-class |
| 230 | + .mat-input-server { |
| 231 | + color: red; |
| 232 | + } |
| 233 | + `, |
| 234 | + ` |
| 235 | + /* TODO: The following rule targets internal classes of input that may no longer apply for the MDC version. */ |
| 236 | +
|
| 237 | + .some-class |
| 238 | + .mat-input-server { |
| 239 | + color: red; |
| 240 | + } |
| 241 | + `, |
| 242 | + ); |
| 243 | + }); |
| 244 | + |
| 245 | + it('should update the legacy mat-input class and add comment for potentially deprecated selector', async () => { |
| 246 | + await runMigrationTest( |
| 247 | + ` |
| 248 | + .mat-input-element.some-class, .mat-input-server { |
| 249 | + color: red; |
| 250 | + } |
| 251 | + `, |
| 252 | + ` |
| 253 | + /* TODO: The following rule targets internal classes of input that may no longer apply for the MDC version. */ |
| 254 | +
|
| 255 | + .mat-mdc-input-element.some-class, .mat-input-server { |
| 256 | + color: red; |
| 257 | + } |
| 258 | + `, |
| 259 | + ); |
| 260 | + }); |
| 261 | + }); |
| 262 | +}); |
0 commit comments