|
| 1 | +import {UnitTestTree} from '@angular-devkit/schematics/testing'; |
| 2 | +import {createTestCaseSetup} from '@angular/cdk/schematics/testing'; |
| 3 | +import {join} from 'path'; |
| 4 | +import {MIGRATION_PATH} from '../../paths'; |
| 5 | + |
| 6 | +const PROJECT_ROOT_DIR = '/projects/cdk-testing'; |
| 7 | +const THEME_FILE_PATH = join(PROJECT_ROOT_DIR, 'src/theme.scss'); |
| 8 | + |
| 9 | +describe('v15 legacy components migration', () => { |
| 10 | + let tree: UnitTestTree; |
| 11 | + |
| 12 | + /** Writes multiple lines to a file. */ |
| 13 | + let writeLines: (path: string, lines: string[]) => void; |
| 14 | + |
| 15 | + /** Reads multiple lines from a file. */ |
| 16 | + let readLines: (path: string) => string[]; |
| 17 | + |
| 18 | + /** Runs the v15 migration on the test application. */ |
| 19 | + let runMigration: () => Promise<{logOutput: string}>; |
| 20 | + |
| 21 | + beforeEach(async () => { |
| 22 | + const testSetup = await createTestCaseSetup('migration-v19', MIGRATION_PATH, []); |
| 23 | + tree = testSetup.appTree; |
| 24 | + runMigration = testSetup.runFixers; |
| 25 | + readLines = (path: string) => tree.readContent(path).split('\n'); |
| 26 | + writeLines = (path: string, lines: string[]) => testSetup.writeFile(path, lines.join('\n')); |
| 27 | + }); |
| 28 | + |
| 29 | + describe('style migrations', () => { |
| 30 | + async function runSassMigrationTest(ctx: string, opts: {old: string[]; new: string[]}) { |
| 31 | + writeLines(THEME_FILE_PATH, opts.old); |
| 32 | + await runMigration(); |
| 33 | + expect(readLines(THEME_FILE_PATH)).withContext(ctx).toEqual(opts.new); |
| 34 | + } |
| 35 | + |
| 36 | + it('should remove uses of the core mixin', async () => { |
| 37 | + await runSassMigrationTest('', { |
| 38 | + old: [`@use '@angular/material' as mat;`, `@include mat.core();`], |
| 39 | + new: [ |
| 40 | + `@use '@angular/material' as mat;`, |
| 41 | + `@include mat.elevation-classes();`, |
| 42 | + `@include mat.app-background();`, |
| 43 | + ], |
| 44 | + }); |
| 45 | + |
| 46 | + await runSassMigrationTest('w/ unique namespace', { |
| 47 | + old: [`@use '@angular/material' as material;`, `@include material.core();`], |
| 48 | + new: [ |
| 49 | + `@use '@angular/material' as material;`, |
| 50 | + `@include material.elevation-classes();`, |
| 51 | + `@include material.app-background();`, |
| 52 | + ], |
| 53 | + }); |
| 54 | + |
| 55 | + await runSassMigrationTest('w/ no namespace', { |
| 56 | + old: [`@use '@angular/material';`, `@include material.core();`], |
| 57 | + new: [ |
| 58 | + `@use '@angular/material';`, |
| 59 | + `@include material.elevation-classes();`, |
| 60 | + `@include material.app-background();`, |
| 61 | + ], |
| 62 | + }); |
| 63 | + |
| 64 | + await runSassMigrationTest('w/ unique whitespace', { |
| 65 | + old: [ |
| 66 | + ` @use '@angular/material' as material ; `, |
| 67 | + ` @include material.core( ) ; `, |
| 68 | + ], |
| 69 | + new: [ |
| 70 | + ` @use '@angular/material' as material ; `, |
| 71 | + ` @include material.elevation-classes();`, |
| 72 | + ` @include material.app-background(); `, |
| 73 | + ], |
| 74 | + }); |
| 75 | + }); |
| 76 | + }); |
| 77 | +}); |
0 commit comments