UNPKG

angular-toaster

Version:

An Angular Toaster Notification library based on AngularJS-Toaster

100 lines (99 loc) 5.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const testing_1 = require("@angular-devkit/schematics/testing"); const path = tslib_1.__importStar(require("path")); const schema_1 = require("@schematics/angular/application/schema"); describe("angular toaster schematic unit test", () => { const schematicRunner = new testing_1.SchematicTestRunner("angular-toaster", path.join(__dirname, "../collection.json")); const defaultOptions = { project: "angular-toaster-app", }; const workspaceOptions = { name: "workspace", newProjectRoot: "projects", version: "0.0.1", }; const appOptions = { name: "angular-toaster-app", inlineStyle: false, inlineTemplate: false, routing: false, style: schema_1.Style.Scss, skipTests: false, skipPackageJson: false, standalone: false, }; let appTree; beforeEach(() => tslib_1.__awaiter(void 0, void 0, void 0, function* () { appTree = yield schematicRunner.runExternalSchematic("@schematics/angular", "workspace", workspaceOptions); appTree = yield schematicRunner.runExternalSchematic("@schematics/angular", "application", appOptions, appTree); const standaloneAppOptions = Object.assign(Object.assign({}, appOptions), { name: "angular-toaster-standalone-app", standalone: true }); appTree = yield schematicRunner.runExternalSchematic("@schematics/angular", "application", standaloneAppOptions, appTree); })); describe("when project is not a standalone application", () => { it("should update app module", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = Object.assign({}, defaultOptions); const tree = yield schematicRunner.runSchematic("ng-add-setup-project", options, appTree); const content = tree.readContent("/projects/angular-toaster-app/src/app/app-module.ts"); expect(content) .withContext("Expected the ToasterModule to be imported.") .toMatch(/import\s+{\s*ToasterModule\s*}\s+from\s+'angular-toaster'/); expect(content) .withContext("Expected the ToasterModule to be added to the imports array.") .toMatch(/imports:\s*\[[^\]]+?,\r?\n\s+ToasterModule\.forRoot\(\)\r?\n/m); })); it("should update angular styles", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = Object.assign({}, defaultOptions); const tree = yield schematicRunner.runSchematic("ng-add-setup-project", options, appTree); const angularJsonContent = tree.readContent("/angular.json"); const angularJson = JSON.parse(angularJsonContent); const angularToasterApp = angularJson.projects["angular-toaster-app"]; const architect = angularToasterApp.architect; const buildArchitect = architect.build; const testArchitect = architect.test; expect(buildArchitect.options.styles) .withContext("Expect the theme css import styles") .toContain("./node_modules/angular-toaster/toaster.css"); expect(testArchitect.options.styles) .withContext("Expect the theme css import styles") .toContain("./node_modules/angular-toaster/toaster.css"); })); }); describe("when project is a standalone application", () => { it("should update app config", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = Object.assign(Object.assign({}, defaultOptions), { project: "angular-toaster-standalone-app" }); const tree = yield schematicRunner.runSchematic("ng-add-setup-project", options, appTree); const content = tree.readContent("/projects/angular-toaster-standalone-app/src/app/app.config.ts"); expect(content) .withContext("Expected the provideAngularToaster to be imported.") .toMatch(/import\s+{\s*provideAngularToaster\s*}\s+from\s+'angular-toaster'/); expect(content) .withContext("Expected provideAngularToaster() to be present") .toContain("provideAngularToaster()"); const providersIndex = content.indexOf("providers:"); const toasterIndex = content.indexOf("provideAngularToaster()"); const nextClosingBrace = content.indexOf("]", providersIndex); expect(providersIndex).toBeGreaterThan(-1); expect(toasterIndex).toBeGreaterThan(-1); expect(toasterIndex).toBeGreaterThan(providersIndex); expect(toasterIndex).toBeLessThan(nextClosingBrace); })); it("should update angular styles", () => tslib_1.__awaiter(void 0, void 0, void 0, function* () { const options = Object.assign(Object.assign({}, defaultOptions), { project: "angular-toaster-standalone-app" }); const tree = yield schematicRunner.runSchematic("ng-add-setup-project", options, appTree); const angularJsonContent = tree.readContent("/angular.json"); const angularJson = JSON.parse(angularJsonContent); const angularToasterApp = angularJson.projects["angular-toaster-standalone-app"]; const architect = angularToasterApp.architect; const buildArchitect = architect.build; const testArchitect = architect.test; expect(buildArchitect.options.styles) .withContext("Expect the theme css import styles") .toContain("./node_modules/angular-toaster/toaster.css"); expect(testArchitect.options.styles) .withContext("Expect the theme css import styles") .toContain("./node_modules/angular-toaster/toaster.css"); })); }); });