Skip to content

Commit

Permalink
Adds tests for application creation (#357)
Browse files Browse the repository at this point in the history
* Remove unnecessary memoization

Signed-off-by: Eugene Lee <[email protected]>

* Add tests for create page

Signed-off-by: Eugene Lee <[email protected]>
  • Loading branch information
eugenesk24 authored Dec 22, 2021
1 parent 6b6c6d3 commit feb3983
Show file tree
Hide file tree
Showing 10 changed files with 16,164 additions and 64 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { CreateApp } from '../components/create';
import { coreStartMock } from '../../../../test/__mocks__/coreMocks';
import DSLService from 'public/services/requests/dsl';
import { render } from '@testing-library/react';

describe('Create Page', () => {
configure({ adapter: new Adapter() });

it('renders empty', () => {
const core = coreStartMock;
const setQuery = jest.fn();
const setFilters = jest.fn();
const setStartTime = jest.fn();
const setEndTime = jest.fn();
const dslService = {
http: jest.fn(),
fetch: jest.fn(),
fetchIndices: jest.fn(),
fetchFields: jest.fn()
} as unknown as DSLService;
const utils = render(
<CreateApp
http={core.http}
chrome={core.chrome}
parentBreadcrumb={{ text: 'test', href: 'test#/' }}
query=""
setQuery={setQuery}
filters={[]}
setFilters={setFilters}
startTime="now-5m"
setStartTime={setStartTime}
endTime="now"
setEndTime={setEndTime}
indicesExist={true}
dslService={dslService}
/>
);

expect(utils).toMatchSnapshot();
});

it('renders with query', () => {
const core = coreStartMock;
const setQuery = jest.fn();
const setFilters = jest.fn();
const setStartTime = jest.fn();
const setEndTime = jest.fn();
const dslService = {
http: jest.fn(),
fetch: jest.fn(),
fetchIndices: jest.fn(),
fetchFields: jest.fn()
} as unknown as DSLService;
const utils = render(
<CreateApp
http={core.http}
chrome={core.chrome}
parentBreadcrumb={{ text: 'test', href: 'test#/' }}
query="source = openserach_dashboard_sample_logs"
setQuery={setQuery}
filters={[]}
setFilters={setFilters}
startTime="now-5m"
setStartTime={setStartTime}
endTime="now"
setEndTime={setEndTime}
indicesExist={true}
dslService={dslService}
/>
);
utils.getByText('Log Source').click();
utils.getByText('Clear').click();
utils.getByText('Cancel').click();

expect(utils).toMatchSnapshot();
});

it('can clear query', () => {
const core = coreStartMock;
const setQuery = jest.fn();
const setFilters = jest.fn();
const setStartTime = jest.fn();
const setEndTime = jest.fn();
const dslService = {
http: jest.fn(),
fetch: jest.fn(),
fetchIndices: jest.fn(),
fetchFields: jest.fn()
} as unknown as DSLService;
const utils = render(
<CreateApp
http={core.http}
chrome={core.chrome}
parentBreadcrumb={{ text: 'test', href: 'test#/' }}
query="source = openserach_dashboard_sample_logs"
setQuery={setQuery}
filters={[]}
setFilters={setFilters}
startTime="now-5m"
setStartTime={setStartTime}
endTime="now"
setEndTime={setEndTime}
indicesExist={true}
dslService={dslService}
/>
);
utils.getByText('Log Source').click();
utils.getByText('Clear').click();
utils.getByText('Clear').click();

expect(utils).toMatchSnapshot();
});

it('renders with one service selected', () => {
const core = coreStartMock;
const setQuery = jest.fn();
const setFilters = jest.fn();
const setStartTime = jest.fn();
const setEndTime = jest.fn();
const dslService = {
http: jest.fn(),
fetch: jest.fn(),
fetchIndices: jest.fn(),
fetchFields: jest.fn()
} as unknown as DSLService;
const serviceFilters = [{
field: 'serviceName',
operator: 'is',
value: 'User',
inverted: false,
disabled: false
}];
const utils = render(
<CreateApp
http={core.http}
chrome={core.chrome}
parentBreadcrumb={{ text: 'test', href: 'test#/' }}
query=""
setQuery={setQuery}
filters={serviceFilters}
setFilters={setFilters}
startTime="now-5m"
setStartTime={setStartTime}
endTime="now"
setEndTime={setEndTime}
indicesExist={true}
dslService={dslService}
/>
);
utils.getByText('Select services & entities to include in this application').click();

expect(utils).toMatchSnapshot();
});
it('renders with one trace selected', () => {
const core = coreStartMock;
const setQuery = jest.fn();
const setFilters = jest.fn();
const setStartTime = jest.fn();
const setEndTime = jest.fn();
const dslService = {
http: jest.fn(),
fetch: jest.fn(),
fetchIndices: jest.fn(),
fetchFields: jest.fn()
} as unknown as DSLService;
const traceFilters = [{
field: 'traceGroup',
operator: 'is',
value: 'test.auto',
inverted: false,
disabled: false
}];
const utils = render(
<CreateApp
http={core.http}
chrome={core.chrome}
parentBreadcrumb={{ text: 'test', href: 'test#/' }}
query=""
setQuery={setQuery}
filters={traceFilters}
setFilters={setFilters}
startTime="now-5m"
setStartTime={setStartTime}
endTime="now"
setEndTime={setEndTime}
indicesExist={true}
dslService={dslService}
/>
);

expect(utils).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { configure, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { LogConfig } from '../components/config_components/log_config';
import { coreStartMock } from '../../../../test/__mocks__/coreMocks';
import DSLService from 'public/services/requests/dsl';

describe('Log Config component', () => {
configure({ adapter: new Adapter() });

it('renders empty log config', () => {
const core = coreStartMock;
const setQuery = jest.fn();
const setFilters = jest.fn();
const setStartTime = jest.fn();
const setEndTime = jest.fn();
const setIsFlyoutVisible = jest.fn();
const dslService = {
http: jest.fn(),
fetch: jest.fn(),
fetchIndices: jest.fn(),
fetchFields: jest.fn()
} as unknown as DSLService;
const wrapper = mount(
<LogConfig
http={core.http}
chrome={core.chrome}
parentBreadcrumb={{ text: 'test', href: 'test#/' }}
query=""
setQuery={setQuery}
filters={[]}
setFilters={setFilters}
startTime="now-5m"
setStartTime={setStartTime}
endTime="now"
setEndTime={setEndTime}
indicesExist={true}
dslService={dslService}
setIsFlyoutVisible={setIsFlyoutVisible}
/>
);

expect(wrapper).toMatchSnapshot();
});

it('renders with query', () => {
const core = coreStartMock;
const setQuery = jest.fn();
const setFilters = jest.fn();
const setStartTime = jest.fn();
const setEndTime = jest.fn();
const setIsFlyoutVisible = jest.fn();
const dslService = {
http: jest.fn(),
fetch: jest.fn(),
fetchIndices: jest.fn(),
fetchFields: jest.fn()
} as unknown as DSLService;
const wrapper = mount(
<LogConfig
http={core.http}
chrome={core.chrome}
parentBreadcrumb={{ text: 'test', href: 'test#/' }}
query="source = openserach_dashboard_sample_logs"
setQuery={setQuery}
filters={[]}
setFilters={setFilters}
startTime="now-5m"
setStartTime={setStartTime}
endTime="now"
setEndTime={setEndTime}
indicesExist={true}
dslService={dslService}
setIsFlyoutVisible={setIsFlyoutVisible}
/>
);

expect(wrapper).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { configure, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import { ServiceConfig } from '../components/config_components/service_config';
import { coreStartMock } from '../../../../test/__mocks__/coreMocks';
import DSLService from 'public/services/requests/dsl';

describe('Service Config component', () => {
configure({ adapter: new Adapter() });

it('renders empty service config', () => {
const core = coreStartMock;
const setQuery = jest.fn();
const setFilters = jest.fn();
const setStartTime = jest.fn();
const setEndTime = jest.fn();
const setSelectedServices = jest.fn();
const dslService = {
http: jest.fn(),
fetch: jest.fn(),
fetchIndices: jest.fn(),
fetchFields: jest.fn()
} as unknown as DSLService;
const wrapper = mount(
<ServiceConfig
http={core.http}
chrome={core.chrome}
parentBreadcrumb={{ text: 'test', href: 'test#/' }}
query=""
setQuery={setQuery}
filters={[]}
setFilters={setFilters}
startTime="now-5m"
setStartTime={setStartTime}
endTime="now"
setEndTime={setEndTime}
indicesExist={true}
dslService={dslService}
selectedServices={[]}
setSelectedServices={setSelectedServices}
/>
);

expect(wrapper).toMatchSnapshot();
});

it('renders with one service selected', () => {
const core = coreStartMock;
const setQuery = jest.fn();
const setFilters = jest.fn();
const setStartTime = jest.fn();
const setEndTime = jest.fn();
const setSelectedServices = jest.fn();
const dslService = {
http: jest.fn(),
fetch: jest.fn(),
fetchIndices: jest.fn(),
fetchFields: jest.fn()
} as unknown as DSLService;
const serviceFilter = [{
field: 'serviceName',
operator: 'is',
value: 'User',
inverted: false,
disabled: false
}];
const wrapper = mount(
<ServiceConfig
http={core.http}
chrome={core.chrome}
parentBreadcrumb={{ text: 'test', href: 'test#/' }}
query=""
setQuery={setQuery}
filters={serviceFilter}
setFilters={setFilters}
startTime="now-5m"
setStartTime={setStartTime}
endTime="now"
setEndTime={setEndTime}
indicesExist={true}
dslService={dslService}
selectedServices={[]}
setSelectedServices={setSelectedServices}
/>
);

expect(wrapper).toMatchSnapshot();
});
});
Loading

0 comments on commit feb3983

Please sign in to comment.