2022-05-09 09:59:31 +00:00
|
|
|
import { expect, it, vi } from 'vitest'
|
|
|
|
import { fireEvent } from '@testing-library/vue'
|
2022-05-07 10:14:35 +00:00
|
|
|
import { eventBus } from '@/utils'
|
|
|
|
import { preferenceStore } from '@/stores'
|
2022-05-09 09:59:31 +00:00
|
|
|
import ComponentTestCase from '@/__tests__/ComponentTestCase'
|
2022-05-07 10:14:35 +00:00
|
|
|
import SupportKoel from './SupportKoel.vue'
|
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
new class extends ComponentTestCase {
|
|
|
|
protected beforeEach () {
|
|
|
|
super.beforeEach(() => vi.useFakeTimers());
|
|
|
|
}
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
protected afterEach () {
|
|
|
|
super.afterEach(() => {
|
|
|
|
vi.useRealTimers()
|
|
|
|
preferenceStore.state.supportBarNoBugging = false
|
|
|
|
})
|
|
|
|
}
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
private async renderComponent () {
|
|
|
|
const result = this.render(SupportKoel)
|
|
|
|
eventBus.emit('KOEL_READY')
|
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-05-09 09:59:31 +00:00
|
|
|
return result
|
|
|
|
}
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
protected test () {
|
|
|
|
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 () => {
|
|
|
|
preferenceStore.state.supportBarNoBugging = true
|
|
|
|
expect((await this.renderComponent()).queryByTestId('support-bar')).toBeNull()
|
|
|
|
})
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
it('hides', async () => {
|
|
|
|
const { getByTestId, queryByTestId } = await this.renderComponent()
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
await fireEvent.click(getByTestId('hide-support-koel'))
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
expect(await queryByTestId('support-bar')).toBeNull()
|
|
|
|
})
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
it('hides and does not bug again', async () => {
|
|
|
|
const { getByTestId, queryByTestId } = await this.renderComponent()
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
await fireEvent.click(getByTestId('stop-support-koel-bugging'))
|
2022-05-07 10:14:35 +00:00
|
|
|
|
2022-05-09 09:59:31 +00:00
|
|
|
expect(await queryByTestId('btn-stop-support-koel-bugging')).toBeNull()
|
|
|
|
expect(preferenceStore.state.supportBarNoBugging).toBe(true)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|