Skip to content

Commit

Permalink
update use_monitor_breadcrumbs test
Browse files Browse the repository at this point in the history
  • Loading branch information
dominiqueclarke committed Jan 11, 2021
1 parent 8cf3403 commit 1866c29
Showing 1 changed file with 24 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,32 @@ import { useMonitorBreadcrumb } from './use_monitor_breadcrumb';
import { OVERVIEW_ROUTE } from '../../../../../common/constants';
import { Ping } from '../../../../../common/runtime_types/ping';
import { JourneyState } from '../../../../state/reducers/journey';
import { chromeServiceMock } from 'src/core/public/mocks';
import { chromeServiceMock, uiSettingsServiceMock } from 'src/core/public/mocks';

describe('useMonitorBreadcrumbs', () => {
it('sets the given breadcrumbs', () => {
const [getBreadcrumbs, core] = mockCore();
let breadcrumbObj: ChromeBreadcrumb[] = [];
const getBreadcrumbs = () => {
return breadcrumbObj;
};

const core = {
chrome: {
...chromeServiceMock.createStartContract(),
setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => {
breadcrumbObj = newBreadcrumbs;
},
},
uiSettings: {
...uiSettingsServiceMock.createSetupContract(),
get(key: string, defaultOverride?: any): any {
return `MMM D, YYYY @ HH:mm:ss.SSS` || defaultOverride;
},
get$(key: string, defaultOverride?: any): any {
return of(`MMM D, YYYY @ HH:mm:ss.SSS`) || of(defaultOverride);
},
},
};

const Component = () => {
useMonitorBreadcrumb({
Expand All @@ -31,7 +52,7 @@ describe('useMonitorBreadcrumbs', () => {
<Route path={OVERVIEW_ROUTE}>
<Component />
</Route>,
{ kibanaProps: { services: { ...core } } }
{ core }
);

expect(getBreadcrumbs()).toMatchInlineSnapshot(`
Expand All @@ -53,28 +74,3 @@ describe('useMonitorBreadcrumbs', () => {
`);
});
});

const mockCore: () => [() => ChromeBreadcrumb[], any] = () => {
let breadcrumbObj: ChromeBreadcrumb[] = [];
const get = () => {
return breadcrumbObj;
};
const core = {
application: {
getUrlForApp: () => '/app/uptime',
navigateToUrl: jest.fn(),
},
chrome: {
...chromeServiceMock.createStartContract,
setBreadcrumbs: (newBreadcrumbs: ChromeBreadcrumb[]) => {
breadcrumbObj = newBreadcrumbs;
},
},
uiSettings: {
get: (key: string) => 'MMM D, YYYY @ HH:mm:ss.SSS',
get$: (key: string) => of('MMM D, YYYY @ HH:mm:ss.SSS'),
},
};

return [get, core];
};

0 comments on commit 1866c29

Please sign in to comment.