forked from angular/components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(material/schematics): Add Material Symbols icon font schematic
- Loading branch information
Showing
2 changed files
with
141 additions
and
7 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
87 changes: 87 additions & 0 deletions
87
src/material/schematics/ng-update/test-cases/v20-mat-symbols-icon-font.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,87 @@ | ||
import {UnitTestTree} from '@angular-devkit/schematics/testing'; | ||
import {createTestCaseSetup} from '@angular/cdk/schematics/testing'; | ||
import {MIGRATION_PATH} from '../../paths'; | ||
|
||
const INDEX_HTML_FILE_PATH = '/projects/cdk-testing/src/index.html'; | ||
|
||
describe('v20 material symbols icon font migration', () => { | ||
let tree: UnitTestTree; | ||
let writeFile: (filename: string, content: string) => void; | ||
let runMigration: () => Promise<unknown>; | ||
|
||
function stripWhitespace(content: string): string { | ||
return content.replace(/\s/g, ''); | ||
} | ||
|
||
beforeEach(async () => { | ||
const testSetup = await createTestCaseSetup('migration-v20', MIGRATION_PATH, []); | ||
tree = testSetup.appTree; | ||
writeFile = testSetup.writeFile; | ||
runMigration = testSetup.runFixers; | ||
}); | ||
|
||
it('should add Material Symbols font to index html file', async () => { | ||
writeFile( | ||
INDEX_HTML_FILE_PATH, | ||
` | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<link rel="preconnect" href="https://fonts.gstatic.com"> | ||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | ||
</head> | ||
<body></body> | ||
</html> | ||
`, | ||
); | ||
|
||
await runMigration(); | ||
|
||
expect(stripWhitespace(tree.readText(INDEX_HTML_FILE_PATH))).toBe( | ||
stripWhitespace(` | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<link rel="preconnect" href="https://fonts.gstatic.com"> | ||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | ||
<link href="https://fonts.googleapis.com/icon?family=Material+Symbols+Outlined" rel="stylesheet"> | ||
</head> | ||
<body></body> | ||
</html> | ||
`), | ||
); | ||
}); | ||
|
||
it('should not add Material Symbols font to index html file if it is already imported', async () => { | ||
writeFile( | ||
INDEX_HTML_FILE_PATH, | ||
` | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<link rel="preconnect" href="https://fonts.gstatic.com"> | ||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | ||
<link href="https://fonts.googleapis.com/icon?family=Material+Symbols+Outlined" rel="stylesheet"> | ||
</head> | ||
<body></body> | ||
</html> | ||
`, | ||
); | ||
|
||
await runMigration(); | ||
|
||
expect(stripWhitespace(tree.readText(INDEX_HTML_FILE_PATH))).toBe( | ||
stripWhitespace(` | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<link rel="preconnect" href="https://fonts.gstatic.com"> | ||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet"> | ||
<link href="https://fonts.googleapis.com/icon?family=Material+Symbols+Outlined" rel="stylesheet"> | ||
</head> | ||
<body></body> | ||
</html> | ||
`), | ||
); | ||
}); | ||
}); |