-
Notifications
You must be signed in to change notification settings - Fork 6.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(material/schematics): split up tests
Splits the tests for the `define-typography-config` migration into a separate file since they didn't make sense in the `multiple-components-styles.spec.ts`. (cherry picked from commit 9f006be)
- Loading branch information
Showing
2 changed files
with
199 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
src/material/schematics/ng-generate/mdc-migration/rules/components/typography-config.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
import {createTestApp, patchDevkitTreeToExposeTypeScript} from '@angular/cdk/schematics/testing'; | ||
import {SchematicTestRunner, UnitTestTree} from '@angular-devkit/schematics/testing'; | ||
import {createNewTestRunner, migrateComponents, THEME_FILE} from './test-setup-helper'; | ||
|
||
describe('typography migrations', () => { | ||
let runner: SchematicTestRunner; | ||
let cliAppTree: UnitTestTree; | ||
|
||
async function runMigrationTest(file: string, oldFileContent: string, newFileContent: string) { | ||
cliAppTree.create(file, oldFileContent); | ||
const tree = await migrateComponents([], runner, cliAppTree); | ||
expect(tree.readContent(file)).toBe(newFileContent); | ||
} | ||
|
||
beforeEach(async () => { | ||
runner = createNewTestRunner(); | ||
cliAppTree = patchDevkitTreeToExposeTypeScript(await createTestApp(runner)); | ||
}); | ||
|
||
it('should migrate an empty typography config call', async () => { | ||
await runMigrationTest( | ||
THEME_FILE, | ||
` | ||
@use '@angular/material' as mat; | ||
$sample-project-theme: mat.define-light-theme(( | ||
color: ( | ||
primary: $sample-project-primary, | ||
accent: $sample-project-accent, | ||
warn: $sample-project-warn, | ||
), | ||
typography: mat.define-legacy-typography-config(), | ||
)); | ||
`, | ||
` | ||
@use '@angular/material' as mat; | ||
$sample-project-theme: mat.define-light-theme(( | ||
color: ( | ||
primary: $sample-project-primary, | ||
accent: $sample-project-accent, | ||
warn: $sample-project-warn, | ||
), | ||
typography: mat.define-typography-config(), | ||
)); | ||
`, | ||
); | ||
}); | ||
|
||
it('should migrate a typography config with positional arguments', async () => { | ||
await runMigrationTest( | ||
THEME_FILE, | ||
` | ||
@use '@angular/material' as mat; | ||
$sample-project-theme: mat.define-light-theme(( | ||
color: ( | ||
primary: $sample-project-primary, | ||
accent: $sample-project-accent, | ||
warn: $sample-project-warn, | ||
), | ||
typography: mat.define-legacy-typography-config($font-family, $display-4, $display-3), | ||
)); | ||
`, | ||
` | ||
@use '@angular/material' as mat; | ||
$sample-project-theme: mat.define-light-theme(( | ||
color: ( | ||
primary: $sample-project-primary, | ||
accent: $sample-project-accent, | ||
warn: $sample-project-warn, | ||
), | ||
typography: mat.define-typography-config($font-family, $display-4, $display-3), | ||
)); | ||
`, | ||
); | ||
}); | ||
|
||
it('should migrate a typography config with named arguments', async () => { | ||
await runMigrationTest( | ||
THEME_FILE, | ||
` | ||
@use '@angular/material' as mat; | ||
$sample-project-theme: mat.define-light-theme(( | ||
color: ( | ||
primary: $sample-project-primary, | ||
accent: $sample-project-accent, | ||
warn: $sample-project-warn, | ||
), | ||
typography: mat.define-legacy-typography-config( | ||
$font-family: $font-family, | ||
$display-4: $display-4, | ||
$display-3: $display-3, | ||
$display-2: $display-2, | ||
$display-1: $display-1, | ||
$headline: $headline, | ||
$title: $title, | ||
$subheading-2: $subheading-2, | ||
$subheading-1: $subheading-1, | ||
$body-2: $body-2, | ||
$body-1: $body-1, | ||
$caption: $caption, | ||
$button: $button, | ||
$input: $input, | ||
), | ||
)); | ||
`, | ||
` | ||
@use '@angular/material' as mat; | ||
$sample-project-theme: mat.define-light-theme(( | ||
color: ( | ||
primary: $sample-project-primary, | ||
accent: $sample-project-accent, | ||
warn: $sample-project-warn, | ||
), | ||
typography: mat.define-typography-config( | ||
$font-family: $font-family, | ||
$headline-1: $display-4, | ||
$headline-2: $display-3, | ||
$headline-3: $display-2, | ||
$headline-4: $display-1, | ||
$headline-5: $headline, | ||
$headline-6: $title, | ||
$subtitle-1: $subheading-2, | ||
$body-1: $subheading-1, | ||
$subtitle-2: $body-2, | ||
$body-2: $body-1, | ||
$caption: $caption, | ||
$button: $button, | ||
$input: $input, | ||
), | ||
)); | ||
`, | ||
); | ||
}); | ||
|
||
it('should migrate multiple typography configs with named arguments within the same file', async () => { | ||
await runMigrationTest( | ||
THEME_FILE, | ||
` | ||
@use '@angular/material' as mat; | ||
$sample-project-theme: mat.define-light-theme(( | ||
color: ( | ||
primary: $sample-project-primary, | ||
accent: $sample-project-accent, | ||
warn: $sample-project-warn, | ||
), | ||
typography: mat.define-legacy-typography-config( | ||
$display-4: $display-4, | ||
$title: $title, | ||
), | ||
)); | ||
$other-sample-project-theme: mat.define-light-theme(( | ||
color: ( | ||
primary: $sample-project-primary, | ||
accent: $sample-project-accent, | ||
warn: $sample-project-warn, | ||
), | ||
typography: mat.define-legacy-typography-config( | ||
$display-2: $display-2, | ||
$subheading-2: $subheading-2, | ||
), | ||
)); | ||
`, | ||
` | ||
@use '@angular/material' as mat; | ||
$sample-project-theme: mat.define-light-theme(( | ||
color: ( | ||
primary: $sample-project-primary, | ||
accent: $sample-project-accent, | ||
warn: $sample-project-warn, | ||
), | ||
typography: mat.define-typography-config( | ||
$headline-1: $display-4, | ||
$headline-6: $title, | ||
), | ||
)); | ||
$other-sample-project-theme: mat.define-light-theme(( | ||
color: ( | ||
primary: $sample-project-primary, | ||
accent: $sample-project-accent, | ||
warn: $sample-project-warn, | ||
), | ||
typography: mat.define-typography-config( | ||
$headline-3: $display-2, | ||
$subtitle-1: $subheading-2, | ||
), | ||
)); | ||
`, | ||
); | ||
}); | ||
}); |