-
-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathindex_spec.ts
More file actions
94 lines (74 loc) · 3.75 KB
/
Copy pathindex_spec.ts
File metadata and controls
94 lines (74 loc) · 3.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { join } from 'path';
import { SchematicTestRunner, UnitTestTree } from '@angular-devkit/schematics/testing';
import { HostTree } from '@angular-devkit/schematics';
import { Schema as MasterDetailOptions } from './schema';
import { createEmptyNsOnlyProject, createEmptySharedProject } from '../../test-utils';
import { toComponentClassName } from '../../utils';
import { getSourceFile, findImports } from '../../ts-utils';
describe('Master-detail schematic', () => {
const master = 'heroes';
const detail = 'hero';
const project = 'some-project';
const importPrefix = '@src';
const masterClassName = toComponentClassName(master);
const detailClassName = toComponentClassName(detail + 'Detail');
const defaultOptions: MasterDetailOptions = {
master,
detail,
project,
};
const schematicRunner = new SchematicTestRunner(
'@nativescript/schematics',
join(__dirname, '../../collection.json'),
);
let appTree: UnitTestTree;
describe('When in {N}-only project', () => {
beforeEach(async () => {
appTree = new UnitTestTree(new HostTree());
appTree = createEmptyNsOnlyProject(project);
appTree = await schematicRunner.runSchematicAsync('master-detail', { ...defaultOptions }, appTree).toPromise();
});
xit('should create all necessary files', () => {
const { files } = appTree;
expect(files).toContain(`/app/${master}/${master}.module.ts`);
expect(files).toContain(`/app/${master}/data.service.ts`);
expect(files).toContain(`/app/${master}/${detail}-detail/${detail}-detail.component.ts`);
expect(files).toContain(`/app/${master}/${detail}-detail/${detail}-detail.component.html`);
expect(files).toContain(`/app/${master}/${master}/${master}.component.ts`);
expect(files).toContain(`/app/${master}/${master}/${master}.component.html`);
});
});
describe('When in web+{N} project', () => {
beforeEach(async () => {
appTree = new UnitTestTree(new HostTree());
appTree = createEmptySharedProject(project);
appTree = await schematicRunner.runSchematicAsync('master-detail', { ...defaultOptions }, appTree).toPromise();
});
it('should create all necessary files', () => {
const { files } = appTree;
expect(files).toContain(`/src/app/${master}/${master}.module.tns.ts`);
expect(files).toContain(`/src/app/${master}/${master}.module.ts`);
expect(files).toContain(`/src/app/${master}/${master}.common.ts`);
expect(files).toContain(`/src/app/${master}/data.service.ts`);
expect(files).toContain(`/src/app/${master}/${detail}-detail/${detail}-detail.component.ts`);
expect(files).toContain(`/src/app/${master}/${detail}-detail/${detail}-detail.component.html`);
expect(files).toContain(`/src/app/${master}/${detail}-detail/${detail}-detail.component.tns.html`);
expect(files).toContain(`/src/app/${master}/${master}/${master}.component.ts`);
expect(files).toContain(`/src/app/${master}/${master}/${master}.component.html`);
expect(files).toContain(`/src/app/${master}/${master}/${master}.component.tns.html`);
});
it('should import the components in common module using @src', () => {
const source = getSourceFile(appTree, `/src/app/${master}/${master}.common.ts`);
const masterImports = findImports(masterClassName, source);
expect(masterImports.length).toEqual(1);
expect(masterImports[0].getFullText()).toContain(`${importPrefix}/app/${master}/${master}/${master}.component`);
const detailImports = findImports(detailClassName, source);
expect(detailImports.length).toEqual(1);
expect(
detailImports[0].getFullText(),
).toContain(
`${importPrefix}/app/${master}/${detail}-detail/${detail}-detail.component`,
);
});
});
});