From fbc9358287d8925cc4ad880d774236909a9f2004 Mon Sep 17 00:00:00 2001 From: jackofdiamond5 Date: Wed, 6 Dec 2023 15:57:08 +0200 Subject: [PATCH] test(*): update specs --- packages/igx-templates/IgniteUIForAngularTemplate.ts | 10 +++++++--- spec/acceptance/add-spec.ts | 4 ++-- spec/unit/add-spec.ts | 6 +++++- .../base-templates/IgniteUIForAngularTemplate-spec.ts | 4 ++++ 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/packages/igx-templates/IgniteUIForAngularTemplate.ts b/packages/igx-templates/IgniteUIForAngularTemplate.ts index cd8047d45..99ff06699 100644 --- a/packages/igx-templates/IgniteUIForAngularTemplate.ts +++ b/packages/igx-templates/IgniteUIForAngularTemplate.ts @@ -64,11 +64,11 @@ export class IgniteUIForAngularTemplate implements Template { // standalone components const mainModulePath = path.join(projectPath, `src/app/${modulePath}`); - if (!App.container.get(FS_TOKEN).fileExists(mainModulePath)) { + if (!this.fileExists(mainModulePath)) { const appRoutesPath = "src/app/app.routes.ts"; const folderName = this.folderName(name); const fileName = this.fileName(name); - if (!(options && options.skipRoute) && App.container.get(FS_TOKEN).fileExists(appRoutesPath)) { + if (!(options && options.skipRoute) && this.fileExists(appRoutesPath)) { const rountesConfig = new TsUpdate(path.join(projectPath, appRoutesPath)); rountesConfig.addRoute( path.join(projectPath, `src/app/${folderName}/${fileName}.component.ts`), @@ -102,7 +102,7 @@ export class IgniteUIForAngularTemplate implements Template { } // ngModule based components - if (!(options && options.skipRoute) && App.container.get(FS_TOKEN).fileExists("src/app/app-routing.module.ts")) { + if (!(options && options.skipRoute) && this.fileExists("src/app/app-routing.module.ts")) { //1) import the component class name, //2) and populate the Routes array with the path and component //for example: { path: 'combo', component: ComboComponent } @@ -140,6 +140,10 @@ export class IgniteUIForAngularTemplate implements Template { } public setExtraConfiguration(extraConfigKeys: {}) { } + public fileExists(filePath: string): boolean { + return App.container.get(FS_TOKEN).fileExists(filePath); + } + protected addClassDeclaration(mainModule: TypeScriptFileUpdate, projPath: string, name: string, modulePath: string) { mainModule.addDeclaration( path.join(projPath, `src/app/${this.folderName(name)}/${this.fileName(name)}.component.ts`), diff --git a/spec/acceptance/add-spec.ts b/spec/acceptance/add-spec.ts index 6a537e7d3..821b956d1 100644 --- a/spec/acceptance/add-spec.ts +++ b/spec/acceptance/add-spec.ts @@ -253,7 +253,7 @@ describe("Add command", () => { dependencies: { [igxPackage]: "9.0.0" } })); fs.writeFileSync(ProjectConfig.configFile, JSON.stringify({ - project: { framework: "angular", projectType: "igx-ts", components: [] } + project: { framework: "angular", projectType: "igx-ts-legacy", components: [] } })); fs.writeFileSync("tslint.json", JSON.stringify({ rules: { @@ -328,7 +328,7 @@ export class AppModule { spyOn(ProjectConfig, "globalConfig").and.returnValue({}); fs.writeFileSync(ProjectConfig.configFile, JSON.stringify({ - project: { framework: "angular", projectType: "igx-ts", components: [] } + project: { framework: "angular", projectType: "igx-ts-legacy", components: [] } })); fs.writeFileSync("tslint.json", JSON.stringify({ rules: { diff --git a/spec/unit/add-spec.ts b/spec/unit/add-spec.ts index e72a645be..5b7b0a7c0 100644 --- a/spec/unit/add-spec.ts +++ b/spec/unit/add-spec.ts @@ -1,5 +1,8 @@ import { IgniteUIForAngularTemplate } from "@igniteui/angular-templates"; -import { App, GoogleAnalytics, PackageManager, ProjectConfig, TypeScriptFileUpdate, TypeScriptUtils, Util } from "@igniteui/cli-core"; +import { + App, FS_TOKEN, GoogleAnalytics, IFileSystem, PackageManager, ProjectConfig, + TypeScriptFileUpdate, TypeScriptUtils, Util +} from "@igniteui/cli-core"; import * as path from "path"; import * as ts from "typescript"; import { default as addCmd } from "../../packages/cli/lib/commands/add"; @@ -138,6 +141,7 @@ describe("Unit - Add command", () => { const mockTemplate = new IgniteUIForAngularTemplate("test"); mockTemplate.packages = []; mockTemplate.dependencies = []; + spyOn(mockTemplate, "fileExists").and.returnValue(true); const directoryPath = path.join("My/Example/Path"); spyOn(process, "cwd").and.returnValue(directoryPath); diff --git a/spec/unit/base-templates/IgniteUIForAngularTemplate-spec.ts b/spec/unit/base-templates/IgniteUIForAngularTemplate-spec.ts index 5432f552b..3017724dd 100644 --- a/spec/unit/base-templates/IgniteUIForAngularTemplate-spec.ts +++ b/spec/unit/base-templates/IgniteUIForAngularTemplate-spec.ts @@ -47,6 +47,7 @@ describe("Unit - IgniteUIForAngularTemplate Base", () => { const mockFS = { fileExists: () => {} }; + spyOn(templ, "fileExists").and.returnValue(true); spyOn(App.container, "get").and.returnValue(mockFS); spyOn(mockFS, "fileExists").and.callFake(file => { if (file === "src/app/app-routing.module.ts") { @@ -76,6 +77,7 @@ describe("Unit - IgniteUIForAngularTemplate Base", () => { }); it("updates NgModule metadata", async done => { const templ = new TestTemplate(); + spyOn(templ, "fileExists").and.returnValue(true); templ.dependencies.push({ import: "test", from: "test" }); templ.registerInProject("", ""); expect(helpers.tsUpdateMock.addNgModuleMeta).toHaveBeenCalledWith( @@ -102,6 +104,7 @@ describe("Unit - IgniteUIForAngularTemplate Base", () => { const filePath = path.join("target", "./test.ts"); const templ = new TestTemplate(); + spyOn(templ, "fileExists").and.returnValue(true); templ.dependencies = [{ from: "./test.ts" }]; templ.registerInProject("target", "name"); @@ -113,6 +116,7 @@ describe("Unit - IgniteUIForAngularTemplate Base", () => { it("should skip route if skipRoute is passed", async done => { const templ = new TestTemplate(); + spyOn(templ, "fileExists").and.returnValue(true); templ.registerInProject("target/path", "view name", { skipRoute: true }); expect(helpers.tsUpdateMock.addRoute).toHaveBeenCalledTimes(0);