Skip to content

Commit

Permalink
NP Migration: Rollup plugin (#53503)
Browse files Browse the repository at this point in the history
* Start shimming rollup plugin

* continued shimming rollup ui

* Remove unnecessarily return

* Register management section

* Replace ui/chrome

* Replace ui/documentation_links

* Replace ui/kfetch and ui/courier

* Start shimming rollup plugin

* continued shimming rollup ui

* Remove unnecessarily return

* Register management section

* Replace ui/chrome

* Replace ui/documentation_links

* Replace ui/kfetch and ui/courier

* Replace ui/notify

* Move ui/ imports to legacy_imports.ts

* Update NP mock for management

* Refactoring

* Read body from error object

* Update setup_environment.js

* Update unit tests

* Get rid of injectI18n

* Replace npStart and npSetup usage to services

* Import search strategy stuff from the top level of the data plugin

* Update unit tests

* Do not prepend the url

* Fix merge conflicts

* Refactoring

* Revert removal of setUserHasLeftApp

* Export getSearchErrorType

* Remove extra wrapper - Router

* Fix cause prop.

* Leave just static imports in legacy_imports.js

* Add TS

* Pass statusCode instead of statusText

* Move template in a separate file

* Move app register to setup

* Add karma mock for management setup

* Add EditorConfigProviderRegistry export

Co-authored-by: Maryia Lapata <mary.lopato@gmail.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
3 people authored Jan 30, 2020
1 parent 326afbc commit 0d03ade
Show file tree
Hide file tree
Showing 70 changed files with 716 additions and 667 deletions.
2 changes: 1 addition & 1 deletion src/legacy/ui/public/agg_types/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

export { aggTypeFilters } from './agg_type_filters';
export { aggTypeFilters, AggTypeFilters } from './agg_type_filters';
export { propFilter } from './prop_filter';
2 changes: 1 addition & 1 deletion src/legacy/ui/public/agg_types/param_types/filter/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
* under the License.
*/

export { aggTypeFieldFilters } from './field_filters';
export { aggTypeFieldFilters, AggTypeFieldFilters } from './field_filters';
12 changes: 12 additions & 0 deletions src/legacy/ui/public/new_platform/new_platform.karma_mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,13 @@ export const npSetup = {
useChartsTheme: sinon.fake(),
},
},
management: {
sections: {
getSection: () => ({
registerApp: sinon.fake(),
}),
},
},
},
};

Expand All @@ -167,6 +174,11 @@ export const npStart = {
hasItem: sinon.fake(),
}),
},
sections: {
getSection: () => ({
registerApp: sinon.fake(),
}),
},
},
embeddable: {
getEmbeddableFactory: sinon.fake(),
Expand Down
3 changes: 2 additions & 1 deletion src/legacy/ui/public/new_platform/new_platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import { DevToolsSetup, DevToolsStart } from '../../../../plugins/dev_tools/publ
import { KibanaLegacySetup, KibanaLegacyStart } from '../../../../plugins/kibana_legacy/public';
import { HomePublicPluginSetup, HomePublicPluginStart } from '../../../../plugins/home/public';
import { SharePluginSetup, SharePluginStart } from '../../../../plugins/share/public';
import { ManagementStart } from '../../../../plugins/management/public';
import { ManagementSetup, ManagementStart } from '../../../../plugins/management/public';
import { BfetchPublicSetup, BfetchPublicStart } from '../../../../plugins/bfetch/public';
import { UsageCollectionSetup } from '../../../../plugins/usage_collection/public';
import {
Expand All @@ -54,6 +54,7 @@ export interface PluginsSetup {
kibana_legacy: KibanaLegacySetup;
share: SharePluginSetup;
usageCollection: UsageCollectionSetup;
management: ManagementSetup;
}

export interface PluginsStart {
Expand Down
2 changes: 1 addition & 1 deletion src/legacy/ui/public/vis/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
* under the License.
*/

export { editorConfigProviders } from './editor_config_providers';
export { editorConfigProviders, EditorConfigProviderRegistry } from './editor_config_providers';
export * from './types';
2 changes: 2 additions & 0 deletions src/plugins/data/public/search/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export {
hasSearchStategyForIndexPattern,
defaultSearchStrategy,
SearchError,
SearchStrategyProvider,
getSearchErrorType,
} from './search_strategy';

export {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { setup as jobCloneSetup } from './job_clone.helpers';

export { nextTick, getRandomString, findTestSubject } from '../../../../../../test_utils';

export { setupEnvironment } from './setup_environment';
export { mockHttpRequest } from './setup_environment';

export { wrapComponent } from './setup_context';

export const pageHelpers = {
jobCreate: { setup: jobCreateSetup },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import { JobCreate } from '../../../public/crud_app/sections';
import { JOB_TO_CLONE } from './constants';
import { deserializeJob } from '../../../public/crud_app/services';

import { wrapComponent } from './setup_context';

export const setup = props => {
const initTestBed = registerTestBed(JobCreate, {
const initTestBed = registerTestBed(wrapComponent(JobCreate), {
store: createRollupJobsStore({
cloneJob: { job: deserializeJob(JOB_TO_CLONE.jobs[0]) },
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import { JobCreate } from '../../../public/crud_app/sections';

import { JOB_TO_CREATE } from './constants';

const initTestBed = registerTestBed(JobCreate, { store: rollupJobsStore });
import { wrapComponent } from './setup_context';

const initTestBed = registerTestBed(wrapComponent(JobCreate), { store: rollupJobsStore });

export const setup = props => {
const testBed = initTestBed(props);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import { registerRouter } from '../../../public/crud_app/services';
import { createRollupJobsStore } from '../../../public/crud_app/store';
import { JobList } from '../../../public/crud_app/sections/job_list';

import { wrapComponent } from './setup_context';

const testBedConfig = {
store: createRollupJobsStore,
memoryRouter: {
Expand All @@ -19,4 +21,4 @@ const testBedConfig = {
},
};

export const setup = registerTestBed(JobList, testBedConfig);
export const setup = registerTestBed(wrapComponent(JobList), testBedConfig);
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FunctionComponent } from 'react';

import { KibanaContextProvider } from '../../../../../../../src/plugins/kibana_react/public';
import { coreMock } from '../../../../../../../src/core/public/mocks';
const startMock = coreMock.createStart();

const services = {
setBreadcrumbs: startMock.chrome.setBreadcrumbs,
};

const wrapComponent = (Component: FunctionComponent) => (props: any) => (
<KibanaContextProvider services={services}>
<Component {...props} />
</KibanaContextProvider>
);

export { wrapComponent };

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

interface RequestMocks {
jobs?: object;
createdJob?: object;
indxPatternVldtResp?: object;
[key: string]: any;
}

const mockHttpRequest = (
http: any,
{ jobs = {}, createdJob = {}, indxPatternVldtResp = {} }: RequestMocks = {}
) => {
http.get.mockImplementation(async (url: string) => {
if (url === '/api/rollup/jobs') {
return jobs;
}

if (url.startsWith('/api/rollup/index_pattern_validity')) {
return {
doesMatchIndices: true,
doesMatchRollupIndices: false,
dateFields: ['foo', 'bar'],
numericFields: [],
keywordFields: [],
...indxPatternVldtResp,
};
}

return {};
});

// mock '/api/rollup/start'
http.post.mockImplementation(async (url: string) => ({}));

// mock '/api/rollup/create
http.put.mockImplementation(async (url: string) => createdJob);
};

export { mockHttpRequest };
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { setupEnvironment, pageHelpers, nextTick } from './helpers';
import { setHttp } from '../../public/crud_app/services';
import { mockHttpRequest, pageHelpers, nextTick } from './helpers';
import { JOB_TO_CLONE, JOB_CLONE_INDEX_PATTERN_CHECK } from './helpers/constants';

jest.mock('ui/new_platform');
Expand All @@ -17,26 +18,28 @@ const {
} = JOB_TO_CLONE;

describe('Cloning a rollup job through create job wizard', () => {
let httpRequestsMockHelpers;
let server;
let find;
let exists;
let form;
let table;
let actions;
let npStart;

beforeAll(() => {
({ server, httpRequestsMockHelpers } = setupEnvironment());
npStart = require('ui/new_platform').npStart; // eslint-disable-line
setHttp(npStart.core.http);
});

beforeEach(() => {
httpRequestsMockHelpers.setIndexPatternValidityResponse(JOB_CLONE_INDEX_PATTERN_CHECK);
mockHttpRequest(npStart.core.http, { indxPatternVldtResp: JOB_CLONE_INDEX_PATTERN_CHECK });

({ exists, find, form, actions, table } = setup());
});

afterAll(() => {
server.restore();
afterEach(() => {
npStart.core.http.get.mockClear();
npStart.core.http.post.mockClear();
npStart.core.http.put.mockClear();
});

it('should have fields correctly pre-populated', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@

import moment from 'moment-timezone';

import { setupEnvironment, pageHelpers } from './helpers';
import { setHttp } from '../../public/crud_app/services';
import { mockHttpRequest, pageHelpers } from './helpers';

jest.mock('ui/new_platform');

Expand All @@ -15,30 +16,31 @@ jest.mock('lodash/function/debounce', () => fn => fn);
const { setup } = pageHelpers.jobCreate;

describe('Create Rollup Job, step 2: Date histogram', () => {
let server;
let httpRequestsMockHelpers;
let find;
let exists;
let actions;
let goToStep;
let form;
let getEuiStepsHorizontalActive;
let npStart;

beforeAll(() => {
({ server, httpRequestsMockHelpers } = setupEnvironment());
npStart = require('ui/new_platform').npStart; // eslint-disable-line
setHttp(npStart.core.http);
});

afterAll(() => {
server.restore();
});

beforeEach(() => {
// Set "default" mock responses by not providing any arguments
httpRequestsMockHelpers.setIndexPatternValidityResponse();
mockHttpRequest(npStart.core.http);

({ find, exists, actions, form, getEuiStepsHorizontalActive, goToStep } = setup());
});

afterEach(() => {
npStart.core.http.get.mockClear();
npStart.core.http.post.mockClear();
npStart.core.http.put.mockClear();
});

describe('layout', () => {
beforeEach(async () => {
await goToStep(2);
Expand Down Expand Up @@ -71,7 +73,7 @@ describe('Create Rollup Job, step 2: Date histogram', () => {
describe('Date field select', () => {
it('should set the options value from the index pattern', async () => {
const dateFields = ['field1', 'field2', 'field3'];
httpRequestsMockHelpers.setIndexPatternValidityResponse({ dateFields });
mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { dateFields } });

await goToStep(2);

Expand All @@ -83,7 +85,7 @@ describe('Create Rollup Job, step 2: Date histogram', () => {

it('should sort the options in ascending order', async () => {
const dateFields = ['field3', 'field2', 'field1'];
httpRequestsMockHelpers.setIndexPatternValidityResponse({ dateFields });
mockHttpRequest(npStart.core.http, { indxPatternVldtResp: { dateFields } });

await goToStep(2);

Expand Down
Loading

0 comments on commit 0d03ade

Please sign in to comment.