@nyaruka/temba-components 0.39.1 → 0.40.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/{7640b448.js → b885f7d6.js} +6 -33
  3. package/dist/index.js +6 -33
  4. package/dist/sw.js +1 -1
  5. package/dist/sw.js.map +1 -1
  6. package/dist/templates/components-body.html +1 -1
  7. package/dist/templates/components-head.html +1 -1
  8. package/out-tsc/src/contacts/ContactBadges.js +5 -5
  9. package/out-tsc/src/contacts/ContactBadges.js.map +1 -1
  10. package/out-tsc/src/list/TembaMenu.js +77 -168
  11. package/out-tsc/src/list/TembaMenu.js.map +1 -1
  12. package/out-tsc/src/vectoricon/index.js +1 -0
  13. package/out-tsc/src/vectoricon/index.js.map +1 -1
  14. package/out-tsc/test/temba-menu.test.js +58 -7
  15. package/out-tsc/test/temba-menu.test.js.map +1 -1
  16. package/package.json +1 -1
  17. package/screenshots/truth/menu/menu-focus.png +0 -0
  18. package/screenshots/truth/menu/menu-focused-with items.png +0 -0
  19. package/screenshots/truth/menu/menu-refresh-1.png +0 -0
  20. package/screenshots/truth/menu/menu-refresh-2.png +0 -0
  21. package/screenshots/truth/menu/menu-root.png +0 -0
  22. package/screenshots/truth/menu/menu-submenu.png +0 -0
  23. package/screenshots/truth/menu/menu-tasks-nextup.png +0 -0
  24. package/screenshots/truth/menu/menu-tasks.png +0 -0
  25. package/src/contacts/ContactBadges.ts +5 -5
  26. package/src/list/TembaMenu.ts +89 -181
  27. package/src/vectoricon/index.ts +1 -0
  28. package/test/temba-menu.test.ts +73 -7
  29. package/test-assets/menu/menu-root.json +33 -0
  30. package/test-assets/menu/menu-schedule.json +21 -0
  31. package/test-assets/{list → menu}/menu-tasks.json +0 -0
  32. package/screenshots/truth/list/menu-root.png +0 -0
  33. package/screenshots/truth/list/menu-submenu.png +0 -0
  34. package/test-assets/list/menu-root.json +0 -17
@@ -20,6 +20,10 @@ const getMenu = async (attrs: any = {}, width = 0) => {
20
20
  return menu;
21
21
  };
22
22
 
23
+ const IDX_CHOOSER = 0;
24
+ const IDX_TASKS = 1;
25
+ const IDX_SCHEDULE = 2;
26
+
23
27
  describe('temba-menu', () => {
24
28
  it('can be created', async () => {
25
29
  const list: TembaMenu = await getMenu();
@@ -29,24 +33,86 @@ describe('temba-menu', () => {
29
33
 
30
34
  it('renders with endpoint', async () => {
31
35
  const menu: TembaMenu = await getMenu({
32
- endpoint: '/test-assets/list/menu-root.json',
36
+ endpoint: '/test-assets/menu/menu-root.json',
33
37
  });
34
38
 
35
- expect(menu.root.items.length).to.equal(2);
36
- await assertScreenshot('list/menu-root', getClip(menu));
39
+ expect(menu.root.items.length).to.equal(3);
40
+ await assertScreenshot('menu/menu-root', getClip(menu));
37
41
  });
38
42
 
39
43
  it('supports submenu', async () => {
40
44
  const menu: TembaMenu = await getMenu({
41
- endpoint: '/test-assets/list/menu-root.json',
45
+ endpoint: '/test-assets/menu/menu-root.json',
46
+ });
47
+
48
+ // click our tasks
49
+ menu.getDiv('#menu-tasks').click();
50
+ await menu.httpComplete;
51
+ menu.requestUpdate();
52
+ // await menu.updateComplete;
53
+
54
+ expect(menu.root.items[IDX_TASKS].items.length).to.equal(3);
55
+ await assertScreenshot('menu/menu-submenu', getClip(menu));
56
+ });
57
+
58
+ it('sets focus', async () => {
59
+ // setting focus just shows the selection, it does
60
+ // not trigger events such as loading or dispatching
61
+
62
+ const menu: TembaMenu = await getMenu({
63
+ endpoint: '/test-assets/menu/menu-root.json',
42
64
  });
43
65
 
44
- // click our first item
66
+ // click our tasks
45
67
  menu.getDiv('#menu-tasks').click();
46
68
  await menu.httpComplete;
47
69
 
48
- expect(menu.root.items[0].items.length).to.equal(3);
70
+ // now set the focus manually
71
+ menu.setFocusedItem('schedule');
72
+
73
+ // setting focus does NOT fetch items
74
+ expect(menu.root.items[IDX_SCHEDULE].items).to.equal(undefined);
75
+
76
+ // now load the items explicitly
77
+ menu.getDiv('#menu-schedule').click();
78
+ await menu.httpComplete;
79
+ expect(menu.root.items[IDX_SCHEDULE].items.length).to.equal(3);
80
+
81
+ await assertScreenshot('menu/menu-focused-with items', getClip(menu));
82
+
83
+ menu.setFocusedItem('tasks');
84
+ await assertScreenshot('menu/menu-tasks', getClip(menu));
85
+
86
+ menu.setFocusedItem('tasks/todo');
87
+ await assertScreenshot('menu/menu-tasks-nextup', getClip(menu));
88
+ });
89
+
90
+ it('refreshes', async () => {
91
+ // the menu should refresh along the selection path without destroying state
92
+ const menu: TembaMenu = await getMenu({
93
+ endpoint: '/test-assets/menu/menu-root.json',
94
+ });
95
+
96
+ // click our tasks
97
+ menu.getDiv('#menu-tasks').click();
98
+ menu.requestUpdate();
99
+ await menu.httpComplete;
100
+ // await menu.updateComplete;
101
+
102
+ // now click on the todo
103
+ menu.getDiv('#menu-todo').click();
104
+ menu.requestUpdate();
105
+ // await menu.updateComplete;
106
+
107
+ expect(menu.root.items[IDX_TASKS].items.length).to.equal(3);
108
+ await assertScreenshot('menu/menu-refresh-1', getClip(menu));
109
+
110
+ // now refresh!
111
+ menu.refresh();
112
+ await menu.httpComplete;
49
113
 
50
- await assertScreenshot('list/menu-submenu', getClip(menu));
114
+ // we should still have our task items
115
+ expect(menu.root.items[IDX_TASKS].items.length).to.equal(3);
116
+ await assertScreenshot('menu/menu-refresh-2', getClip(menu));
51
117
  });
52
118
  });
@@ -0,0 +1,33 @@
1
+ {
2
+ "next": null,
3
+ "previous": null,
4
+ "results": [
5
+ {
6
+ "id": "chooser",
7
+ "avatar": "My Account",
8
+ "popup": true,
9
+ "inline": false,
10
+ "bottom": false,
11
+ "items": [
12
+ {
13
+ "id": "account-other",
14
+ "avatar": "Other Account",
15
+ "name": "Other Account"
16
+ }
17
+ ]
18
+ },
19
+ {
20
+ "id": "tasks",
21
+ "name": "Tasks",
22
+ "icon": "coffee",
23
+ "endpoint": "/test-assets/menu/menu-tasks.json"
24
+ },
25
+ {
26
+ "id": "schedule",
27
+ "name": "Schedule",
28
+ "icon": "calendar",
29
+ "endpoint": "/test-assets/menu/menu-schedule.json"
30
+
31
+ }
32
+ ]
33
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "next": null,
3
+ "previous": null,
4
+ "results": [
5
+ {
6
+ "id": "Jan",
7
+ "name": "January",
8
+ "count": 23
9
+ },
10
+ {
11
+ "id": "Feb",
12
+ "name": "February",
13
+ "count": 39
14
+ },
15
+ {
16
+ "id": "Mar",
17
+ "name": "March",
18
+ "count": 17
19
+ }
20
+ ]
21
+ }
File without changes
@@ -1,17 +0,0 @@
1
- {
2
- "next": null,
3
- "previous": null,
4
- "results": [
5
- {
6
- "id": "tasks",
7
- "name": "Tasks",
8
- "icon": "coffee",
9
- "endpoint": "/test-assets/list/menu-tasks.json"
10
- },
11
- {
12
- "id": "calendar",
13
- "name": "Schedule",
14
- "icon": "calendar"
15
- }
16
- ]
17
- }