2024-01-18 11:13:05 +00:00
|
|
|
import Router from '@/router'
|
2022-07-13 11:03:10 +00:00
|
|
|
import { expect, it } from 'vitest'
|
|
|
|
import UnitTestCase from '@/__tests__/UnitTestCase'
|
|
|
|
import { settingStore } from '@/stores'
|
2022-11-29 10:18:58 +00:00
|
|
|
import { screen, waitFor } from '@testing-library/vue'
|
2022-07-26 14:46:02 +00:00
|
|
|
import { DialogBoxStub } from '@/__tests__/stubs'
|
2022-11-29 10:18:58 +00:00
|
|
|
import SettingsScreen from './SettingsScreen.vue'
|
2022-07-13 11:03:10 +00:00
|
|
|
|
|
|
|
new class extends UnitTestCase {
|
|
|
|
protected test () {
|
|
|
|
it('renders', () => expect(this.render(SettingsScreen).html()).toMatchSnapshot())
|
|
|
|
|
|
|
|
it('submits the settings form', async () => {
|
|
|
|
const updateMock = this.mock(settingStore, 'update')
|
2024-01-18 11:13:05 +00:00
|
|
|
const goMock = this.mock(Router, 'go')
|
2022-07-13 11:03:10 +00:00
|
|
|
|
|
|
|
settingStore.state.media_path = ''
|
2022-11-29 10:18:58 +00:00
|
|
|
this.render(SettingsScreen)
|
2022-07-13 11:03:10 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.type(screen.getByLabelText('Media Path'), '/media')
|
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Scan' }))
|
2022-07-13 11:03:10 +00:00
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(updateMock).toHaveBeenCalledWith({ media_path: '/media' })
|
|
|
|
expect(goMock).toHaveBeenCalledWith('home')
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('confirms upon media path change', async () => {
|
|
|
|
const updateMock = this.mock(settingStore, 'update')
|
2024-01-18 11:13:05 +00:00
|
|
|
const goMock = this.mock(Router, 'go')
|
2022-07-26 14:46:02 +00:00
|
|
|
const confirmMock = this.mock(DialogBoxStub.value, 'confirm')
|
2022-07-13 11:03:10 +00:00
|
|
|
|
|
|
|
settingStore.state.media_path = '/old'
|
2022-11-29 10:18:58 +00:00
|
|
|
this.render(SettingsScreen)
|
2022-07-13 11:03:10 +00:00
|
|
|
|
2022-11-29 10:18:58 +00:00
|
|
|
await this.type(screen.getByLabelText('Media Path'), '/new')
|
|
|
|
await this.user.click(screen.getByRole('button', { name: 'Scan' }))
|
2022-07-13 11:03:10 +00:00
|
|
|
|
|
|
|
await waitFor(() => {
|
|
|
|
expect(updateMock).not.toHaveBeenCalled()
|
|
|
|
expect(goMock).not.toHaveBeenCalled()
|
|
|
|
expect(confirmMock).toHaveBeenCalled()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|