Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support attribute format for some properties
This allows users to set the locale, data source, and skin tone emoji using HTML attributes as well as properties. Fixes #7
- Loading branch information
1 parent
c7293e1
commit c3bcf11
Showing
4 changed files
with
78 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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('🏃') | ||
}) | ||
}) |