Skip to content

Commit

Permalink
[UiActions] Don't throw an error if there are no compatible actions t…
Browse files Browse the repository at this point in the history
…o execute (#78917)
  • Loading branch information
Dosant authored Sep 30, 2020
1 parent eebe4ad commit 6771279
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { openContextMenu } from '../context_menu';
import { uiActionsPluginMock } from '../mocks';
import { Trigger } from '../triggers';
import { TriggerId, ActionType } from '../types';
import { wait } from '@testing-library/dom';
import { waitFor } from '@testing-library/dom';

jest.mock('../context_menu');

Expand Down Expand Up @@ -85,7 +85,7 @@ test('executes a single action mapped to a trigger', async () => {
expect(executeFn).toBeCalledWith(expect.objectContaining(context));
});

test('throws an error if there are no compatible actions to execute', async () => {
test("doesn't throw an error if there are no compatible actions to execute", async () => {
const { setup, doStart } = uiActions;
const trigger: Trigger = {
id: 'MY-TRIGGER' as TriggerId,
Expand All @@ -98,9 +98,7 @@ test('throws an error if there are no compatible actions to execute', async () =
const start = doStart();
await expect(
start.executeTriggerActions('MY-TRIGGER' as TriggerId, context)
).rejects.toMatchObject(
new Error('No compatible actions found to execute for trigger [triggerId = MY-TRIGGER].')
);
).resolves.toBeUndefined();
});

test('does not execute an incompatible action', async () => {
Expand Down Expand Up @@ -149,7 +147,7 @@ test('shows a context menu when more than one action is mapped to a trigger', as

jest.runAllTimers();

await wait(() => {
await waitFor(() => {
expect(executeFn).toBeCalledTimes(0);
expect(openContextMenu).toHaveBeenCalledTimes(1);
});
Expand Down Expand Up @@ -197,7 +195,7 @@ test("doesn't show a context menu for auto executable actions", async () => {

jest.runAllTimers();

await wait(() => {
await waitFor(() => {
expect(executeFn).toBeCalledTimes(2);
expect(openContextMenu).toHaveBeenCalledTimes(0);
});
Expand Down
6 changes: 0 additions & 6 deletions src/plugins/ui_actions/public/triggers/trigger_internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ export class TriggerInternal<T extends TriggerId> {
const triggerId = this.trigger.id;
const actions = await this.service.getTriggerCompatibleActions!(triggerId, context);

if (!actions.length) {
throw new Error(
`No compatible actions found to execute for trigger [triggerId = ${triggerId}].`
);
}

await Promise.all([
actions.map((action) =>
this.service.executionService.execute({
Expand Down

0 comments on commit 6771279

Please sign in to comment.