Skip to content

Commit

Permalink
[Graph] Fix default discover url template building (#47587)
Browse files Browse the repository at this point in the history
  • Loading branch information
flash1293 authored Oct 9, 2019
1 parent 08de89b commit dba9da9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
updateFieldProperties,
} from './fields';
import { AdvancedSettings, WorkspaceField, WorkspaceNode } from '../types';
import { loadTemplates, syncTemplatesSaga } from './url_templates';

/**
* This suite tests all the sagas that only exist to sync the legacy world
Expand All @@ -25,7 +26,13 @@ describe('legacy sync sagas', () => {

beforeEach(() => {
env = createMockGraphStore({
sagas: [syncSettingsSaga, updateSaveButtonSaga, syncFieldsSaga, syncNodeStyleSaga],
sagas: [
syncSettingsSaga,
updateSaveButtonSaga,
syncFieldsSaga,
syncNodeStyleSaga,
syncTemplatesSaga,
],
initialStateOverwrites: {
fields: {
field1: {
Expand Down Expand Up @@ -67,6 +74,12 @@ describe('legacy sync sagas', () => {
expect(env.mockedDeps.getWorkspace()!.options.exploreControls).toBe(newSettings);
});

it('syncs templates with workspace', () => {
env.store.dispatch(loadTemplates([]));
expect(env.mockedDeps.setUrlTemplates).toHaveBeenCalledWith([]);
expect(env.mockedDeps.notifyAngular).toHaveBeenCalled();
});

it('notifies angular when fields are selected', () => {
env.store.dispatch(selectField('field1'));
expect(env.mockedDeps.notifyAngular).toHaveBeenCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe('url_templates', () => {
);
expect(templates.length).toBe(1);
expect(templates[0].encoder).toBe(outlinkEncoders[0]);
expect(templates[0].url).toContain('test-pattern');
expect(templates[0].url).not.toContain('test-pattern');
expect(templates[0].url).toContain('123456');
expect(templates[0].isDefault).toBe(true);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ function generateDefaultTemplate(
'_a',
rison.encode({
columns: ['_source'],
index: datasource.title,
index: datasource.id,
interval: 'auto',
query: { language: 'kuery', query: urlTemplatePlaceholder },
sort: ['_score', 'desc'],
Expand Down Expand Up @@ -106,6 +106,9 @@ export const syncTemplatesSaga = ({ setUrlTemplates, notifyAngular }: GraphStore
}

return function*() {
yield takeEvery(matchesOne(loadTemplates, saveTemplate, removeTemplate), syncTemplates);
yield takeEvery(
matchesOne(loadTemplates, saveTemplate, removeTemplate, requestDatasource, setDatasource),
syncTemplates
);
};
};

0 comments on commit dba9da9

Please sign in to comment.