Files
alamin-br 94e374dbac fix: don't open a linked row after its cell or modal is closed (#6992)
The linked row modal can be unmounted while it fetches the row, which
left its modal ref null and threw on show.
2026-12-02 13:50:20 +01:00

56 lines
1.5 KiB
JavaScript

import { beforeEach, describe, expect, test, vi } from 'vitest'
import { h } from 'vue'
import { mount } from '@vue/test-utils'
import ForeignRowEditModal from '@baserow/modules/database/components/row/ForeignRowEditModal'
let resolveRow
vi.mock('@baserow/modules/database/services/row', () => ({
default: () => ({
get: () => new Promise((resolve) => (resolveRow = resolve)),
}),
}))
const showRowEditModal = vi.fn()
function mountModal() {
const wrapper = mount(ForeignRowEditModal, {
props: { tableId: 1 },
global: {
mocks: { $client: {}, $store: { getters: { 'application/getAll': [] } } },
stubs: {
RowEditModal: {
methods: { show: showRowEditModal },
render: () => h('div'),
},
},
},
})
wrapper.vm.fetchedTableAndFields = true
return wrapper
}
describe('ForeignRowEditModal', () => {
beforeEach(() => showRowEditModal.mockClear())
test('opens the row once it is fetched', async () => {
const wrapper = mountModal()
const show = wrapper.vm.show(2)
resolveRow({ data: { id: 2 } })
await show
expect(showRowEditModal).toHaveBeenCalledWith(2, { id: 2 })
wrapper.unmount()
})
test('does nothing when closed while the row is being fetched', async () => {
// For example when the grid cell is deselected while the row loads.
const wrapper = mountModal()
const show = wrapper.vm.show(2)
wrapper.unmount()
resolveRow({ data: { id: 2 } })
await expect(show).resolves.toBeUndefined()
expect(showRowEditModal).not.toHaveBeenCalled()
})
})