recent-documents-block.component.spec.ts
3.74 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 {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
import {Provider, Input, provide, Component} from 'ng-forward';
import {provideFilters} from '../../../../spec/helpers';
import {RecentDocumentsBlockComponent} from './recent-documents-block.component';
import * as helpers from "./../../../../spec/helpers";
const htmlTemplate: string = '<noosfero-recent-documents-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-recent-documents-block>';
const tcb = new TestComponentBuilder();
describe("Components", () => {
describe("Recent Documents Block Component", () => {
let settingsObj = {};
let article = <noosfero.Article>{ name: "article1" };
let mockedBlockService = {
getApiContent: (block: noosfero.Block): any => {
return Promise.resolve({ articles: [article], headers: (name: string) => { return name; } });
}
};
let articleService: any = helpers.mocks.articleService;
let profile = { name: 'profile-name' };
beforeEach(angular.mock.module("templates"));
let state = jasmine.createSpyObj("state", ["go"]);
function getProviders() {
return [
new Provider('$state', { useValue: state }),
new Provider('BlockService', {
useValue: mockedBlockService
}),
new Provider('ArticleService', { useValue: articleService })
].concat(provideFilters("truncateFilter", "stripTagsFilter"));
}
let componentClass: any = null;
function getComponent() {
@Component({ selector: 'test-container-component', template: htmlTemplate, directives: [RecentDocumentsBlockComponent], providers: getProviders() })
class BlockContainerComponent {
block = { type: 'Block', settings: settingsObj };
owner = profile;
constructor() {
}
}
return BlockContainerComponent;
}
it("get recent documents from the block service", done => {
tcb.createAsync(getComponent()).then(fixture => {
let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
expect(recentDocumentsBlock.documents).toEqual([article]);
done();
});
});
it("go to article page when open a document", done => {
tcb.createAsync(getComponent()).then(fixture => {
let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
recentDocumentsBlock.openDocument({ path: "path", profile: { identifier: "identifier" } });
expect(state.go).toHaveBeenCalledWith("main.profile.page", { page: "path", profile: "identifier" });
done();
});
});
it("verify removed article has been removed from list", done => {
tcb.createAsync(getComponent()).then(fixture => {
let recentDocumentsBlock: RecentDocumentsBlockComponent = fixture.debugElement.componentViewChildren[0].componentInstance;
expect(recentDocumentsBlock.documents.length).toEqual(1);
simulateRemovedEvent(recentDocumentsBlock);
expect(recentDocumentsBlock.documents.length).toEqual(0);
done();
});
});
/**
* Simulate the ArticleService ArticleEvent.removed event
*/
function simulateRemovedEvent(recentDocumentsBlock: RecentDocumentsBlockComponent) {
recentDocumentsBlock.articleService["modelRemovedEventEmitter"].next(article);
}
});
});