|
| 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('snack-bar 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(['snack-bar'], 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.snack-bar-theme($theme); |
| 27 | + `, |
| 28 | + ` |
| 29 | + @use '@angular/material' as mat; |
| 30 | + $theme: (); |
| 31 | + @include mat.mdc-snack-bar-theme($theme); |
| 32 | + @include mat.mdc-snack-bar-typography($theme); |
| 33 | + @include mat.mdc-button-theme($theme); |
| 34 | + @include mat.mdc-button-typography($theme); |
| 35 | + `, |
| 36 | + ); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should replace the old theme with the new ones and keep the non MDC button theme', async () => { |
| 40 | + await runMigrationTest( |
| 41 | + ` |
| 42 | + @use '@angular/material' as mat; |
| 43 | + $theme: (); |
| 44 | + @include mat.button-theme($theme); |
| 45 | + @include mat.snack-bar-theme($theme); |
| 46 | + `, |
| 47 | + ` |
| 48 | + @use '@angular/material' as mat; |
| 49 | + $theme: (); |
| 50 | + @include mat.button-theme($theme); |
| 51 | + @include mat.mdc-snack-bar-theme($theme); |
| 52 | + @include mat.mdc-snack-bar-typography($theme); |
| 53 | + @include mat.mdc-button-theme($theme); |
| 54 | + @include mat.mdc-button-typography($theme); |
| 55 | + `, |
| 56 | + ); |
| 57 | + }); |
| 58 | + |
| 59 | + it('should replace the old theme with the non-duplicated new ones', async () => { |
| 60 | + await runMigrationTest( |
| 61 | + ` |
| 62 | + @use '@angular/material' as mat; |
| 63 | + $theme: (); |
| 64 | + @include mat.snack-bar-theme($theme); |
| 65 | + @include mat.mdc-button-theme($theme); |
| 66 | + @include mat.mdc-button-typography($theme); |
| 67 | + `, |
| 68 | + ` |
| 69 | + @use '@angular/material' as mat; |
| 70 | + $theme: (); |
| 71 | + @include mat.mdc-snack-bar-theme($theme); |
| 72 | + @include mat.mdc-snack-bar-typography($theme); |
| 73 | + @include mat.mdc-button-theme($theme); |
| 74 | + @include mat.mdc-button-typography($theme); |
| 75 | + `, |
| 76 | + ); |
| 77 | + }); |
| 78 | + |
| 79 | + it('should use the correct namespace', async () => { |
| 80 | + await runMigrationTest( |
| 81 | + ` |
| 82 | + @use '@angular/material' as arbitrary; |
| 83 | + $theme: (); |
| 84 | + @include arbitrary.snack-bar-theme($theme); |
| 85 | + `, |
| 86 | + ` |
| 87 | + @use '@angular/material' as arbitrary; |
| 88 | + $theme: (); |
| 89 | + @include arbitrary.mdc-snack-bar-theme($theme); |
| 90 | + @include arbitrary.mdc-snack-bar-typography($theme); |
| 91 | + @include arbitrary.mdc-button-theme($theme); |
| 92 | + @include arbitrary.mdc-button-typography($theme); |
| 93 | + `, |
| 94 | + ); |
| 95 | + }); |
| 96 | + |
| 97 | + it('should handle updating multiple themes', async () => { |
| 98 | + await runMigrationTest( |
| 99 | + ` |
| 100 | + @use '@angular/material' as mat; |
| 101 | + $light-theme: (); |
| 102 | + $dark-theme: (); |
| 103 | + @include mat.snack-bar-theme($light-theme); |
| 104 | + @include mat.snack-bar-theme($dark-theme); |
| 105 | + `, |
| 106 | + ` |
| 107 | + @use '@angular/material' as mat; |
| 108 | + $light-theme: (); |
| 109 | + $dark-theme: (); |
| 110 | + @include mat.mdc-snack-bar-theme($light-theme); |
| 111 | + @include mat.mdc-snack-bar-typography($light-theme); |
| 112 | + @include mat.mdc-button-theme($light-theme); |
| 113 | + @include mat.mdc-button-typography($light-theme); |
| 114 | + @include mat.mdc-snack-bar-theme($dark-theme); |
| 115 | + @include mat.mdc-snack-bar-typography($dark-theme); |
| 116 | + @include mat.mdc-button-theme($dark-theme); |
| 117 | + @include mat.mdc-button-typography($dark-theme); |
| 118 | + `, |
| 119 | + ); |
| 120 | + }); |
| 121 | + |
| 122 | + it('should preserve whitespace', async () => { |
| 123 | + await runMigrationTest( |
| 124 | + ` |
| 125 | + @use '@angular/material' as mat; |
| 126 | + $theme: (); |
| 127 | +
|
| 128 | +
|
| 129 | + @include mat.snack-bar-theme($theme); |
| 130 | +
|
| 131 | +
|
| 132 | + `, |
| 133 | + ` |
| 134 | + @use '@angular/material' as mat; |
| 135 | + $theme: (); |
| 136 | +
|
| 137 | +
|
| 138 | + @include mat.mdc-snack-bar-theme($theme); |
| 139 | + @include mat.mdc-snack-bar-typography($theme); |
| 140 | + @include mat.mdc-button-theme($theme); |
| 141 | + @include mat.mdc-button-typography($theme); |
| 142 | +
|
| 143 | +
|
| 144 | + `, |
| 145 | + ); |
| 146 | + }); |
| 147 | + }); |
| 148 | + |
| 149 | + describe('selector migrations', () => { |
| 150 | + it('should update the legacy mat-snack-bar-container classname', async () => { |
| 151 | + await runMigrationTest( |
| 152 | + ` |
| 153 | + .mat-snack-bar-container { |
| 154 | + padding: 24px; |
| 155 | + } |
| 156 | + `, |
| 157 | + ` |
| 158 | + .mat-mdc-snack-bar-container { |
| 159 | + padding: 24px; |
| 160 | + } |
| 161 | + `, |
| 162 | + ); |
| 163 | + }); |
| 164 | + |
| 165 | + it('should update multiple legacy classnames', async () => { |
| 166 | + await runMigrationTest( |
| 167 | + ` |
| 168 | + .mat-snack-bar-container { |
| 169 | + padding: 24px; |
| 170 | + } |
| 171 | + .mat-simple-snackbar { |
| 172 | + color: red; |
| 173 | + } |
| 174 | + `, |
| 175 | + ` |
| 176 | + .mat-mdc-snack-bar-container { |
| 177 | + padding: 24px; |
| 178 | + } |
| 179 | + .mat-mdc-simple-snack-bar { |
| 180 | + color: red; |
| 181 | + } |
| 182 | + `, |
| 183 | + ); |
| 184 | + }); |
| 185 | + |
| 186 | + it('should update a legacy classname w/ multiple selectors', async () => { |
| 187 | + await runMigrationTest( |
| 188 | + ` |
| 189 | + .some-class.mat-snack-bar-container, .another-class { |
| 190 | + padding: 24px; |
| 191 | + } |
| 192 | + `, |
| 193 | + ` |
| 194 | + .some-class.mat-mdc-snack-bar-container, .another-class { |
| 195 | + padding: 24px; |
| 196 | + } |
| 197 | + `, |
| 198 | + ); |
| 199 | + }); |
| 200 | + |
| 201 | + it('should preserve the whitespace of multiple selectors', async () => { |
| 202 | + await runMigrationTest( |
| 203 | + ` |
| 204 | + .some-class, |
| 205 | + .mat-snack-bar-container, |
| 206 | + .another-class { padding: 24px; } |
| 207 | + `, |
| 208 | + ` |
| 209 | + .some-class, |
| 210 | + .mat-mdc-snack-bar-container, |
| 211 | + .another-class { padding: 24px; } |
| 212 | + `, |
| 213 | + ); |
| 214 | + }); |
| 215 | + }); |
| 216 | +}); |
0 commit comments