Skip to content

Commit 8c6e421

Browse files
committed
refactor(igx-ts): add standalone components to module imports instead
1 parent d882813 commit 8c6e421

3 files changed

Lines changed: 71 additions & 4 deletions

File tree

packages/igx-templates/IgniteUIForAngularTemplate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ export class IgniteUIForAngularTemplate implements Template {
99
public components: string[];
1010
public controlGroup: string;
1111
public listInComponentTemplates: boolean = true;
12-
public addAsNgModelDeclaration: boolean = true;
12+
public addAsNgModelDeclaration: boolean = false;
13+
public addAsNgModelImport: boolean = true;
1314
public listInCustomTemplates: boolean = false;
1415
public id: string;
1516
public name: string;
@@ -127,6 +128,7 @@ export class IgniteUIForAngularTemplate implements Template {
127128
const mainModule = new TsUpdate(mainModulePath, false, { indentSize: 2, singleQuotes: true });
128129
mainModule.addNgModuleMeta({
129130
declare: this.addAsNgModelDeclaration ? [className] : [],
131+
import: this.addAsNgModelImport ? [className] : [],
130132
from: Util.relativePath(mainModulePath, componentFilePath, true, true),
131133
export: modulePath !== "app-module.ts" ? [className] : []
132134
},

spec/unit/add-spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ describe("Unit - Add command", () => {
297297
expect(routeSpy).toHaveBeenCalledTimes(1);
298298
expect(ngMetaSpy).toHaveBeenCalledTimes(1);
299299
expect(ngMetaSpy).toHaveBeenCalledWith({
300-
declare: [
300+
declare: [],
301+
import: [
301302
"TestFileName"
302303
],
303304
from: "../test-file-name/test-file-name",

spec/unit/base-templates/IgniteUIForAngularTemplate-spec.ts

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@ describe("Unit - IgniteUIForAngularTemplate Base", () => {
8989
.toHaveBeenCalledWith(path.join("target/path", "src/app/app-module.ts"), false, { indentSize: 2, singleQuotes: true });
9090
expect(helpers.tsUpdateMock.addNgModuleMeta).toHaveBeenCalledWith(
9191
{
92-
declare: [
92+
declare: [],
93+
import: [
9394
"ViewName",
9495
],
9596
from: "./view-name/view-name",
@@ -189,7 +190,8 @@ describe("Unit - IgniteUIForAngularTemplate Base", () => {
189190
.toHaveBeenCalledWith(path.join("target/path", "src/app/app-module.ts"), false, { indentSize: 2, singleQuotes: true });
190191
expect(helpers.tsUpdateMock.addNgModuleMeta).toHaveBeenCalledWith(
191192
{
192-
declare: [
193+
declare: [],
194+
import: [
193195
"ViewName",
194196
],
195197
from: "./view-name/view-name",
@@ -201,6 +203,68 @@ describe("Unit - IgniteUIForAngularTemplate Base", () => {
201203
expect(helpers.tsUpdateMock.finalize).toHaveBeenCalled();
202204
});
203205

206+
it("should declare in NgModule when addAsNgModelDeclaration is true", async () => {
207+
const templ = new TestTemplate();
208+
templ.addAsNgModelDeclaration = true;
209+
templ.addAsNgModelImport = false;
210+
const mockFS = {
211+
fileExists: (file: string): boolean => {
212+
return false;
213+
},
214+
readFile: (file: string, encoding?: BufferEncoding): string => {
215+
return JSON.stringify({ key: "value" });
216+
},
217+
writeFile: (file: string, text: string): void => {},
218+
};
219+
spyOn(App.container, "get").and.returnValue(mockFS);
220+
spyOn(templ, "fileExists").and.returnValue(true);
221+
templ.registerInProject("target/path", "view name");
222+
expect(helpers.tsUpdateMock.addNgModuleMeta).toHaveBeenCalledWith(
223+
{
224+
declare: [
225+
"ViewName",
226+
],
227+
import: [],
228+
from: "./view-name/view-name",
229+
export: []
230+
},
231+
jasmine.any(Object),
232+
true
233+
);
234+
});
235+
236+
it("should both declare and import in NgModule when both flags are true", async () => {
237+
const templ = new TestTemplate();
238+
templ.addAsNgModelDeclaration = true;
239+
templ.addAsNgModelImport = true;
240+
const mockFS = {
241+
fileExists: (file: string): boolean => {
242+
return false;
243+
},
244+
readFile: (file: string, encoding?: BufferEncoding): string => {
245+
return JSON.stringify({ key: "value" });
246+
},
247+
writeFile: (file: string, text: string): void => {},
248+
};
249+
spyOn(App.container, "get").and.returnValue(mockFS);
250+
spyOn(templ, "fileExists").and.returnValue(true);
251+
templ.registerInProject("target/path", "view name");
252+
expect(helpers.tsUpdateMock.addNgModuleMeta).toHaveBeenCalledWith(
253+
{
254+
declare: [
255+
"ViewName",
256+
],
257+
import: [
258+
"ViewName",
259+
],
260+
from: "./view-name/view-name",
261+
export: []
262+
},
263+
jasmine.any(Object),
264+
true
265+
);
266+
});
267+
204268
it("generateConfig merges variables passed under extraConfig", async () => {
205269
const expected = {
206270
camelCaseName: "test",

0 commit comments

Comments
 (0)