-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtemba-datepicker.test.ts
103 lines (82 loc) · 3.39 KB
/
temba-datepicker.test.ts
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
import { fixture, expect, assert } from '@open-wc/testing';
import DatePicker from '../src/datepicker/DatePicker';
import { assertScreenshot, getAttributes, getClip } from './utils.test';
export const getPickerHTML = (attrs: any = {}) => {
return `<temba-datepicker ${getAttributes(attrs)}></temba-datepicker>`;
};
export const createPicker = async (def: string) => {
const parentNode = document.createElement('div');
parentNode.setAttribute('style', 'width: 400px;');
parentNode.id = 'parent';
const picker: DatePicker = await fixture(def, { parentNode });
return picker;
};
describe('temba-datepicker', () => {
it('can create a date picker', async () => {
const picker: DatePicker = await createPicker(getPickerHTML());
assert.instanceOf(picker, DatePicker);
await assertScreenshot('datepicker/date', getClip(picker));
});
it('can create a datetime picker', async () => {
const picker: DatePicker = await createPicker(
getPickerHTML({ time: true })
);
assert.instanceOf(picker, DatePicker);
// await assertScreenshot('datepicker/datetime', getClip(picker));
});
it('can be initialized with an iso date', async () => {
const picker: DatePicker = await createPicker(
getPickerHTML({ value: '2020-01-20T14:00Z', time: true })
);
// default should be browser locale, which for our tests is UTC
// expect(picker.timezone).to.equal('UTC');
// we should display in the current locale
// await assertScreenshot('datepicker/initial-value', getClip(picker));
// but our value should be our original value as a full iso date
expect(picker.value).is.equal('2020-01-20T14:00:00.000Z');
});
it('can be initialized with a timezone', async () => {
const picker: DatePicker = await createPicker(
getPickerHTML({
value: '2020-01-20T14:00Z',
timezone: 'America/New_York',
time: true
})
);
expect(picker.timezone).to.equal('America/New_York');
// we should display in the eastern timezone
await assertScreenshot('datepicker/initial-timezone', getClip(picker));
expect(picker.value).to.equal('2020-01-20T14:00:00.000Z');
});
it('can be updated via keyboard', async () => {
const picker: DatePicker = await createPicker(
getPickerHTML({ value: '2020-01-20T14:00Z', id: 'picker', time: true })
);
// click into the picker and update the date
await click('#picker');
await typeInto('#picker', '01202024', false);
// click away to update
picker.blur();
expect(picker.value).to.equal('2024-01-20T14:00:00.000Z');
// await assertScreenshot('datepicker/updated-keyboard', getClip(picker));
});
it('can update date via keyboard', async () => {
const picker: DatePicker = await createPicker(
getPickerHTML({ value: '2020-01-20', id: 'picker' })
);
// click into the picker and update the date
await click('#picker');
await typeInto('#picker', '12252024', false);
// click away to update
picker.blur();
expect(picker.value).to.equal('2024-12-25');
await assertScreenshot('datepicker/updated-keyboard-date', getClip(picker));
});
it('truncates time on dates', async () => {
const picker: DatePicker = await createPicker(
getPickerHTML({ value: '2020-01-20 00:00:00' })
);
expect(picker.value).to.equal('2020-01-20');
await assertScreenshot('datepicker/date-truncated-time', getClip(picker));
});
});