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

Commit 4b97be0

Browse files
Add unit tests for new routing
1 parent 55ed000 commit 4b97be0

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

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

+100
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,104 @@ describe('SKY UX Builder route generator', () => {
188188
}
189189
})).toThrow(new Error(`As a best practice, only export one guard per file in ${file}`));
190190
});
191+
192+
it('should handle top-level routes', () => {
193+
spyOn(glob, 'sync').and.callFake(() => ['my-custom-src/my-custom-route/index.html']);
194+
spyOn(path, 'join').and.returnValue('');
195+
const routes = generator.getRoutes({
196+
runtime: {
197+
srcPath: ''
198+
}
199+
});
200+
201+
expect(routes.declarations).toContain(
202+
`path: 'my-custom-src/my-custom-route'`
203+
);
204+
});
205+
206+
it('should handle child routes', () => {
207+
spyOn(glob, 'sync').and.callFake(() => ['my-custom-src/#my-custom-route/index.html']);
208+
spyOn(path, 'join').and.returnValue('');
209+
const routes = generator.getRoutes({
210+
runtime: {
211+
srcPath: ''
212+
}
213+
});
214+
215+
expect(routes.declarations).toContain(
216+
`path: 'my-custom-src'`
217+
);
218+
219+
expect(routes.declarations).toContain(
220+
`path: 'my-custom-route'`
221+
);
222+
});
223+
224+
it('should handle nested child routes', () => {
225+
spyOn(glob, 'sync').and.callFake(() => ['my-custom-src/#my-custom-route/#nested/index.html']);
226+
spyOn(path, 'join').and.returnValue('');
227+
const routes = generator.getRoutes({
228+
runtime: {
229+
srcPath: ''
230+
}
231+
});
232+
233+
expect(routes.declarations).toContain(
234+
`path: 'my-custom-src'`
235+
);
236+
237+
expect(routes.declarations).toContain(
238+
`path: 'my-custom-route'`
239+
);
240+
241+
expect(routes.declarations).toContain(
242+
`path: 'nested'`
243+
);
244+
});
245+
246+
it('should merge child routes when necessary', () => {
247+
spyOn(glob, 'sync').and.callFake(() => [
248+
'my-custom-src/#my-custom-route/#nested/index.html',
249+
'my-custom-src/#my-custom-route/index.html',
250+
''
251+
]);
252+
spyOn(fs, 'readFileSync').and.returnValue(`@Injectable() export class Guard {
253+
canActivate() {}
254+
canDeactivate() {}
255+
canActivateChild() {}
256+
}`);
257+
spyOn(fs, 'existsSync').and.returnValue(true);
258+
spyOn(path, 'join').and.returnValue('');
259+
const routes = generator.getRoutes({
260+
runtime: {
261+
srcPath: ''
262+
}
263+
});
264+
265+
expect(routes.declarations).toContain(
266+
`path: 'my-custom-src'`
267+
);
268+
269+
expect(routes.declarations).toContain(
270+
`path: 'my-custom-route'`
271+
);
272+
273+
expect(routes.declarations).toContain(
274+
`path: 'nested'`
275+
);
276+
});
277+
278+
it('should handle top-level routes within a child route', () => {
279+
spyOn(glob, 'sync').and.callFake(() => ['my-custom-src/#my-custom-route/top-level/index.html']);
280+
spyOn(path, 'join').and.returnValue('');
281+
const routes = generator.getRoutes({
282+
runtime: {
283+
srcPath: ''
284+
}
285+
});
286+
287+
expect(routes.declarations).toContain(
288+
`path: 'my-custom-src/my-custom-route/top-level'`
289+
);
290+
});
191291
});

0 commit comments

Comments
 (0)