Files
baserow/web-frontend/test/unit/database/components/table/createTableModal.spec.js
alamin-br 4ffb9ac8c7 fix: switching table type in the create table modal (#7018)
* fix: don't throw when switching from a data sync to a new table

The modal resets the form on a type change before the data sync form is
swapped out, and the data sync form had no reset method.

* fix: reset the sync options when switching data sync type

A two-way sync left on from PostgreSQL was sent for iCal, which doesn't
support it, so creating the table failed.

* fix: clear leftover data sync state when the type changes

Keeps the sync option defaults in one place, shows a failed restored sync
as an error with the form, and ignores properties for a previous type.

* test: reuse the data sync mount helper
2026-12-03 12:15:28 +01:00

100 lines
3.3 KiB
JavaScript

import { flushPromises } from '@vue/test-utils'
import { TestApp } from '@baserow/test/helpers/testApp'
import CreateTableModal from '@baserow/modules/database/components/table/CreateTableModal'
import CreateDataSync from '@baserow/modules/database/components/table/CreateDataSync'
describe('CreateTableModal', () => {
let testApp = null
beforeEach(() => {
testApp = new TestApp()
})
afterEach(async () => {
await testApp.afterEach()
})
test('switches from a data sync back to a new table', async () => {
const wrapper = await testApp.mount(CreateTableModal, {
propsData: { database: { id: 1, workspace: { id: 1 }, tables: [] } },
})
await wrapper.vm.show()
await flushPromises()
wrapper.vm.setChosenType('ical_calendar')
await flushPromises()
// The data sync form is still the rendered one when the type changes.
expect(() => wrapper.vm.setChosenType('')).not.toThrow()
await flushPromises()
expect(wrapper.vm.isImporter).toBe(true)
})
const mountDataSync = (testApp, chosenType) =>
testApp.mount(CreateDataSync, {
propsData: {
database: { id: 1, workspace: { id: 1 }, tables: [] },
chosenType,
},
// The type specific forms aren't needed here.
global: { stubs: { TableForm: true } },
})
test('switching data sync type turns the sync options back to defaults', async () => {
const wrapper = await mountDataSync(testApp, 'postgresql')
wrapper.vm.twoWaySync = true
wrapper.vm.autoAddNewProperties = true
wrapper.vm.deleteUnmatchedRows = false
// iCal doesn't support two-way sync, so a leftover `true` is rejected by
// the backend.
await wrapper.setProps({ chosenType: 'ical_calendar' })
const { twoWaySync, autoAddNewProperties, deleteUnmatchedRows } = wrapper.vm
expect({ twoWaySync, autoAddNewProperties, deleteUnmatchedRows }).toEqual({
twoWaySync: false,
autoAddNewProperties: false,
deleteUnmatchedRows: true,
})
})
test('shows the error and the form when a restored sync fails', async () => {
const wrapper = await mountDataSync(testApp, 'ical_calendar')
wrapper.vm.job = { id: 1, state: 'started', progress_percentage: 10 }
wrapper.vm.restoredFromStore = true
await flushPromises()
wrapper.vm.job = {
id: 1,
state: 'failed',
human_readable_error: 'The calendar URL is unreachable',
}
await flushPromises()
expect(wrapper.vm.restoredFromStore).toBe(false)
expect(wrapper.text()).toContain('The calendar URL is unreachable')
})
test('ignores properties that arrive after the type changed', async () => {
let reply
testApp.mock
.onPost('/database/data-sync/database/1/properties/')
.reply(() => new Promise((resolve) => (reply = resolve)))
const wrapper = await mountDataSync(testApp, 'postgresql')
const submitted = wrapper.vm.submitted({ name: 'Table' })
await flushPromises()
await wrapper.setProps({ chosenType: 'ical_calendar' })
reply([200, [{ key: 'id', name: 'id', initially_selected: true }]])
await submitted
const { loadedProperties, loadingProperties, properties } = wrapper.vm
expect({ loadedProperties, loadingProperties, properties }).toEqual({
loadedProperties: false,
loadingProperties: false,
properties: null,
})
})
})