From dea2e082818fa247d6639345699b7b980d3367e2 Mon Sep 17 00:00:00 2001 From: Vadim Dalecky Date: Mon, 19 Aug 2019 14:31:32 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20pass=20whole=20action=20c?= =?UTF-8?q?ontext=20to=20isCompatible()=20method=20(#43457)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: 🐛 pass whole action context to isCompatible() method * test: 💍 add function test for saved search filtering in pie * test: 💍 move save search functional test in its own test suite --- .../public/api/execute_trigger_actions.ts | 4 +-- .../tests/execute_trigger_actions.test.ts | 27 +++++++++++++++++++ .../apps/dashboard/dashboard_filter_bar.js | 18 +++++++++++++ .../services/visualizations/pie_chart.js | 6 +++++ 4 files changed, 52 insertions(+), 3 deletions(-) diff --git a/src/legacy/core_plugins/embeddable_api/public/np_ready/public/api/execute_trigger_actions.ts b/src/legacy/core_plugins/embeddable_api/public/np_ready/public/api/execute_trigger_actions.ts index 75d6b2597cf8d..5c6216fb629ac 100644 --- a/src/legacy/core_plugins/embeddable_api/public/np_ready/public/api/execute_trigger_actions.ts +++ b/src/legacy/core_plugins/embeddable_api/public/np_ready/public/api/execute_trigger_actions.ts @@ -35,9 +35,7 @@ const executeSingleAction = async (action: Action, actionContext: ActionContext) export const executeTriggerActions: EmbeddableApiPure['executeTriggerActions'] = ({ api, }) => async (triggerId, actionContext) => { - const actions = await api.getTriggerCompatibleActions!(triggerId, { - embeddable: actionContext.embeddable, - }); + const actions = await api.getTriggerCompatibleActions!(triggerId, actionContext); if (!actions.length) { throw new Error( diff --git a/src/legacy/core_plugins/embeddable_api/public/np_ready/public/tests/execute_trigger_actions.test.ts b/src/legacy/core_plugins/embeddable_api/public/np_ready/public/tests/execute_trigger_actions.test.ts index 55fe13db0a29e..a2406a548b0cb 100644 --- a/src/legacy/core_plugins/embeddable_api/public/np_ready/public/tests/execute_trigger_actions.test.ts +++ b/src/legacy/core_plugins/embeddable_api/public/np_ready/public/tests/execute_trigger_actions.test.ts @@ -179,3 +179,30 @@ test('shows a context menu when more than one action is mapped to a trigger', as expect(executeFn).toBeCalledTimes(0); expect(openContextMenu).toHaveBeenCalledTimes(1); }); + +test('passes whole action context to isCompatible()', async () => { + const { setup, doStart } = embeddables; + const trigger = { + id: 'MY-TRIGGER', + title: 'My trigger', + actionIds: ['test'], + }; + const action = new TestAction('test', ({ triggerContext }) => { + expect(triggerContext).toEqual({ + foo: 'bar', + }); + return true; + }); + + setup.registerTrigger(trigger); + setup.registerAction(action); + const start = doStart(); + + const context = { + embeddable: {} as any, + triggerContext: { + foo: 'bar', + }, + }; + await start.executeTriggerActions('MY-TRIGGER', context); +}); diff --git a/test/functional/apps/dashboard/dashboard_filter_bar.js b/test/functional/apps/dashboard/dashboard_filter_bar.js index 7b85c55e17ef2..312066000c63c 100644 --- a/test/functional/apps/dashboard/dashboard_filter_bar.js +++ b/test/functional/apps/dashboard/dashboard_filter_bar.js @@ -124,5 +124,23 @@ export default function ({ getService, getPageObjects }) { await pieChart.expectPieSliceCount(1); }); }); + + describe('saved search filtering', function () { + before(async () => { + await filterBar.ensureFieldEditorModalIsClosed(); + await PageObjects.dashboard.gotoDashboardLandingPage(); + await PageObjects.dashboard.clickNewDashboard(); + await PageObjects.dashboard.setTimepickerInDataRange(); + }); + + it('are added when pie chart legend item is clicked', async function () { + await dashboardAddPanel.addVisualization('Rendering Test: pie'); + await PageObjects.dashboard.waitForRenderComplete(); + await pieChart.filterByLegendItem('4,886'); + + const filterCount = await filterBar.getFilterCount(); + expect(filterCount).to.equal(1); + }); + }); }); } diff --git a/test/functional/services/visualizations/pie_chart.js b/test/functional/services/visualizations/pie_chart.js index 362f46e37ac59..ffe033df299f0 100644 --- a/test/functional/services/visualizations/pie_chart.js +++ b/test/functional/services/visualizations/pie_chart.js @@ -44,6 +44,12 @@ export function PieChartProvider({ getService }) { } } + async filterByLegendItem(label) { + log.debug(`PieChart.filterByLegendItem(${label})`); + await testSubjects.click(`legend-${label}`); + await testSubjects.click(`legend-${label}-filterIn`); + } + async getPieSlice(name) { return await testSubjects.find(`pieSlice-${name.split(' ').join('-')}`); }