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

[Backport 2.x] Fixed a unit test. #583

Merged
merged 1 commit into from
Jul 6, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,8 @@ export default class AlertsDashboardFlyoutComponent extends Component {
const { location, monitors, monitor_id } = this.props;
const monitor = _.get(_.find(monitors, { _id: monitor_id }), '_source');
const monitorType = _.get(monitor, 'monitor_type', MONITOR_TYPE.QUERY_LEVEL);
const {
alertState,
from,
search,
severityLevel,
size,
sortDirection,
sortField,
} = getURLQueryParams(location);
const { alertState, from, search, severityLevel, size, sortDirection, sortField } =
getURLQueryParams(location);

this.state = {
alerts: [],
Expand All @@ -93,16 +86,8 @@ export default class AlertsDashboardFlyoutComponent extends Component {
}

componentDidMount() {
const {
alertState,
page,
search,
severityLevel,
size,
sortDirection,
sortField,
monitorIds,
} = this.state;
const { alertState, page, search, severityLevel, size, sortDirection, sortField, monitorIds } =
this.state;
this.getAlerts(
page * size,
size,
Expand Down Expand Up @@ -175,15 +160,8 @@ export default class AlertsDashboardFlyoutComponent extends Component {

getAlerts = async () => {
this.setState({ loading: true, tabContent: undefined });
const {
from,
search,
sortField,
sortDirection,
severityLevel,
alertState,
monitorIds,
} = this.state;
const { from, search, sortField, sortDirection, severityLevel, alertState, monitorIds } =
this.state;

const { httpClient, history, notifications, triggerID } = this.props;

Expand All @@ -201,7 +179,7 @@ export default class AlertsDashboardFlyoutComponent extends Component {
const queryParamsString = queryString.stringify(params);
history.replace({ ...this.props.location, search: queryParamsString });

httpClient.get('../api/alerting/alerts', { query: params }).then((resp) => {
httpClient.get('../api/alerting/alerts', { query: params })?.then((resp) => {
if (resp.ok) {
const { alerts } = resp;
const filteredAlerts = _.filter(alerts, { trigger_id: triggerID });
Expand Down Expand Up @@ -250,16 +228,8 @@ export default class AlertsDashboardFlyoutComponent extends Component {
.catch((error) => error)
);

const {
page,
size,
search,
sortField,
sortDirection,
severityLevel,
alertState,
monitorIds,
} = this.state;
const { page, size, search, sortField, sortDirection, severityLevel, alertState, monitorIds } =
this.state;
await this.getAlerts(
page * size,
size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import React from 'react';
import { shallow } from 'enzyme';
import AlertsDashboardFlyoutComponent from './AlertsDashboardFlyoutComponent';
import { historyMock, httpClientMock } from '../../../../../test/mocks';

describe('AlertsDashboardFlyoutComponent', () => {
test('renders', () => {
Expand All @@ -14,6 +15,8 @@ describe('AlertsDashboardFlyoutComponent', () => {
location={{ pathname: '/dashboard', search: '' }}
flyout={{ type: 'message', payload: null }}
onClose={jest.fn()}
history={historyMock}
httpClient={httpClientMock}
/>
);
expect(wrapper).toMatchSnapshot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ exports[`AlertsDashboardFlyoutComponent renders 1`] = `
}
}
>
Loading conditions...
-
</p>
</EuiText>
</EuiFlexItem>
Expand Down Expand Up @@ -128,7 +128,7 @@ exports[`AlertsDashboardFlyoutComponent renders 1`] = `
Filters
</strong>
<p>
Loading filters...
-
</p>
</EuiText>
</EuiFlexItem>
Expand All @@ -141,7 +141,7 @@ exports[`AlertsDashboardFlyoutComponent renders 1`] = `
Group by
</strong>
<p>
Loading groups...
-
</p>
</EuiText>
</EuiFlexItem>
Expand Down Expand Up @@ -231,8 +231,8 @@ exports[`AlertsDashboardFlyoutComponent renders 1`] = `
isSelectable={true}
itemId={[Function]}
items={Array []}
loading={true}
noItemsMessage="Loading alerts..."
loading={false}
noItemsMessage="No alerts."
onChange={[Function]}
pagination={
Object {
Expand Down