mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 16:28:31 +00:00
* fix(database): open new-tab URL buttons in Safari Safari blocks window.open once the dispatch request has returned, so the button opens the tab on click and the Open URL action navigates it. * fix(database): take opens_new_tab from the field after saving actions The action list is stale when refreshing it fails. * test(database): match button flags by label, not list order * fix(database): leave no empty tab for mailto and tel button URLs Such URLs hand off to another app, so they navigate the current page and the placeholder tab is closed. Covers opens_new_tab in the broadcast test.
96 lines
2.9 KiB
JavaScript
96 lines
2.9 KiB
JavaScript
import { vi } from 'vitest'
|
|
import { TestApp } from '@baserow/test/helpers/testApp'
|
|
import FunctionalGridViewFieldButtonField from '@baserow/modules/database/components/view/grid/fields/FunctionalGridViewFieldButtonField'
|
|
|
|
describe('FunctionalGridViewFieldButtonField', () => {
|
|
let testApp = null
|
|
let openUrlType = null
|
|
|
|
beforeAll(() => {
|
|
testApp = new TestApp()
|
|
openUrlType = testApp._app.$registry.get(
|
|
'databaseWorkflowActionType',
|
|
'open_url'
|
|
)
|
|
})
|
|
|
|
afterEach(() => {
|
|
testApp.afterEach()
|
|
vi.restoreAllMocks()
|
|
})
|
|
|
|
const field = {
|
|
id: 2,
|
|
type: 'button',
|
|
label: 'Open',
|
|
has_workflow_actions: true,
|
|
}
|
|
|
|
const mountCell = async (props = {}, responseData = {}) => {
|
|
const wrapper = await testApp.mount(FunctionalGridViewFieldButtonField, {
|
|
propsData: {
|
|
field,
|
|
value: null,
|
|
row: { id: 1, field_1: 'ada' },
|
|
...props,
|
|
},
|
|
})
|
|
wrapper.vm.$client.post = vi.fn().mockResolvedValue({
|
|
data: { results: [], client_actions: [], ...responseData },
|
|
})
|
|
return wrapper
|
|
}
|
|
|
|
test('a field without actions renders a disabled button and no link', async () => {
|
|
const wrapper = await mountCell({
|
|
field: { ...field, has_workflow_actions: false },
|
|
})
|
|
|
|
expect(wrapper.find('a').exists()).toBe(false)
|
|
expect(wrapper.find('button').attributes('disabled')).toBeDefined()
|
|
expect(wrapper.find('button').text()).toBe('Open')
|
|
})
|
|
|
|
test('a field that needs reconfiguring renders a disabled button with a warning', async () => {
|
|
const wrapper = await mountCell({
|
|
field: { ...field, requires_reconfiguration: true },
|
|
})
|
|
|
|
const button = wrapper.find('button')
|
|
expect(button.attributes('disabled')).toBeDefined()
|
|
expect(wrapper.find('.iconoir-warning-triangle').exists()).toBe(true)
|
|
// Nothing in between, or the button's max width shrinks with the label.
|
|
expect(wrapper.find('.grid-field-button > button').exists()).toBe(true)
|
|
|
|
await button.trigger('click')
|
|
|
|
expect(wrapper.vm.$client.post).not.toHaveBeenCalled()
|
|
})
|
|
|
|
test('resolves the client action fields from the field store', async () => {
|
|
const storeFields = [{ id: 1, type: 'text', name: 'Slug' }, field]
|
|
testApp.store.commit('field/SET_ITEMS', storeFields)
|
|
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
|
|
const action = {
|
|
id: 1,
|
|
type: 'open_url',
|
|
url: { formula: "'https://example.com'", mode: 'simple', version: 1 },
|
|
target: 'blank',
|
|
}
|
|
const wrapper = await mountCell({}, { client_actions: [action] })
|
|
|
|
await wrapper.find('button').trigger('click')
|
|
await wrapper.vm.$nextTick()
|
|
|
|
expect(execute).toHaveBeenCalledWith({
|
|
workflowAction: action,
|
|
applicationContext: {
|
|
row: { id: 1, field_1: 'ada' },
|
|
fields: storeFields,
|
|
previousActionResults: {},
|
|
newTab: null,
|
|
},
|
|
})
|
|
})
|
|
})
|