2022-03-21 02:59:26 -05:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2023-01-02 00:23:55 -06:00
|
|
|
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
2022-03-21 02:59:26 -05:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
import jasmineEnzyme from 'jasmine-enzyme';
|
|
|
|
import React from 'react';
|
|
|
|
import '../helper/enzyme.helper';
|
|
|
|
import { withTheme } from '../fake_theme';
|
|
|
|
import { createMount } from '@material-ui/core/test-utils';
|
|
|
|
import QueryThresholds from '../../../pgadmin/static/js/components/QueryThresholds';
|
2022-03-23 02:58:35 -05:00
|
|
|
import { InputText } from '../../../pgadmin/static/js/components/FormComponents';
|
2022-03-21 02:59:26 -05:00
|
|
|
|
|
|
|
/* MUI Components need to be wrapped in Theme for theme vars */
|
|
|
|
describe('QueryThresholds', () => {
|
|
|
|
let mount;
|
|
|
|
let defult_value = {
|
|
|
|
'warning': 5,
|
|
|
|
'alert': 6
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Use createMount so that material ui components gets the required context */
|
|
|
|
/* https://material-ui.com/guides/testing/#api */
|
|
|
|
beforeAll(() => {
|
|
|
|
mount = createMount();
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(() => {
|
|
|
|
mount.cleanUp();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jasmineEnzyme();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('QueryThresholds', () => {
|
|
|
|
let ThemedFormInputQueryThresholds = withTheme(QueryThresholds), ctrl;
|
2022-03-23 02:58:35 -05:00
|
|
|
let onChange = jasmine.createSpy('onChange');
|
2022-03-21 02:59:26 -05:00
|
|
|
beforeEach(() => {
|
|
|
|
ctrl = mount(
|
|
|
|
<ThemedFormInputQueryThresholds
|
2022-03-23 02:58:35 -05:00
|
|
|
testcid="QueryThresholdCid"
|
2022-03-21 02:59:26 -05:00
|
|
|
helpMessage="some help message"
|
|
|
|
value={defult_value}
|
|
|
|
controlProps={{
|
|
|
|
extraprop: 'test'
|
|
|
|
}}
|
2022-03-23 02:58:35 -05:00
|
|
|
onChange={onChange}
|
2022-03-21 02:59:26 -05:00
|
|
|
/>);
|
|
|
|
});
|
|
|
|
|
2022-03-23 02:58:35 -05:00
|
|
|
it('Warning', (done) => {
|
|
|
|
ctrl.find(InputText).at(0).find('input').simulate('change', { warning: 5, alert: 6 });
|
|
|
|
expect(ctrl.find(InputText).at(0).prop('value')).toBe(5);
|
2022-03-21 02:59:26 -05:00
|
|
|
|
2022-03-23 02:58:35 -05:00
|
|
|
expect(onChange).toHaveBeenCalledWith({ warning: '5', alert: 6 });
|
|
|
|
done();
|
2022-03-21 02:59:26 -05:00
|
|
|
});
|
|
|
|
|
2022-03-23 02:58:35 -05:00
|
|
|
it('Alert', (done) => {
|
|
|
|
ctrl.find(InputText).at(1).find('input').simulate('change', { warning: 5, alert: 6 });
|
|
|
|
expect(ctrl.find(InputText).at(1).prop('value')).toBe(6);
|
2022-03-21 02:59:26 -05:00
|
|
|
|
2022-03-23 02:58:35 -05:00
|
|
|
expect(onChange).toHaveBeenCalledWith({ warning: 5, alert: '6' });
|
|
|
|
done();
|
2022-03-21 02:59:26 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|