-
Notifications
You must be signed in to change notification settings - Fork 79
/
attributes.test.js
47 lines (40 loc) · 1.68 KB
/
attributes.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
import { basicAfterEach, basicBeforeEach, FR_EMOJI, ALL_EMOJI, mockFrenchDataSource, tick } from '../shared'
import Picker from '../../../src/picker/PickerElement.js'
import { getByRole } from '@testing-library/dom'
describe('attributes tests', () => {
beforeEach(async () => {
basicBeforeEach()
mockFrenchDataSource()
})
afterEach(basicAfterEach)
test('setting initial locale/dataSource issues only one GET', async () => {
const picker = new Picker()
picker.setAttribute('locale', 'fr')
picker.setAttribute('data-source', FR_EMOJI)
document.body.appendChild(picker)
await tick(20)
expect(fetch).toHaveBeenCalledTimes(1)
expect(fetch).toHaveBeenLastCalledWith(FR_EMOJI, undefined)
expect(picker.locale).toEqual('fr')
expect(picker.dataSource).toEqual(FR_EMOJI)
expect(picker.getAttribute('locale')).toEqual('fr')
expect(picker.getAttribute('data-source')).toEqual(FR_EMOJI)
})
test('can set skintone emoji using an attribute', async () => {
const picker = new Picker()
picker.setAttribute('data-source', ALL_EMOJI)
picker.setAttribute('skin-tone-emoji', '✌')
document.body.appendChild(picker)
await tick(20)
expect(getByRole(picker.shadowRoot, 'button', { name: /Choose a skin tone/ }).innerHTML)
.toContain('✌')
expect(picker.skinToneEmoji).toEqual('✌')
expect(picker.getAttribute('skin-tone-emoji')).toEqual('✌')
expect(picker.locale).toEqual('en')
picker.setAttribute('skin-tone-emoji', '🏃')
await tick(20)
expect(getByRole(picker.shadowRoot, 'button', { name: /Choose a skin tone/ }).innerHTML)
.toContain('🏃')
expect(picker.skinToneEmoji).toEqual('🏃')
})
})