Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scottybollinger committed Apr 14, 2021
1 parent e42ff83 commit 8342dd4
Showing 1 changed file with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
* 2.0.
*/

import { LogicMounter, mockFlashMessageHelpers, mockHttpValues } from '../../../../../__mocks__';
import {
LogicMounter,
mockFlashMessageHelpers,
mockHttpValues,
mockKibanaValues,
} from '../../../../../__mocks__';
import { exampleResult } from '../../../../__mocks__/content_sources.mock';

import { nextTick } from '@kbn/test/jest';
Expand All @@ -25,6 +30,7 @@ import { DisplaySettingsLogic, defaultSearchResultConfig } from './display_setti

describe('DisplaySettingsLogic', () => {
const { http } = mockHttpValues;
const { navigateToUrl } = mockKibanaValues;
const { clearFlashMessages, flashAPIErrors, setSuccessMessage } = mockFlashMessageHelpers;
const { mount } = new LogicMounter(DisplaySettingsLogic);

Expand Down Expand Up @@ -204,6 +210,12 @@ describe('DisplaySettingsLogic', () => {
});
});

it('setNavigatingBetweenTabs', () => {
DisplaySettingsLogic.actions.setNavigatingBetweenTabs(true);

expect(DisplaySettingsLogic.values.navigatingBetweenTabs).toEqual(true);
});

it('addDetailField', () => {
const newField = { label: 'Monkey', fieldName: 'primate' };
DisplaySettingsLogic.actions.setServerResponseData(serverProps);
Expand Down Expand Up @@ -352,6 +364,31 @@ describe('DisplaySettingsLogic', () => {
expect(flashAPIErrors).toHaveBeenCalledWith('this is an error');
});
});

describe('handleSelectedTabChanged', () => {
beforeEach(() => {
DisplaySettingsLogic.actions.onInitializeDisplaySettings(serverProps);
});

it('calls sets navigatingBetweenTabs', async () => {
const setNavigatingBetweenTabsSpy = jest.spyOn(
DisplaySettingsLogic.actions,
'setNavigatingBetweenTabs'
);
DisplaySettingsLogic.actions.handleSelectedTabChanged('search_results');
await nextTick();

expect(setNavigatingBetweenTabsSpy).toHaveBeenCalledWith(true);
expect(navigateToUrl).toHaveBeenCalledWith('/p/sources/123/display_settings/');
});

it('calls calls correct route for "result_detail"', async () => {
DisplaySettingsLogic.actions.handleSelectedTabChanged('result_detail');
await nextTick();

expect(navigateToUrl).toHaveBeenCalledWith('/p/sources/123/display_settings/result_detail');
});
});
});

describe('selectors', () => {
Expand Down

0 comments on commit 8342dd4

Please sign in to comment.