Skip to content
This repository was archived by the owner on Dec 8, 2022. It is now read-only.

Commit 194255a

Browse files
Add e2e tests, improve unit test for route merging
1 parent 4b97be0 commit 194255a

5 files changed

+208
-10
lines changed

e2e/shared/common.js

+31-1
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,34 @@ function writeAppFile(filePath, content) {
211211
});
212212
}
213213

214+
/**
215+
* Verify directory exists in src/app folder
216+
*/
217+
function verifyAppFolder(folderPath) {
218+
const resolvedFolderPath = path.join(path.resolve(tmp), 'src', 'app', folderPath);
219+
return new Promise((resolve, reject) => {
220+
if (!fs.existsSync(resolvedFolderPath)) {
221+
fs.mkdirSync(resolvedFolderPath);
222+
}
223+
224+
resolve();
225+
});
226+
}
227+
228+
/**
229+
* Verify directory exists in src/app folder
230+
*/
231+
function removeAppFolder(folderPath) {
232+
const resolvedFolderPath = path.join(path.resolve(tmp), 'src', 'app', folderPath);
233+
return new Promise((resolve, reject) => {
234+
if (fs.existsSync(resolvedFolderPath)) {
235+
fs.rmdirSync(resolvedFolderPath);
236+
}
237+
238+
resolve();
239+
});
240+
}
241+
214242
/**
215243
* Remove file from the src/app folder -- Used for cleaning up after we've injected
216244
* files for a specific test or group of tests
@@ -242,5 +270,7 @@ module.exports = {
242270
prepareServe: prepareServe,
243271
tmp: tmp,
244272
writeAppFile: writeAppFile,
245-
removeAppFile: removeAppFile
273+
removeAppFile: removeAppFile,
274+
verifyAppFolder: verifyAppFolder,
275+
removeAppFolder: removeAppFolder
246276
};

e2e/shared/tests.js

+35-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*jshint jasmine: true, node: true */
2-
/*global element, by, $$*/
2+
/*global element, by, $$, protractor, browser*/
33
'use strict';
44

55
const fs = require('fs');
@@ -52,6 +52,40 @@ module.exports = {
5252
const nav = $$('.sky-navbar-item a');
5353
nav.get(1).click();
5454
expect(element(by.tagName('h1')).getText()).toBe('SKY UX Template');
55+
56+
const aboutComponent = $$('my-about')[0];
57+
expect(aboutComponent).toBe(undefined);
58+
59+
done();
60+
},
61+
62+
respectRootGuard: (done) => {
63+
// if the home component isn't there, the outlet was not
64+
// allowed to activate due to the Guard!
65+
const homeComponent = $$('my-home')[0];
66+
expect(homeComponent).toBe(undefined);
67+
done();
68+
},
69+
70+
verifyChildRoute: (done) => {
71+
$$('#test').get(0).click();
72+
expect($$('h1').get(0).getText()).toBe('Hi');
73+
done();
74+
},
75+
76+
verifyNestedChildRoute: (done) => {
77+
$$('#child').get(0).click();
78+
79+
expect($$('h1').get(0).getText()).toBe('Hi');
80+
expect($$('#text').get(0).getText()).toBe('Child');
81+
done();
82+
},
83+
84+
verifyNestedTopRoute: (done) => {
85+
$$('#top').get(0).click();
86+
87+
expect($$('h1')[0]).toBe(undefined);
88+
expect($$('#text').get(0).getText()).toBe('Top');
5589
done();
5690
}
5791
};

e2e/skyux-build-aot.e2e-spec.js

+69
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,73 @@ export class AboutGuard {
5454
.catch(console.error);
5555
});
5656
});
57+
58+
describe('w/root level guard', () => {
59+
beforeAll((done) => {
60+
const guard = `
61+
import { Injectable } from '@angular/core';
62+
63+
@Injectable()
64+
export class RootGuard {
65+
canActivateChild(next: any, state: any) {
66+
return false;
67+
}
68+
}
69+
`;
70+
71+
common.writeAppFile('index.guard.ts', guard)
72+
.then(() => prepareBuild())
73+
.then(done)
74+
.catch(console.error);
75+
});
76+
77+
it('should respect root guard', tests.respectRootGuard);
78+
79+
afterAll((done) => {
80+
common.removeAppFile('index.guard.ts')
81+
.then(() => common.afterAll())
82+
.then(done)
83+
.catch(console.error);
84+
});
85+
});
86+
87+
describe('w/child routes', () => {
88+
beforeAll((done) => {
89+
common.verifyAppFolder('test')
90+
.then(() => common.writeAppFile('index.html', '<a id="test" routerLink="/test">Test</a>'))
91+
.then(() => common.writeAppFile(
92+
'test/index.html',
93+
'<h1>Hi</h1>' +
94+
'<a id="child" routerLink="/test/child">Child</a>' +
95+
'<a id="top" routerLink="/test/child/top">Top</a>' +
96+
'<router-outlet></router-outlet>')
97+
)
98+
.then(() => common.verifyAppFolder('test/#child'))
99+
.then(() => common.writeAppFile('test/#child/index.html', '<div id="text">Child</div>'))
100+
.then(() => common.verifyAppFolder('test/#child/top'))
101+
.then(() => common.writeAppFile('test/#child/top/index.html', '<div id="text">Top</div>'))
102+
.then(() => prepareBuild())
103+
.then(done)
104+
.catch(console.error);
105+
});
106+
107+
it('should have working child route', tests.verifyChildRoute);
108+
109+
it('should have working nested child route', tests.verifyNestedChildRoute);
110+
111+
it('should have working top level route inside child route folder', tests.verifyNestedTopRoute);
112+
113+
afterAll((done) => {
114+
common.removeAppFile('test/#child/top/index.html')
115+
.then(() => common.writeAppFile('index.html', '<my-home></my-home>'))
116+
.then(() => common.removeAppFile('test/#child/index.html'))
117+
.then(() => common.removeAppFile('test/index.html'))
118+
.then(() => common.removeAppFolder('test/#child/top'))
119+
.then(() => common.removeAppFolder('test/#child'))
120+
.then(() => common.removeAppFolder('test'))
121+
.then(() => common.afterAll())
122+
.then(done)
123+
.catch(console.error);
124+
});
125+
});
57126
});

e2e/skyux-build-jit.e2e-spec.js

+69
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,73 @@ export class AboutGuard {
5454
.catch(console.error);
5555
});
5656
});
57+
58+
describe('w/root level guard', () => {
59+
beforeAll((done) => {
60+
const guard = `
61+
import { Injectable } from '@angular/core';
62+
63+
@Injectable()
64+
export class RootGuard {
65+
canActivateChild(next: any, state: any) {
66+
return false;
67+
}
68+
}
69+
`;
70+
71+
common.writeAppFile('index.guard.ts', guard)
72+
.then(() => prepareBuild())
73+
.then(done)
74+
.catch(console.error);
75+
});
76+
77+
it('should respect root guard', tests.respectRootGuard);
78+
79+
afterAll((done) => {
80+
common.removeAppFile('index.guard.ts')
81+
.then(() => common.afterAll())
82+
.then(done)
83+
.catch(console.error);
84+
});
85+
});
86+
87+
describe('w/child routes', () => {
88+
beforeAll((done) => {
89+
common.verifyAppFolder('test')
90+
.then(() => common.writeAppFile('index.html', '<a id="test" routerLink="/test">Test</a>'))
91+
.then(() => common.writeAppFile(
92+
'test/index.html',
93+
'<h1>Hi</h1>' +
94+
'<a id="child" routerLink="/test/child">Child</a>' +
95+
'<a id="top" routerLink="/test/child/top">Top</a>' +
96+
'<router-outlet></router-outlet>')
97+
)
98+
.then(() => common.verifyAppFolder('test/#child'))
99+
.then(() => common.writeAppFile('test/#child/index.html', '<div id="text">Child</div>'))
100+
.then(() => common.verifyAppFolder('test/#child/top'))
101+
.then(() => common.writeAppFile('test/#child/top/index.html', '<div id="text">Top</div>'))
102+
.then(() => prepareBuild())
103+
.then(done)
104+
.catch(console.error);
105+
});
106+
107+
it('should have working child route', tests.verifyChildRoute);
108+
109+
it('should have working nested child route', tests.verifyNestedChildRoute);
110+
111+
it('should have working top level route inside child route folder', tests.verifyNestedTopRoute);
112+
113+
afterAll((done) => {
114+
common.removeAppFile('test/#child/top/index.html')
115+
.then(() => common.writeAppFile('index.html', '<my-home></my-home>'))
116+
.then(() => common.removeAppFile('test/#child/index.html'))
117+
.then(() => common.removeAppFile('test/index.html'))
118+
.then(() => common.removeAppFolder('test/#child/top'))
119+
.then(() => common.removeAppFolder('test/#child'))
120+
.then(() => common.removeAppFolder('test'))
121+
.then(() => common.afterAll())
122+
.then(done)
123+
.catch(console.error);
124+
});
125+
});
57126
});

test/sky-pages-route-generator.spec.js

+4-8
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,10 @@ describe('SKY UX Builder route generator', () => {
230230
}
231231
});
232232

233-
expect(routes.declarations).toContain(
234-
`path: 'my-custom-src'`
235-
);
236-
237-
expect(routes.declarations).toContain(
238-
`path: 'my-custom-route'`
239-
);
240-
233+
// expect only one instance each of `my-custom-src` and `my-custom-route`
234+
// in the declarations
235+
expect(routes.declarations.match(/path\:\s\'my\-custom\-src\'/g).length).toBe(1);
236+
expect(routes.declarations.match(/path\:\s\'my\-custom\-route\'/g).length).toBe(1);
241237
expect(routes.declarations).toContain(
242238
`path: 'nested'`
243239
);

0 commit comments

Comments
 (0)