Skip to content

Commit

Permalink
Extend engine_logic.mock
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen authored and JasonStoltz committed Feb 26, 2021
1 parent 9c20faf commit a948765
Showing 3 changed files with 19 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -5,18 +5,26 @@
* 2.0.
*/

import { EngineDetails } from '../components/engine/types';
import { generateEncodedPath } from '../utils/encode_path_params';

export const mockEngineValues = {
engineName: 'some-engine',
engine: {},
engine: {} as EngineDetails,
};

export const mockEngineActions = {
initializeEngine: jest.fn(),
};

export const mockGenerateEnginePath = jest.fn((path, pathParams = {}) =>
generateEncodedPath(path, { engineName: mockEngineValues.engineName, ...pathParams })
);

jest.mock('../components/engine', () => ({
EngineLogic: { values: mockEngineValues },
EngineLogic: {
values: mockEngineValues,
actions: mockEngineActions,
},
generateEnginePath: mockGenerateEnginePath,
}));
Original file line number Diff line number Diff line change
@@ -5,4 +5,4 @@
* 2.0.
*/

export { mockEngineValues } from './engine_logic.mock';
export { mockEngineValues, mockEngineActions } from './engine_logic.mock';
Original file line number Diff line number Diff line change
@@ -6,19 +6,10 @@
*/

import { LogicMounter, mockFlashMessageHelpers, mockHttpValues } from '../../../__mocks__';
import { mockEngineValues, mockEngineActions } from '../../__mocks__';

import { nextTick } from '@kbn/test/jest';

jest.mock('../engine', () => ({
EngineLogic: {
values: {},
actions: {
initializeEngine: jest.fn(),
},
},
}));
import { EngineLogic } from '../engine';

import { Boost, BoostOperation, BoostType, FunctionalBoostFunction } from './types';

import { RelevanceTuningLogic } from './';
@@ -79,14 +70,9 @@ describe('RelevanceTuningLogic', () => {

beforeEach(() => {
jest.clearAllMocks();
// cast to any so that we don't have to provide a value for all of EngineLogic's values
EngineLogic.values = {
engineName: 'test-engine',
engine: {
invalidBoosts: false,
unsearchedUnconfirmedFields: false,
},
} as any;
mockEngineValues.engineName = 'test-engine';
mockEngineValues.engine.invalidBoosts = false;
mockEngineValues.engine.unsearchedUnconfirmedFields = false;
});

it('has expected default values', () => {
@@ -546,25 +532,25 @@ describe('RelevanceTuningLogic', () => {
});

it('will re-fetch the current engine after settings are updated if there were invalid boosts', async () => {
EngineLogic.values.engine.invalidBoosts = true;
mockEngineValues.engine.invalidBoosts = true;
mount({});
http.put.mockReturnValueOnce(Promise.resolve(searchSettings));

RelevanceTuningLogic.actions.updateSearchSettings();
await nextTick();

expect(EngineLogic.actions.initializeEngine).toHaveBeenCalled();
expect(mockEngineActions.initializeEngine).toHaveBeenCalled();
});

it('will re-fetch the current engine after settings are updated if there were unconfirmed search fieldds', async () => {
EngineLogic.values.engine.unsearchedUnconfirmedFields = true;
mockEngineValues.engine.unsearchedUnconfirmedFields = true;
mount({});
http.put.mockReturnValueOnce(Promise.resolve(searchSettings));

RelevanceTuningLogic.actions.updateSearchSettings();
await nextTick();

expect(EngineLogic.actions.initializeEngine).toHaveBeenCalled();
expect(mockEngineActions.initializeEngine).toHaveBeenCalled();
});
});

0 comments on commit a948765

Please sign in to comment.