diff --git a/resources/assets/js/components/screens/SettingsScreen.spec.ts b/resources/assets/js/components/screens/SettingsScreen.spec.ts new file mode 100644 index 00000000..e4a5bb9b --- /dev/null +++ b/resources/assets/js/components/screens/SettingsScreen.spec.ts @@ -0,0 +1,47 @@ +import { expect, it } from 'vitest' +import UnitTestCase from '@/__tests__/UnitTestCase' +import SettingsScreen from './SettingsScreen.vue' +import { settingStore } from '@/stores' +import { fireEvent, waitFor } from '@testing-library/vue' +import router from '@/router' +import { alerts } from '@/utils' + +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') + const goMock = this.mock(router, 'go') + + settingStore.state.media_path = '' + const { getByLabelText, getByText } = this.render(SettingsScreen) + + await fireEvent.update(getByLabelText('Media Path'), '/media') + await fireEvent.click(getByText('Scan')) + + 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') + const goMock = this.mock(router, 'go') + const confirmMock = this.mock(alerts, 'confirm') + + settingStore.state.media_path = '/old' + const { getByLabelText, getByText } = this.render(SettingsScreen) + + await fireEvent.update(getByLabelText('Media Path'), '/new') + await fireEvent.click(getByText('Scan')) + + await waitFor(() => { + expect(updateMock).not.toHaveBeenCalled() + expect(goMock).not.toHaveBeenCalled() + expect(confirmMock).toHaveBeenCalled() + }) + }) + } +} diff --git a/resources/assets/js/components/screens/__snapshots__/SettingsScreen.spec.ts.snap b/resources/assets/js/components/screens/__snapshots__/SettingsScreen.spec.ts.snap new file mode 100644 index 00000000..344d90bc --- /dev/null +++ b/resources/assets/js/components/screens/__snapshots__/SettingsScreen.spec.ts.snap @@ -0,0 +1,18 @@ +// Vitest Snapshot v1 + +exports[`renders 1`] = ` +
+
+
+
+

Settings

+
+
+
+
+

The absolute path to the server directory containing your media. Koel will scan this directory for songs and extract any available information.
Scanning may take a while, especially if you have a lot of songs, so be patient.

+
+
+
+
+`;