pgadmin4/web/regression/javascript/components/SelectThemes.spec.js
Nikhil Mohite 2f37f0ca51 Fixes for the preferences dialog
1) Add server mode validation in the binary path.
  2) Updated preferences tree rendering to avoid using the ReactDOM render.
  3) Updated CSS for keyboard shortcuts checkbox border makes it consistent with input box border.
  4) Fixed jasmine test case and improved code coverage.
  5) Fixed SonarQube issues.
  6) Added validation to disable "Maximum column with" option if "Column sized by" option is set to "Column name" in Query Tool -> Result grid.
  7) Updated documentation with the latest screenshots.
  8) Correct typo in the documentation. Fixes #7261

refs #7149
2022-03-23 13:28:35 +05:30

97 lines
2.4 KiB
JavaScript

/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
// Copyright (C) 2013 - 2022, The pgAdmin Development Team
// 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 SelectThemes from '../../../pgadmin/static/js/components/SelectThemes';
import { InputSelect } from '../../../pgadmin/static/js/components/FormComponents';
/* MUI Components need to be wrapped in Theme for theme vars */
describe('SelectThemes', () => {
let mount;
let options = [{
value: 'standard',
preview_src: 'sd',
selected: true,
label: 'Standard'
}, {
value: 'dark',
preview_src: 'test',
selected: false,
label: 'Dark'
},
{
value: 'high_contrast',
preview_src: 'hc',
selected: false,
label: 'High Contrast',
}
];
/* 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('Select Themes', () => {
let ThemedFormInputThemes = withTheme(SelectThemes), ctrl, onChange = jasmine.createSpy('onChange');
beforeEach(() => {
ctrl = mount(
<ThemedFormInputThemes
testcid="SelectThemeCid"
helpMessage="some help message"
options={options}
onChange={onChange}
value={'standard'}
/>);
});
it('init options', () => {
expect(ctrl.find(InputSelect).at(0).prop('options').length).toBe(3);
});
it('change value', () => {
ctrl.setProps({
value: 'dark',
onChange: onChange,
});
expect(ctrl.find(InputSelect).at(0).prop('value')).toBe('dark');
});
it('onChange', () => {
let select = ctrl.find(InputSelect).at(0);
const input = select.find('input');
input.simulate('keyDown', { key: 'ArrowDown', keyCode: 40 });
input.simulate('keyDown', { key: 'Enter', keyCode: 13 });
ctrl.setProps({
value: 'dark',
onChange: onChange,
});
expect(ctrl.find(InputSelect).at(0).prop('value')).toBe('dark');
});
});
});