people-block.component.spec.ts
2.87 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
import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
import {Provider} from 'ng-forward';
import {ComponentTestHelper, createClass} from './../../../../spec/component-test-helper';
import {providers} from 'ng-forward/cjs/testing/providers';
import {PeopleBlockComponent} from './people-block.component';
const htmlTemplate: string = '<noosfero-people-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-people-block>';
describe("Components", () => {
describe("People Block Component", () => {
let serviceMock = {
getEnvironmentPeople: (filters: any): any => {
return Promise.resolve([{ identifier: "person1" }]);
}
};
let providers = [new Provider('EnvironmentService', { useValue: serviceMock })];
let helper: ComponentTestHelper;
beforeEach( angular.mock.module("templates") );
/**
* The beforeEach procedure will initialize the helper and parse
* the component according to the given providers. Unfortunetly, in
* this mode, the providers and properties given to the construtor
* can't be overriden.
*/
beforeEach( (done) => {
// Create the component bed for the test. Optionally, this could be done
// in each test if one needs customization of these parameters per test
let cls = createClass({
template: htmlTemplate,
directives: [PeopleBlockComponent],
providers: providers,
properties: {}
});
helper = new ComponentTestHelper(cls, done);
});
/**
* By default the helper will have the component, with all properties
* ready to be used. Here the mock provider 'EnvironmentService' will
* return the given array with one person.
*/
it("get block with one people", () => {
expect(helper.component.people[0].identifier).toEqual("person1");
});
/**
* There are helper functions to access the JQuery DOM like this.
*/
it("render the profile image for each person", () => {
expect(helper.all("noosfero-profile-image").length).toEqual(1);
});
/**
* The main debugElement element is also available
*/
it("render the main noosfero people block", () => {
expect(helper.debugElement.children().length).toEqual(1, "The people-block should have a div children");
});
/**
* Just another example of a JQuery DOM helper function
*/
it("render the noosfero people block div", () => {
let div = helper.findChildren("noosfero-people-block", "div");
expect(div.className).toBe('people-block', "The class should be people-block");
});
});
});