Ocelot-Social/webapp/components/ShoutButton.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

64 lines
1.7 KiB
JavaScript

import { render, screen, fireEvent } from '@testing-library/vue'
import '@testing-library/jest-dom'
import Vue from 'vue'
import ShoutButton from './ShoutButton.vue'
const localVue = global.localVue
describe('ShoutButton.vue', () => {
let mocks
beforeEach(() => {
mocks = {
$t: jest.fn((t) => t),
$apollo: {
mutate: jest.fn(),
},
}
})
let wrapper
const Wrapper = ({ isShouted = false } = {}) => {
return render(ShoutButton, { mocks, localVue, propsData: { isShouted } })
}
beforeEach(() => {
wrapper = Wrapper()
})
it('renders button and text', () => {
expect(wrapper.container).toMatchSnapshot()
const button = screen.getByRole('button')
expect(button).toBeInTheDocument()
})
it('toggle the button', async () => {
mocks.$apollo.mutate = jest.fn().mockResolvedValue({ data: { shout: 'WeDoShout' } })
const button = screen.getByRole('button')
await fireEvent.click(button)
expect(wrapper.container).toMatchSnapshot()
const shoutedCount = screen.getByText('1')
expect(shoutedCount).toBeInTheDocument()
})
it('toggle the button, but backend fails', async () => {
mocks.$apollo.mutate = jest.fn().mockRejectedValue({ message: 'Ouch!' })
const button = screen.getByRole('button')
await fireEvent.click(button)
expect(wrapper.container).toMatchSnapshot()
let shoutedCount = screen.getByText('1')
expect(shoutedCount).toBeInTheDocument()
await Vue.nextTick()
shoutedCount = screen.getByText('0')
expect(shoutedCount).toBeInTheDocument()
})
describe('when shouted', () => {
it('renders', () => {
wrapper = Wrapper({ isShouted: true })
expect(wrapper.container).toMatchSnapshot()
})
})
})