Skip to content

Commit

Permalink
First iteration of watch public -> new platform
Browse files Browse the repository at this point in the history
Still need to switch to np ready version of use_request
  • Loading branch information
jloleysens committed Nov 15, 2019
1 parent 4f88819 commit 2a401e3
Show file tree
Hide file tree
Showing 122 changed files with 645 additions and 475 deletions.
3 changes: 2 additions & 1 deletion x-pack/dev-tools/jest/create_jest_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function createJestConfig({ kibanaDirectory, xPackKibanaDirectory }) {
'uiExports/(.*)': fileMockPath,
'^src/core/(.*)': `${kibanaDirectory}/src/core/$1`,
'^src/legacy/(.*)': `${kibanaDirectory}/src/legacy/$1`,
'^plugins/watcher/models/(.*)': `${xPackKibanaDirectory}/legacy/plugins/watcher/public/models/$1`,
'^plugins/watcher/np_ready/application/models/(.*)':
`${xPackKibanaDirectory}/legacy/plugins/watcher/public/np_ready/application/models/$1`,
'^plugins/([^/.]*)(.*)': `${kibanaDirectory}/src/legacy/core_plugins/$1/public$2`,
'^legacy/plugins/xpack_main/(.*);': `${xPackKibanaDirectory}/legacy/plugins/xpack_main/public/$1`,
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': fileMockPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 from 'react';
import { ComponentType } from 'enzyme';

import { AppContextProvider } from '../../../public/np_ready/application/app_context';

export const withAppContext = (Component: ComponentType<any>) => (props: any) => {
return (
<AppContextProvider
value={{
docLinks: {
DOC_LINK_VERSION: 'test',
ELASTIC_WEBSITE_URL: 'test',
links: {} as any,
},
savedObjects: {
create: jest.fn(),
} as any,
uiSettings: {} as any,
chrome: {
setBreadCrumbs: () => {},
},
TimeBuckets: class MockTimeBuckets {
setBounds(_domain: any) {
return {};
}
getInterval() {
return {
expression: {},
};
}
},
uiSettings: {
get: () => {},
isDefault: () => true,
},
MANAGEMENT_BREADCRUMB: { text: 'test' },
}}
>
<Component {...props} />
</AppContextProvider>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import axios from 'axios';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';
import { init as initHttpRequests } from './http_requests';
import { setHttpClient, setSavedObjectsClient } from '../../../public/lib/api';
import { setHttpClient, setSavedObjectsClient } from '../../../public/np_ready/application/lib/api';

const mockHttpClient = axios.create({ adapter: axiosXhrAdapter });

Expand All @@ -23,7 +23,7 @@ export const setupEnvironment = () => {
// @ts-ignore
setHttpClient(mockHttpClient);

setSavedObjectsClient(mockSavedObjectsClient());
setSavedObjectsClient(mockSavedObjectsClient() as any);

return {
server,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { withAppContext } from './app_context.mock';
import { registerTestBed, TestBed, TestBedConfig } from '../../../../../../test_utils';
import { WatchEdit } from '../../../public/sections/watch_edit/components/watch_edit';
import { WatchEdit } from '../../../public/np_ready/application/sections/watch_edit/components/watch_edit';
import { ROUTES, WATCH_TYPES } from '../../../common/constants';
import { registerRouter } from '../../../public/lib/navigation';
import { registerRouter } from '../../../public/np_ready/application/lib/navigation';

const testBedConfig: TestBedConfig = {
memoryRouter: {
Expand All @@ -17,7 +18,7 @@ const testBedConfig: TestBedConfig = {
doMountAsync: true,
};

const initTestBed = registerTestBed(WatchEdit, testBedConfig);
const initTestBed = registerTestBed(withAppContext(WatchEdit), testBedConfig);

export interface WatchCreateJsonTestBed extends TestBed<WatchCreateJsonTestSubjects> {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { registerTestBed, TestBed, TestBedConfig } from '../../../../../../test_utils';
import { WatchEdit } from '../../../public/sections/watch_edit/components/watch_edit';
import { WatchEdit } from '../../../public/np_ready/application/sections/watch_edit/components/watch_edit';
import { ROUTES, WATCH_TYPES } from '../../../common/constants';
import { registerRouter } from '../../../public/lib/navigation';
import { registerRouter } from '../../../public/np_ready/application/lib/navigation';
import { withAppContext } from './app_context.mock';

const testBedConfig: TestBedConfig = {
memoryRouter: {
Expand All @@ -17,7 +18,7 @@ const testBedConfig: TestBedConfig = {
doMountAsync: true,
};

const initTestBed = registerTestBed(WatchEdit, testBedConfig);
const initTestBed = registerTestBed(withAppContext(WatchEdit), testBedConfig);

export interface WatchCreateThresholdTestBed extends TestBed<WatchCreateThresholdTestSubjects> {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { registerTestBed, TestBed, TestBedConfig } from '../../../../../../test_utils';
import { WatchEdit } from '../../../public/sections/watch_edit/components/watch_edit';
import { WatchEdit } from '../../../public/np_ready/application/sections/watch_edit/components/watch_edit';
import { ROUTES } from '../../../common/constants';
import { registerRouter } from '../../../public/lib/navigation';
import { registerRouter } from '../../../public/np_ready/application/lib/navigation';
import { WATCH_ID } from './constants';
import { withAppContext } from './app_context.mock';

const testBedConfig: TestBedConfig = {
memoryRouter: {
Expand All @@ -18,7 +19,7 @@ const testBedConfig: TestBedConfig = {
doMountAsync: true,
};

const initTestBed = registerTestBed(WatchEdit, testBedConfig);
const initTestBed = registerTestBed(withAppContext(WatchEdit), testBedConfig);

export interface WatchEditTestBed extends TestBed<WatchEditSubjects> {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {
TestBedConfig,
nextTick,
} from '../../../../../../test_utils';
import { WatchList } from '../../../public/sections/watch_list/components/watch_list';
import { WatchList } from '../../../public/np_ready/application/sections/watch_list/components/watch_list';
import { ROUTES } from '../../../common/constants';
import { withAppContext } from './app_context.mock';

const testBedConfig: TestBedConfig = {
memoryRouter: {
Expand All @@ -23,7 +24,7 @@ const testBedConfig: TestBedConfig = {
doMountAsync: true,
};

const initTestBed = registerTestBed(WatchList, testBedConfig);
const initTestBed = registerTestBed(withAppContext(WatchList), testBedConfig);

export interface WatchListTestBed extends TestBed<WatchListTestSubjects> {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import {
TestBedConfig,
nextTick,
} from '../../../../../../test_utils';
import { WatchStatus } from '../../../public/sections/watch_status/components/watch_status';
import { WatchStatus } from '../../../public/np_ready/application/sections/watch_status/components/watch_status';
import { ROUTES } from '../../../common/constants';
import { WATCH_ID } from './constants';
import { withAppContext } from './app_context.mock';

const testBedConfig: TestBedConfig = {
memoryRouter: {
Expand All @@ -25,7 +26,7 @@ const testBedConfig: TestBedConfig = {
doMountAsync: true,
};

const initTestBed = registerTestBed(WatchStatus, testBedConfig);
const initTestBed = registerTestBed(withAppContext(WatchStatus), testBedConfig);

export interface WatchStatusTestBed extends TestBed<WatchStatusTestSubjects> {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@ import { act } from 'react-dom/test-utils';
import { setupEnvironment, pageHelpers, nextTick } from './helpers';
import { WatchCreateJsonTestBed } from './helpers/watch_create_json.helpers';
import { WATCH } from './helpers/constants';
import defaultWatchJson from '../../public/models/watch/default_watch.json';
import defaultWatchJson from '../../public/np_ready/application/models/watch/default_watch.json';
import { getExecuteDetails } from '../../test/fixtures';

jest.mock('ui/chrome', () => ({
breadcrumbs: { set: () => {} },
addBasePath: (path: string) => path || '/api/watcher',
}));

jest.mock('ui/time_buckets', () => {});

const { setup } = pageHelpers.watchCreateJson;

describe.skip('<JsonWatchEdit /> create route', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,8 @@ const WATCH_VISUALIZE_DATA = {

const mockHttpClient = axios.create({ adapter: axiosXhrAdapter });

jest.mock('ui/chrome', () => ({
breadcrumbs: { set: () => {} },
addBasePath: (path: string) => path || '/api/watcher',
getUiSettingsClient: () => ({
get: () => {},
isDefault: () => true,
}),
}));

jest.mock('ui/time_buckets', () => {
class MockTimeBuckets {
setBounds(_domain: any) {
return {};
}
getInterval() {
return {
expression: {},
};
}
}
return { TimeBuckets: MockTimeBuckets };
});

jest.mock('../../public/lib/api', () => ({
...jest.requireActual('../../public/lib/api'),
jest.mock('../../public/np_ready/application/lib/api', () => ({
...jest.requireActual('../../public/np_ready/application/lib/api'),
loadIndexPatterns: async () => {
const INDEX_PATTERNS = [
{ attributes: { title: 'index1' } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,14 @@ import axios from 'axios';
import { setupEnvironment, pageHelpers, nextTick } from './helpers';
import { WatchEditTestBed } from './helpers/watch_edit.helpers';
import { WATCH } from './helpers/constants';
import defaultWatchJson from '../../public/models/watch/default_watch.json';
import defaultWatchJson from '../../public/np_ready/application/models/watch/default_watch.json';
import { getWatch } from '../../test/fixtures';
import { getRandomString } from '../../../../../test_utils';

const mockHttpClient = axios.create({ adapter: axiosXhrAdapter });

jest.mock('ui/chrome', () => ({
breadcrumbs: { set: () => {} },
addBasePath: (path: string) => path || '/api/watcher',
}));

jest.mock('ui/time_buckets', () => {
class MockTimeBuckets {
setBounds(_domain: any) {
return {};
}
getInterval() {
return {
expression: {},
};
}
}
return { TimeBuckets: MockTimeBuckets };
});

jest.mock('../../public/lib/api', () => ({
...jest.requireActual('../../public/lib/api'),
jest.mock('../../public/np_ready/application/lib/api', () => ({
...jest.requireActual('../../public/np_ready/application/lib/api'),
loadIndexPatterns: async () => {
const INDEX_PATTERNS = [
{ attributes: { title: 'index1' } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ import { ROUTES } from '../../common/constants';

const { API_ROOT } = ROUTES;

jest.mock('ui/chrome', () => ({
breadcrumbs: { set: () => {} },
addBasePath: (path: string) => path || '/api/watcher',
}));

jest.mock('ui/time_buckets', () => {});

const { setup } = pageHelpers.watchList;

describe.skip('<WatchList />', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ import { WATCH_STATES, ACTION_STATES } from '../../common/constants';

const { API_ROOT } = ROUTES;

jest.mock('ui/chrome', () => ({
breadcrumbs: { set: () => {} },
addBasePath: (path: string) => path || '/api/watcher',
}));

jest.mock('ui/time_buckets', () => {});

const { setup } = pageHelpers.watchStatus;

const watchHistory1 = getWatchHistory({ startTime: '2019-06-04T01:11:11.294' });
Expand Down
9 changes: 9 additions & 0 deletions x-pack/legacy/plugins/watcher/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "watcher",
"version": "kibana",
"requiredPlugins": [
"feature_catalogue"
],
"server": true,
"ui": true
}
4 changes: 2 additions & 2 deletions x-pack/legacy/plugins/watcher/plugin_definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export const pluginDefinition = {
publicDir: resolve(__dirname, 'public'),
require: ['kibana', 'elasticsearch', 'xpack_main'],
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
managementSections: ['plugins/watcher'],
styleSheetPaths: resolve(__dirname, 'public/np_ready/application/index.scss'),
managementSections: ['plugins/watcher/legacy'],
home: ['plugins/watcher/register_feature'],
},
init: function (server) {
Expand Down
3 changes: 0 additions & 3 deletions x-pack/legacy/plugins/watcher/public/app.html

This file was deleted.

8 changes: 0 additions & 8 deletions x-pack/legacy/plugins/watcher/public/index.js

This file was deleted.

Loading

0 comments on commit 2a401e3

Please sign in to comment.