display-content-block.component.spec.ts
2.95 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
import {TestComponentBuilder} from 'ng-forward/cjs/testing/test-component-builder';
import {Provider, provide} from 'ng-forward';
import {ComponentTestHelper, createClass} from './../../../../spec/component-test-helper';
import {providers} from 'ng-forward/cjs/testing/providers';
import {DisplayContentBlockComponent} from './display-content-block.component';
import * as helpers from './../../../../spec/helpers';
const htmlTemplate: string = '<noosfero-display-content-block [block]="ctrl.block" [owner]="ctrl.owner"></noosfero-display-content-block>';
describe("Components", () => {
describe("Display Content Block Component", () => {
let state = jasmine.createSpyObj("state", ["go"]);
let providers = [
provide('ArticleService', {
useValue: helpers.mocks.articleService
}),
provide('$state', { useValue: state })
].concat(helpers.provideFilters("translateFilter"));
let sections: noosfero.Section[] = [
{ value: 'abstract', checked: 'abstract'},
{ value: 'title', checked: 'title' }
];
let settings: noosfero.Settings = {
limit: 6,
sections: sections
};
let helper: ComponentTestHelper<DisplayContentBlockComponent>;
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: [DisplayContentBlockComponent],
providers: providers,
properties: {
block: {
settings: settings
}
}
});
helper = new ComponentTestHelper<DisplayContentBlockComponent>(cls, done);
});
it("verify settings is injected", () => {
expect(helper.component.block).not.toBeNull;
expect(helper.component.block.settings).not.toBeNull;
expect(helper.component.block.settings.limit).toEqual(6);
expect(helper.component.block.settings.sections.length).toEqual(3);
});
it("verify abstract is displayed", () => {
expect(helper.all("div[ng-bind-html|='article.abstract']")[0]).not.toBeNull;
});
it("verify title is displayed", () => {
expect(helper.all("div > h5")[0]).not.toBeNull;
});
it("verify body is not displayed", () => {
expect(helper.all("div[ng-bind-html|='article.body']")[0]).toBeNull;
});
});
});