-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaction-list.spec.ts
88 lines (71 loc) · 2.66 KB
/
action-list.spec.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
import { expect, fixture, html } from '@open-wc/testing';
import { sendMouse } from '@web/test-runner-commands';
import { spy } from 'sinon';
import './action-list.js';
import type { ActionList } from './ActionList.js';
function timeout(ms: number) {
return new Promise(res => {
setTimeout(res, ms * 1);
});
}
mocha.timeout(4000 * 1);
describe('Custom List component ActionList', () => {
describe('allows to define primary action on list item', () => {
let list: ActionList;
const action = () => {};
const primaryActionSpy = spy(action);
const firstActionSpy = spy(action);
const secondActionSpy = spy(action);
const thirdActionSpy = spy(action);
beforeEach(async () => {
list = await fixture(
html`<action-list
.items=${[
{
headline: 'item',
primaryAction: primaryActionSpy,
actions: [
{ icon: 'edit', callback: firstActionSpy },
{
icon: 'delete',
label: 'secondAction',
callback: secondActionSpy,
},
{ icon: 'add', label: 'thirdAction', callback: thirdActionSpy },
],
},
]}
></action-list>`
);
await timeout(200);
});
it('triggers primaryAction callback on list item click', async () => {
primaryActionSpy.resetHistory();
await sendMouse({ type: 'click', position: [30, 20] });
// eslint-disable-next-line no-unused-expressions
expect(primaryActionSpy).to.have.been.calledOnce;
});
it('triggers first actions callback callback on first actions icon click', async () => {
firstActionSpy.resetHistory();
await sendMouse({ type: 'click', position: [700, 20] });
// eslint-disable-next-line no-unused-expressions
expect(firstActionSpy).to.have.been.calledOnce;
});
it('triggers second actions callback on list menu item click', async () => {
secondActionSpy.resetHistory();
await sendMouse({ type: 'click', position: [740, 20] });
await timeout(400);
await sendMouse({ type: 'click', position: [700, 100] });
// eslint-disable-next-line no-unused-expressions
expect(secondActionSpy).to.have.been.calledOnce;
});
it('triggers second actions callback on list menu item click', async () => {
thirdActionSpy.resetHistory();
await sendMouse({ type: 'click', position: [740, 40] });
await timeout(200);
await sendMouse({ type: 'click', position: [700, 160] });
// eslint-disable-next-line no-unused-expressions
expect(thirdActionSpy).to.have.been.calledOnce;
});
});
});