Files
alamin-br 2dd4defb3b feat(database): run a button click with external actions as a job (#6164)
* fix: keep every button action card in place after a save

A retyped action can keep its id, and an action created by an earlier
save still carries its client id, so the refetched list must keep the
client id of every buffered action rather than only the created ones.

* feat(jobs): let a job type choose its Celery queue

* test: assert the job enqueue through apply_async

* refactor(database): expose the button click pre-checks on the service

* refactor(database): share the button click payload and outcome mapping

* feat(database): run a button click with external actions as a job

* fix(database): map click races on the job and assert the audit entry

* feat(database): answer a click with external actions with a job

The request returns 202 and the job runs the sequence, so a slow endpoint
holds a Celery worker instead of a WSGI one.

* fix(database): give a capped click its slots back and cover the denied job

* refactor(database): raise a plain exception for a denied click job

* chore: consume the button_dispatch queue on the default worker

* chore: add the button_dispatch queue to the Zed worker launch config

* feat(database): wait on the job of an accepted button click

* fix(database): stop waiting on a button click job after a deadline

* test(e2e): a slow endpoint no longer blocks the grid during a click

* test(e2e): name the second-button test for what a single worker can prove

* test: assert the airtable import job enqueue through apply_async

* chore: changelog for the button dispatch job

* fix(database): keep the clicker's IP and session on a button click job

The audit log and analytics read both from the user, which the job only restores through these mixins.

* fix(database): fail a button click job whose field or table was trashed

* fix(database): serialize the busy check of a click with its job creation

Two racing requests could both see the cell free and each start a job, so a single worker sent every request twice.

Also drops the budget bookkeeping from the inline path, which no longer reaches outside Baserow.

* test: assert a refused dispatch check records no audit entry

* docs: say a button click job shares the default worker with realtime updates

Also adds the automation_workflow and button_dispatch queues to the example supervisor config.

* fix(database): check a button click job once more at the deadline

The job store stops polling before the deadline, so a job that finished unseen was reported as still running.

* test: cover an accepted click in the row modal and on a card

* refactor(database): ask the service whether a cell has a click in flight

The view queried the job table itself; the check belongs beside the
other dispatch rules in the service.

* fix(database): run only the action list a click was accepted with

The request checks and charges one list; the job re-read the field's
current one, so an action added while the job waited ran unchecked and
an added external one sent without a rate-limit slot.

* fix(database): keep queued button clicks sane across crashes, retypes and trash

A dead worker's job no longer blocks its cell until cleanup, a retype no longer deletes a queued job, and a trashed database refuses the click.
Core permission refusals use the API's wording. The cell lock is shared and the unused refund plumbing is gone.

* fix(database): stop a queued button click from sending twice or unchecked

A late or replica-blind click no longer repeats its requests, a retype to external is caught, and a quota refusal answers in the request.
Slots come back when no job row was written, and the stored answer is safe for jsonb.

* fix: keep polling a button click job after one failed poll

A click waits on the job store, which stopped for good after a single failed poll. A settled click's job is dropped so the store stops polling it.

* fix(database): stop a cancelled button click between actions

The owner can cancel a running job, and later actions still ran. The last job check at the deadline is bounded too, so a hung request cannot keep the button spinning.

* test: cover a job's answer reaching Open URL and a click edited while queued

* fix(database): let a click job finish when its button is retyped mid-run

The worker's save wrote the old field id back and failed. Timeouts and unmapped failures no longer name the job type, and a job that is already final leaves the store.

* fix(database): run button click jobs on the export queue

Review feedback: the celery queue is for fast tasks, and a new queue needs every self-hosted worker changed.
Also strips lone surrogates from the stored answer, moves the enqueue rules into the service and drops the unused websocket id.

* fix(database): drop a waiting button click on logout or table switch

A job can end minutes after the click, when its toast or Open URL no longer belongs to the page.

* chore: drop the changelog entry for #6134

The button field has not shipped yet, so there is no fix to announce.

* fix(database): point a click job at the base field

A retype deletes the button row, so a job pointing at it had to be
nulled first, and a click landing meanwhile failed the retype.

* fix(database): keep a button spinning for its job after a reload

The spinner only knew about clicks made in this page, so a reload
dropped it while the job ran and a second click got the 409 toast.

* fix(database): ignore a late job_started for a settled button click

On a single worker the broadcast reaches the clicking tab after the job
ended, and its started copy spun the button again until the next poll.

* docs(database): correct the dispatch signal and e2e comments

The signal's first send for a job click happens before the enqueue lock.
2026-09-28 11:13:42 +02:00

669 lines
22 KiB
JavaScript

import { vi } from 'vitest'
import flushPromises from 'flush-promises'
import { TestApp } from '@baserow/test/helpers/testApp'
import GridViewFieldButtonField from '@baserow/modules/database/components/view/grid/fields/GridViewFieldButtonField'
import {
DISPATCH_JOB_DEADLINE_MS,
DISPATCH_JOB_LAST_CHECK_MS,
} from '@baserow/modules/database/mixins/buttonField'
describe('GridViewFieldButtonField', () => {
let testApp = null
let openUrlType = null
beforeAll(() => {
testApp = new TestApp()
openUrlType = testApp._app.$registry.get(
'databaseWorkflowActionType',
'open_url'
)
})
afterEach(() => {
testApp.afterEach()
vi.restoreAllMocks()
vi.useRealTimers()
})
const field = {
id: 2,
type: 'button',
label: 'Open',
has_workflow_actions: true,
}
const openUrlAction = {
id: 1,
type: 'open_url',
url: { formula: "'https://example.com'", mode: 'simple', version: 1 },
target: 'blank',
}
const mountCell = async (props = {}, responseData = {}, options = {}) => {
const wrapper = await testApp.mount(GridViewFieldButtonField, {
...options,
propsData: {
field,
value: null,
row: { id: 1, field_1: 'ada' },
allFieldsInTable: [{ id: 1, type: 'text', name: 'Slug' }, field],
selected: false,
readOnly: true,
storePrefix: 'page/',
workspaceId: 1,
...props,
},
})
// Dispatch goes through the real $client instance shared by the test
// app, so replace .post with a fresh mock per mount instead of hitting
// the network mock adapter.
wrapper.vm.$client.post = vi.fn().mockResolvedValue({
status: 200,
data: { results: [], client_actions: [], ...responseData },
})
return wrapper
}
test('a field with actions renders a button and dispatches on click', async () => {
const wrapper = await mountCell()
expect(wrapper.find('button').attributes('disabled')).toBeUndefined()
expect(wrapper.find('button').text()).toBe('Open')
await wrapper.find('button').trigger('click')
expect(wrapper.vm.$client.post).toHaveBeenCalledWith(
`database/field/${field.id}/workflow_actions/dispatch/`,
{ row_id: 1 },
{ omitWebSocketId: true }
)
})
test('the selected cell is outlined like every other field', async () => {
// The grid only mounts this component for the selected cell, and the
// outline comes from the `active` class.
const wrapper = await mountCell({ selected: true })
expect(wrapper.find('.grid-view__cell').classes()).toContain('active')
})
test('a user who may not click gets a disabled button', async () => {
const hasPermission = vi.fn().mockReturnValue(false)
const wrapper = await mountCell(
{ workspaceId: 9 },
{},
{ global: { mocks: { $hasPermission: hasPermission } } }
)
expect(wrapper.find('button').attributes('disabled')).toBeDefined()
// Asked of the field, which is all a cell has, in the field's workspace.
expect(hasPermission).toHaveBeenCalledWith(
'database.table.field.workflow_action.dispatch',
field,
9
)
await wrapper.find('button').trigger('click')
expect(wrapper.vm.$client.post).not.toHaveBeenCalled()
})
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(button.text()).toBe('Open')
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('runs the returned client actions after the response', async () => {
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
const wrapper = await mountCell({}, { client_actions: [openUrlAction] })
await wrapper.find('button').trigger('click')
await wrapper.vm.$nextTick()
expect(execute).toHaveBeenCalledTimes(1)
expect(execute).toHaveBeenCalledWith({
workflowAction: openUrlAction,
applicationContext: {
row: { id: 1, field_1: 'ada' },
fields: [{ id: 1, type: 'text', name: 'Slug' }, field],
previousActionResults: {},
newTab: null,
},
})
})
test('a client action sees the row as it was at click time', async () => {
// The dispatch takes its own realtime broadcast, so a row action can
// update the cell's row while the request is still in flight.
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
const wrapper = await mountCell({}, { client_actions: [openUrlAction] })
wrapper.vm.$client.post = vi.fn().mockImplementation(async () => {
wrapper.vm.row.field_1 = 'updated by an earlier action'
return { data: { results: [], client_actions: [openUrlAction] } }
})
await wrapper.find('button').trigger('click')
await flushPromises()
expect(execute.mock.calls[0][0].applicationContext.row).toEqual({
id: 1,
field_1: 'ada',
})
})
test('runs the client actions in the order the backend returned them', async () => {
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
const second = { ...openUrlAction, id: 2, target: 'self' }
const wrapper = await mountCell(
{},
{ client_actions: [openUrlAction, second] }
)
await wrapper.find('button').trigger('click')
await flushPromises()
expect(execute.mock.calls.map((call) => call[0].workflowAction.id)).toEqual(
[1, 2]
)
})
test('a client action that could not run stops the ones after it', async () => {
// The real `execute` here, not a mock: a refused URL has to report itself
// as not run, or the action after it navigates away and takes the message
// with it.
const open = vi.spyOn(window, 'open').mockImplementation(() => null)
const refused = {
...openUrlAction,
url: { formula: "'javascript:alert(1)'", mode: 'simple', version: 1 },
}
const second = { ...openUrlAction, id: 2 }
const wrapper = await mountCell({}, { client_actions: [refused, second] })
const dispatch = vi.spyOn(testApp.store, 'dispatch')
await wrapper.find('button').trigger('click')
await flushPromises()
expect(dispatch).toHaveBeenCalledWith(
'toast/error',
expect.objectContaining({
title: 'openUrlWorkflowAction.invalidUrlTitle',
})
)
expect(open).not.toHaveBeenCalled()
})
test('waits for a client action to settle before running the next one', async () => {
// `open_url` with target `self` navigates the document away. Firing the
// next action at a navigating page is exactly what awaiting each one
// prevents, so an unawaited loop has to fail here.
let release
const firstSettles = new Promise((resolve) => {
release = resolve
})
const execute = vi
.spyOn(openUrlType, 'execute')
.mockImplementationOnce(() => firstSettles)
.mockResolvedValue()
const second = { ...openUrlAction, id: 2, target: 'self' }
const wrapper = await mountCell(
{},
{ client_actions: [openUrlAction, second] }
)
await wrapper.find('button').trigger('click')
await flushPromises()
expect(execute).toHaveBeenCalledTimes(1)
expect(wrapper.vm.dispatching).toBe(true)
release()
await flushPromises()
expect(execute).toHaveBeenCalledTimes(2)
expect(execute.mock.calls[1][0].workflowAction.id).toBe(2)
expect(wrapper.vm.dispatching).toBe(false)
})
test('a failed dispatch runs no client action and leaves the cell clickable', async () => {
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
const wrapper = await mountCell()
wrapper.vm.$client.post.mockRejectedValueOnce(new Error('nope'))
await wrapper.find('button').trigger('click')
await wrapper.vm.$nextTick()
expect(execute).not.toHaveBeenCalled()
expect(wrapper.vm.dispatching).toBe(false)
})
test('a second cell for the same row shows the dispatch in flight', async () => {
// The grid swaps an unselected cell for its own component on the first
// click, so a flag held by the component that started the request would be
// thrown away by that remount.
let release
const held = new Promise((resolve) => {
release = resolve
})
const first = await mountCell()
const second = await mountCell()
// `$client` is shared by the test app, so the held mock has to go on after
// both mounts or the second one replaces it.
first.vm.$client.post = vi.fn().mockImplementation(async () => {
await held
return { data: { results: [], client_actions: [] } }
})
first.find('button').trigger('click')
await flushPromises()
expect(second.vm.dispatching).toBe(true)
release()
await flushPromises()
expect(second.vm.dispatching).toBe(false)
})
test('a client action that throws leaves the cell clickable', async () => {
vi.spyOn(openUrlType, 'execute').mockRejectedValue(new Error('nope'))
const wrapper = await mountCell({}, { client_actions: [openUrlAction] })
await wrapper.find('button').trigger('click')
await wrapper.vm.$nextTick()
expect(wrapper.vm.dispatching).toBe(false)
})
const acceptedJob = () => ({
id: 7,
type: 'button_field_dispatch',
state: 'pending',
progress_percentage: 0,
human_readable_error: '',
results: null,
client_actions: null,
})
const finishJob = async (wrapper, values) => {
const store = wrapper.vm.$store
const job = store.getters['job/get'](acceptedJob().id)
await store.dispatch('job/forceUpdate', {
job,
data: { ...acceptedJob(), ...values },
})
await flushPromises()
}
test('an accepted click waits on its job and then runs the client actions', async () => {
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
const wrapper = await mountCell()
wrapper.vm.$client.post = vi
.fn()
.mockResolvedValue({ status: 202, data: acceptedJob() })
await wrapper.find('button').trigger('click')
await flushPromises()
// Still waiting: the spinner stays and nothing has run.
expect(wrapper.vm.dispatching).toBe(true)
expect(execute).not.toHaveBeenCalled()
expect(wrapper.vm.$store.getters['job/get'](acceptedJob().id)).toBeTruthy()
await finishJob(wrapper, {
state: 'finished',
results: [
{
workflow_action_id: 3,
order: 1,
position: 1,
status: 'completed',
data: { id: 99 },
field_names: {},
},
],
client_actions: [{ ...openUrlAction, position: 2 }],
})
expect(wrapper.vm.dispatching).toBe(false)
expect(execute).toHaveBeenCalledTimes(1)
expect(
execute.mock.calls[0][0].applicationContext.previousActionResults
).toEqual({
3: { data: { id: 99 }, fieldNames: {}, order: 1, position: 1 },
})
// Settled, so the store no longer polls it.
expect(wrapper.vm.$store.getters['job/get'](acceptedJob().id)).toBeFalsy()
})
test('a failed job shows its message and clears the spinner', async () => {
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
const wrapper = await mountCell()
wrapper.vm.$client.post = vi
.fn()
.mockResolvedValue({ status: 202, data: acceptedJob() })
const toast = vi.spyOn(wrapper.vm.$store, 'dispatch')
await wrapper.find('button').trigger('click')
await flushPromises()
await finishJob(wrapper, {
state: 'failed',
error_code: 'WorkflowActionDispatchError',
human_readable_error:
'Action 1 ran before action 2 failed: No table selected',
})
expect(wrapper.vm.dispatching).toBe(false)
expect(execute).not.toHaveBeenCalled()
expect(toast).toHaveBeenCalledWith('toast/error', {
title: 'buttonField.dispatchErrorTitle',
message: 'Action 1 ran before action 2 failed: No table selected',
})
})
test('a failure the job type did not map shows the generic message', async () => {
const wrapper = await mountCell()
wrapper.vm.$client.post = vi
.fn()
.mockResolvedValue({ status: 202, data: acceptedJob() })
const toast = vi.spyOn(wrapper.vm.$store, 'dispatch')
await wrapper.find('button').trigger('click')
await flushPromises()
await finishJob(wrapper, {
state: 'failed',
error_code: '',
human_readable_error:
'Something went wrong during the button_field_dispatch job execution.',
})
expect(toast).toHaveBeenCalledWith('toast/error', {
title: 'buttonField.dispatchErrorTitle',
message: 'buttonField.dispatchErrorMessage',
})
})
test('a job that ends after another table was opened runs no client actions', async () => {
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
const wrapper = await mountCell()
wrapper.vm.$client.post = vi
.fn()
.mockResolvedValue({ status: 202, data: acceptedJob() })
const tableState = wrapper.vm.$store.state.table
const selectedBefore = tableState.selected
await wrapper.find('button').trigger('click')
await flushPromises()
tableState.selected = { id: 42 }
try {
await finishJob(wrapper, {
state: 'finished',
results: [],
client_actions: [openUrlAction],
})
} finally {
tableState.selected = selectedBefore
}
expect(execute).not.toHaveBeenCalled()
expect(wrapper.vm.dispatching).toBe(false)
})
test('logging out while the job runs stops the spinner without a toast', async () => {
const wrapper = await mountCell()
wrapper.vm.$client.post = vi
.fn()
.mockResolvedValue({ status: 202, data: acceptedJob() })
const toast = vi.spyOn(wrapper.vm.$store, 'dispatch')
await wrapper.find('button').trigger('click')
await flushPromises()
await wrapper.vm.$store.dispatch('job/clearAll')
await flushPromises()
expect(wrapper.vm.dispatching).toBe(false)
expect(toast).not.toHaveBeenCalledWith('toast/error', expect.anything())
})
test('the spinner survives a remount while the job polls', async () => {
const wrapper = await mountCell()
wrapper.vm.$client.post = vi
.fn()
.mockResolvedValue({ status: 202, data: acceptedJob() })
await wrapper.find('button').trigger('click')
await flushPromises()
// The grid swaps the cell component on selection; the flag is keyed by
// field and row outside the component, so the new one still spins.
const remounted = await mountCell({ selected: true })
expect(remounted.vm.dispatching).toBe(true)
await finishJob(wrapper, {
state: 'finished',
results: [],
client_actions: [],
})
expect(remounted.vm.dispatching).toBe(false)
})
// A click's job loaded into the store after a page reload, so no click in
// this page waits on it.
const reloadedJob = (values = {}) => ({
...acceptedJob(),
id: 21,
state: 'started',
field_id: field.id,
row_id: 1,
created_on: new Date().toISOString(),
...values,
})
test('a job still running from before a reload keeps the button spinning', async () => {
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
const wrapper = await mountCell()
const store = wrapper.vm.$store
const toast = vi.spyOn(store, 'dispatch')
await store.dispatch('job/forceCreate', reloadedJob())
await wrapper.vm.$nextTick()
expect(wrapper.vm.dispatching).toBe(true)
expect(wrapper.find('button').attributes('disabled')).toBeDefined()
const job = store.getters['job/get'](21)
await store.dispatch('job/forceUpdate', {
job,
data: reloadedJob({
state: 'finished',
results: [],
client_actions: [openUrlAction],
}),
})
await flushPromises()
expect(wrapper.vm.dispatching).toBe(false)
expect(store.getters['job/get'](21)).toBeFalsy()
// The page it was clicked on is gone: nothing runs and nothing is said.
expect(execute).not.toHaveBeenCalled()
expect(toast).not.toHaveBeenCalledWith('toast/error', expect.anything())
})
test('a job from before a reload past the deadline neither spins nor stays', async () => {
const wrapper = await mountCell()
const store = wrapper.vm.$store
const stale = reloadedJob({
created_on: new Date(
Date.now() - DISPATCH_JOB_DEADLINE_MS - 1000
).toISOString(),
})
await store.dispatch('job/forceCreate', stale)
await wrapper.vm.$nextTick()
expect(wrapper.vm.dispatching).toBe(false)
expect(wrapper.find('button').attributes('disabled')).toBeUndefined()
// The next poll drops it, so the store stops polling it.
await store.dispatch('job/forceUpdate', { job: stale, data: stale })
await flushPromises()
expect(store.getters['job/get'](21)).toBeFalsy()
})
test('a job from before a reload on another row leaves this button alone', async () => {
const wrapper = await mountCell()
await wrapper.vm.$store.dispatch(
'job/forceCreate',
reloadedJob({ row_id: 2 })
)
await wrapper.vm.$nextTick()
expect(wrapper.vm.dispatching).toBe(false)
})
test('a late job_started for a click that already ended does not spin the button', async () => {
const wrapper = await mountCell()
const job = reloadedJob({ id: 22, state: 'pending' })
wrapper.vm.$client.post = vi
.fn()
.mockResolvedValue({ status: 202, data: job })
await wrapper.find('button').trigger('click')
await flushPromises()
const store = wrapper.vm.$store
await store.dispatch('job/forceUpdate', {
job: store.getters['job/get'](22),
data: { ...job, state: 'finished', results: [], client_actions: [] },
})
await flushPromises()
// The broadcast of the job's start, reaching this tab only now.
await store.dispatch('job/create', { ...job, state: 'started' })
await wrapper.vm.$nextTick()
expect(wrapper.vm.dispatching).toBe(false)
expect(wrapper.find('button').attributes('disabled')).toBeUndefined()
})
// Answers the one fetch of the click's job the deadline makes, and leaves
// every other request, the job store's own polls included, to the client.
const answerJobFetch = (wrapper, job) => {
const client = wrapper.vm.$client
const originalGet = client.get
const get = vi.fn((url, ...args) =>
url === `/jobs/${acceptedJob().id}/`
? Promise.resolve({ data: job })
: originalGet.call(client, url, ...args)
)
client.get = get
return get
}
test('a click gives up on a job that never reaches a final state', async () => {
// Only the timer the deadline itself uses is faked, so the promise
// machinery the dispatch, the store and `flushPromises` all rely on
// keeps working as normal.
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
const wrapper = await mountCell()
wrapper.vm.$client.post = vi
.fn()
.mockResolvedValue({ status: 202, data: acceptedJob() })
const get = answerJobFetch(wrapper, acceptedJob())
const toast = vi.spyOn(wrapper.vm.$store, 'dispatch')
await wrapper.find('button').trigger('click')
await flushPromises()
expect(wrapper.vm.dispatching).toBe(true)
await vi.advanceTimersByTimeAsync(DISPATCH_JOB_DEADLINE_MS + 1)
await flushPromises()
expect(get).toHaveBeenCalledWith(`/jobs/${acceptedJob().id}/`)
expect(wrapper.vm.dispatching).toBe(false)
expect(execute).not.toHaveBeenCalled()
expect(toast).toHaveBeenCalledWith('toast/error', {
title: 'buttonField.stillRunningTitle',
message: 'buttonField.stillRunningMessage',
})
})
test('a job the poller stopped watching still runs its client actions if it finished by the deadline', async () => {
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
const execute = vi.spyOn(openUrlType, 'execute').mockResolvedValue()
const wrapper = await mountCell()
wrapper.vm.$client.post = vi
.fn()
.mockResolvedValue({ status: 202, data: acceptedJob() })
answerJobFetch(wrapper, {
...acceptedJob(),
state: 'finished',
results: [],
client_actions: [openUrlAction],
})
const toast = vi.spyOn(wrapper.vm.$store, 'dispatch')
await wrapper.find('button').trigger('click')
await flushPromises()
await vi.advanceTimersByTimeAsync(DISPATCH_JOB_DEADLINE_MS + 1)
await flushPromises()
expect(wrapper.vm.dispatching).toBe(false)
expect(execute).toHaveBeenCalledTimes(1)
expect(toast).not.toHaveBeenCalledWith('toast/error', expect.anything())
})
test('a last check that never answers still clears the spinner', async () => {
vi.useFakeTimers({ toFake: ['setTimeout', 'clearTimeout'] })
const wrapper = await mountCell()
wrapper.vm.$client.post = vi
.fn()
.mockResolvedValue({ status: 202, data: acceptedJob() })
const client = wrapper.vm.$client
const originalGet = client.get
client.get = vi.fn((url, ...args) =>
url === `/jobs/${acceptedJob().id}/`
? new Promise(() => {})
: originalGet.call(client, url, ...args)
)
const toast = vi.spyOn(wrapper.vm.$store, 'dispatch')
await wrapper.find('button').trigger('click')
await flushPromises()
await vi.advanceTimersByTimeAsync(DISPATCH_JOB_DEADLINE_MS + 1)
await flushPromises()
expect(wrapper.vm.dispatching).toBe(true)
await vi.advanceTimersByTimeAsync(DISPATCH_JOB_LAST_CHECK_MS + 1)
await flushPromises()
expect(wrapper.vm.dispatching).toBe(false)
expect(toast).toHaveBeenCalledWith('toast/error', {
title: 'buttonField.stillRunningTitle',
message: 'buttonField.stillRunningMessage',
})
})
})