sidebar.component.spec.ts
2.61 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
import {provide} from 'ng-forward';
import {ComponentTestHelper, createClass} from '../../../spec/component-test-helper';
import {providers} from 'ng-forward/cjs/testing/providers';
import {SidebarComponent} from './sidebar.component';
import {SidebarSectionComponent} from './sidebar-section.component';
import * as helpers from '../../../spec/helpers';
const htmlTemplate: string = '<sidebar [visible]="false"></sidebar>';
describe('Sidebar Component', () => {
let helper: ComponentTestHelper<SidebarComponent>;
let notifyService: any = {
event: Function,
subscribe: (fn: (visible: boolean) => void) => {
notifyService.event = fn;
},
next: (value: any) => {
notifyService.event(value);
},
setVisibility: (visible: boolean) => {
notifyService.event(visible);
}
};
let sessionService: any = {
currentUser: (): any => {
return {
person: { name: 'test' }
};
}
};
beforeEach(angular.mock.module("templates"));
beforeEach((done: Function) => {
providers((provide: any) => {
return <any>[
provide('SidebarNotificationService', {
useValue: notifyService
}),
provide('SessionService', {
useValue: sessionService
}),
provide('SidebarSectionComponent', {
useValue: SidebarSectionComponent
})
];
});
let cls = createClass({
template: htmlTemplate,
directives: [SidebarComponent],
properties: {
visible: false
}
});
helper = new ComponentTestHelper<SidebarComponent>(cls, done);
});
it('render the sidebar html content', () => {
expect(helper.all('div#nav-col').length).toEqual(1);
});
it('show sidebar only if a service emit a visibility event', () => {
notifyService.setVisibility(true);
expect(helper.component.isVisible()).toBeTruthy();
});
it('show user name into sidebar', () => {
notifyService.setVisibility(true);
expect(helper.component.user.name).toEqual(sessionService.currentUser().person.name);
expect(helper.debugElement.query('div.user-box .name a').text()).toMatch(sessionService.currentUser().person.name);
});
it('show sidebar section with a menu itens', () => {
notifyService.setVisibility(true);
expect(helper.debugElement.query('li.active a span').text()).toMatch('Friends');
});
});