Files
baserow/web-frontend/test/unit/builder/components/event/Event.spec.js
Tsering PaljorandJeremie Pardou 250748c8dc feat: Workspace level integrations (#6547)
* Add ADR-013 for workspace level integrations

* Add implementation

* Improve context section and remove technical points

* Move bulk replacement point to v2

* Remove workspace-level ownership on import since manual promotion should handle this.

* Add a glossary section

* Do Lazy creation + Celery migration

* Remove demotion

* Tighten the Options considered section

* Add Decision describing where the integrations are managed

* Update implementation plan after changes to ADR

* Sync plan and adr

* Rename adr and implementation

* Add the shared application that owns workspace integrations

* Create the shared application of every workspace

* Let only workspace admins manage workspace integrations

* Let applications use the integrations of their workspace.

* Trash workspace integrations in their workspace.

* Copy workspace integrations into exports and keep them in duplicates.

* Workspace admins can share integrations with every application in the workspace.

* Load the shared application of each workspace in the frontend and keep it out of application lists.

* Manage workspace integrations from an Integrations page in workspace settings.

* Offer workspace integrations in the integration dropdowns of every application.

* Move promoted integrations to the workspace list in other open tabs.

* Let admins make an app's integration available to the whole workspace from its integration settings.

* Preselect a workspace integration for new nodes and data sources when the app has none of its own.

* fix tests

* Delete implementation file

* More fixes after rebase

* Fix tests

* Let builders of an application see and use the workspace integrations from it.

* Show the workspace integrations, read-only, in the integration settings of applications.

* Keep a dashboard's integration out of promotion to the workspace.

* Leave the shared applications out of the admin dashboard's application count.

* Create the shared application of the workspaces made by the fill commands.

* Say in the promotion modal that an integration nobody authorized will run as the promoting admin.

* Say in the promotion modal that undoing it won't make the integration run as the previous person again.

* Ignore integration ids in sample data when publishing copies the workspace integrations an app uses.

* Let only undoing a promotion move an integration out of the workspace.

* Let the shared application backfill stop itself after 5 minutes and skip workspaces another transaction has locked.

* Say in the workspace integrations settings that published applications and workflows keep their own copy until they're published again.

* Leave the shared application out of the assistant evals' application counts.

* Refresh the workspace integrations when the Builder's data, events, users and integrations panels open.

* Say that anything new using a promoted integration blocks undoing the promotion, even from its own application.

* Warn when a database button sends through a workspace integration with no host or token.

* Refuse roles and invitations on the shared application.

* Fix tests

* Show an application only the workspace integrations of types it can use.

* Say in the promotion modal what builders of other applications can do as the integration.

* Leave the shared application type out of the API docs for creating and updating applications.

* Check who receives a workspace integration event in one permission call.

* Say which workspaces have a shared application and who creates it.

* Let a redone promotion record what uses the integration again.

* Update docstrings

* Stop template visitors from listing the integrations of the template's workspace.

* Let database buttons find their own copy of a workspace integration after an import.

* Say what holds the workspace row lock while a shared application is created.

* Fix tests

* Stop the workspace integration form component from being made reactive.

* Make test runs use a new copy of the workflow after an integration it uses changes.

* Hide the Members settings tab from members who can't list the workspace members.

* Add changelog

* Fix migration conflict

* Fix migration conflict

* Fix test

* Update comments and ADR number

* Link to the workspace integrations from the sidebar's Settings menu.

* fix: refresh agent action errors when workspace integrations change

* fix: move workspace integrations into workspace settings

* fix: use share icon for workspace integration promotion

* refactor: use explicit shared application relations

* feat: centralize default integration selection

* refactor: share integration change notifications

* refactor: prepare integration mappings before import

* refactor: collect integration references during export

* refactor: prepare integration ownership changes without a new hook

* test: restore registered service model after mocking

* test: cover shared integration defaults in Builder

* test: include Slack in Agent workspace integration choices

* Fix migrations

* Stop template visitors from listing the workspace integrations through an application of the template.

* Only offer integrations of the user source's integration type when updating a user source.

* Say the workspace integration copy means published Application Builder apps and automation workflows.

* Use the same spacing under both integration settings sections and enlarge their headings.

* Keep the shared application out of automatic snapshot schedules.

* Fix test after rebase

---------

Co-authored-by: Jeremie Pardou <571533+jrmi@users.noreply.github.com>
2026-11-27 15:49:32 +04:00

329 lines
9.3 KiB
JavaScript

import { defineComponent } from 'vue'
import { flushPromises } from '@vue/test-utils'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import { vi } from 'vitest'
import '@baserow/modules/builder/enums'
import EventComponent from '@baserow/modules/builder/components/event/Event'
import { Event as BuilderEvent } from '@baserow/modules/builder/eventTypes'
import ApplicationBuilderFormulaInput from '@baserow/modules/builder/components/ApplicationBuilderFormulaInput.vue'
import FormulaInputField from '@baserow/modules/core/components/formula/FormulaInputField.vue'
import { DATA_SCOPES } from '@baserow/modules/builder/constants'
const ContextStub = defineComponent({
name: 'Context',
methods: {
show() {},
hide() {},
},
template: '<div><slot /></div>',
})
const ButtonTextStub = defineComponent({
name: 'ButtonText',
template: '<button><slot /></button>',
})
const coreGroup = {
id: 'core',
label: 'Core',
icon: 'iconoir-package',
}
const workflowActionType = {
label: 'Show Notification',
description: 'Show a notification message to the user.',
icon: 'iconoir-chat-bubble-empty',
image: null,
group: coreGroup,
getType: () => 'notification',
isDeactivated: () => false,
isDeactivatedReason: () => null,
getDeactivatedClickModal: () => null,
}
const localBaserowGroup = {
id: 'integration-local_baserow',
label: 'Local Baserow',
image: '/local-baserow.svg',
icon: null,
}
const createRowWorkflowActionType = {
label: 'Create row',
description: 'Add a new record to a table.',
icon: 'iconoir-plus',
image: null,
group: localBaserowGroup,
getType: () => 'create_row',
isDeactivated: () => false,
isDeactivatedReason: () => null,
getDeactivatedClickModal: () => null,
}
describe('Event', () => {
test.each([false, true])(
'a table button action formula offers row fields when using a property: %s',
async (usesProperty) => {
const app = useNuxtApp()
const parent = {
id: 2,
page_id: 2,
type: 'repeat',
data_source_id: 5,
schema_property: null,
}
const element = {
id: 3,
page_id: 2,
type: 'table',
data_source_id: usesProperty ? null : 5,
schema_property: usesProperty ? 'rows' : null,
fields: [{ id: 1, uid: 'button-1', type: 'button', name: 'Notify' }],
}
const page = {
id: 2,
_: { dataSourceLoading: false, dataSourceContentLoading: false },
workflowActions: [],
dataSources: [
{
id: 5,
type: 'local_baserow_list_rows',
table_id: 1,
schema: {
type: 'array',
items: {
type: 'object',
properties: usesProperty
? {
parentName: { type: 'string' },
rows: {
type: 'array',
items: {
type: 'object',
properties: { cellName: { type: 'string' } },
},
},
}
: { field_1: { type: 'string', title: 'Name' } },
},
},
},
],
graph: usesProperty
? { 0: 2, 2: { children: { '': [3] } }, 3: {} }
: { 0: 3, 3: {} },
}
const builder = {
id: 1,
pages: [{ id: 1, shared: true, dataSources: [], graph: {} }, page],
theme: {},
}
app.$store.commit('element/SET_ITEMS', {
builder,
page,
elements: usesProperty ? [parent, element] : [element],
})
const tableType = app.$registry.get('element', 'table')
const event = tableType.getEvents(element)[0]
const workflowAction = {
id: 10,
type: 'notification',
title: { formula: '' },
description: { formula: '' },
}
const wrapper = await mountSuspended(EventComponent, {
props: {
event,
element,
applicationContextAdditions: event.applicationContextAdditions,
workflowActions: [workflowAction],
availableWorkflowActionTypes: [
app.$registry.get('workflowAction', 'notification'),
],
},
global: {
provide: {
applicationContext: {
builder,
page,
element,
mode: 'editing',
dataScope: DATA_SCOPES.EXCLUDE_TARGET_SUBTREE,
},
builder,
elementPage: page,
workspace: { id: 1 },
mode: 'editing',
formulaComponent: ApplicationBuilderFormulaInput,
dataProvidersAllowed: ['current_record'],
},
stubs: {
Context: ContextStub,
SidebarExpandable: {
template: '<div><slot name="title" /><slot /></div>',
},
},
mocks: {
$store: { dispatch: vi.fn().mockResolvedValue({}), getters: {} },
},
},
})
await flushPromises()
const titleInput = wrapper.findComponent(FormulaInputField)
const currentRecord = titleInput
.props('nodesHierarchy')
.flatMap((group) => group.nodes || [])
.find((node) => node.identifier === 'current_record')
const fields = currentRecord.nodes.map((node) => node.identifier)
expect(fields).toContain(usesProperty ? 'cellName' : 'field_1')
if (usesProperty) {
expect(fields).not.toContain('parentName')
}
wrapper.unmount()
}
)
test('fetches every integration the builder can use when it mounts', async () => {
// The workspace ones too, so a row action offers the tables as they are
// now: no realtime event about the integration tells the store.
const builder = { id: 1 }
const elementPage = { id: 2 }
const workspace = { id: 4 }
const store = {
dispatch: vi.fn().mockResolvedValue({}),
getters: {},
}
await mountSuspended(EventComponent, {
props: {
event: new BuilderEvent({ app: {}, name: 'click', label: 'Click' }),
element: { id: 3 },
workflowActions: [],
availableWorkflowActionTypes: [workflowActionType],
},
global: {
provide: {
applicationContext: { builder, page: elementPage, workspace },
builder,
elementPage,
workspace,
},
directives: {
autoOverflowScroll: {},
tooltip: {},
},
stubs: {
ButtonText: ButtonTextStub,
Context: ContextStub,
},
mocks: {
$store: store,
$t: (key) => key,
},
},
})
await flushPromises()
expect(store.dispatch).toHaveBeenCalledWith('integration/fetchUsable', {
application: builder,
})
expect(store.dispatch).not.toHaveBeenCalledWith(
'integration/fetch',
expect.anything()
)
})
test('creates a workflow action selected from the shared menu', async () => {
const builder = { id: 1 }
const elementPage = { id: 2 }
const element = { id: 3 }
const workspace = { id: 4 }
const store = {
dispatch: vi.fn().mockResolvedValue({}),
getters: {},
}
const event = new BuilderEvent({
app: {},
name: 'click',
label: 'Click',
})
const wrapper = await mountSuspended(EventComponent, {
props: {
event,
element,
workflowActions: [],
availableWorkflowActionTypes: [
workflowActionType,
createRowWorkflowActionType,
],
},
global: {
provide: {
applicationContext: { builder, page: elementPage, workspace },
builder,
elementPage,
workspace,
},
directives: {
autoOverflowScroll: {},
tooltip: {},
},
stubs: {
ButtonText: ButtonTextStub,
Context: ContextStub,
},
mocks: {
$store: store,
$t: (key) => key,
},
},
})
await flushPromises()
expect(
wrapper
.findAll('.grouped-menu__navigation .menu-list__item-label')
.map((item) => item.text())
).toEqual(['Core', 'Local Baserow'])
expect(
wrapper
.findAll('.grouped-menu__actions .menu-list__item-label')
.map((item) => item.text())
).toEqual(['Show Notification'])
expect(
wrapper
.findAll('.grouped-menu__actions .menu-list__item-description')
.map((item) => item.text())
).toEqual(['Show a notification message to the user.'])
await wrapper
.findAll('.grouped-menu__navigation .menu-list__item-button')
.find((item) => item.text().includes('Local Baserow'))
.trigger('click')
expect(
wrapper.find('.grouped-menu__actions .menu-list__item-description').text()
).toBe('Add a new record to a table.')
await wrapper
.findAll('.grouped-menu__actions .menu-list__item-button')
.find((item) => item.text().includes('Create row'))
.trigger('click')
await flushPromises()
expect(store.dispatch).toHaveBeenCalledWith(
'builderWorkflowAction/create',
{
page: elementPage,
workflowActionType: 'create_row',
eventType: 'click',
configuration: { element_id: element.id },
}
)
})
})