Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UiActions] Don't throw an error if there are no compatible actions to execute #78917

Merged
merged 1 commit into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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