/
custom.test.js
134 lines (104 loc) · 4.37 KB
/
custom.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
import { ALL_EMOJI, basicAfterEach, basicBeforeEach, tick } from '../shared'
import { groups } from '../../../src/picker/groups'
import Picker from '../../../src/picker/PickerElement'
import { getAllByRole, getByRole, waitFor } from '@testing-library/dom'
import { getAccessibleName } from '../utils'
describe('Custom emojis tests', () => {
beforeEach(async () => {
await basicBeforeEach()
await tick(40)
})
afterEach(async () => {
await tick(40)
await basicAfterEach()
await tick(40)
})
test('Setting custom emoji shows the proper first page', async () => {
const picker = new Picker({
locale: 'en',
dataSource: ALL_EMOJI
})
picker.customEmoji = [
{
name: 'monkey',
shortcodes: ['monkey'],
url: 'monkey.png'
}
]
document.body.appendChild(picker)
const container = picker.shadowRoot.querySelector('.picker')
await waitFor(() => expect(getAllByRole(container, 'tab')).toHaveLength(groups.length + 1))
// We actually have to sleep here, because we want to test for a race condition where the
// custom emoji show first, but then are replaced by the non-custom emoji
// https://github.com/nolanlawson/emoji-picker-element/issues/84
await tick(50)
await waitFor(() => expect(getByRole(container, 'menuitem', { name: 'monkey' })).toBeVisible())
await waitFor(async () => (
expect(
await Promise.all(getAllByRole(container, 'menu').map(node => getAccessibleName(container, node)))
).toStrictEqual([
'Custom',
'Favorites'
])
))
// Visibility test, has nothing to do with accessibility. We don't visually show the label if there's
// just one category and it's the default "Custom" one.
expect(container.querySelector('.category').textContent).toEqual('Custom')
expect(container.querySelector('.category')).toHaveClass('gone')
await tick(40)
document.body.removeChild(picker)
await tick(40)
})
test('Setting custom emoji, selecting flags, unsetting custom emoji', async () => {
const picker = new Picker({
locale: 'en',
dataSource: ALL_EMOJI
})
picker.customEmoji = [
{
name: 'themonkey',
shortcodes: ['themonkey'],
url: 'themonkey.png'
}
]
document.body.appendChild(picker)
const container = picker.shadowRoot.querySelector('.picker')
await waitFor(() => expect(getAllByRole(container, 'tab')).toHaveLength(groups.length + 1))
await waitFor(() => expect(getByRole(container, 'menuitem', { name: 'themonkey' })).toBeVisible())
expect(getByRole(container, 'menuitem', { name: 'themonkey' }).getAttribute('title')).toStrictEqual('themonkey')
expect(getByRole(container, 'menuitem', { name: 'themonkey' }).getAttribute('aria-label')).toStrictEqual('themonkey')
getByRole(container, 'tab', { name: 'Flags' }).click()
await waitFor(() => expect(getByRole(container, 'menuitem', { name: /🏁/ })).toBeVisible())
picker.customEmoji = undefined
await waitFor(() => expect(getAllByRole(container, 'tab')).toHaveLength(groups.length))
await waitFor(() => expect(getByRole(container, 'menuitem', { name: /🏁/ })).toBeVisible())
expect(getByRole(container, 'tab', { name: 'Flags' }).getAttribute('aria-selected')).toEqual('true')
await tick(40)
document.body.removeChild(picker)
await tick(40)
})
test('Setting custom emoji, unsetting custom emoji', async () => {
const picker = new Picker({
locale: 'en',
dataSource: ALL_EMOJI
})
picker.customEmoji = [
{
name: 'themonkey',
shortcodes: ['themonkey'],
url: 'themonkey.png'
}
]
document.body.appendChild(picker)
const container = picker.shadowRoot.querySelector('.picker')
await waitFor(() => expect(getAllByRole(container, 'tab')).toHaveLength(groups.length + 1))
await waitFor(() => expect(getByRole(container, 'menuitem', { name: 'themonkey' })).toBeVisible())
picker.customEmoji = undefined
await waitFor(() => expect(getAllByRole(container, 'tab')).toHaveLength(groups.length))
await waitFor(() => expect(getByRole(container, 'menuitem', { name: /😀/ })).toBeVisible())
expect(getByRole(container, 'tab', { name: 'Smileys and emoticons' }).getAttribute('aria-selected')).toEqual('true')
await tick(40)
document.body.removeChild(picker)
await tick(40)
})
})