Skip to content

Commit

Permalink
fixed UTs
Browse files Browse the repository at this point in the history
Signed-off-by: Amardeepsingh Siglani <amardeep7194@gmail.com>
  • Loading branch information
amsiglan committed Aug 20, 2024
1 parent 37376fb commit 736a3b2
Show file tree
Hide file tree
Showing 18 changed files with 114 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { httpServiceMock, notificationServiceMock } from '../../../../../../src/
import { shallow } from 'enzyme';
import AddAlertingMonitor from './AddAlertingMonitor';
import { setClient, setNotifications } from '../../../services';
import { setupCoreStart } from '../../../../test/utils/helpers';

beforeAll(() => {
setupCoreStart();
});

describe('AddAlertingMonitor', () => {
const httpClient = httpServiceMock.createStartContract();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import React from 'react';
import { mount, render } from 'enzyme';
import { FeatureChart } from './FeatureChart';
import AlertingFakes from '../../../../../../test/utils/helpers';
import { AlertingFakes } from '../../../../../../test/utils/helpers';

const alertingFakes = new AlertingFakes('random seed');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { httpServiceMock } from '../../../../../../../src/core/public/mocks';
import CreateMonitor from './CreateMonitor';
import { historyMock, httpClientMock } from '../../../../../test/mocks';
import { FORMIK_INITIAL_VALUES } from './utils/constants';
import AlertingFakes from '../../../../../test/utils/helpers';
import { AlertingFakes, setupCoreStart } from '../../../../../test/utils/helpers';
import { SEARCH_TYPE } from '../../../../utils/constants';
import { TRIGGER_TYPE } from '../../../CreateTrigger/containers/CreateTrigger/utils/constants';
import { setClient, setNotifications } from '../../../../services';
Expand All @@ -37,6 +37,11 @@ const location = {
search: '',
state: undefined,
};

beforeAll(() => {
setupCoreStart();
});

beforeEach(() => {
jest.clearAllMocks();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import { historyMock, httpClientMock } from '../../../../../test/mocks';
import AcknowledgeAlertsModal from './AcknowledgeAlertsModal';
import { FORMIK_INITIAL_VALUES } from '../../../CreateMonitor/containers/CreateMonitor/utils/constants';
import coreMock from '../../../../../test/mocks/CoreMock';
import { setupCoreStart } from '../../../../../test/utils/helpers';

beforeEach(() => {
jest.clearAllMocks();
setupCoreStart();
});

describe('AcknowledgeAlertsModal', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import PropTypes from 'prop-types';
import { EuiSmallButton, EuiSmallButtonEmpty, EuiEmptyPrompt, EuiText } from '@elastic/eui';

import { APP_PATH } from '../../../../utils/constants';
import { MONITORS_NAV_ID, PLUGIN_NAME } from '../../../../../utils/constants';
import { MONITORS_NAV_ID } from '../../../../../utils/constants';
import { getUseUpdatedUx } from '../../../../services';

const createMonitorText =
Expand All @@ -18,7 +18,7 @@ const createTriggerText =
const editTriggerConditionsText =
'There are no existing alerts. Adjust trigger conditions to start alerting. Once an alarm is triggered, the state will show in this table.';

const createMonitorButton = (
const getCreateMonitorButton = () => (
<EuiSmallButton
fill
href={`${getUseUpdatedUx() ? MONITORS_NAV_ID : ''}#${APP_PATH.CREATE_MONITOR}`}
Expand All @@ -41,7 +41,7 @@ const DashboardEmptyPrompt = ({ onCreateTrigger, isModal = false }) => {
? undefined
: isModal
? editMonitorButton(onCreateTrigger)
: createMonitorButton;
: getCreateMonitorButton();
return (
<EuiEmptyPrompt
style={{ maxWidth: '45em' }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import React from 'react';
import { render } from 'enzyme';

import DashboardEmptyPrompt from './DashboardEmptyPrompt';
import { setupCoreStart } from '../../../../../test/utils/helpers';

beforeAll(() => {
setupCoreStart();
});

describe('DashboardEmptyPrompt', () => {
test('renders', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ exports[`DashboardEmptyPrompt renders 1`] = `
/>
<a
class="euiButton euiButton--primary euiButton--small euiButton--fill"
href="alerting#/create-monitor"
href="#/create-monitor"
rel="noreferrer"
>
<span
Expand Down
5 changes: 5 additions & 0 deletions public/pages/Dashboard/containers/Dashboard.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { mount } from 'enzyme';

import Dashboard from './Dashboard';
import { historyMock, httpClientMock } from '../../../../test/mocks';
import { setupCoreStart } from '../../../../test/utils/helpers';

const location = {
hash: '',
Expand Down Expand Up @@ -56,6 +57,10 @@ const sampleQueryAlerts = [

const runAllPromises = () => new Promise(setImmediate);

beforeAll(() => {
setupCoreStart();
});

describe('Dashboard', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ exports[`Dashboard renders in flyout 1`] = `
"padding": "initial",
}
}
panelOptions={
Object {
"hideTitleBorder": false,
}
}
title="Alerts"
titleSize="s"
>
Expand Down Expand Up @@ -300,14 +305,15 @@ exports[`Dashboard renders in flyout 1`] = `
state="ALL"
>
<EuiFlexGroup
gutterSize="s"
style={
Object {
"padding": "0px 5px",
}
}
>
<div
className="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
className="euiFlexGroup euiFlexGroup--gutterSmall euiFlexGroup--directionRow euiFlexGroup--responsive"
style={
Object {
"padding": "0px 5px",
Expand Down Expand Up @@ -1498,7 +1504,7 @@ exports[`Dashboard renders in flyout 1`] = `
actions={
<EuiSmallButton
fill={true}
href="alerting#/create-monitor"
href="#/create-monitor"
>
Create monitor
</EuiSmallButton>
Expand Down Expand Up @@ -1560,26 +1566,26 @@ exports[`Dashboard renders in flyout 1`] = `
</EuiSpacer>
<EuiSmallButton
fill={true}
href="alerting#/create-monitor"
href="#/create-monitor"
>
<EuiButton
fill={true}
href="alerting#/create-monitor"
href="#/create-monitor"
size="s"
>
<EuiButtonDisplay
baseClassName="euiButton"
element="a"
fill={true}
href="alerting#/create-monitor"
href="#/create-monitor"
isDisabled={false}
rel="noreferrer"
size="s"
>
<a
className="euiButton euiButton--primary euiButton--small euiButton--fill"
disabled={false}
href="alerting#/create-monitor"
href="#/create-monitor"
rel="noreferrer"
style={
Object {
Expand Down Expand Up @@ -1706,6 +1712,11 @@ exports[`Dashboard renders with alert by triggers view 1`] = `
"padding": "initial",
}
}
panelOptions={
Object {
"hideTitleBorder": undefined,
}
}
title="Alerts by triggers"
titleSize="s"
>
Expand Down Expand Up @@ -1958,14 +1969,15 @@ exports[`Dashboard renders with alert by triggers view 1`] = `
state="ALL"
>
<EuiFlexGroup
gutterSize="s"
style={
Object {
"padding": "0px 5px",
}
}
>
<div
className="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
className="euiFlexGroup euiFlexGroup--gutterSmall euiFlexGroup--directionRow euiFlexGroup--responsive"
style={
Object {
"padding": "0px 5px",
Expand Down Expand Up @@ -3549,7 +3561,7 @@ exports[`Dashboard renders with alert by triggers view 1`] = `
actions={
<EuiSmallButton
fill={true}
href="alerting#/create-monitor"
href="#/create-monitor"
>
Create monitor
</EuiSmallButton>
Expand Down Expand Up @@ -3611,26 +3623,26 @@ exports[`Dashboard renders with alert by triggers view 1`] = `
</EuiSpacer>
<EuiSmallButton
fill={true}
href="alerting#/create-monitor"
href="#/create-monitor"
>
<EuiButton
fill={true}
href="alerting#/create-monitor"
href="#/create-monitor"
size="s"
>
<EuiButtonDisplay
baseClassName="euiButton"
element="a"
fill={true}
href="alerting#/create-monitor"
href="#/create-monitor"
isDisabled={false}
rel="noreferrer"
size="s"
>
<a
className="euiButton euiButton--primary euiButton--small euiButton--fill"
disabled={false}
href="alerting#/create-monitor"
href="#/create-monitor"
rel="noreferrer"
style={
Object {
Expand Down Expand Up @@ -3751,6 +3763,11 @@ exports[`Dashboard renders with per alert view 1`] = `
"padding": "initial",
}
}
panelOptions={
Object {
"hideTitleBorder": false,
}
}
title="Alerts"
titleSize="s"
>
Expand Down Expand Up @@ -3943,14 +3960,15 @@ exports[`Dashboard renders with per alert view 1`] = `
state="ALL"
>
<EuiFlexGroup
gutterSize="s"
style={
Object {
"padding": "0px 5px",
}
}
>
<div
className="euiFlexGroup euiFlexGroup--gutterLarge euiFlexGroup--directionRow euiFlexGroup--responsive"
className="euiFlexGroup euiFlexGroup--gutterSmall euiFlexGroup--directionRow euiFlexGroup--responsive"
style={
Object {
"padding": "0px 5px",
Expand Down Expand Up @@ -5315,7 +5333,7 @@ exports[`Dashboard renders with per alert view 1`] = `
actions={
<EuiSmallButton
fill={true}
href="alerting#/create-monitor"
href="#/create-monitor"
>
Create monitor
</EuiSmallButton>
Expand Down Expand Up @@ -5377,26 +5395,26 @@ exports[`Dashboard renders with per alert view 1`] = `
</EuiSpacer>
<EuiSmallButton
fill={true}
href="alerting#/create-monitor"
href="#/create-monitor"
>
<EuiButton
fill={true}
href="alerting#/create-monitor"
href="#/create-monitor"
size="s"
>
<EuiButtonDisplay
baseClassName="euiButton"
element="a"
fill={true}
href="alerting#/create-monitor"
href="#/create-monitor"
isDisabled={false}
rel="noreferrer"
size="s"
>
<a
className="euiButton euiButton--primary euiButton--small euiButton--fill"
disabled={false}
href="alerting#/create-monitor"
href="#/create-monitor"
rel="noreferrer"
style={
Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import React from 'react';
import { render } from 'enzyme';

import FullPageNotificationsInfoCallOut from './FullPageNotificationsInfoCallOut';
import { setupCoreStart } from '../../../../../test/utils/helpers';

beforeAll(() => {
setupCoreStart();
});

describe('FullPageNotificationsInfoCallOut', () => {
test('renders when Notifications plugin is installed', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import React from 'react';
import { render } from 'enzyme';

import NotificationsInfoCallOut from './NotificationsInfoCallOut';
import { setupCoreStart } from '../../../../../test/utils/helpers';

beforeAll(() => {
setupCoreStart();
});

describe('NotificationsInfoCallOut', () => {
test('renders when Notifications plugin is installed', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import DestinationsList from './DestinationsList';
import { historyMock, httpClientMock } from '../../../../../test/mocks';
import { DESTINATION_TYPE } from '../../utils/constants';
import { OS_NOTIFICATION_PLUGIN } from '../../../../utils/constants';
import { setupCoreStart } from '../../../../../test/utils/helpers';

const location = {
hash: '',
Expand All @@ -19,6 +20,10 @@ const location = {

const runAllPromises = () => new Promise(setImmediate);

beforeAll(() => {
setupCoreStart();
});

describe('DestinationsList', () => {
beforeEach(() => {
jest.clearAllMocks();
Expand Down
5 changes: 5 additions & 0 deletions public/pages/Main/Main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import * as Breadcrumbs from '../../components/Breadcrumbs/Breadcrumbs';
import { createMemoryHistory } from 'history';

import Main from './Main';
import { setupCoreStart } from '../../../test/utils/helpers';

beforeAll(() => {
setupCoreStart();
});

describe('Main', () => {
test('renders', () => {
Expand Down
Loading

0 comments on commit 736a3b2

Please sign in to comment.