forked from roshiro/TitleNotifier.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtitle_notifier.js
More file actions
100 lines (83 loc) · 2.31 KB
/
Copy pathtitle_notifier.js
File metadata and controls
100 lines (83 loc) · 2.31 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
describe('TitleNotifier', () => {
document.title = 'TitleNotifier unit tests';
var getTitle = () => {
return document.title;
}
var isNumber = (n) => {
return !isNaN(parseFloat(n)) && isFinite(n);
}
var expectedTitle = (number) => {
if(!isNumber(number) || number > 0) {
return '(' + number + ') TitleNotifier unit tests';
}
else {
return 'TitleNotifier unit tests';
}
}
it('should reset', () => {
titlenotifier.reset();
titlenotifier.reset();
expect(getTitle()).toBe(expectedTitle(0));
});
it('should add without param', () => {
titlenotifier.reset();
titlenotifier.add();
expect(getTitle()).toBe(expectedTitle(1));
});
it('should add with param', () => {
titlenotifier.reset();
titlenotifier.add(10);
expect(getTitle()).toBe(expectedTitle(10));
});
it('should sub without param', () => {
titlenotifier.reset();
titlenotifier.add(10);
titlenotifier.sub();
expect(getTitle()).toBe(expectedTitle(9));
});
it('should sub with param', () => {
titlenotifier.reset();
titlenotifier.add(10);
titlenotifier.sub(2);
expect(getTitle()).toBe(expectedTitle(8));
});
it('should sub when param is bigger than total', () => {
titlenotifier.reset();
titlenotifier.add(10);
titlenotifier.sub(20);
expect(getTitle()).toBe(expectedTitle(0));
});
it('should set without param', () => {
titlenotifier.reset();
titlenotifier.set();
expect(getTitle()).toBe(expectedTitle(0));
});
it('should set with param', () => {
titlenotifier.reset();
titlenotifier.set(30);
expect(getTitle()).toBe(expectedTitle(30));
});
it('should get notifications', () => {
titlenotifier.reset();
titlenotifier.set(5);
expect(titlenotifier.get()).toBe(5);
});
it('should get notifications empty', () => {
titlenotifier.reset();
expect(titlenotifier.get()).toBe(0);
});
it('should set a max value', () => {
titlenotifier.reset();
titlenotifier.max(99);
titlenotifier.set(98);
titlenotifier.add();
titlenotifier.add();
expect(getTitle()).toBe(expectedTitle('99+'));
});
it('should set a max value after', () => {
titlenotifier.reset();
titlenotifier.set(200);
titlenotifier.max(99);
expect(getTitle()).toBe(expectedTitle('99+'));
});
});