Ocelot-Social/webapp/components/ActionButton.spec.js
Ulf Gebhardt 4b3a26d517
feat(webapp): shout comments (#8600)
* shout comments

* fix notifications

* Remove whitespace for empty category sections

* Overhaul post actions

* Adjust spacing

* Allow fine-grained size control for icons and circle buttons via css variables; adjust comments layout

* Adjust spacing

* Add test for ActionButton (WIP)

* Rename import

* Remove text and add count bubble

* Use filled icons to indicate active states

* Adjust sizes and orientation

* Remove unused properties, add test

* Fix ObserveButton test

* Fix ShoutButton test

* fix tests

* Adapt styles

* Adjust style for larger numbers

* Remove unused icon

* Fix test structure

* Remove unused class names

---------

Co-authored-by: Maximilian Harz <maxharz@gmail.com>
2025-05-31 00:13:15 +02:00

65 lines
1.4 KiB
JavaScript

import { render, screen, fireEvent } from '@testing-library/vue'
import '@testing-library/jest-dom'
import ActionButton from './ActionButton.vue'
const localVue = global.localVue
describe('ActionButton.vue', () => {
let mocks
beforeEach(() => {
mocks = {
$t: jest.fn((t) => t),
}
})
let wrapper
const Wrapper = ({ isDisabled = false } = {}) => {
return render(ActionButton, {
mocks,
localVue,
propsData: {
icon: 'heart',
text: 'Click me',
count: 7,
disabled: isDisabled,
},
})
}
beforeEach(() => {
wrapper = Wrapper()
})
describe('when not disabled', () => {
it('renders', () => {
const wrapper = Wrapper()
expect(wrapper.container).toMatchSnapshot()
})
it('shows count', () => {
const count = screen.getByText('7')
expect(count).toBeInTheDocument()
})
it('button emits click event', async () => {
const button = screen.getByRole('button')
await fireEvent.click(button)
expect(wrapper.emitted().click).toEqual([[]])
})
})
describe('when disabled', () => {
it('renders', () => {
const wrapper = Wrapper({ isDisabled: true })
expect(wrapper.container).toMatchSnapshot()
})
it('button does not emit click event', async () => {
const button = screen.getByRole('button')
await fireEvent.click(button)
expect(wrapper.emitted().click).toEqual([[]])
})
})
})