link-list.component.spec.ts
2.52 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
import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
import {Pipe, Input, provide, Component} from 'ng-forward';
import {provideFilters} from '../../../../spec/helpers';
import {LinkListBlock} from './link-list.component';
const tcb = new TestComponentBuilder();
const htmlTemplate: string = '<noosfero-link-list-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-link-list-block>';
describe("Components", () => {
describe("Link List Block Component", () => {
beforeEach(angular.mock.module("templates"));
it("receives the block and the owner as inputs", done => {
// Creating a container component (BlockContainerComponent) to include
// the component under test (Block)
@Component({ selector: 'test-container-component', template: htmlTemplate, directives: [LinkListBlock] })
class BlockContainerComponent {
block = { type: 'Block' };
owner = { name: 'profile-name' };
constructor() {
}
}
// uses the TestComponentBuilder instance to initialize the component
//.overrideView(LinkListBlock, { template: 'asdasdasd', pipes: [NoosferoTemplate] })
tcb.createAsync(BlockContainerComponent).then(fixture => {
// and here we can inspect and run the test assertions
let myComponent: LinkListBlock = fixture.componentInstance;
// assure the block object inside the Block matches
// the provided through the parent component
expect(myComponent.block.type).toEqual("Block");
expect(myComponent.owner.name).toEqual("profile-name");
done();
});
});
it("display links stored in block settings", done => {
@Component({
selector: 'test-container-component',
template: htmlTemplate,
directives: [LinkListBlock],
providers: provideFilters("noosferoTemplateFilter")
})
class CustomBlockType {
block: any = { settings: { links: [{ name: 'link1', address: 'address1' }, { name: 'link2', address: 'address2' }] } };
owner: any = { name: 'profile-name' };
}
tcb.createAsync(CustomBlockType).then(fixture => {
expect(fixture.debugElement.queryAll(".link-list-block a").length).toEqual(2);
done();
});
});
});
});