-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.test.js
148 lines (125 loc) · 4.23 KB
/
app.test.js
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import Core, { TimeElement } from './src/app';
import clock from 'clock';
const getTime = (injectedDate, format) => {
const minutes = ("0" + injectedDate.getMinutes()).slice(-2);
const time12h = `${("0" + ((injectedDate.getHours() + 11) % 12 + 1)).slice(-2)}:${minutes}`;
const time24h = `${("0" + injectedDate.getHours()).slice(-2)}:${minutes}`;
if (format === '12h') {
return time12h;
}
return time24h;
}
const core = new Core({
timeId: 'time'
}, {
dateId: 'date'
});
const ES_DAYS = [
'Domingo',
'Lunes',
'Martes',
'Miércoles',
'Jueves',
'Viernes',
'Sábado'
];
core.initialize();
describe('fitbit-settings/app', () => {
test('core instance should provide time and date as accessible elements', () => {
expect(core.time).toBeDefined();
expect(core.date).toBeDefined();
});
test('time should have time display per user preference', () => {
const time12h = getTime(new Date(), '12h');
expect(core.time.get().text).toEqual(time12h);
});
test('time and date should render for custom fitfonts', () => {
const coreInstance = new Core(
{
timeId: 'time',
fitfont: {
font: 'QDBetterComicSans_20',
halign: 'middle',
valign: 'top',
letterspacing: 1
}
},
{
dateId: 'date',
fitfont: {
font: 'QDBetterComicSans_20',
halign: 'middle',
valign: 'top',
letterspacing: 1
}
}
);
const now = new Date();
const time12h = getTime(now, "12h");
expect(coreInstance.time.fitfont).toBeDefined;
expect(coreInstance.date.fitfont).toBeDefined;
coreInstance.initialize();
expect(coreInstance.time.element.text.mock.calls[0][0]).toEqual(time12h)
expect(coreInstance.date.element.text.mock.calls[0][0].includes(now.getDay())).toBeTrue;
});
test('time should support 24 hour format', () => {
const coreInstance = new Core({
timeId: 'time',
format: '24h'
}, {
dateId: 'date'
});
const time24h = getTime(new Date(), '24h');
coreInstance.initialize();
expect(coreInstance.time.get().text).toEqual(time24h);
});
test('time should call tickCallback on time tick', () => {
const tickMock = jest.fn();
const coreInstance = new Core({
timeId: 'time',
format: '24h',
onTick: tickMock
}, {
dateId: 'date'
});
coreInstance.initialize();
clock.emitTick(new Date());
expect(tickMock.mock.calls.length).toEqual(1);
});
test('time and date should update on clock ticks', () => {
const coreInstance = new Core({
timeId: 'time',
}, {
dateId: 'date',
});
coreInstance.initialize();
// Verify Time is Correct
const time12h = getTime(new Date(), '12h');
expect(coreInstance.time.get().text).toEqual(time12h)
// Store Previous Day
const previousDay = coreInstance.date.get().text;
// Update Date to Next Day
const futureDate = new Date();
futureDate.setDate(futureDate.getDate() + 1);
const futureMinutes = (futureDate.getMinutes() + 10) % 60;
futureDate.setMinutes(futureMinutes);
const futureTime12H = getTime(futureDate, '12h');
// Emit Event and Check Update
clock.emitTick(futureDate);
expect(coreInstance.time.get().text).toEqual(futureTime12H);
expect(coreInstance.date.get().text).not.toBe(previousDay);
});
test('date should support multi-language hour format', () => {
const coreInstance = new Core({
timeId: 'time',
format: '24h'
}, {
dateId: 'date',
i18n: true
});
const now = new Date();
const weekday = ES_DAYS[now.getDay()];
coreInstance.initialize();
expect(coreInstance.date.get().text.includes(weekday)).toBe(true);
});
});