-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Adds in a get-panel-actions csv test
- Loading branch information
Joel Griffith
authored
Jun 18, 2020
1 parent
cedbd70
commit c89d1f0
Showing
2 changed files
with
108 additions
and
1 deletion.
There are no files selected for viewing
107 changes: 107 additions & 0 deletions
107
x-pack/plugins/reporting/public/panel_actions/get_csv_panel_action.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { of } from 'rxjs'; | ||
import { first } from 'rxjs/operators'; | ||
import { LicensingPluginSetup } from '../../../licensing/public'; | ||
import { GetCsvReportPanelAction } from './get_csv_panel_action'; | ||
|
||
type licenseResults = 'valid' | 'invalid' | 'unavailable' | 'expired'; | ||
|
||
describe('GetCsvReportPanelAction', () => { | ||
let core: any; | ||
let context: any; | ||
let mockLicense$: any; | ||
|
||
beforeAll(() => { | ||
if (typeof window.URL.revokeObjectURL === 'undefined') { | ||
Object.defineProperty(window.URL, 'revokeObjectURL', { value: () => {} }); | ||
} | ||
}); | ||
|
||
beforeEach(() => { | ||
mockLicense$ = (state: licenseResults = 'valid') => { | ||
return (of({ | ||
check: jest.fn().mockImplementation(() => ({ state })), | ||
}) as unknown) as LicensingPluginSetup['license$']; | ||
}; | ||
|
||
core = { | ||
http: { | ||
post: jest.fn().mockImplementation(() => Promise.resolve(true)), | ||
}, | ||
notifications: { | ||
toasts: { | ||
addSuccess: jest.fn(), | ||
addDanger: jest.fn(), | ||
}, | ||
}, | ||
uiSettings: { | ||
get: () => 'Browser', | ||
}, | ||
} as any; | ||
|
||
context = { | ||
embeddable: { | ||
type: 'search', | ||
getSavedSearch: () => ({ id: 'lebowski' }), | ||
getTitle: () => `The Dude`, | ||
getInspectorAdapters: () => null, | ||
getInput: () => ({ | ||
viewMode: 'list', | ||
timeRange: { | ||
to: 'now', | ||
from: 'now-7d', | ||
}, | ||
}), | ||
}, | ||
} as any; | ||
}); | ||
|
||
it('allows downloading for valid licenses', async () => { | ||
const panel = new GetCsvReportPanelAction(core, mockLicense$()); | ||
|
||
await panel.execute(context); | ||
|
||
expect(core.http.post).toHaveBeenCalled(); | ||
}); | ||
|
||
it('shows a good old toastie when it successfully starts', async () => { | ||
const panel = new GetCsvReportPanelAction(core, mockLicense$()); | ||
|
||
await panel.execute(context); | ||
|
||
expect(core.notifications.toasts.addSuccess).toHaveBeenCalled(); | ||
expect(core.notifications.toasts.addDanger).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('shows a bad old toastie when it successfully fails', async () => { | ||
const coreFails = { | ||
...core, | ||
http: { | ||
post: jest.fn().mockImplementation(() => Promise.reject('No more ram!')), | ||
}, | ||
}; | ||
const panel = new GetCsvReportPanelAction(coreFails, mockLicense$()); | ||
|
||
await panel.execute(context); | ||
|
||
expect(core.notifications.toasts.addDanger).toHaveBeenCalled(); | ||
}); | ||
|
||
it(`doesn't allow downloads with bad licenses`, async () => { | ||
const licenseMock = mockLicense$('invalid'); | ||
const plugin = new GetCsvReportPanelAction(core, licenseMock); | ||
await licenseMock.pipe(first()).toPromise(); | ||
expect(await plugin.isCompatible(context)).toEqual(false); | ||
}); | ||
|
||
it('sets a display and icon type', () => { | ||
const panel = new GetCsvReportPanelAction(core, mockLicense$()); | ||
expect(panel.getIconType()).toMatchInlineSnapshot(`"document"`); | ||
expect(panel.getDisplayName()).toMatchInlineSnapshot(`"Download CSV"`); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters