Skip to content

Commit

Permalink
Merge 4959a41 into b566223
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Aug 13, 2021
2 parents b566223 + 4959a41 commit 9f334fa
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 0 additions & 2 deletions src/picker/components/Picker/Picker.js
Expand Up @@ -496,8 +496,6 @@ async function clickEmoji (unicodeOrName) {
.find(_ => (_.id === unicodeOrName))
const skinTonedUnicode = emojiSummary.unicode && unicodeWithSkin(emojiSummary, currentSkinTone)
await database.incrementFavoriteEmojiCount(unicodeOrName)
// eslint-disable-next-line no-self-assign
defaultFavoriteEmojis = defaultFavoriteEmojis // force favorites to re-render
fireEvent('emoji-click', {
emoji,
skinTone: currentSkinTone,
Expand Down
22 changes: 18 additions & 4 deletions test/spec/picker/favorites.test.js
Expand Up @@ -8,7 +8,6 @@ import allData from 'emoji-picker-element-data/en/emojibase/data.json'
import { MOST_COMMONLY_USED_EMOJI } from '../../../src/picker/constants'
import { uniqBy } from '../../../src/shared/uniqBy'
import { groups } from '../../../src/picker/groups'
import Database from '../../../src/database/Database'

const dataSource = 'with-favs.json'

Expand Down Expand Up @@ -37,21 +36,33 @@ describe('Favorites UI', () => {
await tick(40)
document.body.removeChild(picker)
await tick(40)
await new Database({ dataSource, locale: 'en' }).delete()
await tick(40)
basicAfterEach()
})

async function remount () {
await tick(40)
document.body.removeChild(picker)
await tick(40)
document.body.appendChild(picker)
container = picker.shadowRoot
await tick(40)
}

test('Favorites UI basic test', async () => {
// using a testId because testing-library seems to think role=menu has no aria-label
const favoritesBar = getByTestId(container, 'favorites')
let favoritesBar = getByTestId(container, 'favorites')
expect(favoritesBar).toBeVisible()
await waitFor(() => expect(getAllByRole(favoritesBar, 'menuitem')).toHaveLength(8))
expect(getAllByRole(favoritesBar, 'menuitem').map(_ => _.getAttribute('id').substring(4))).toStrictEqual(
MOST_COMMONLY_USED_EMOJI.slice(0, 8)
)
await waitFor(() => expect(getByRole(container, 'menuitem', { name: /🤣/ })).toBeVisible())
fireEvent.click(getByRole(container, 'menuitem', { name: /🤣/ }))

// have to unmount/remount to force a favorites refresh
await remount()

favoritesBar = getByTestId(container, 'favorites')
await waitFor(() => expect(getAllByRole(favoritesBar, 'menuitem')
.map(_ => _.getAttribute('id').substring(4))).toStrictEqual([
'🤣',
Expand Down Expand Up @@ -98,6 +109,9 @@ describe('Favorites UI', () => {
fireEvent.click(getByRole(container, 'menuitem', { name: /transparent/i }))
fireEvent.click(getByRole(container, 'menuitem', { name: /black/i }))

// have to unmount/remount to force a favorites refresh
await remount()

await waitFor(
() => expect(getByRole(getByTestId(container, 'favorites'), 'menuitem', { name: /transparent/i })).toBeVisible
)
Expand Down

0 comments on commit 9f334fa

Please sign in to comment.