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

Commit e7e9223

Browse files
Bobby EarlBlackbaud-PaulCrowder
Bobby Earl
authored andcommitted
Added lots of tests for src/app (#174)
1 parent 7751d89 commit e7e9223

File tree

1 file changed

+149
-3
lines changed

1 file changed

+149
-3
lines changed

src/app/app.component.spec.ts

+149-3
Original file line numberDiff line numberDiff line change
@@ -178,24 +178,170 @@ describe('AppComponent', () => {
178178
});
179179
}));
180180

181-
it('should not create BBOmnibarNavigation if the omnibar nav property is set', async(() => {
181+
it('should not create BBOmnibarNavigation if omnibar.nav is set', async(() => {
182+
let spyOmnibar = spyOn(BBOmnibar, 'load');
183+
skyAppConfig.skyux.omnibar = {
184+
nav: {
185+
junk: true
186+
}
187+
};
188+
189+
setup(skyAppConfig, false).then(() => {
190+
fixture.detectChanges();
191+
expect(spyOmnibar.calls.first().args[0].nav.junk).toEqual(true);
192+
});
193+
}));
194+
195+
it('should mark first service as selected if no omnibar.nav.services are selected', async(() => {
196+
let spyOmnibar = spyOn(BBOmnibar, 'load');
197+
skyAppConfig.skyux.omnibar = {
198+
nav: {
199+
services: [
200+
{ },
201+
{ }
202+
]
203+
}
204+
};
205+
206+
setup(skyAppConfig, false).then(() => {
207+
fixture.detectChanges();
208+
expect(spyOmnibar.calls.first().args[0].nav.services[0].selected).toEqual(true);
209+
});
210+
}));
182211

212+
it('should not markt he first service as select if another one is already marked', async(() => {
213+
let spyOmnibar = spyOn(BBOmnibar, 'load');
214+
skyAppConfig.skyux.omnibar = {
215+
nav: {
216+
services: [
217+
{ },
218+
{ selected: true }
219+
]
220+
}
221+
};
222+
223+
setup(skyAppConfig, false).then(() => {
224+
fixture.detectChanges();
225+
expect(spyOmnibar.calls.first().args[0].nav.services[1].selected).toEqual(true);
226+
});
183227
}));
184228

185-
it('should create BBOmnibarNavigation if the omnibar nav property is not set', async(() => {
229+
it('should recursively set the url property to omnibar.nav.services.items', async(() => {
230+
let spyOmnibar = spyOn(BBOmnibar, 'load');
231+
232+
skyAppConfig.skyux.host.url = 'base.com/';
233+
skyAppConfig.runtime.app.base = 'custom-base/';
234+
skyAppConfig.skyux.omnibar = {
235+
nav: {
236+
services: [
237+
{
238+
items: [
239+
{
240+
url: 'ignored.com'
241+
},
242+
{
243+
route: '/custom-route'
244+
},
245+
{
246+
items: [
247+
{
248+
route: '/another-custom-route'
249+
},
250+
{
251+
url: 'another-ignored.com'
252+
}
253+
]
254+
}
255+
]
256+
}
257+
]
258+
}
259+
};
186260

261+
setup(skyAppConfig, false).then(() => {
262+
fixture.detectChanges();
263+
const items = spyOmnibar.calls.first().args[0].nav.services[0].items;
264+
expect(items[0].url).toEqual('ignored.com');
265+
expect(items[1].url).toEqual('base.com/custom-base/custom-route');
266+
expect(items[2].items[0].url).toEqual('base.com/custom-base/another-custom-route');
267+
expect(items[2].items[1].url).toEqual('another-ignored.com');
268+
});
187269
}));
188270

189271
it('should add the beforeNavCallback', async(() => {
272+
let spyOmnibar = spyOn(BBOmnibar, 'load');
273+
274+
skyAppConfig.skyux.host.url = 'base.com/';
275+
skyAppConfig.runtime.app.base = 'custom-base/';
190276

277+
setup(skyAppConfig, false).then(() => {
278+
fixture.detectChanges();
279+
expect(spyOmnibar.calls.first().args[0].nav.beforeNavCallback).toBeDefined();
280+
});
191281
}));
192282

193283
it('should call navigateByUrl, return false in the beforeNavCallback if local link', async(() => {
284+
let spyOmnibar = spyOn(BBOmnibar, 'load');
285+
286+
skyAppConfig.skyux.host.url = 'base.com/';
287+
skyAppConfig.runtime.app.base = 'custom-base/';
288+
289+
setup(skyAppConfig, false).then(() => {
290+
fixture.detectChanges();
291+
const cb = spyOmnibar.calls.first().args[0].nav.beforeNavCallback;
292+
293+
const globalLink = cb({ url: 'asdf.com' });
294+
expect(globalLink).not.toBeDefined();
295+
expect(navigateByUrlParams).not.toBeDefined();
296+
297+
const localLink = cb({ url: 'base.com/custom-base/new-place' });
298+
expect(localLink).toEqual(false);
299+
expect(navigateByUrlParams).toEqual('/new-place');
300+
});
301+
}));
302+
303+
it('should handle no public routes during serve', async(() => {
304+
let spyOmnibar = spyOn(BBOmnibar, 'load');
305+
skyAppConfig.runtime.command = 'serve';
306+
skyAppConfig.skyux.routes = {};
194307

308+
setup(skyAppConfig, false).then(() => {
309+
fixture.detectChanges();
310+
expect(spyOmnibar.calls.first().args[0].nav.localNavItems).not.toBeDefined();
311+
});
195312
}));
196313

197-
it('should add global routes to omnibar during serve', async(() => {
314+
it('should add global public routes as localNavItems during serve', async(() => {
315+
let spyOmnibar = spyOn(BBOmnibar, 'load');
198316

317+
skyAppConfig.skyux.host.url = 'base.com/';
318+
skyAppConfig.runtime.app.base = 'custom-base/';
319+
skyAppConfig.runtime.command = 'serve';
320+
skyAppConfig.skyux.routes = {
321+
public: [
322+
{
323+
global: false
324+
},
325+
{
326+
global: true,
327+
name: 'my-name',
328+
route: '/my-route'
329+
}
330+
]
331+
};
332+
333+
setup(skyAppConfig, false).then(() => {
334+
fixture.detectChanges();
335+
expect(spyOmnibar.calls.first().args[0].nav.localNavItems[0]).toEqual({
336+
title: 'my-name',
337+
url: 'base.com/custom-base/my-route',
338+
data: {
339+
global: true,
340+
name: 'my-name',
341+
route: '/my-route'
342+
}
343+
});
344+
});
199345
}));
200346

201347
it('should not call BBHelp.load if config.skyux.help does not exist', async(() => {

0 commit comments

Comments
 (0)