Ocelot-Social/webapp/components/BadgeSelection.spec.js
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

77 lines
1.8 KiB
JavaScript

import { render, screen, fireEvent } from '@testing-library/vue'
import BadgeSelection from './BadgeSelection.vue'
const localVue = global.localVue
describe('Badges.vue', () => {
const Wrapper = (propsData) => {
return render(BadgeSelection, {
propsData,
localVue,
})
}
describe('without badges', () => {
it('renders', () => {
const wrapper = Wrapper({ badges: [] })
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',
},
]
let wrapper
beforeEach(() => {
wrapper = Wrapper({ badges })
})
it('renders', () => {
expect(wrapper.container).toMatchSnapshot()
})
describe('clicking on a badge', () => {
beforeEach(async () => {
const badge = screen.getByText(badges[1].description)
await fireEvent.click(badge)
})
it('emits badge-selected with badge', async () => {
expect(wrapper.emitted()['badge-selected']).toEqual([[badges[1]]])
})
})
describe('clicking twice on a badge', () => {
beforeEach(async () => {
const badge = screen.getByText(badges[1].description)
await fireEvent.click(badge)
await fireEvent.click(badge)
})
it('emits badge-selected with null', async () => {
expect(wrapper.emitted()['badge-selected']).toEqual([[badges[1]], [null]])
})
})
})
})