boxes.component.spec.ts
3.01 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
import {Component} from 'ng-forward';
import {BoxesComponent} from './boxes.component';
import * as helpers from "../../../spec/helpers";
import {ComponentTestHelper, createClass} from '../../../spec/component-test-helper';
// this htmlTemplate will be re-used between the container components in this spec file
const htmlTemplate: string = '<noosfero-boxes [boxes]="ctrl.boxes" [owner]="ctrl.profile"></noosfero-blog>';
describe("Boxes Component", () => {
let helper: ComponentTestHelper<BoxesComponent>;
beforeEach(() => {
angular.mock.module("templates");
});
let properties = {
boxes: [
{ id: 1, position: 1 },
{ id: 2, position: 2 }
],
owner: {
id: 1,
identifier: 'profile-name',
type: 'Person'
}
};
beforeEach((done) => {
let cls = createClass({
template: htmlTemplate,
directives: [BoxesComponent],
properties: properties,
providers: [
helpers.createProviderToValue('SessionService', helpers.mocks.sessionWithCurrentUser({})),
helpers.createProviderToValue('AuthService', helpers.mocks.authService),
helpers.createProviderToValue('$state', state)
]
});
helper = new ComponentTestHelper<BoxesComponent>(cls, done);
});
let state = jasmine.createSpyObj("state", ["current"]);
state.current = { name: "" };
it("renders boxes into a container", () => {
expect(helper.find('div.col-md-7').length).toEqual(1);
expect(helper.find('div.col-md-2-5').length).toEqual(1);
});
it("check the boxes order", () => {
expect(helper.component.boxesOrder(properties['boxes'][0])).toEqual(1);
expect(helper.component.boxesOrder(properties['boxes'][1])).toEqual(0);
});
it("set isHomepage as false by default", () => {
expect(helper.component.isHomepage).toBeFalsy();
});
it("set isHomepage as true when in profile home page", () => {
state.current = { name: "main.profile.home" };
helper.component.ngOnInit();
expect(helper.component.isHomepage).toBeTruthy();
});
it("set isHomepage as true when in profile info page", () => {
state.current = { name: "main.profile.info" };
helper.component.ngOnInit();
expect(helper.component.isHomepage).toBeTruthy();
});
it("set isHomepage as true when in profile page", () => {
state.current = { name: "main.profile.page" };
state.params = { page: "/page" };
(<noosfero.Profile>helper.component.owner).homepage = '/page';
helper.component.ngOnInit();
expect(helper.component.isHomepage).toBeTruthy();
});
it("set isHomepage as true when in environment home page", () => {
state.current = { name: "main.environment.home" };
helper.component.owner = <noosfero.Environment>{};
helper.component.ngOnInit();
expect(helper.component.isHomepage).toBeTruthy();
});
});