fix: fix category with unsetting customEmoji (#277)

Fixes #276
This commit is contained in:
Nolan Lawson 2022-04-15 17:51:17 -07:00 committed by GitHub
parent e2ee956519
commit 3601f79eaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 0 deletions

View File

@ -162,6 +162,11 @@ $: {
if (customEmoji && customEmoji.length) {
groups = [customGroup, ...defaultGroups]
} else if (groups !== defaultGroups) {
if (currentGroupIndex) {
// If the current group is anything other than "custom" (which is first), decrement.
// This fixes the odd case where you set customEmoji, then pick a category, then unset customEmoji
currentGroupIndex--
}
groups = defaultGroups
}
}

View File

@ -50,4 +50,72 @@ describe('Custom emojis tests', () => {
document.body.removeChild(picker)
await tick(20)
})
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())
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')
document.body.removeChild(picker)
await tick(20)
})
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')
document.body.removeChild(picker)
await tick(20)
})
})