sebastian2357 2fd138697f
feat(webapp): badges UI (#8426)
- New badge UI, including editor.
- Adds config to enable/disable badges.

---------

Co-authored-by: Sebastian Stein <sebastian@codepassion.de>
Co-authored-by: Maximilian Harz <maxharz@gmail.com>
2025-04-25 16:55:46 +00:00

116 lines
3.0 KiB
JavaScript

import { render, screen, fireEvent } from '@testing-library/vue'
import Badges from './Badges.vue'
const localVue = global.localVue
describe('Badges.vue', () => {
const Wrapper = (propsData) => {
return render(Badges, {
propsData,
localVue,
})
}
describe('without badges', () => {
it('renders in presentation mode', () => {
const wrapper = Wrapper({ badges: [], selectionMode: false })
expect(wrapper.container).toMatchSnapshot()
})
it('renders in selection mode', () => {
const wrapper = Wrapper({ badges: [], selectionMode: true })
expect(wrapper.container).toMatchSnapshot()
})
})
describe('with badges', () => {
const badges = [
{
id: '1',
icon: '/path/to/some/icon',
isDefault: false,
description: 'Some description',
},
{
id: '2',
icon: '/path/to/another/icon',
isDefault: true,
description: 'Another description',
},
{
id: '3',
icon: '/path/to/third/icon',
isDefault: false,
description: 'Third description',
},
]
describe('in presentation mode', () => {
let wrapper
beforeEach(() => {
wrapper = Wrapper({ badges, scale: 1.2, selectionMode: false })
})
it('renders', () => {
expect(wrapper.container).toMatchSnapshot()
})
it('clicking on second badge does nothing', async () => {
const badge = screen.getByTitle(badges[1].description)
await fireEvent.click(badge)
expect(wrapper.emitted()).toEqual({})
})
})
describe('in selection mode', () => {
let wrapper
beforeEach(() => {
wrapper = Wrapper({ badges, scale: 1.2, selectionMode: true })
})
it('renders', () => {
expect(wrapper.container).toMatchSnapshot()
})
it('clicking on first badge does nothing', async () => {
const badge = screen.getByTitle(badges[0].description)
await fireEvent.click(badge)
expect(wrapper.emitted()).toEqual({})
})
describe('clicking on second badge', () => {
beforeEach(async () => {
const badge = screen.getByTitle(badges[1].description)
await fireEvent.click(badge)
})
it('selects badge', () => {
expect(wrapper.container).toMatchSnapshot()
})
it('emits badge-selected with index', async () => {
expect(wrapper.emitted()['badge-selected']).toEqual([[1]])
})
})
describe('clicking twice on second badge', () => {
beforeEach(async () => {
const badge = screen.getByTitle(badges[1].description)
await fireEvent.click(badge)
await fireEvent.click(badge)
})
it('deselects badge', () => {
expect(wrapper.container).toMatchSnapshot()
})
it('emits badge-selected with null', async () => {
expect(wrapper.emitted()['badge-selected']).toEqual([[1], [null]])
})
})
})
})
})