Files
baserow/web-frontend/test/unit/database/components/row/rowEditModal.spec.js
Davide Silvestri 89184e9b27 fix: stop editing rows hidden by restricted view filters (#6217)
* fix: stop editing rows hidden by restricted view filters

Cancel edits still queued for a row that the backend reported as hidden,
including pasted values, in grid, gallery, timeline, kanban and calendar,
so they are neither sent nor put back on screen. Close the row modal when
its row gets hidden in a restricted view; other views keep it open.

* test: cover builders and ignore broadcast order in restricted view tests

* test: add e2e tests for restricted view row visibility

Cover creating, editing, pasting and dragging rows in a restricted view
while the HTTP response is held after the server commits, the row modal
closing only in restricted views, and view default values.

* fix: hide rows created with the grid's floating add button when filtered out

createNewRowConfirmed used the single-row endpoint, which doesn't return
hidden_row_ids, so a restricted editor kept a row the view's filters
exclude. Create it through the batch endpoint and report hidden rows like
the other create paths.

* test: expect the batch endpoint for the grid's floating add button

* fix: cancel queued kanban edits when a drag hides the card
2026-10-08 09:23:06 +02:00

112 lines
3.0 KiB
JavaScript

import { flushPromises } from '@vue/test-utils'
import { TestApp } from '@baserow/test/helpers/testApp'
import RowEditModal from '@baserow/modules/database/components/row/RowEditModal'
import Modal from '@baserow/modules/core/components/Modal'
describe('RowEditModal', () => {
let testApp = null
beforeEach(() => {
testApp = new TestApp()
})
afterEach(async () => {
await testApp.afterEach()
})
const database = { id: 1, workspace: { id: 1 } }
const table = { id: 1 }
const view = { id: 1, ownership_type: 'collaborative' }
const row = { id: 1, _: {} }
const openModal = async () => {
const wrapper = await testApp.mount(RowEditModal, {
props: {
database,
table,
view,
allFieldsInTable: [],
visibleFields: [],
rows: [row],
readOnly: true,
},
global: {
stubs: { RowEditModalFieldsList: true, RowEditModalSidebar: true },
},
})
wrapper.vm.show(row.id)
await flushPromises()
return wrapper
}
test('closes when the backend hides its row', async () => {
const wrapper = await openModal()
await testApp.store.dispatch('rowModal/rowsHiddenByBackend', {
tableId: table.id,
rowIds: [row.id],
})
await flushPromises()
expect(wrapper.emitted('hidden')).toEqual([[{ row }]])
})
test('closes the modals opened on top of it first when the backend hides its row', async () => {
const wrapper = await openModal()
const rootModal = wrapper.vm.getRootModal()
const openChildModal = async (parentModal) => {
const child = await testApp.mount(Modal, {
global: {
provide: {
registerChild: parentModal.registerChild,
unregisterChild: parentModal.unregisterChild,
},
},
})
child.vm.show()
return child
}
const child = await openChildModal(rootModal)
const grandchild = await openChildModal(child.vm)
// A modal only flips `open` after a timeout, so the closes cascade over timers.
const waitForModalsToClose = async () => {
for (let i = 0; i < 3; i++) {
await new Promise((resolve) => setTimeout(resolve))
await flushPromises()
}
}
await testApp.store.dispatch('rowModal/rowsHiddenByBackend', {
tableId: table.id,
rowIds: [row.id],
})
await waitForModalsToClose()
expect(grandchild.emitted('hidden')).toEqual([[]])
expect(child.emitted('hidden')).toEqual([[]])
expect(wrapper.emitted('hidden')).toEqual([[{ row }]])
})
test('stays open when another row is hidden', async () => {
const wrapper = await openModal()
await testApp.store.dispatch('rowModal/rowsHiddenByBackend', {
tableId: table.id,
rowIds: [2],
})
await flushPromises()
expect(wrapper.emitted('hidden')).toBeUndefined()
})
test('stays open when its row leaves the view buffer', async () => {
const wrapper = await openModal()
await wrapper.setProps({ rows: [] })
await flushPromises()
expect(wrapper.emitted('hidden')).toBeUndefined()
})
})