2022-05-09 09:59:31 +00:00
|
|
|
import { expect, it, vi } from 'vitest'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen } from '@testing-library/vue'
|
2022-05-07 10:14:35 +00:00
|
|
|
import { preferenceStore } from '@/stores'
|
2022-05-13 17:58:38 +00:00
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
2022-05-07 10:14:35 +00:00
|
|
|
import SupportKoel from './SupportKoel.vue'
|
2024-04-22 21:04:03 +00:00
|
|
|
import { http } from '@/services'
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-13 17:58:38 +00:00
|
|
|
new class extends UnitTestCase {
|
2022-05-09 09:59:31 +00:00
|
|
|
protected beforeEach () {
|
2024-04-22 21:04:03 +00:00
|
|
|
// Prevent actual HTTP requests from being made
|
|
|
|
this.setReadOnlyProperty(http, 'silently', {
|
|
|
|
patch: vi.fn()
|
|
|
|
})
|
|
|
|
|
2022-10-30 23:13:57 +00:00
|
|
|
super.beforeEach(() => vi.useFakeTimers())
|
2022-05-09 09:59:31 +00:00
|
|
|
}
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
protected afterEach () {
|
|
|
|
super.afterEach(() => {
|
|
|
|
vi.useRealTimers()
|
2024-01-23 22:50:50 +00:00
|
|
|
preferenceStore.state.support_bar_no_bugging = false
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
}
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
private async renderComponent () {
|
2022-10-30 23:13:57 +00:00
|
|
|
preferenceStore.initialized.value = true
|
|
|
|
const rendered = this.render(SupportKoel)
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
vi.advanceTimersByTime(30 * 60 * 1000)
|
|
|
|
await this.tick()
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-10-30 23:13:57 +00:00
|
|
|
return rendered
|
2022-05-09 09:59:31 +00:00
|
|
|
}
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
protected test () {
|
2022-11-29 10:18:58 +00:00
|
|
|
it('shows after a delay', async () => expect((await this.renderComponent()).html()).toMatchSnapshot())
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
it('does not show if user so demands', async () => {
|
2024-01-23 22:50:50 +00:00
|
|
|
preferenceStore.state.support_bar_no_bugging = true
|
2022-10-30 23:13:57 +00:00
|
|
|
preferenceStore.initialized.value = true
|
2022-05-09 09:59:31 +00:00
|
|
|
expect((await this.renderComponent()).queryByTestId('support-bar')).toBeNull()
|
|
|
|
})
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2024-01-15 22:26:50 +00:00
|
|
|
it('does not show for Plus edition', async () => {
|
|
|
|
this.enablePlusEdition()
|
|
|
|
expect((await this.renderComponent()).queryByTestId('support-bar')).toBeNull()
|
|
|
|
})
|
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
it('hides', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Hide' }))
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(screen.queryByTestId('support-bar')).toBeNull()
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
it('hides and does not bug again', async () => {
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.renderComponent()
|
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Don\'t bug me again' }))
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
expect(await screen.queryByTestId('support-bar')).toBeNull()
|
2024-01-23 22:50:50 +00:00
|
|
|
expect(preferenceStore.state.support_bar_no_bugging).toBe(true)
|
2022-05-09 09:59:31 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|