Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"**/*.d.ts",
"output/",
"packages/cli/templates/**/files/",
"packages/igx-templates/",
"packages/igx-templates/**/files/",
"packages/igniteui-mcp/"
],
"reporter": [
Expand Down
13 changes: 10 additions & 3 deletions packages/ng-schematics/src/utils/cli-config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,28 +5,35 @@ import { createCliConfig } from "./cli-config";
describe("createCliConfig", () => {
let tree: UnitTestTree;
let context: SchematicContext;
let rule: (tree: UnitTestTree, context: SchematicContext) => Promise<void>;

beforeEach(() => {
tree = new UnitTestTree(new EmptyTree());
context = {
logger: jasmine.createSpyObj("logger", ["info", "warn"])
} as unknown as SchematicContext;
rule = createCliConfig() as (tree: UnitTestTree, context: SchematicContext) => Promise<void>;
});

it("should report a missing angular.json", async () => {
const rule = createCliConfig() as (tree: UnitTestTree, context: SchematicContext) => Promise<void>;

await expectAsync(rule(tree, context))
.toBeRejectedWithError(SchematicsException, "angular.json was not found in the project's root");
expect(tree.exists("ignite-ui-cli.json")).toBeFalse();
});

it("should report a missing angular.json when the root has other files", async () => {
tree.create("package.json", "{}");
const rule = createCliConfig() as (tree: UnitTestTree, context: SchematicContext) => Promise<void>;

await expectAsync(rule(tree, context))
.toBeRejectedWithError(SchematicsException, "angular.json was not found in the project's root");
expect(tree.exists("ignite-ui-cli.json")).toBeFalse();
});

it("should rethrow other workspace read errors", async () => {
tree.create("angular.json", "{ not json");

await expectAsync(rule(tree, context))
.toBeRejectedWithError(Error, "Unknown format - version specifier not found.");
expect(tree.exists("ignite-ui-cli.json")).toBeFalse();
});
});
47 changes: 47 additions & 0 deletions spec/unit/IgniteUIForReactTemplate-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { Util } from "@igniteui/cli-core";
import { IgniteUIForReactTemplate } from "../../packages/cli/lib/templates/IgniteUIForReactTemplate";

describe("Unit - IgniteUIForReactTemplate", () => {
let template: IgniteUIForReactTemplate;

beforeEach(() => {
spyOn(Util, "version").and.returnValue("1.0.0");
template = new IgniteUIForReactTemplate("root/path");
});

describe("generateConfig", () => {
it("generates the base variables from the component name", () => {
const config = template.generateConfig("my component", {});

expect(config).toEqual({
path: "my-component",
name: "my component",
ClassName: "MyComponent",
filePrefix: "my-component",
cliVersion: "1.0.0"
});
});

it("merges the extra configuration into the generated config", () => {
const config = template.generateConfig("my component", {
extraConfig: { selectionType: "multi", name: "overridden" }
});

expect(config["selectionType"]).toBe("multi");
// base variables take precedence over extra configuration
expect(config["name"]).toBe("my component");
expect(config["ClassName"]).toBe("MyComponent");
});

it("adds widget and description variables when set", () => {
template["widget"] = "igr-grid";
template.description = "Test description";

const config = template.generateConfig("my component", {});

expect(config["widget"]).toBe("igr-grid");
expect(config["Control"]).toBe("IgrGrid");
expect(config["description"]).toBe("Test description");
});
});
});
53 changes: 53 additions & 0 deletions spec/unit/igx-templates/calendar-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { App, ControlExtraConfigType, Template } from "@igniteui/cli-core";
import * as path from "path";
import { requireFresh } from "../../helpers/utils";

const templatePath = path.join(__dirname, "../../../packages/igx-templates/igx-ts/calendar/default");

describe("Unit - igx-ts Calendar template", () => {
let template: Template;

beforeAll(() => {
App.initialize();
});

beforeEach(() => {
template = requireFresh<Template>(templatePath);
});

it("offers the selection type as a single choice extra configuration", () => {
const [extraConfig] = template.getExtraConfiguration();

expect(template.hasExtraConfiguration).toBeTrue();
expect(extraConfig.key).toBe("selectionType");
expect(extraConfig.type).toBe(ControlExtraConfigType.Choice);
expect(extraConfig.choices).toEqual(["Single selection", "Multi selection", "Range selection"]);
expect(extraConfig.default).toBe("Single selection");
});

it("generates empty selection variables when no selection type is set", () => {
const config = template.generateConfig("my calendar");

expect(config).toEqual(jasmine.objectContaining({
name: "my calendar",
ClassName: "MyCalendar",
selectionMode: "",
selectionType: ""
}));
});

for (const [selectionMode, selectionType] of [
["Single selection", ""],
["Multi selection", `selection="multi"`],
["Range selection", `selection="range"`]
]) {
it(`sets the selection attribute for '${selectionMode}'`, () => {
template.setExtraConfiguration({ selectionType: selectionMode });

const config = template.generateConfig("my calendar");

expect(config.selectionMode).toBe(selectionMode);
expect(config.selectionType).toBe(selectionType);
});
}
});
113 changes: 112 additions & 1 deletion spec/unit/igx-templates/grid-custom-spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { App, Template } from "@igniteui/cli-core";
import { App, ControlExtraConfigType, Template } from "@igniteui/cli-core";
import * as path from "path";
import { requireFresh } from "../../helpers/utils";

const templatePath = path.join(__dirname, "../../../packages/igx-templates/igx-ts/grid/grid-custom");
const featureUrl = "https://www.infragistics.com/products/ignite-ui-angular/angular/components/grid/";

describe("Unit - igx-ts Custom Grid template", () => {
let template: Template;
Expand All @@ -23,6 +24,44 @@ describe("Unit - igx-ts Custom Grid template", () => {
return template.generateConfig("my grid");
}

it("offers grid features as a multi choice extra configuration", () => {
const [extraConfig] = template.getExtraConfiguration();

expect(template.hasExtraConfiguration).toBeTrue();
expect(extraConfig.key).toBe("columnFeatures");
expect(extraConfig.type).toBe(ControlExtraConfigType.MultiChoice);
expect(extraConfig.choices).toEqual(["Sorting", "Filtering", "Cell Editing", "Row Editing", "Group By",
"Resizing", "Row Selection", "Paging", "Column Pinning", "Column Moving", "Column Hiding"]);
});

it("generates empty feature variables when no features are selected", () => {
const baseDependencies = [...template.dependencies];
const config = generate();

expect(config).toEqual(jasmine.objectContaining({
name: "my grid",
ClassName: "MyGrid",
additionalMarkup: "",
checkBoxBind: `[checked]="cell.value" [disabled]="true"`,
columnPinning: "",
datePickerEditor: "",
groupByColumn: "",
selectedFeatures: "",
columnBoolFeatures: "",
columnFeatures: "",
gridFeatures: ""
}));
expect(template.dependencies).toEqual(baseDependencies);
});

it("adds column features for sorting, filtering and resizing", () => {
const config = generate(["Sorting", "Filtering", "Resizing"]);

expect(config.columnFeatures).toBe(`[sortable]="true" [filterable]="true" [resizable]="true"`);
expect(config.columnBoolFeatures).toBe(config.columnFeatures);
expect(config.gridFeatures).toBe(`[allowFiltering]="true"`);
});

it("does not enable grid filtering for sorting", () => {
const config = generate(["Sorting"]);

Expand All @@ -36,4 +75,76 @@ describe("Unit - igx-ts Custom Grid template", () => {
expect(config.columnFeatures).toBe(`[sortable]="true" [filterable]="true"`);
expect(config.gridFeatures).toBe(`[allowFiltering]="true"`);
});

it("makes columns editable and binds checkboxes for cell editing", () => {
const config = generate(["Cell Editing"]);

expect(config.columnFeatures).toBe(`[editable]="true"`);
expect(config.columnBoolFeatures).toBe("");
expect(config.checkBoxBind).toBe(`[ngModel]="cell.value" (ngModelChange)="cell.update($event)"`);
expect(template.dependencies).toContain(
jasmine.objectContaining({ import: "FormsModule", from: "@angular/forms" }));
});

it("adds grid features for row editing, row selection and column moving", () => {
const config = generate(["Row Editing", "Row Selection", "Column Moving"]);

expect(config.gridFeatures).toBe(`[rowEditable]="true" rowSelection="multiple" [moving]="true"`);
expect(template.dependencies).toContain(jasmine.objectContaining({ import: "IgxDatePickerComponent" }));
});

it("adds a paginator for paging", () => {
const config = generate(["Paging"]);

expect(config.additionalMarkup).toBe("\n <igx-paginator></igx-paginator>");
expect(template.dependencies).toContain(jasmine.objectContaining({ import: "IgxPaginatorComponent" }));
});

it("marks columns as groupable for group by", () => {
const config = generate(["Group By"]);

expect(config.groupByColumn).toBe(`[groupable]="true"`);
});

it("adds a toolbar with pinning and hiding actions before the paginator", () => {
const config = generate(["Column Pinning", "Paging", "Column Hiding"]);

expect(config.columnPinning).toBe(`[pinned]="true"`);
expect(config.additionalMarkup).toBe([
"",
" <igx-grid-toolbar>",
" <igx-grid-toolbar-title>Employees</igx-grid-toolbar-title>",
" <igx-grid-toolbar-actions>",
" <igx-grid-toolbar-pinning></igx-grid-toolbar-pinning>",
" <igx-grid-toolbar-hiding></igx-grid-toolbar-hiding>",
" </igx-grid-toolbar-actions>",
" </igx-grid-toolbar>",
" <igx-paginator></igx-paginator>"
].join("\n"));
for (const toolbarImport of ["IgxGridToolbarComponent", "IgxGridToolbarTitleComponent",
"IgxGridToolbarActionsComponent", "IgxGridToolbarPinningComponent", "IgxGridToolbarHidingComponent"]) {
expect(template.dependencies).toContain(jasmine.objectContaining({ import: toolbarImport }));
}
});

it("links every selected feature to its documentation", () => {
const features: [string, string][] = [
["Sorting", "sorting"],
["Filtering", "filtering"],
["Cell Editing", "editing"],
["Row Editing", "row-editing"],
["Group By", "groupby"],
["Resizing", "column-resizing"],
["Row Selection", "selection"],
["Paging", "paging"],
["Column Pinning", "column-pinning"],
["Column Moving", "column-moving"],
["Column Hiding", "column-hiding"]
];

const config = generate(features.map(([feature]) => feature));

const links = features.map(([feature, page]) => ` <a href="${featureUrl}${page}" target="_blank">${feature}</a>`);
expect(config.selectedFeatures).toBe(`<p>Active Features: ${links.join(",")}</p>`);
});
});
Loading
Loading