mirror of
https://github.com/baserow/baserow.git
synced 2026-12-05 08:48:35 +00:00
* feat(database): add import context item component for sidebar tables * feat(database): show import into table item in sidebar context menu * chore: changelog for sidebar table import (#5284) * fix(database): populate fetched fields for sidebar table import The import modal reads field._.type; raw FieldService.fetchAll objects lack that store metadata, so the field-mapping dropdown threw and the importer hung on "Parsing data". Populate the fetched fields via populateField before passing them to ImportFileModal. Adds a full CSV-import e2e test. * test(database): cover import item permission gating in SidebarItem * fix(database): disable sidebar import item during table delete Wire :disabled="deleteLoading" into SidebarImportTableContextItem so the prop (and its re-entry guard) is no longer inert, matching the Duplicate item and preventing the import modal from opening on a table mid-delete. * fix(database): hide context menu on import field-fetch error; scope e2e selectors Address Copilot review: emit click in a finally block so the sidebar context menu closes even when fetching fields fails (matching the duplicate item), and add an error-path unit test. Scope the e2e test's table/three-dots locators to the sidebar row to avoid ambiguity with the table name elsewhere on the page. * test(database): make import error-path test reject with a realistic API error Reject fetchAll with an error carrying a .handler (like a real API error) so notifyIf reports it instead of re-throwing, removing the unhandled rejection that made the vitest run exit non-zero. Also assert the error is surfaced.
68 lines
2.5 KiB
JavaScript
68 lines
2.5 KiB
JavaScript
import { mountSuspended } from '@nuxt/test-utils/runtime'
|
|
import { expect, test, describe } from 'vitest'
|
|
|
|
import SidebarItem from '@baserow/modules/database/components/sidebar/SidebarItem'
|
|
|
|
describe('SidebarItem import permission gating', () => {
|
|
const database = {
|
|
id: 1,
|
|
workspace: { id: 10 },
|
|
_: { loading: false },
|
|
tables: [],
|
|
}
|
|
const table = { id: 5, name: 'Cars', _: { selected: false }, data_sync: null }
|
|
|
|
// Mount with an explicit set of granted permission operations. The context
|
|
// menu content lives inside a <Context> slot (only rendered once opened), so
|
|
// Context is stubbed to render its slot immediately.
|
|
const mountSidebar = (granted) =>
|
|
mountSuspended(SidebarItem, {
|
|
props: { database, table },
|
|
global: {
|
|
mocks: {
|
|
$hasPermission: (operation) => granted.includes(operation),
|
|
},
|
|
stubs: {
|
|
SidebarImportTableContextItem: {
|
|
name: 'SidebarImportTableContextItem',
|
|
props: ['disabled'],
|
|
template: '<a class="import-item-stub" />',
|
|
},
|
|
SidebarDuplicateTableContextItem: true,
|
|
ExportTableModal: true,
|
|
WebhookModal: true,
|
|
SyncTableModal: true,
|
|
ConfigureDataSyncModal: true,
|
|
Context: { template: '<div><slot /></div>' },
|
|
},
|
|
},
|
|
})
|
|
|
|
test('shows the import item when the user has import_rows permission', async () => {
|
|
const wrapper = await mountSidebar(['database.table.import_rows'])
|
|
expect(wrapper.find('.import-item-stub').exists()).toBe(true)
|
|
// import_rows alone must reveal the three-dots menu button (showOptions).
|
|
expect(wrapper.find('.tree__options').exists()).toBe(true)
|
|
})
|
|
|
|
test('hides the import item without import_rows permission', async () => {
|
|
// Export is granted so the menu still opens; the import item must stay gated.
|
|
const wrapper = await mountSidebar(['database.table.run_export'])
|
|
expect(wrapper.find('.tree__options').exists()).toBe(true)
|
|
expect(wrapper.find('.import-item-stub').exists()).toBe(false)
|
|
})
|
|
|
|
test('disables the import item while a table delete is in progress', async () => {
|
|
const wrapper = await mountSidebar(['database.table.import_rows'])
|
|
const item = wrapper.findComponent({
|
|
name: 'SidebarImportTableContextItem',
|
|
})
|
|
expect(item.props('disabled')).toBe(false)
|
|
|
|
wrapper.vm.deleteLoading = true
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(item.props('disabled')).toBe(true)
|
|
})
|
|
})
|