article-content.component.spec.ts
5.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
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import {CommentParagraphArticleContentHotspotComponent} from './article-content.component';
import {ComponentTestHelper, createClass} from './../../../../spec/component-test-helper';
const htmlTemplate: string = '<comment-paragraph-article-content-hotspot [article]="ctrl.article"></comment-paragraph-article-content-hotspot>';
describe("Components", () => {
describe("Article Content Hotspot Component", () => {
let helper: ComponentTestHelper<CommentParagraphArticleContentHotspotComponent>;
beforeEach(angular.mock.module("templates"));
beforeEach((done) => {
let properties = { article: {} };
let cls = createClass({
template: htmlTemplate,
directives: [CommentParagraphArticleContentHotspotComponent],
properties: properties
});
helper = new ComponentTestHelper<CommentParagraphArticleContentHotspotComponent>(cls, done);
});
it("return false in isDiscussion when no type was specified", () => {
expect(helper.component.isDiscussion()).toBeFalsy();
});
it("return false in isDiscussion when other type was specified", () => {
helper.changeProperties({ article: { type: "TextArticle" } });
expect(helper.component.isDiscussion()).toBeFalsy();
});
it("return true in isDiscussion when discussion type was specified", () => {
helper.changeProperties({ article: { type: "CommentParagraphPlugin::Discussion" } });
expect(helper.component.isDiscussion()).toBeTruthy();
});
it("return true in notOpened when start date is after today", () => {
let date = new Date();
date.setDate(date.getDate() + 1);
helper.changeProperties({ article: { start_date: date.toISOString() } });
expect(helper.component.notOpened()).toBeTruthy();
expect(helper.component.available()).toBeFalsy();
expect(helper.component.closed()).toBeFalsy();
});
it("return false in notOpened when start date is before today", () => {
let date = new Date();
date.setDate(date.getDate() - 1);
helper.changeProperties({ article: { start_date: date.toISOString() } });
expect(helper.component.notOpened()).toBeFalsy();
});
it("return false in notOpened when start date is null", () => {
helper.changeProperties({ article: { start_date: null } });
expect(helper.component.notOpened()).toBeFalsy();
});
it("return true in closed when end date is before today", () => {
let date = new Date();
date.setDate(date.getDate() - 1);
helper.changeProperties({ article: { end_date: date.toISOString() } });
expect(helper.component.closed()).toBeTruthy();
expect(helper.component.available()).toBeFalsy();
expect(helper.component.notOpened()).toBeFalsy();
});
it("return false in closed when start date is after today", () => {
let date = new Date();
date.setDate(date.getDate() + 1);
helper.changeProperties({ article: { end_date: date.toISOString() } });
expect(helper.component.closed()).toBeFalsy();
});
it("return false in closed when end date is null", () => {
helper.changeProperties({ article: { start_date: null } });
expect(helper.component.closed()).toBeFalsy();
});
it("return true in available when start date is before today and end date is after", () => {
let date = new Date();
date.setDate(date.getDate() - 1);
let startDate = date.toISOString();
date.setDate(date.getDate() + 3);
let endDate = date.toISOString();
helper.changeProperties({ article: { start_date: startDate, end_date: endDate } });
expect(helper.component.available()).toBeTruthy();
expect(helper.component.closed()).toBeFalsy();
expect(helper.component.notOpened()).toBeFalsy();
});
it("return true in available when start date is before today and end date is null", () => {
let date = new Date();
date.setDate(date.getDate() - 1);
let startDate = date.toISOString();
helper.changeProperties({ article: { start_date: startDate, end_date: null } });
expect(helper.component.available()).toBeTruthy();
expect(helper.component.closed()).toBeFalsy();
expect(helper.component.notOpened()).toBeFalsy();
});
it("return true in available when start date is null and end date is after today", () => {
let date = new Date();
date.setDate(date.getDate() + 3);
let endDate = date.toISOString();
helper.changeProperties({ article: { start_date: null, end_date: endDate } });
expect(helper.component.available()).toBeTruthy();
expect(helper.component.closed()).toBeFalsy();
expect(helper.component.notOpened()).toBeFalsy();
});
});
});