communities-block.component.spec.ts
2.1 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
import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
import {Provider, Input, provide, Component} from 'ng-forward';
import {CommunitiesBlockComponent} from './communities-block.component';
const htmlTemplate: string = '<noosfero-communities-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-communities-block>';
const tcb = new TestComponentBuilder();
describe("Components", () => {
describe("Communities Block Component", () => {
beforeEach(angular.mock.module("templates"));
let state = jasmine.createSpyObj("state", ["go"]);
let providers = [
new Provider('truncateFilter', { useValue: () => { } }),
new Provider('stripTagsFilter', { useValue: () => { } }),
new Provider('$state', { useValue: state }),
new Provider('CommunityService', {
useValue: {
getByOwner: (owner: any, params: any): any => {
return Promise.resolve({ data: [{ identifier: "community1" }] });
}
}
}),
];
@Component({ selector: 'test-container-component', template: htmlTemplate, directives: [CommunitiesBlockComponent], providers: providers })
class BlockContainerComponent {
block = { type: 'Block', settings: {} };
owner = { name: 'profile-name' };
}
it("get communities", done => {
tcb.createAsync(BlockContainerComponent).then(fixture => {
let block: CommunitiesBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
expect(block.profiles).toEqual([{ identifier: "community1" }]);
done();
});
});
it("render the profile image for each community", done => {
tcb.createAsync(BlockContainerComponent).then(fixture => {
fixture.debugElement.getLocal("$rootScope").$apply();
expect(fixture.debugElement.queryAll("noosfero-profile-image").length).toEqual(1);
done();
});
});
});
});