Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event analytics unit tests #342

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`No result component Renders No result component 1`] = `
<NoResults>
<I18nProvider>
<IntlProvider
defaultLocale="en"
formats={
Object {
"date": Object {
"full": Object {
"day": "numeric",
"month": "long",
"weekday": "long",
"year": "numeric",
},
"long": Object {
"day": "numeric",
"month": "long",
"year": "numeric",
},
"medium": Object {
"day": "numeric",
"month": "short",
"year": "numeric",
},
"short": Object {
"day": "numeric",
"month": "numeric",
"year": "2-digit",
},
},
"number": Object {
"currency": Object {
"style": "currency",
},
"percent": Object {
"style": "percent",
},
},
"relative": Object {
"days": Object {
"units": "day",
},
"hours": Object {
"units": "hour",
},
"minutes": Object {
"units": "minute",
},
"months": Object {
"units": "month",
},
"seconds": Object {
"units": "second",
},
"years": Object {
"units": "year",
},
},
"time": Object {
"full": Object {
"hour": "numeric",
"minute": "numeric",
"second": "numeric",
"timeZoneName": "short",
},
"long": Object {
"hour": "numeric",
"minute": "numeric",
"second": "numeric",
"timeZoneName": "short",
},
"medium": Object {
"hour": "numeric",
"minute": "numeric",
"second": "numeric",
},
"short": Object {
"hour": "numeric",
"minute": "numeric",
},
},
}
}
locale="en"
messages={Object {}}
textComponent={Symbol(react.fragment)}
>
<PseudoLocaleWrapper>
<EuiSpacer
size="xl"
>
<div
className="euiSpacer euiSpacer--xl"
/>
</EuiSpacer>
<EuiFlexGroup
justifyContent="center"
>
<div
className="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--justifyContentCenter euiFlexGroup--directionRow euiFlexGroup--responsive"
>
<EuiFlexItem
className="dscNoResults"
grow={false}
>
<div
className="euiFlexItem euiFlexItem--flexGrowZero dscNoResults"
>
<EuiCallOut
color="warning"
data-test-subj="discoverNoResults"
iconType="help"
title={
<FormattedMessage
defaultMessage="No results match your search criteria"
id="discover.noResults.searchExamples.noResultsMatchSearchCriteriaTitle"
values={Object {}}
/>
}
>
<div
className="euiCallOut euiCallOut--warning"
data-test-subj="discoverNoResults"
>
<div
className="euiCallOutHeader"
>
<EuiIcon
aria-hidden="true"
className="euiCallOutHeader__icon"
size="m"
type="help"
>
<EuiIconEmpty
aria-hidden={true}
className="euiIcon euiIcon--medium euiIcon-isLoading euiCallOutHeader__icon"
focusable="false"
role="img"
style={null}
>
<svg
aria-hidden={true}
className="euiIcon euiIcon--medium euiIcon-isLoading euiCallOutHeader__icon"
focusable="false"
height={16}
role="img"
style={null}
viewBox="0 0 16 16"
width={16}
xmlns="http://www.w3.org/2000/svg"
/>
</EuiIconEmpty>
</EuiIcon>
<span
className="euiCallOutHeader__title"
>
<FormattedMessage
defaultMessage="No results match your search criteria"
id="discover.noResults.searchExamples.noResultsMatchSearchCriteriaTitle"
values={Object {}}
>
No results match your search criteria
</FormattedMessage>
</span>
</div>
</div>
</EuiCallOut>
<EuiSpacer
size="xl"
>
<div
className="euiSpacer euiSpacer--xl"
/>
</EuiSpacer>
<EuiText>
<div
className="euiText euiText--medium"
>
<h2
data-test-subj="discoverNoResultsTimefilter"
>
<FormattedMessage
defaultMessage="Expand your time range or modify your query"
id="discover.noResults.expandYourTimeRangeTitle"
values={Object {}}
>
Expand your time range or modify your query
</FormattedMessage>
</h2>
<p>
<FormattedMessage
defaultMessage="Your query may not match anything in the current time range, or there may not be any data at all in the currently selected time range. Try change time range, query filters or choose different time fields"
id="discover.noResults.queryMayNotMatchTitle"
values={Object {}}
>
Your query may not match anything in the current time range, or there may not be any data at all in the currently selected time range. Try change time range, query filters or choose different time fields
</FormattedMessage>
</p>
</div>
</EuiText>
</div>
</EuiFlexItem>
</div>
</EuiFlexGroup>
</PseudoLocaleWrapper>
</IntlProvider>
</I18nProvider>
</NoResults>
`;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { configure, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import { waitFor } from '@testing-library/react';
import { DataGrid } from '../data_grid';
import {
SELECTED_FIELDS,
AVAILABLE_FIELDS,
UNSELECTED_FIELDS,
QUERIED_FIELDS
} from '../../../../common/constants/explorer';
import {
AVAILABLE_FIELDS as SIDEBAR_AVAILABLE_FIELDS,
QUERY_FIELDS,
DATA_GRID_ROWS
} from '../../../../test/event_analytics_constants';

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

it('Renders data grid component', async () => {
const explorerFields = {
[SELECTED_FIELDS]: [],
[UNSELECTED_FIELDS]: [],
[AVAILABLE_FIELDS]: SIDEBAR_AVAILABLE_FIELDS,
[QUERIED_FIELDS]: QUERY_FIELDS
};

const wrapper = mount(
<DataGrid
rows={DATA_GRID_ROWS}
rowsAll={[]}
explorerFields={explorerFields}
/>
);

wrapper.update();

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

import { configure, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import { waitFor } from '@testing-library/react';
import httpClientMock from '../../../../test/__mocks__/httpClientMock';
import { Explorer } from '../explorer';
import PPLService from '../../../services/requests/ppl';
import DSLService from '../../../services/requests/dsl';
import SavedObjects from '../../../services/saved_objects/event_analytics/saved_objects';
import TimestampUtils from '../../../services/timestamp/timestamp';
import { coreStartMock } from '../../../../test/__mocks__/coreMocks';

describe.skip('Event explorer component', () => {
configure({ adapter: new Adapter() });

it('Renders explorer component', async () => {
const pplService = new PPLService(httpClientMock);
const dslService = new DSLService(httpClientMock);
const tabId = 'query-panel-1';
const savedObjects = new SavedObjects(httpClientMock);
const timestampUtils = new TimestampUtils(dslService);
const setToast = jest.fn();
const history = jest.fn() as any;
history.replace = jest.fn();
history.push = jest.fn();
const notifications = coreStartMock.notifications;
const savedObjectId = 'JIcoln0BYMuJGDsOLTnM';

const wrapper = mount(
<Explorer
pplService={pplService}
dslService={dslService}
tabId={tabId}
savedObjects={savedObjects}
timestampUtils={timestampUtils}
setToast={setToast}
history={history}
notifications={notifications}
savedObjectId={savedObjectId}
/>
);

wrapper.update();

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

import { configure, mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import React from 'react';
import { waitFor } from '@testing-library/react';
import { NoResults } from '../no_results';

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

it('Renders No result component', async () => {

const wrapper = mount(
<NoResults />
);

wrapper.update();

await waitFor(() => {
expect(wrapper).toMatchSnapshot();
});
});
});
Loading