Skip to content

Commit

Permalink
Added jest test
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomThomson committed Aug 19, 2020
1 parent ccacce9 commit 57db0d2
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions x-pack/plugins/lens/public/app_plugin/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ describe('Lens App', () => {
originatingApp: string | undefined;
onAppLeave: AppMountParameters['onAppLeave'];
history: History;
getAppNameFromId?: (appId: string) => string | undefined;
}> {
return ({
navigation: navigationStartMock,
Expand Down Expand Up @@ -187,6 +188,7 @@ describe('Lens App', () => {
originatingApp: string | undefined;
onAppLeave: AppMountParameters['onAppLeave'];
history: History;
getAppNameFromId?: (appId: string) => string | undefined;
}>;
}

Expand Down Expand Up @@ -298,6 +300,38 @@ describe('Lens App', () => {
]);
});

it('sets originatingApp breadcrumb when the document title changes', async () => {
const defaultArgs = makeDefaultArgs();
defaultArgs.originatingApp = 'ultraCoolDashboard';
defaultArgs.getAppNameFromId = () => 'The Coolest Container Ever Made';
instance = mount(<App {...defaultArgs} />);

expect(core.chrome.setBreadcrumbs).toHaveBeenCalledWith([
{ text: 'The Coolest Container Ever Made', onClick: expect.anything() },
{ text: 'Visualize', href: '/testbasepath/app/visualize#/', onClick: expect.anything() },
{ text: 'Create' },
]);

(defaultArgs.docStorage.load as jest.Mock).mockResolvedValue({
id: '1234',
title: 'Daaaaaaadaumching!',
expression: 'valid expression',
state: {
query: 'fake query',
datasourceMetaData: { filterableIndexPatterns: [{ id: '1', title: 'saved' }] },
},
});
await act(async () => {
instance.setProps({ docId: '1234' });
});

expect(defaultArgs.core.chrome.setBreadcrumbs).toHaveBeenCalledWith([
{ text: 'The Coolest Container Ever Made', onClick: expect.anything() },
{ text: 'Visualize', href: '/testbasepath/app/visualize#/', onClick: expect.anything() },
{ text: 'Daaaaaaadaumching!' },
]);
});

describe('persistence', () => {
it('does not load a document if there is no document id', () => {
const args = makeDefaultArgs();
Expand Down

0 comments on commit 57db0d2

Please sign in to comment.