Files
baserow/web-frontend/test/unit/database/components/sidebar/sidebarImportTableContextItem.spec.js
Jonathan Adelineandpeter_baserow a8bf3b73ae feat: redesign app sidebar (#6798)
* feat: redesign sidebar workspace navigation

* feat: redesign the sidebar footer and account menu

Match the account menu to the sidebar prototype and reuse the admin
navigation in a submenu. Keep Add new above the footer while the
application list scrolls.

* fix: show the sortable indicator only when dragging

* feat: refine workspace sidebar application navigation

* feat: reorganize workspace sidebar shortcuts

* fix: isolate workspace sidebar menus and actions

* fix: cancel sortable drops on hidden lists

* fix(enterprise): allow retrying Direct support

* feat: simplify the workspace overview header

* fix: prevent horizontal overflow around the sidebar

Constrain animated tree groups to the width of the sidebar so long labels truncate. On narrow screens, let the sidebar expand over the content instead of reducing the usable page width.

* fix: fit workspace cards and creation menus on mobile

* test: keep the current table selected after reload

* fix: undo and redo edits across expanded sidebar applications

* fix: keep sidebar groups out of the tab order

* fix: highlight the active database in the tables tour

* feat: label workspace integrations in the settings menu

* fix: keep the workspace sidebar and guided tour usable on phones

* fix: undo sidebar row imports in the destination database

* fix: keep the guided tour highlight on the current step

* fix: show an empty state in the workspace picker

* fix: confirm workspace deletion before moving it to trash

* feat: open registered workspace settings tabs from the sidebar

* fix: keep the sidebar logo the same size across workspaces

---------

Co-authored-by: peter_baserow <peter@baserow.io>
2026-11-23 20:42:20 +04:00

130 lines
4.2 KiB
JavaScript

import { flushPromises } from '@vue/test-utils'
import { TestApp } from '@baserow/test/helpers/testApp'
import SidebarImportTableContextItem from '@baserow/modules/database/components/sidebar/table/SidebarImportTableContextItem'
import FieldService from '@baserow/modules/database/services/field'
import { populateTable } from '@baserow/modules/database/store/table'
vi.mock('@baserow/modules/database/services/field', () => ({
default: vi.fn(),
}))
describe('SidebarImportTableContextItem', () => {
let testApp = null
beforeEach(() => {
testApp = new TestApp()
})
afterEach(async () => {
await testApp.afterEach()
vi.clearAllMocks()
})
const database = { id: 1, workspace: { id: 10 } }
const table = { id: 5, name: 'Cars' }
const fields = [{ id: 100, name: 'Name', type: 'text' }]
const mockFetchAll = () => {
const fetchAll = vi.fn().mockResolvedValue({ data: fields })
FieldService.mockReturnValue({ fetchAll })
return fetchAll
}
const mountItem = async (props = {}) => {
const show = vi.fn()
const wrapper = await testApp.mount(SidebarImportTableContextItem, {
props: { database, table, ...props },
global: {
stubs: {
ImportFileModal: {
name: 'ImportFileModal',
props: ['database', 'table', 'fields', 'undoInApplication'],
template: '<div />',
methods: { show },
},
},
},
})
return { wrapper, show }
}
const importModal = (wrapper) =>
wrapper.findComponent({ name: 'ImportFileModal' })
test('uses table-level undo when importing into the selected table', async () => {
const selected = populateTable(table)
const { wrapper } = await mountItem()
expect(importModal(wrapper).props('undoInApplication')).toBe(true)
await testApp.store.dispatch('table/forceSelect', {
database: { ...database, tables: [selected] },
table: selected,
})
expect(importModal(wrapper).props('undoInApplication')).toBe(false)
})
test('fetches fields, emits click, and opens the modal', async () => {
const fetchAll = mockFetchAll()
const { wrapper, show } = await mountItem()
await wrapper.find('a').trigger('click')
await flushPromises()
expect(fetchAll).toHaveBeenCalledWith(table.id)
// The modal reads `field._.type.iconClass`, so the fetched fields must be
// populated with the store's internal metadata before being passed in.
const passedFields = importModal(wrapper).props('fields')
expect(passedFields).toHaveLength(1)
expect(passedFields[0].id).toBe(100)
expect(passedFields[0]._?.type).toBeDefined()
expect(wrapper.emitted('click')).toBeTruthy()
expect(show).toHaveBeenCalled()
})
test('still hides the context menu when fetching fields fails', async () => {
// Mimic a real API error: it carries a `handler` so notifyIf reports it
// instead of re-throwing.
const notifyIfHandler = vi.fn()
const apiError = Object.assign(new Error('boom'), {
handler: { notifyIf: notifyIfHandler },
})
const fetchAll = vi.fn(() => Promise.reject(apiError))
FieldService.mockReturnValue({ fetchAll })
const { wrapper, show } = await mountItem()
await wrapper.find('a').trigger('click')
await flushPromises()
// The error is surfaced, the modal never opens, but the menu still closes.
expect(notifyIfHandler).toHaveBeenCalled()
expect(show).not.toHaveBeenCalled()
expect(wrapper.emitted('click')).toBeTruthy()
})
test('does nothing when disabled', async () => {
const fetchAll = mockFetchAll()
const { wrapper, show } = await mountItem({ disabled: true })
await wrapper.find('a').trigger('click')
await flushPromises()
expect(fetchAll).not.toHaveBeenCalled()
expect(show).not.toHaveBeenCalled()
})
test('blocks re-entry while a fetch is already in progress', async () => {
const fetchAll = mockFetchAll()
const { wrapper } = await mountItem()
const link = wrapper.find('a')
// Fire both clicks synchronously, before the resolved fetchAll promise's
// continuation (which flips loading back off) gets to run as a microtask.
link.trigger('click')
link.trigger('click')
await flushPromises()
expect(fetchAll).toHaveBeenCalledTimes(1)
})
})