-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtemba-menu.test.ts
139 lines (112 loc) · 4.2 KB
/
temba-menu.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
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
import { assert, expect } from '@open-wc/testing';
import { TembaMenu } from '../src/list/TembaMenu';
import { assertScreenshot, getClip, getComponent } from './utils.test';
import { extractInitials } from '../src/utils/index';
const TAG = 'temba-menu';
const getMenu = async (attrs: any = {}, width = 0) => {
const menu = (await getComponent(
TAG,
attrs,
'',
width,
0,
'display:inline-block'
)) as TembaMenu;
// wait for the fetch
await menu.httpComplete;
return menu;
};
const IDX_TASKS = 1;
const IDX_SCHEDULE = 2;
describe('temba-menu', () => {
it('can be created', async () => {
const list: TembaMenu = await getMenu();
assert.instanceOf(list, TembaMenu);
expect(list.root).is.undefined;
});
it('renders with endpoint', async () => {
const menu: TembaMenu = await getMenu({
endpoint: '/test-assets/menu/menu-root.json'
});
expect(menu.root.items.length).to.equal(3);
await assertScreenshot('menu/menu-root', getClip(menu));
});
it('supports submenu', async () => {
const menu: TembaMenu = await getMenu({
endpoint: '/test-assets/menu/menu-root.json'
});
// click our tasks
menu.getDiv('#menu-tasks').click();
await menu.httpComplete;
menu.requestUpdate();
// await menu.updateComplete;
expect(menu.root.items[IDX_TASKS].items.length).to.equal(3);
await assertScreenshot('menu/menu-submenu', getClip(menu));
});
it('sets focus', async () => {
// setting focus just shows the selection, it does
// not trigger events such as loading or dispatching
const menu: TembaMenu = await getMenu({
endpoint: '/test-assets/menu/menu-root.json'
});
// click our tasks
menu.getDiv('#menu-tasks').click();
await menu.httpComplete;
// now set the focus manually
menu.setFocusedItem('schedule');
// setting focus does NOT fetch items
expect(menu.root.items[IDX_SCHEDULE].items).to.equal(undefined);
// now load the items explicitly
menu.getDiv('#menu-schedule').click();
await menu.httpComplete;
expect(menu.root.items[IDX_SCHEDULE].items.length).to.equal(3);
await assertScreenshot('menu/menu-focused-with items', getClip(menu));
menu.setFocusedItem('tasks');
await assertScreenshot('menu/menu-tasks', getClip(menu));
menu.setFocusedItem('tasks/todo');
await assertScreenshot('menu/menu-tasks-nextup', getClip(menu));
});
it('refreshes', async () => {
// the menu should refresh along the selection path without destroying state
const menu: TembaMenu = await getMenu({
endpoint: '/test-assets/menu/menu-root.json'
});
// click our tasks
menu.getDiv('#menu-tasks').click();
menu.requestUpdate();
await menu.httpComplete;
// await menu.updateComplete;
// now click on the todo
menu.getDiv('#menu-todo').click();
menu.requestUpdate();
// await menu.updateComplete;
expect(menu.root.items[IDX_TASKS].items.length).to.equal(3);
await assertScreenshot('menu/menu-refresh-1', getClip(menu));
// now refresh!
menu.refresh();
await menu.httpComplete;
// we should still have our task items
expect(menu.root.items[IDX_TASKS].items.length).to.equal(3);
await assertScreenshot('menu/menu-refresh-2', getClip(menu));
});
});
describe('avatars', () => {
it('can generate initials from text', async () => {
assert.equal(extractInitials(''), '?');
assert.equal(extractInitials('~~'), '?');
assert.equal(extractInitials('X'), 'X');
assert.equal(extractInitials('鸡'), '鸡');
assert.equal(extractInitials('Acme'), 'AC');
assert.equal(extractInitials('Cool Flows'), 'CF');
assert.equal(extractInitials('Very Cool Flows'), 'VC');
assert.equal(extractInitials('1Password'), '1P');
assert.equal(extractInitials('تدفقات باردة'), 'تب');
assert.equal(extractInitials('U-Report'), 'UR');
assert.equal(extractInitials('U-Report Nigeria'), 'UN');
assert.equal(extractInitials('al-Jazeera'), 'AJ');
assert.equal(extractInitials('al-Jazeera News'), 'AN');
assert.equal(extractInitials('UNICEF - Ireland'), 'UI');
assert.equal(extractInitials('Dave & Busters'), 'DB');
assert.equal(extractInitials('Dave and Busters'), 'DB');
});
});