Skip to content

Commit

Permalink
test(*): update specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jackofdiamond5 committed Dec 6, 2023
1 parent 89927ef commit fbc9358
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/igx-templates/IgniteUIForAngularTemplate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ export class IgniteUIForAngularTemplate implements Template {

// standalone components
const mainModulePath = path.join(projectPath, `src/app/${modulePath}`);
if (!App.container.get<IFileSystem>(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<IFileSystem>(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`),
Expand Down Expand Up @@ -102,7 +102,7 @@ export class IgniteUIForAngularTemplate implements Template {
}

// ngModule based components
if (!(options && options.skipRoute) && App.container.get<IFileSystem>(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 }
Expand Down Expand Up @@ -140,6 +140,10 @@ export class IgniteUIForAngularTemplate implements Template {
}
public setExtraConfiguration(extraConfigKeys: {}) { }

public fileExists(filePath: string): boolean {
return App.container.get<IFileSystem>(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`),
Expand Down
4 changes: 2 additions & 2 deletions spec/acceptance/add-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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: {
Expand Down
6 changes: 5 additions & 1 deletion spec/unit/add-spec.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions spec/unit/base-templates/IgniteUIForAngularTemplate-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down Expand Up @@ -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(
Expand All @@ -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");

Expand All @@ -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);

Expand Down

0 comments on commit fbc9358

Please sign in to comment.