|
| 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('typography migrations', () => { |
| 6 | + let runner: SchematicTestRunner; |
| 7 | + let cliAppTree: UnitTestTree; |
| 8 | + |
| 9 | + async function runMigrationTest(file: string, oldFileContent: string, newFileContent: string) { |
| 10 | + cliAppTree.create(file, oldFileContent); |
| 11 | + const tree = await migrateComponents([], runner, cliAppTree); |
| 12 | + expect(tree.readContent(file)).toBe(newFileContent); |
| 13 | + } |
| 14 | + |
| 15 | + beforeEach(async () => { |
| 16 | + runner = createNewTestRunner(); |
| 17 | + cliAppTree = patchDevkitTreeToExposeTypeScript(await createTestApp(runner)); |
| 18 | + }); |
| 19 | + |
| 20 | + it('should migrate an empty typography config call', async () => { |
| 21 | + await runMigrationTest( |
| 22 | + THEME_FILE, |
| 23 | + ` |
| 24 | + @use '@angular/material' as mat; |
| 25 | +
|
| 26 | + $sample-project-theme: mat.define-light-theme(( |
| 27 | + color: ( |
| 28 | + primary: $sample-project-primary, |
| 29 | + accent: $sample-project-accent, |
| 30 | + warn: $sample-project-warn, |
| 31 | + ), |
| 32 | + typography: mat.define-legacy-typography-config(), |
| 33 | + )); |
| 34 | + `, |
| 35 | + ` |
| 36 | + @use '@angular/material' as mat; |
| 37 | +
|
| 38 | + $sample-project-theme: mat.define-light-theme(( |
| 39 | + color: ( |
| 40 | + primary: $sample-project-primary, |
| 41 | + accent: $sample-project-accent, |
| 42 | + warn: $sample-project-warn, |
| 43 | + ), |
| 44 | + typography: mat.define-typography-config(), |
| 45 | + )); |
| 46 | + `, |
| 47 | + ); |
| 48 | + }); |
| 49 | + |
| 50 | + it('should migrate a typography config with positional arguments', async () => { |
| 51 | + await runMigrationTest( |
| 52 | + THEME_FILE, |
| 53 | + ` |
| 54 | + @use '@angular/material' as mat; |
| 55 | +
|
| 56 | + $sample-project-theme: mat.define-light-theme(( |
| 57 | + color: ( |
| 58 | + primary: $sample-project-primary, |
| 59 | + accent: $sample-project-accent, |
| 60 | + warn: $sample-project-warn, |
| 61 | + ), |
| 62 | + typography: mat.define-legacy-typography-config($font-family, $display-4, $display-3), |
| 63 | + )); |
| 64 | + `, |
| 65 | + ` |
| 66 | + @use '@angular/material' as mat; |
| 67 | +
|
| 68 | + $sample-project-theme: mat.define-light-theme(( |
| 69 | + color: ( |
| 70 | + primary: $sample-project-primary, |
| 71 | + accent: $sample-project-accent, |
| 72 | + warn: $sample-project-warn, |
| 73 | + ), |
| 74 | + typography: mat.define-typography-config($font-family, $display-4, $display-3), |
| 75 | + )); |
| 76 | + `, |
| 77 | + ); |
| 78 | + }); |
| 79 | + |
| 80 | + it('should migrate a typography config with named arguments', async () => { |
| 81 | + await runMigrationTest( |
| 82 | + THEME_FILE, |
| 83 | + ` |
| 84 | + @use '@angular/material' as mat; |
| 85 | +
|
| 86 | + $sample-project-theme: mat.define-light-theme(( |
| 87 | + color: ( |
| 88 | + primary: $sample-project-primary, |
| 89 | + accent: $sample-project-accent, |
| 90 | + warn: $sample-project-warn, |
| 91 | + ), |
| 92 | + typography: mat.define-legacy-typography-config( |
| 93 | + $font-family: $font-family, |
| 94 | + $display-4: $display-4, |
| 95 | + $display-3: $display-3, |
| 96 | + $display-2: $display-2, |
| 97 | + $display-1: $display-1, |
| 98 | + $headline: $headline, |
| 99 | + $title: $title, |
| 100 | + $subheading-2: $subheading-2, |
| 101 | + $subheading-1: $subheading-1, |
| 102 | + $body-2: $body-2, |
| 103 | + $body-1: $body-1, |
| 104 | + $caption: $caption, |
| 105 | + $button: $button, |
| 106 | + $input: $input, |
| 107 | + ), |
| 108 | + )); |
| 109 | + `, |
| 110 | + ` |
| 111 | + @use '@angular/material' as mat; |
| 112 | +
|
| 113 | + $sample-project-theme: mat.define-light-theme(( |
| 114 | + color: ( |
| 115 | + primary: $sample-project-primary, |
| 116 | + accent: $sample-project-accent, |
| 117 | + warn: $sample-project-warn, |
| 118 | + ), |
| 119 | + typography: mat.define-typography-config( |
| 120 | + $font-family: $font-family, |
| 121 | + $headline-1: $display-4, |
| 122 | + $headline-2: $display-3, |
| 123 | + $headline-3: $display-2, |
| 124 | + $headline-4: $display-1, |
| 125 | + $headline-5: $headline, |
| 126 | + $headline-6: $title, |
| 127 | + $subtitle-1: $subheading-2, |
| 128 | + $body-1: $subheading-1, |
| 129 | + $subtitle-2: $body-2, |
| 130 | + $body-2: $body-1, |
| 131 | + $caption: $caption, |
| 132 | + $button: $button, |
| 133 | + $input: $input, |
| 134 | + ), |
| 135 | + )); |
| 136 | + `, |
| 137 | + ); |
| 138 | + }); |
| 139 | + |
| 140 | + it('should migrate multiple typography configs with named arguments within the same file', async () => { |
| 141 | + await runMigrationTest( |
| 142 | + THEME_FILE, |
| 143 | + ` |
| 144 | + @use '@angular/material' as mat; |
| 145 | +
|
| 146 | + $sample-project-theme: mat.define-light-theme(( |
| 147 | + color: ( |
| 148 | + primary: $sample-project-primary, |
| 149 | + accent: $sample-project-accent, |
| 150 | + warn: $sample-project-warn, |
| 151 | + ), |
| 152 | + typography: mat.define-legacy-typography-config( |
| 153 | + $display-4: $display-4, |
| 154 | + $title: $title, |
| 155 | + ), |
| 156 | + )); |
| 157 | +
|
| 158 | + $other-sample-project-theme: mat.define-light-theme(( |
| 159 | + color: ( |
| 160 | + primary: $sample-project-primary, |
| 161 | + accent: $sample-project-accent, |
| 162 | + warn: $sample-project-warn, |
| 163 | + ), |
| 164 | + typography: mat.define-legacy-typography-config( |
| 165 | + $display-2: $display-2, |
| 166 | + $subheading-2: $subheading-2, |
| 167 | + ), |
| 168 | + )); |
| 169 | + `, |
| 170 | + ` |
| 171 | + @use '@angular/material' as mat; |
| 172 | +
|
| 173 | + $sample-project-theme: mat.define-light-theme(( |
| 174 | + color: ( |
| 175 | + primary: $sample-project-primary, |
| 176 | + accent: $sample-project-accent, |
| 177 | + warn: $sample-project-warn, |
| 178 | + ), |
| 179 | + typography: mat.define-typography-config( |
| 180 | + $headline-1: $display-4, |
| 181 | + $headline-6: $title, |
| 182 | + ), |
| 183 | + )); |
| 184 | +
|
| 185 | + $other-sample-project-theme: mat.define-light-theme(( |
| 186 | + color: ( |
| 187 | + primary: $sample-project-primary, |
| 188 | + accent: $sample-project-accent, |
| 189 | + warn: $sample-project-warn, |
| 190 | + ), |
| 191 | + typography: mat.define-typography-config( |
| 192 | + $headline-3: $display-2, |
| 193 | + $subtitle-1: $subheading-2, |
| 194 | + ), |
| 195 | + )); |
| 196 | + `, |
| 197 | + ); |
| 198 | + }); |
| 199 | +}); |
0 commit comments