mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Significant changes to use ReactJS extensively.
1. Replace the current layout library wcDocker with ReactJS based rc-dock. #6479 2. Have close buttons on individual panel tabs instead of common. #2821 3. Changes in the context menu on panel tabs - Add close, close all and close others menu items. #5394 4. Allow closing all the tabs, including SQL and Properties. #4733 5. Changes in docking behaviour of different tabs based on user requests and remove lock layout menu. 6. Fix an issue where the scroll position of panels was not remembered on Firefox. #2986 7. Reset layout now will not require page refresh and is done spontaneously. 8. Use the zustand store for storing preferences instead of plain JS objects. This will help reflecting preferences immediately. 9. The above fix incorrect format (no indent) of SQL stored functions/procedures. #6720 10. New version check is moved to an async request now instead of app start to improve startup performance. 11. Remove jQuery and Bootstrap completely. 12. Replace jasmine and karma test runner with jest. Migrate all the JS test cases to jest. This will save time in writing and debugging JS tests. 13. Other important code improvements and cleanup.
This commit is contained in:
281
web/regression/javascript/SchemaView/SchemaDialogView.spec.js
Normal file
281
web/regression/javascript/SchemaView/SchemaDialogView.spec.js
Normal file
@@ -0,0 +1,281 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { act, render } from '@testing-library/react';
|
||||
import {TestSchema} from './TestSchema.ui';
|
||||
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
import pgAdmin from '../fake_pgadmin';
|
||||
import { withBrowser } from '../genericFunctions';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
function getSchema() {
|
||||
return new TestSchema();
|
||||
}
|
||||
|
||||
describe('SchemaView', ()=>{
|
||||
const SchemaViewWithBrowser = withBrowser(SchemaView);
|
||||
const user = userEvent.setup();
|
||||
let confirmSpy;
|
||||
|
||||
beforeAll(()=>{
|
||||
jest.spyOn(pgAdmin.Browser.notifier, 'alert').mockImplementation(() => {});
|
||||
confirmSpy = jest.spyOn(pgAdmin.Browser.notifier, 'confirm');
|
||||
});
|
||||
|
||||
describe('SchemaDialogView', ()=>{
|
||||
let ctrl,
|
||||
onSave=jest.fn(() => Promise.resolve()),
|
||||
onClose=jest.fn(),
|
||||
onHelp=jest.fn(),
|
||||
onEdit=jest.fn(),
|
||||
onDataChange=jest.fn(),
|
||||
getSQLValue=jest.fn(() => {
|
||||
return Promise.resolve('select 1;');
|
||||
}),
|
||||
ctrlMount = async (props)=>{
|
||||
await act(async ()=>{
|
||||
ctrl = await render(
|
||||
<SchemaViewWithBrowser
|
||||
formType='dialog'
|
||||
schema={getSchema()}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={onSave}
|
||||
onClose={onClose}
|
||||
onHelp={onHelp}
|
||||
onEdit={onEdit}
|
||||
onDataChange={onDataChange}
|
||||
confirmOnCloseReset={true}
|
||||
hasSQL={true}
|
||||
getSQLValue={getSQLValue}
|
||||
disableSqlHelp={false}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
},
|
||||
simulateValidData = async ()=>{
|
||||
await user.type(ctrl.container.querySelector('[name="field1"]'), 'val1');
|
||||
await user.type(ctrl.container.querySelector('[name="field2"]'), '2');
|
||||
await user.type(ctrl.container.querySelector('[name="field5"]'), 'val5');
|
||||
/* Add a row */
|
||||
await user.click(ctrl.container.querySelector('[data-test="add-row"]'));
|
||||
await user.click(ctrl.container.querySelector('[data-test="add-row"]'));
|
||||
await user.type(ctrl.container.querySelectorAll('[name="field5"]')[0], 'rval51');
|
||||
await user.type(ctrl.container.querySelectorAll('[name="field5"]')[1], 'rval52');
|
||||
};
|
||||
|
||||
describe('form fields', ()=>{
|
||||
beforeEach(async ()=>{
|
||||
await ctrlMount({
|
||||
getInitData: ()=>Promise.resolve({}),
|
||||
});
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
expect(ctrl.container.querySelectorAll('[data-testid="form-input"]').length).toBe(5);
|
||||
expect(ctrl.container.querySelector('[data-test="Reset"]').hasAttribute('disabled')).toBe(true);
|
||||
expect(ctrl.container.querySelector('[data-test="Save"]').hasAttribute('disabled')).toBe(true);
|
||||
});
|
||||
|
||||
it('change text', async ()=>{
|
||||
await user.type(ctrl.container.querySelector('[name="field2"]'), '2');
|
||||
/* Error should come for field1 as it is empty and noEmpty true */
|
||||
expect(ctrl.container.querySelector('[data-test="notifier-message"]')).toHaveTextContent('\'Field1\' cannot be empty.');
|
||||
expect(ctrl.container.querySelector('[data-test="Save"]').hasAttribute('disabled')).toBe(true);
|
||||
});
|
||||
|
||||
it('close error on click', async ()=>{
|
||||
await user.click(ctrl.container.querySelector('[data-test="notifier-message"] button'));
|
||||
expect(ctrl.container.querySelector('[data-test="notifier-message"]')).toBe(null);
|
||||
});
|
||||
|
||||
it('valid form data', async ()=>{
|
||||
await simulateValidData();
|
||||
expect(ctrl.container.querySelector('[data-test="notifier-message"]')).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('DataGridView', ()=>{
|
||||
beforeEach(async ()=>{
|
||||
await ctrlMount({
|
||||
getInitData: ()=>Promise.resolve({}),
|
||||
});
|
||||
});
|
||||
|
||||
it('add row', async ()=>{
|
||||
await simulateValidData();
|
||||
await user.click(ctrl.container.querySelector('[data-test="add-row"]'));
|
||||
expect(ctrl.container.querySelectorAll('[data-test="data-table-row"]').length).toBe(3);
|
||||
});
|
||||
|
||||
it('remove row OK', async ()=>{
|
||||
await simulateValidData();
|
||||
/* Press OK */
|
||||
confirmSpy.mockClear();
|
||||
await user.click(ctrl.container.querySelector('[data-test="delete-row"]'));
|
||||
await act(async ()=>{
|
||||
await new Promise(resolve => setTimeout(resolve));
|
||||
confirmSpy.mock.calls[0][2]();
|
||||
});
|
||||
expect(confirmSpy.mock.calls[0][0]).toBe('Custom delete title');
|
||||
expect(confirmSpy.mock.calls[0][1]).toBe('Custom delete message');
|
||||
});
|
||||
|
||||
it('remove row Cancel', async ()=>{
|
||||
await simulateValidData();
|
||||
/* Press Cancel */
|
||||
confirmSpy.mockClear();
|
||||
await user.click(ctrl.container.querySelector('[data-test="delete-row"]'));
|
||||
await act(async ()=>{
|
||||
await new Promise(resolve => setTimeout(resolve));
|
||||
confirmSpy.mock.calls[0][3]();
|
||||
});
|
||||
expect(ctrl.container.querySelector('[data-test="notifier-message"]')).toBe(null);
|
||||
});
|
||||
|
||||
it('expand row', async ()=>{
|
||||
await simulateValidData();
|
||||
await user.click(ctrl.container.querySelector('[data-test="expand-row"]'));
|
||||
expect(ctrl.container.querySelectorAll('[data-test="data-grid-view"] [data-test="form-view"]').length).toBe(1);
|
||||
});
|
||||
|
||||
it('unique col test', async ()=>{
|
||||
await simulateValidData();
|
||||
await user.clear(ctrl.container.querySelectorAll('[name="field5"]')[1]);
|
||||
await user.type(ctrl.container.querySelectorAll('[name="field5"]')[1], 'rval51');
|
||||
expect(ctrl.container.querySelector('[data-test="notifier-message"]')).toHaveTextContent('Field5 in FieldColl must be unique.');
|
||||
});
|
||||
});
|
||||
|
||||
describe('SQL tab', ()=>{
|
||||
beforeEach(async ()=>{
|
||||
await ctrlMount({
|
||||
getInitData: ()=>Promise.resolve({}),
|
||||
});
|
||||
});
|
||||
|
||||
it('no changes', async ()=>{
|
||||
await user.click(ctrl.container.querySelector('button[data-test="SQL"]'));
|
||||
expect(ctrl.container.querySelector('[data-testid="SQL"] textarea')).toHaveValue('-- No updates.');
|
||||
});
|
||||
|
||||
it('data invalid', async ()=>{
|
||||
await user.clear(ctrl.container.querySelector('[name="field2"]'));
|
||||
await user.type(ctrl.container.querySelector('[name="field2"]'), '2');
|
||||
await user.click(ctrl.container.querySelector('button[data-test="SQL"]'));
|
||||
expect(ctrl.container.querySelector('[data-testid="SQL"] textarea')).toHaveValue('-- Definition incomplete.');
|
||||
});
|
||||
|
||||
it('valid data', async ()=>{
|
||||
await simulateValidData();
|
||||
await user.click(ctrl.container.querySelector('button[data-test="SQL"]'));
|
||||
expect(ctrl.container.querySelector('[data-testid="SQL"] textarea')).toHaveValue('select 1;');
|
||||
});
|
||||
});
|
||||
|
||||
describe('others', ()=>{
|
||||
beforeEach(async ()=>{
|
||||
await ctrlMount({
|
||||
getInitData: ()=>Promise.resolve({}),
|
||||
});
|
||||
});
|
||||
|
||||
it('onSave click', async ()=>{
|
||||
await simulateValidData();
|
||||
onSave.mockClear();
|
||||
await user.click(ctrl.container.querySelector('button[data-test="Save"]'));
|
||||
expect(onSave.mock.calls[0][0]).toBe(true);
|
||||
expect(onSave.mock.calls[0][1]).toEqual({
|
||||
id: undefined,
|
||||
field1: 'val1',
|
||||
field2: '2',
|
||||
field5: 'val5',
|
||||
fieldcoll: [
|
||||
{field3: null, field4: null, field5: 'rval51'},
|
||||
{field3: null, field4: null, field5: 'rval52'},
|
||||
]
|
||||
});
|
||||
expect(pgAdmin.Browser.notifier.alert).toHaveBeenCalledWith('Warning', 'some inform text');
|
||||
});
|
||||
|
||||
it('onHelp SQL', async ()=>{
|
||||
await user.click(ctrl.container.querySelector('[data-test="sql-help"]'));
|
||||
expect(onHelp).toHaveBeenCalledWith(true, true);
|
||||
});
|
||||
|
||||
it('onHelp Dialog', async ()=>{
|
||||
await user.click(ctrl.container.querySelector('[data-test="dialog-help"]'));
|
||||
expect(onHelp).toHaveBeenCalledWith(false, true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('onReset', ()=>{
|
||||
let onResetAction = (data)=> {
|
||||
expect(ctrl.container.querySelector('[data-test="Reset"]').hasAttribute('disabled')).toBe(true);
|
||||
expect(ctrl.container.querySelector('[data-test="Save"]').hasAttribute('disabled')).toBe(true);
|
||||
expect(onDataChange).toHaveBeenCalledWith(false, data);
|
||||
};
|
||||
|
||||
beforeEach(async ()=>{
|
||||
await ctrlMount({
|
||||
getInitData: ()=>Promise.resolve({}),
|
||||
});
|
||||
});
|
||||
|
||||
it('with confirm check and yes click', async ()=>{
|
||||
await simulateValidData();
|
||||
onDataChange.mockClear();
|
||||
confirmSpy.mockClear();
|
||||
await user.click(ctrl.container.querySelector('button[data-test="Reset"]'));
|
||||
/* Press OK */
|
||||
await act(async ()=>{
|
||||
await new Promise(resolve => setTimeout(resolve));
|
||||
confirmSpy.mock.calls[0][2]();
|
||||
});
|
||||
onResetAction({ id: undefined, field1: null, field2: null, fieldcoll: null });
|
||||
});
|
||||
|
||||
it('with confirm check and cancel click', async ()=>{
|
||||
await simulateValidData();
|
||||
confirmSpy.mockClear();
|
||||
await user.click(ctrl.container.querySelector('button[data-test="Reset"]'));
|
||||
/* Press cancel */
|
||||
await act(async ()=>{
|
||||
await new Promise(resolve => setTimeout(resolve));
|
||||
confirmSpy.mock.calls[0][3]();
|
||||
});
|
||||
expect(ctrl.container.querySelector('[data-test="Reset"]').hasAttribute('disabled')).toBe(false);
|
||||
expect(ctrl.container.querySelector('[data-test="Save"]').hasAttribute('disabled')).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
it('no confirm check', async ()=>{
|
||||
await ctrlMount({
|
||||
confirmOnCloseReset: false,
|
||||
});
|
||||
|
||||
await simulateValidData();
|
||||
onDataChange.mockClear();
|
||||
confirmSpy.mockClear();
|
||||
await user.click(ctrl.container.querySelector('button[data-test="Reset"]'));
|
||||
expect(confirmSpy).not.toHaveBeenCalled();
|
||||
expect(ctrl.container.querySelector('[data-test="Reset"]').hasAttribute('disabled')).toBe(true);
|
||||
expect(ctrl.container.querySelector('[data-test="Save"]').hasAttribute('disabled')).toBe(true);
|
||||
// on reset, orig data will be considered
|
||||
expect(onDataChange).toHaveBeenCalledWith(false, { id: undefined, field1: null, field2: null, fieldcoll: null });
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,154 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { act, render } from '@testing-library/react';
|
||||
import {TestSchema} from './TestSchema.ui';
|
||||
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
import pgAdmin from '../fake_pgadmin';
|
||||
import { withBrowser } from '../genericFunctions';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
const initData = {
|
||||
id: 1,
|
||||
field1: 'field1val',
|
||||
field2: 1,
|
||||
fieldcoll: [
|
||||
{field3: 1, field4: 'field4val1', field5: 'field5val1'},
|
||||
{field3: 2, field4: 'field4val2', field5: 'field5val2'},
|
||||
],
|
||||
field3: 3,
|
||||
field4: 'field4val',
|
||||
};
|
||||
|
||||
function getInitData() {
|
||||
return Promise.resolve(initData);
|
||||
}
|
||||
|
||||
function getSchema() {
|
||||
return new TestSchema();
|
||||
}
|
||||
|
||||
describe('SchemaView', ()=>{
|
||||
const SchemaViewWithBrowser = withBrowser(SchemaView);
|
||||
const user = userEvent.setup();
|
||||
|
||||
beforeAll(()=>{
|
||||
jest.spyOn(pgAdmin.Browser.notifier, 'alert').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
describe('SchemaDialogView', ()=>{
|
||||
let ctrl,
|
||||
onSave=jest.fn(() => Promise.resolve()),
|
||||
onClose=jest.fn(),
|
||||
onHelp=jest.fn(),
|
||||
onEdit=jest.fn(),
|
||||
onDataChange=jest.fn(),
|
||||
getSQLValue=jest.fn(() => Promise.resolve('select 1;')),
|
||||
ctrlMount = async (props)=>{
|
||||
await act(async ()=>{
|
||||
ctrl = render(
|
||||
<SchemaViewWithBrowser
|
||||
formType='dialog'
|
||||
schema={getSchema()}
|
||||
viewHelperProps={{
|
||||
mode: 'edit',
|
||||
}}
|
||||
onSave={onSave}
|
||||
onClose={onClose}
|
||||
onHelp={onHelp}
|
||||
onEdit={onEdit}
|
||||
onDataChange={onDataChange}
|
||||
confirmOnCloseReset={true}
|
||||
hasSQL={true}
|
||||
getSQLValue={getSQLValue}
|
||||
disableSqlHelp={false}
|
||||
getInitData={getInitData}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
describe('edit mode', ()=>{
|
||||
let simulateChanges = async ()=>{
|
||||
await user.clear(ctrl.container.querySelector('[name="field1"]'));
|
||||
await user.type(ctrl.container.querySelector('[name="field1"]'), 'val1');
|
||||
await user.clear(ctrl.container.querySelector('[name="field5"]'));
|
||||
await user.type(ctrl.container.querySelector('[name="field5"]'), 'val5');
|
||||
/* Add a row */
|
||||
await user.click(ctrl.container.querySelector('[data-test="add-row"]'));
|
||||
await user.type(ctrl.container.querySelectorAll('[data-test="data-table-row"] [name="field5"]')[2], 'rval53');
|
||||
/* Remove the 1st row */
|
||||
let confirmSpy = jest.spyOn(pgAdmin.Browser.notifier, 'confirm');
|
||||
confirmSpy.mockClear();
|
||||
await user.click(ctrl.container.querySelectorAll('[data-test="delete-row"]')[0]);
|
||||
await act(async ()=>{
|
||||
confirmSpy.mock.calls[0][2]();
|
||||
});
|
||||
|
||||
/* Edit the 2nd row which is first now*/
|
||||
await user.type(ctrl.container.querySelectorAll('[data-test="data-table-row"] [name="field5"]')[0], 'rvalnew');
|
||||
};
|
||||
beforeEach(async ()=>{
|
||||
await ctrlMount();
|
||||
});
|
||||
it('init', ()=>{
|
||||
expect(ctrl.container.querySelectorAll('[data-testid="form-input"]').length).toBe(3);
|
||||
expect(ctrl.container.querySelectorAll('[data-test="data-table-row"').length).toBe(2);
|
||||
expect(ctrl.container.querySelector('[data-test="Reset"]').hasAttribute('disabled')).toBe(true);
|
||||
expect(ctrl.container.querySelector('[data-test="Save"]').hasAttribute('disabled')).toBe(true);
|
||||
});
|
||||
|
||||
it('onSave after change', async ()=>{
|
||||
pgAdmin.Browser.notifier.alert.mockClear();
|
||||
onSave.mockClear();
|
||||
// TODO: don't know why save button remains disabled.
|
||||
// await simulateChanges();
|
||||
// await user.click(ctrl.container.querySelector('[data-test="Save"]'));
|
||||
|
||||
// expect(onSave.mock.calls[0][0]).toBe(false);
|
||||
// expect(onSave.mock.calls[0][1]).toEqual({
|
||||
// id: 1,
|
||||
// field1: 'val1',
|
||||
// field5: 'val5',
|
||||
// fieldcoll: {
|
||||
// added: [
|
||||
// { field3: null, field4: null, field5: 'rval53'}
|
||||
// ],
|
||||
// changed: [
|
||||
// { field3: 2, field4: 'field4val2', field5: 'rvalnew'}
|
||||
// ],
|
||||
// deleted: [
|
||||
// { field3: 1, field4: 'field4val1', field5: 'field5val1'}
|
||||
// ]
|
||||
// }
|
||||
// });
|
||||
// expect(pgAdmin.Browser.notifier.alert).toHaveBeenCalledWith('Warning', 'some inform text');
|
||||
});
|
||||
|
||||
it('onReset after change', async ()=>{
|
||||
onDataChange.mockClear();
|
||||
await simulateChanges();
|
||||
let confirmSpy = jest.spyOn(pgAdmin.Browser.notifier, 'confirm');
|
||||
await user.click(ctrl.container.querySelector('[data-test="Reset"]'));
|
||||
/* Press OK */
|
||||
await act(async ()=>{
|
||||
confirmSpy.mock.calls[confirmSpy.mock.calls.length - 1][2]();
|
||||
});
|
||||
expect(ctrl.container.querySelector('[data-test="Reset"]').hasAttribute('disabled')).toBe(true);
|
||||
expect(ctrl.container.querySelector('[data-test="Save"]').hasAttribute('disabled')).toBe(true);
|
||||
expect(onDataChange).toHaveBeenCalledWith(false, {});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,87 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { act, render } from '@testing-library/react';
|
||||
import {TestSchema} from './TestSchema.ui';
|
||||
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
import pgAdmin from '../fake_pgadmin';
|
||||
import { withBrowser } from '../genericFunctions';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
const initData = {
|
||||
id: 1,
|
||||
field1: 'field1val',
|
||||
field2: 1,
|
||||
fieldcoll: [
|
||||
{field3: 1, field4: 'field4val1', field5: 'field5val1'},
|
||||
{field3: 2, field4: 'field4val2', field5: 'field5val2'},
|
||||
],
|
||||
field3: 3,
|
||||
field4: 'field4val',
|
||||
};
|
||||
|
||||
function getInitData() {
|
||||
return Promise.resolve(initData);
|
||||
}
|
||||
|
||||
function getSchema() {
|
||||
return new TestSchema();
|
||||
}
|
||||
|
||||
describe('SchemaView', ()=>{
|
||||
const SchemaViewWithBrowser = withBrowser(SchemaView);
|
||||
const user = userEvent.setup();
|
||||
|
||||
beforeAll(()=>{
|
||||
jest.spyOn(pgAdmin.Browser.notifier, 'alert').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
describe('SchemaPropertiesView', ()=>{
|
||||
let onEdit = jest.fn(),
|
||||
onHelp = jest.fn(),
|
||||
ctrl = null;
|
||||
|
||||
beforeEach(async ()=>{
|
||||
await act(async ()=>{
|
||||
ctrl = render(
|
||||
<SchemaViewWithBrowser
|
||||
formType='tab'
|
||||
schema={getSchema()}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={onHelp}
|
||||
disableSqlHelp={false}
|
||||
onEdit={onEdit}
|
||||
/>
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
expect(ctrl.container.querySelectorAll('[data-testid="form-input"]').length).toBe(5);
|
||||
expect(ctrl.container.querySelectorAll('.MuiAccordion-root').length).toBe(2);
|
||||
});
|
||||
|
||||
it('onHelp', async ()=>{
|
||||
await user.click(ctrl.container.querySelector('button[data-test="help"]'));
|
||||
expect(onHelp).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onEdit', async ()=>{
|
||||
await user.click(ctrl.container.querySelector('button[data-test="edit"]'));
|
||||
expect(onEdit).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,552 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import _ from 'lodash';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import {TestSchema, TestSchemaAllTypes} from './TestSchema.ui';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import {messages} from '../fake_messages';
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
import Notify from '../../../pgadmin/static/js/helpers/Notifier';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
|
||||
const initData = {
|
||||
id: 1,
|
||||
field1: 'field1val',
|
||||
field2: 1,
|
||||
fieldcoll: [
|
||||
{field3: 1, field4: 'field4val1', field5: 'field5val1'},
|
||||
{field3: 2, field4: 'field4val2', field5: 'field5val2'},
|
||||
],
|
||||
field3: 3,
|
||||
field4: 'field4val',
|
||||
};
|
||||
|
||||
function getInitData() {
|
||||
return Promise.resolve(initData);
|
||||
}
|
||||
|
||||
function getSchema() {
|
||||
return new TestSchema();
|
||||
}
|
||||
|
||||
function getSchemaAllTypes() {
|
||||
return new TestSchemaAllTypes();
|
||||
}
|
||||
|
||||
describe('SchemaView', ()=>{
|
||||
let mount;
|
||||
let numberChangeEvent = (value)=>{
|
||||
return {
|
||||
target: {
|
||||
value: value,
|
||||
validity: {
|
||||
valid: true,
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(()=>{
|
||||
mount = createMount();
|
||||
spyOn(Notify, 'alert');
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
});
|
||||
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
/* messages used by validators */
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.messages = pgAdmin.Browser.messages || messages;
|
||||
});
|
||||
|
||||
describe('SchemaDialogView', ()=>{
|
||||
let ctrl,
|
||||
onSave=jasmine.createSpy('onSave').and.returnValue(Promise.resolve()),
|
||||
onClose=jasmine.createSpy('onClose'),
|
||||
onHelp=jasmine.createSpy('onHelp'),
|
||||
onEdit=jasmine.createSpy('onEdit'),
|
||||
onDataChange=jasmine.createSpy('onDataChange'),
|
||||
getSQLValue=jasmine.createSpy('onEdit').and.returnValue(Promise.resolve('select 1;')),
|
||||
ctrlMount = (props)=>{
|
||||
ctrl?.unmount();
|
||||
ctrl = mount(<Theme>
|
||||
<SchemaView
|
||||
formType='dialog'
|
||||
schema={getSchema()}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={onSave}
|
||||
onClose={onClose}
|
||||
onHelp={onHelp}
|
||||
onEdit={onEdit}
|
||||
onDataChange={onDataChange}
|
||||
confirmOnCloseReset={true}
|
||||
hasSQL={true}
|
||||
getSQLValue={getSQLValue}
|
||||
disableSqlHelp={false}
|
||||
{...props}
|
||||
/>
|
||||
</Theme>);
|
||||
},
|
||||
simulateValidData = ()=>{
|
||||
ctrl.find('MappedFormControl[id="field1"]').find('input').simulate('change', {target: {value: 'val1'}});
|
||||
ctrl.find('MappedFormControl[id="field2"]').find('input').simulate('change', numberChangeEvent('2'));
|
||||
ctrl.find('MappedFormControl[id="field5"]').find('textarea').simulate('change', {target: {value: 'val5'}});
|
||||
/* Add a row */
|
||||
ctrl.find('DataGridView').find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
ctrl.find('DataGridView').find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
ctrl.find('MappedCellControl[id="field5"]').at(0).find('input').simulate('change', {target: {value: 'rval51'}});
|
||||
ctrl.find('MappedCellControl[id="field5"]').at(1).find('input').simulate('change', {target: {value: 'rval52'}});
|
||||
};
|
||||
beforeEach(()=>{
|
||||
ctrlMount({
|
||||
getInitData: ()=>Promise.resolve({}),
|
||||
});
|
||||
});
|
||||
|
||||
it('init', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('MappedFormControl').length).toBe(6);
|
||||
expect(ctrl.find('FormView').length).toBe(2);
|
||||
expect(ctrl.find('DataGridView').length).toBe(1);
|
||||
expect(ctrl.find('DefaultButton[data-test="Reset"]').prop('disabled')).toBeTrue();
|
||||
expect(ctrl.find('PrimaryButton[data-test="Save"]').prop('disabled')).toBeTrue();
|
||||
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('change text', (done)=>{
|
||||
ctrl.find('MappedFormControl[id="field2"]').find('input').simulate('change', numberChangeEvent('2'));
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
/* Error should come for field1 as it is empty and noEmpty true */
|
||||
expect(ctrl.find('FormFooterMessage').prop('message')).toBe(_.escape('\'Field1\' cannot be empty.'));
|
||||
expect(ctrl.find('PrimaryButton[data-test="Save"]').prop('disabled')).toBeTrue();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('close error on click', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
ctrl.find('FormFooterMessage').find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('FormFooterMessage').prop('message')).toBe('');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('valid form data', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
simulateValidData();
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('FormFooterMessage').prop('message')).toBeFalsy();
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
describe('DataGridView', ()=>{
|
||||
let ctrlUpdate = (done)=> {
|
||||
ctrl.update();
|
||||
expect(ctrl.find('DataGridView').find('DataTableRow').length).toBe(1);
|
||||
done();
|
||||
};
|
||||
|
||||
it('add row', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
ctrl.find('DataGridView').find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrlUpdate(done);
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('remove row', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
simulateValidData();
|
||||
|
||||
/* Press OK */
|
||||
let confirmSpy = spyOn(Notify, 'confirm').and.callThrough();
|
||||
ctrl.find('DataGridView').find('PgIconButton[data-test="delete-row"]').at(0).find('button').simulate('click');
|
||||
confirmSpy.calls.argsFor(0)[2]();
|
||||
|
||||
expect(confirmSpy.calls.argsFor(0)[0]).toBe('Custom delete title');
|
||||
expect(confirmSpy.calls.argsFor(0)[1]).toBe('Custom delete message');
|
||||
/* Press Cancel */
|
||||
confirmSpy.calls.reset();
|
||||
ctrl.find('DataGridView').find('PgIconButton[data-test="delete-row"]').at(0).find('button').simulate('click');
|
||||
confirmSpy.calls.argsFor(0)[3]();
|
||||
|
||||
setTimeout(()=>{
|
||||
ctrlUpdate(done);
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('expand row', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
simulateValidData();
|
||||
ctrl.find('DataGridView').find('PgIconButton[data-test="expand-row"]').at(0).find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('DataGridView').find('FormView').length).toBe(1);
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('unique col test', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
simulateValidData();
|
||||
ctrl.find('MappedCellControl[id="field5"]').at(1).find('input').simulate('change', {target: {value: 'rval51'}});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('FormFooterMessage').prop('message')).toBe('Field5 in FieldColl must be unique.');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('SQL tab', ()=>{
|
||||
it('no changes', (done)=>{
|
||||
ctrl.find('ForwardRef(Tab)[label="SQL"]').find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('CodeMirror').prop('value')).toBe('-- No updates.');
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('data invalid', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
ctrl.find('MappedFormControl[id="field2"]').find('input').simulate('change', numberChangeEvent('2'));
|
||||
ctrl.find('ForwardRef(Tab)[label="SQL"]').find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('CodeMirror').prop('value')).toBe('-- Definition incomplete.');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('valid data', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
simulateValidData();
|
||||
ctrl.find('ForwardRef(Tab)[label="SQL"]').find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('CodeMirror').prop('value')).toBe('select 1;');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
it('onSave click', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
simulateValidData();
|
||||
onSave.calls.reset();
|
||||
ctrl.find('PrimaryButton[data-test="Save"]').simulate('click');
|
||||
setTimeout(()=>{
|
||||
expect(onSave.calls.argsFor(0)[0]).toBe(true);
|
||||
expect(onSave.calls.argsFor(0)[1]).toEqual({
|
||||
id: undefined,
|
||||
field1: 'val1',
|
||||
field2: '2',
|
||||
field5: 'val5',
|
||||
fieldcoll: [
|
||||
{field3: null, field4: null, field5: 'rval51'},
|
||||
{field3: null, field4: null, field5: 'rval52'},
|
||||
]
|
||||
});
|
||||
expect(Notify.alert).toHaveBeenCalledWith('Warning', 'some inform text');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
let onResetAction = (done, data)=> {
|
||||
ctrl.update();
|
||||
expect(ctrl.find('DefaultButton[data-test="Reset"]').prop('disabled')).toBeTrue();
|
||||
expect(ctrl.find('PrimaryButton[data-test="Save"]').prop('disabled')).toBeTrue();
|
||||
expect(onDataChange).toHaveBeenCalledWith(false, data);
|
||||
done();
|
||||
};
|
||||
|
||||
describe('onReset', ()=>{
|
||||
it('with confirm check and yes click', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
simulateValidData();
|
||||
onDataChange.calls.reset();
|
||||
let confirmSpy = spyOn(Notify, 'confirm').and.callThrough();
|
||||
ctrl.find('DefaultButton[data-test="Reset"]').simulate('click');
|
||||
/* Press OK */
|
||||
confirmSpy.calls.argsFor(0)[2]();
|
||||
setTimeout(()=>{
|
||||
onResetAction(done, { id: undefined, field1: null, field2: null, fieldcoll: null });
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('with confirm check and cancel click', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
simulateValidData();
|
||||
let confirmSpy = spyOn(Notify, 'confirm').and.callThrough();
|
||||
ctrl.find('DefaultButton[data-test="Reset"]').simulate('click');
|
||||
/* Press cancel */
|
||||
confirmSpy.calls.argsFor(0)[3]();
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('DefaultButton[data-test="Reset"]').prop('disabled')).toBeFalse();
|
||||
expect(ctrl.find('PrimaryButton[data-test="Save"]').prop('disabled')).toBeFalse();
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
|
||||
it('no confirm check', (done)=>{
|
||||
ctrlMount({
|
||||
confirmOnCloseReset: false,
|
||||
});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
simulateValidData();
|
||||
onDataChange.calls.reset();
|
||||
let confirmSpy = spyOn(Notify, 'confirm').and.callThrough();
|
||||
ctrl.find('DefaultButton[data-test="Reset"]').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(confirmSpy).not.toHaveBeenCalled();
|
||||
expect(ctrl.find('DefaultButton[data-test="Reset"]').prop('disabled')).toBeTrue();
|
||||
expect(ctrl.find('PrimaryButton[data-test="Save"]').prop('disabled')).toBeTrue();
|
||||
// on reset, orig data will be considered
|
||||
expect(onDataChange).toHaveBeenCalledWith(false, { id: undefined, field1: null, field2: null, fieldcoll: null });
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
it('onHelp SQL', (done)=>{
|
||||
ctrl.find('PgIconButton[data-test="sql-help"]').find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(onHelp).toHaveBeenCalledWith(true, true);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('onHelp Dialog', (done)=>{
|
||||
ctrl.find('PgIconButton[data-test="dialog-help"]').find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(onHelp).toHaveBeenCalledWith(false, true);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
describe('edit mode', ()=>{
|
||||
let simulateChanges = ()=>{
|
||||
ctrl.find('MappedFormControl[id="field1"]').find('input').simulate('change', {target: {value: 'val1'}});
|
||||
ctrl.find('MappedFormControl[id="field5"]').find('textarea').simulate('change', {target: {value: 'val5'}});
|
||||
|
||||
/* Add a row */
|
||||
ctrl.find('DataGridView').find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
ctrl.find('MappedCellControl[id="field5"]').at(2).find('input').simulate('change', {target: {value: 'rval53'}});
|
||||
|
||||
/* Remove the 1st row */
|
||||
let confirmSpy = spyOn(Notify, 'confirm').and.callThrough();
|
||||
ctrl.find('DataTableRow').find('PgIconButton[data-test="delete-row"]').at(0).find('button').simulate('click');
|
||||
confirmSpy.calls.argsFor(0)[2]();
|
||||
|
||||
/* Edit the 2nd row which is first now*/
|
||||
ctrl.find('MappedCellControl[id="field5"]').at(0).find('input').simulate('change', {target: {value: 'rvalnew'}});
|
||||
|
||||
};
|
||||
beforeEach(()=>{
|
||||
ctrlMount({
|
||||
getInitData: getInitData,
|
||||
viewHelperProps: {
|
||||
mode: 'edit',
|
||||
}
|
||||
});
|
||||
});
|
||||
it('init', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('MappedFormControl').length).toBe(4);
|
||||
expect(ctrl.find('FormView').length).toBe(2);
|
||||
expect(ctrl.find('DataGridView').length).toBe(1);
|
||||
expect(ctrl.find('DataTableRow').length).toBe(2);
|
||||
expect(ctrl.find('DefaultButton[data-test="Reset"]').prop('disabled')).toBeTrue();
|
||||
expect(ctrl.find('PrimaryButton[data-test="Save"]').prop('disabled')).toBeTrue();
|
||||
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('onSave after change', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
simulateChanges();
|
||||
|
||||
onSave.calls.reset();
|
||||
ctrl.find('PrimaryButton[data-test="Save"]').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(onSave.calls.argsFor(0)[0]).toBe(false);
|
||||
expect(onSave.calls.argsFor(0)[1]).toEqual({
|
||||
id: 1,
|
||||
field1: 'val1',
|
||||
field5: 'val5',
|
||||
fieldcoll: {
|
||||
added: [
|
||||
{ field3: null, field4: null, field5: 'rval53'}
|
||||
],
|
||||
changed: [
|
||||
{ field3: 2, field4: 'field4val2', field5: 'rvalnew'}
|
||||
],
|
||||
deleted: [
|
||||
{ field3: 1, field4: 'field4val1', field5: 'field5val1'}
|
||||
]
|
||||
}
|
||||
});
|
||||
expect(Notify.alert).toHaveBeenCalledWith('Warning', 'some inform text');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('onReset after change', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
simulateChanges();
|
||||
onDataChange.calls.reset();
|
||||
let confirmSpy = spyOn(Notify, 'confirm').and.callThrough();
|
||||
ctrl.find('DefaultButton[data-test="Reset"]').simulate('click');
|
||||
/* Press OK */
|
||||
confirmSpy.calls.mostRecent().args[2]();
|
||||
setTimeout(()=>{
|
||||
onResetAction(done, {});
|
||||
}, 0);
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('all types', ()=>{
|
||||
let ctrl;
|
||||
beforeEach(()=>{
|
||||
ctrl?.unmount();
|
||||
ctrl = mount(<Theme>
|
||||
<SchemaView
|
||||
formType='dialog'
|
||||
schema={getSchemaAllTypes()}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onClose={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onHelp={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onEdit={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onDataChange={()=>{/*This is intentional (SonarQube)*/}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={true}
|
||||
getSQLValue={()=>'select 1;'}
|
||||
disableSqlHelp={false}
|
||||
/>
|
||||
</Theme>);
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
/* Add a row */
|
||||
ctrl.find('DataGridView').find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('SchemaPropertiesView', ()=>{
|
||||
let onEdit = jasmine.createSpy('onEdit'),
|
||||
onHelp = jasmine.createSpy('onHelp'),
|
||||
ctrl = null;
|
||||
|
||||
beforeEach(()=>{
|
||||
ctrl = mount(<Theme>
|
||||
<SchemaView
|
||||
formType='tab'
|
||||
schema={getSchema()}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={onHelp}
|
||||
disableSqlHelp={false}
|
||||
onEdit={onEdit}
|
||||
/>
|
||||
</Theme>);
|
||||
});
|
||||
|
||||
it('init', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('MappedFormControl').length).toBe(6);
|
||||
expect(ctrl.find('ForwardRef(Accordion)').length).toBe(2);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('onHelp', (done)=>{
|
||||
ctrl.find('PgIconButton[data-test="help"]').find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(onHelp).toHaveBeenCalled();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('onEdit', (done)=>{
|
||||
ctrl.find('PgIconButton[data-test="edit"]').find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(onEdit).toHaveBeenCalled();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,64 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
import React from 'react';
|
||||
|
||||
import { act, render } from '@testing-library/react';
|
||||
import { TestSchemaAllTypes} from './TestSchema.ui';
|
||||
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
import pgAdmin from '../fake_pgadmin';
|
||||
import { withBrowser } from '../genericFunctions';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
|
||||
function getSchemaAllTypes() {
|
||||
return new TestSchemaAllTypes();
|
||||
}
|
||||
|
||||
describe('SchemaView', ()=>{
|
||||
const SchemaViewWithBrowser = withBrowser(SchemaView);
|
||||
const user = userEvent.setup();
|
||||
|
||||
beforeAll(()=>{
|
||||
jest.spyOn(pgAdmin.Browser.notifier, 'alert').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
describe('all types', ()=>{
|
||||
let ctrl;
|
||||
beforeEach(async ()=>{
|
||||
await act(async ()=>{
|
||||
ctrl = render(
|
||||
<SchemaViewWithBrowser
|
||||
formType='dialog'
|
||||
schema={getSchemaAllTypes()}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onClose={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onHelp={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onEdit={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onDataChange={()=>{/*This is intentional (SonarQube)*/}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={true}
|
||||
getSQLValue={()=>'select 1;'}
|
||||
disableSqlHelp={false}
|
||||
/>
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('init', async ()=>{
|
||||
/* Add a row */
|
||||
await user.click(ctrl.container.querySelector('[data-test="add-row"]'));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -7,46 +7,26 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { render } from '@testing-library/react';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import ForgotPasswordPage from '../../../pgadmin/static/js/SecurityPages/ForgotPasswordPage';
|
||||
|
||||
describe('ForgotPasswordPage', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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();
|
||||
});
|
||||
|
||||
let ctrlMount = (props)=>{
|
||||
return mount(<Theme>
|
||||
return render(<Theme>
|
||||
<ForgotPasswordPage {...props}/>
|
||||
</Theme>);
|
||||
};
|
||||
|
||||
it('basic', (done)=>{
|
||||
it('basic', ()=>{
|
||||
const ctrl = ctrlMount({
|
||||
actionUrl: '/forgot/url',
|
||||
csrfToken: 'some-token',
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(ctrl.find('form')).toHaveProp('action', '/forgot/url');
|
||||
expect(ctrl.find('input[name="email"]')).toExist();
|
||||
ctrl.unmount();
|
||||
done();
|
||||
}, 100);
|
||||
expect(ctrl.container.querySelector('form').getAttribute('action')).toBe('/forgot/url');
|
||||
expect(ctrl.container.querySelector('input[name="email"]')).not.toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,37 +7,23 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { render } from '@testing-library/react';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import LoginPage from '../../../pgadmin/static/js/SecurityPages/LoginPage';
|
||||
|
||||
describe('LoginPage', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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();
|
||||
});
|
||||
|
||||
let ctrlMount = (props)=>{
|
||||
return mount(<Theme>
|
||||
return render(<Theme>
|
||||
<LoginPage {...props}/>
|
||||
</Theme>);
|
||||
};
|
||||
|
||||
it('internal', (done)=>{
|
||||
it('internal', ()=>{
|
||||
const ctrl = ctrlMount({
|
||||
userLanguage: 'en',
|
||||
langOptions: [{
|
||||
@@ -55,16 +41,12 @@ describe('LoginPage', ()=>{
|
||||
oauth2Config: [],
|
||||
loginBanner: 'login banner'
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(ctrl.find('form')).toHaveProp('action', '/login/url');
|
||||
expect(ctrl.find('input[name="email"]')).toExist();
|
||||
expect(ctrl.find('input[name="password"]')).toExist();
|
||||
ctrl.unmount();
|
||||
done();
|
||||
}, 100);
|
||||
expect(ctrl.container.querySelector('form').getAttribute('action')).toBe('/login/url');
|
||||
expect(ctrl.container.querySelector('input[name="email"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('input[name="password"]')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('oauth2', (done)=>{
|
||||
it('oauth2', ()=>{
|
||||
const ctrl = ctrlMount({
|
||||
userLanguage: 'en',
|
||||
langOptions: [{
|
||||
@@ -87,13 +69,9 @@ describe('LoginPage', ()=>{
|
||||
}],
|
||||
loginBanner: ''
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(ctrl.find('form')).toHaveProp('action', '/login/url');
|
||||
expect(ctrl.find('input[name="email"]')).toExist();
|
||||
expect(ctrl.find('input[name="password"]')).toExist();
|
||||
expect(ctrl.find('button[name="oauth2_button"]')).toHaveProp('value', 'github');
|
||||
ctrl.unmount();
|
||||
done();
|
||||
}, 100);
|
||||
expect(ctrl.container.querySelector('form').getAttribute('action')).toBe('/login/url');
|
||||
expect(ctrl.container.querySelector('input[name="email"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('input[name="password"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('button[name="oauth2_button"]')).toHaveValue('github');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,37 +7,23 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { render } from '@testing-library/react';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import MfaRegisterPage from '../../../pgadmin/static/js/SecurityPages/MfaRegisterPage';
|
||||
|
||||
describe('MfaRegisterPage', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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();
|
||||
});
|
||||
|
||||
let ctrlMount = (props)=>{
|
||||
return mount(<Theme>
|
||||
return render(<Theme>
|
||||
<MfaRegisterPage {...props}/>
|
||||
</Theme>);
|
||||
};
|
||||
|
||||
it('email registered', (done)=>{
|
||||
it('email registered', ()=>{
|
||||
const ctrl = ctrlMount({
|
||||
actionUrl: '/mfa/register',
|
||||
mfaList: [{
|
||||
@@ -52,18 +38,14 @@ describe('MfaRegisterPage', ()=>{
|
||||
nextUrl: '',
|
||||
mfaView: null,
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(ctrl.find('form')).toHaveProp('action', '/mfa/register');
|
||||
expect(ctrl.find('EmailRegisterView')).not.toExist();
|
||||
expect(ctrl.find('AuthenticatorRegisterView')).not.toExist();
|
||||
expect(ctrl.find('SecurityButton[value="DELETE"]').length).toBe(1);
|
||||
expect(ctrl.find('SecurityButton[value="SETUP"]').length).toBe(1);
|
||||
ctrl.unmount();
|
||||
done();
|
||||
}, 100);
|
||||
expect(ctrl.container.querySelector('form').getAttribute('action')).toBe('/mfa/register');
|
||||
expect(ctrl.container.querySelector('[data-test="email-register-view"]')).toBeNull();
|
||||
expect(ctrl.container.querySelector('[data-test="auth-register-view"]')).toBeNull();
|
||||
expect(ctrl.container.querySelectorAll('button[value="DELETE"]').length).toBe(1);
|
||||
expect(ctrl.container.querySelectorAll('button[value="SETUP"]').length).toBe(1);
|
||||
});
|
||||
|
||||
it('both registered', (done)=>{
|
||||
it('both registered', ()=>{
|
||||
const ctrl = ctrlMount({
|
||||
actionUrl: '/mfa/register',
|
||||
mfaList: [{
|
||||
@@ -78,18 +60,14 @@ describe('MfaRegisterPage', ()=>{
|
||||
nextUrl: '',
|
||||
mfaView: null,
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(ctrl.find('form')).toHaveProp('action', '/mfa/register');
|
||||
expect(ctrl.find('EmailRegisterView')).not.toExist();
|
||||
expect(ctrl.find('AuthenticatorRegisterView')).not.toExist();
|
||||
expect(ctrl.find('SecurityButton[value="DELETE"]').length).toBe(2);
|
||||
expect(ctrl.find('SecurityButton[value="SETUP"]').length).toBe(0);
|
||||
ctrl.unmount();
|
||||
done();
|
||||
}, 100);
|
||||
expect(ctrl.container.querySelector('form').getAttribute('action')).toBe('/mfa/register');
|
||||
expect(ctrl.container.querySelector('[data-test="email-register-view"]')).toBeNull();
|
||||
expect(ctrl.container.querySelector('[data-test="auth-register-view"]')).toBeNull();
|
||||
expect(ctrl.container.querySelectorAll('button[value="DELETE"]').length).toBe(2);
|
||||
expect(ctrl.container.querySelectorAll('button[value="SETUP"]').length).toBe(0);
|
||||
});
|
||||
|
||||
it('email view register', (done)=>{
|
||||
it('email view register', ()=>{
|
||||
const ctrl = ctrlMount({
|
||||
actionUrl: '/mfa/register',
|
||||
mfaList: [{
|
||||
@@ -112,19 +90,15 @@ describe('MfaRegisterPage', ()=>{
|
||||
note:'This email address will only be used for two factor'
|
||||
},
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(ctrl.find('form')).toHaveProp('action', '/mfa/register');
|
||||
expect(ctrl.find('EmailRegisterView')).toExist();
|
||||
expect(ctrl.find('input[name="send_to"]')).toExist();
|
||||
expect(ctrl.find('AuthenticatorRegisterView')).not.toExist();
|
||||
expect(ctrl.find('SecurityButton[value="DELETE"]').length).toBe(0);
|
||||
expect(ctrl.find('SecurityButton[value="SETUP"]').length).toBe(0);
|
||||
ctrl.unmount();
|
||||
done();
|
||||
}, 100);
|
||||
expect(ctrl.container.querySelector('form').getAttribute('action')).toBe('/mfa/register');
|
||||
expect(ctrl.container.querySelector('[data-test="email-register-view"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('input[name="send_to"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('[data-test="auth-register-view"]')).toBeNull();
|
||||
expect(ctrl.container.querySelectorAll('button[value="DELETE"]').length).toBe(0);
|
||||
expect(ctrl.container.querySelectorAll('button[value="SETUP"]').length).toBe(0);
|
||||
});
|
||||
|
||||
it('email view otp code', (done)=>{
|
||||
it('email view otp code', ()=>{
|
||||
const ctrl = ctrlMount({
|
||||
actionUrl: '/mfa/register',
|
||||
mfaList: [{
|
||||
@@ -147,19 +121,15 @@ describe('MfaRegisterPage', ()=>{
|
||||
note:'This email address will only be used for two factor'
|
||||
},
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(ctrl.find('form')).toHaveProp('action', '/mfa/register');
|
||||
expect(ctrl.find('EmailRegisterView')).toExist();
|
||||
expect(ctrl.find('input[name="code"]')).toExist();
|
||||
expect(ctrl.find('AuthenticatorRegisterView')).not.toExist();
|
||||
expect(ctrl.find('SecurityButton[value="DELETE"]').length).toBe(0);
|
||||
expect(ctrl.find('SecurityButton[value="SETUP"]').length).toBe(0);
|
||||
ctrl.unmount();
|
||||
done();
|
||||
}, 100);
|
||||
expect(ctrl.container.querySelector('form').getAttribute('action')).toBe('/mfa/register');
|
||||
expect(ctrl.container.querySelector('[data-test="email-register-view"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('input[name="code"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('[data-test="auth-register-view"]')).toBeNull();
|
||||
expect(ctrl.container.querySelectorAll('button[value="DELETE"]').length).toBe(0);
|
||||
expect(ctrl.container.querySelectorAll('button[value="SETUP"]').length).toBe(0);
|
||||
});
|
||||
|
||||
it('authenticator view register', (done)=>{
|
||||
it('authenticator view register', ()=>{
|
||||
const ctrl = ctrlMount({
|
||||
actionUrl: '/mfa/register',
|
||||
mfaList: [{
|
||||
@@ -181,15 +151,12 @@ describe('MfaRegisterPage', ()=>{
|
||||
otp_placeholder: 'Enter code'
|
||||
},
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(ctrl.find('form')).toHaveProp('action', '/mfa/register');
|
||||
expect(ctrl.find('EmailRegisterView')).not.toExist();
|
||||
expect(ctrl.find('AuthenticatorRegisterView')).toExist();
|
||||
expect(ctrl.find('input[name="code"]')).toExist();
|
||||
expect(ctrl.find('SecurityButton[value="DELETE"]').length).toBe(0);
|
||||
expect(ctrl.find('SecurityButton[value="SETUP"]').length).toBe(0);
|
||||
ctrl.unmount();
|
||||
done();
|
||||
}, 100);
|
||||
|
||||
expect(ctrl.container.querySelector('form').getAttribute('action')).toBe('/mfa/register');
|
||||
expect(ctrl.container.querySelector('[data-test="email-register-view"]')).toBeNull();
|
||||
expect(ctrl.container.querySelector('input[name="code"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('[data-test="auth-register-view"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelectorAll('button[value="DELETE"]').length).toBe(0);
|
||||
expect(ctrl.container.querySelectorAll('button[value="SETUP"]').length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,121 +7,103 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { act, render } from '@testing-library/react';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import MfaValidatePage from '../../../pgadmin/static/js/SecurityPages/MfaValidatePage';
|
||||
|
||||
describe('MfaValidatePage', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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();
|
||||
});
|
||||
|
||||
let ctrlMount = (props)=>{
|
||||
return mount(<Theme>
|
||||
let ctrlMount = async (props)=>{
|
||||
return render(<Theme>
|
||||
<MfaValidatePage {...props}/>
|
||||
</Theme>);
|
||||
};
|
||||
|
||||
it('email selected', (done)=>{
|
||||
const ctrl = ctrlMount({
|
||||
actionUrl: '/mfa/validate',
|
||||
views: {
|
||||
'email': {
|
||||
id: 'email',
|
||||
label: 'Email',
|
||||
icon: '',
|
||||
selected: true,
|
||||
view: {
|
||||
description: 'description',
|
||||
otp_placeholder: 'otp_placeholder',
|
||||
button_label: 'button_label',
|
||||
button_label_sending: 'button_label_sending'
|
||||
it('email selected', async ()=>{
|
||||
let ctrl;
|
||||
await act(async ()=>{
|
||||
ctrl = await ctrlMount({
|
||||
actionUrl: '/mfa/validate',
|
||||
views: {
|
||||
'email': {
|
||||
id: 'email',
|
||||
label: 'Email',
|
||||
icon: '',
|
||||
selected: true,
|
||||
view: {
|
||||
description: 'description',
|
||||
otp_placeholder: 'otp_placeholder',
|
||||
button_label: 'button_label',
|
||||
button_label_sending: 'button_label_sending'
|
||||
}
|
||||
},
|
||||
'authenticator': {
|
||||
id: 'authenticator',
|
||||
label: 'Authenticator',
|
||||
icon: '',
|
||||
selected: false,
|
||||
view: {
|
||||
auth_description: 'auth_description',
|
||||
otp_placeholder: 'otp_placeholder',
|
||||
}
|
||||
}
|
||||
},
|
||||
'authenticator': {
|
||||
id: 'authenticator',
|
||||
label: 'Authenticator',
|
||||
icon: '',
|
||||
selected: false,
|
||||
view: {
|
||||
auth_description: 'auth_description',
|
||||
otp_placeholder: 'otp_placeholder',
|
||||
}
|
||||
}
|
||||
},
|
||||
logoutUrl: '/logout/url',
|
||||
sendEmailUrl: '/send/email',
|
||||
csrfHeader: 'csrfHeader',
|
||||
csrfToken: 'csrfToken',
|
||||
logoutUrl: '/logout/url',
|
||||
sendEmailUrl: '/send/email',
|
||||
csrfHeader: 'csrfHeader',
|
||||
csrfToken: 'csrfToken',
|
||||
});
|
||||
});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('form')).toHaveProp('action', '/mfa/validate');
|
||||
expect(ctrl.find('EmailValidateView')).toExist();
|
||||
expect(ctrl.find('AuthenticatorValidateView')).not.toExist();
|
||||
expect(ctrl.find('button[name="send_code"]')).toExist();
|
||||
expect(ctrl.find('input[name="mfa_method"]').instance().value).toBe('email');
|
||||
ctrl.unmount();
|
||||
done();
|
||||
}, 100);
|
||||
expect(ctrl.container.querySelector('form').getAttribute('action')).toBe('/mfa/validate');
|
||||
expect(ctrl.container.querySelector('[data-test="email-validate-view"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('[data-test="auth-validate-view"]')).toBeNull();
|
||||
expect(ctrl.container.querySelector('input[name="mfa_method"]')).toHaveValue('email');
|
||||
});
|
||||
|
||||
it('authenticator selected', (done)=>{
|
||||
const ctrl = ctrlMount({
|
||||
actionUrl: '/mfa/validate',
|
||||
views: {
|
||||
'email': {
|
||||
id: 'email',
|
||||
label: 'Email',
|
||||
icon: '',
|
||||
selected: false,
|
||||
view: {
|
||||
description: 'description',
|
||||
otp_placeholder: 'otp_placeholder',
|
||||
button_label: 'button_label',
|
||||
button_label_sending: 'button_label_sending'
|
||||
it('authenticator selected', async ()=>{
|
||||
let ctrl;
|
||||
await act(async ()=>{
|
||||
ctrl = await ctrlMount({
|
||||
actionUrl: '/mfa/validate',
|
||||
views: {
|
||||
'email': {
|
||||
id: 'email',
|
||||
label: 'Email',
|
||||
icon: '',
|
||||
selected: false,
|
||||
view: {
|
||||
description: 'description',
|
||||
otp_placeholder: 'otp_placeholder',
|
||||
button_label: 'button_label',
|
||||
button_label_sending: 'button_label_sending'
|
||||
}
|
||||
},
|
||||
'authenticator': {
|
||||
id: 'authenticator',
|
||||
label: 'Authenticator',
|
||||
icon: '',
|
||||
selected: true,
|
||||
view: {
|
||||
auth_description: 'auth_description',
|
||||
otp_placeholder: 'otp_placeholder',
|
||||
}
|
||||
}
|
||||
},
|
||||
'authenticator': {
|
||||
id: 'authenticator',
|
||||
label: 'Authenticator',
|
||||
icon: '',
|
||||
selected: true,
|
||||
view: {
|
||||
auth_description: 'auth_description',
|
||||
otp_placeholder: 'otp_placeholder',
|
||||
}
|
||||
}
|
||||
},
|
||||
logoutUrl: '/logout/url',
|
||||
sendEmailUrl: '/send/email',
|
||||
csrfHeader: 'csrfHeader',
|
||||
csrfToken: 'csrfToken',
|
||||
logoutUrl: '/logout/url',
|
||||
sendEmailUrl: '/send/email',
|
||||
csrfHeader: 'csrfHeader',
|
||||
csrfToken: 'csrfToken',
|
||||
});
|
||||
});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('form')).toHaveProp('action', '/mfa/validate');
|
||||
expect(ctrl.find('EmailValidateView')).not.toExist();
|
||||
expect(ctrl.find('AuthenticatorValidateView')).toExist();
|
||||
expect(ctrl.find('input[name="code"]')).toExist();
|
||||
expect(ctrl.find('input[name="mfa_method"]').instance().value).toBe('authenticator');
|
||||
ctrl.unmount();
|
||||
done();
|
||||
}, 100);
|
||||
|
||||
expect(ctrl.container.querySelector('form').getAttribute('action')).toBe('/mfa/validate');
|
||||
expect(ctrl.container.querySelector('[data-test="email-validate-view"]')).toBeNull();
|
||||
expect(ctrl.container.querySelector('[data-test="auth-validate-view"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('input[name="code"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('input[name="mfa_method"]')).toHaveValue('authenticator');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,32 +7,18 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { render } from '@testing-library/react';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import PasswordResetPage from '../../../pgadmin/static/js/SecurityPages/PasswordResetPage';
|
||||
|
||||
describe('PasswordResetPage', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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();
|
||||
});
|
||||
|
||||
let ctrlMount = (props)=>{
|
||||
return mount(<Theme>
|
||||
return render(<Theme>
|
||||
<PasswordResetPage {...props}/>
|
||||
</Theme>);
|
||||
};
|
||||
@@ -43,10 +29,10 @@ describe('PasswordResetPage', ()=>{
|
||||
csrfToken: 'some-token',
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(ctrl.find('form')).toHaveProp('action', '/reset/url');
|
||||
expect(ctrl.find('input[name="password"]')).toExist();
|
||||
expect(ctrl.find('input[name="password_confirm"]')).toExist();
|
||||
ctrl.unmount();
|
||||
expect(ctrl.container.querySelector('form').getAttribute('action')).toBe('/reset/url');
|
||||
expect(ctrl.container.querySelector('input[name="password"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('input[name="password_confirm"]')).not.toBeNull();
|
||||
|
||||
done();
|
||||
}, 100);
|
||||
});
|
||||
|
||||
16
web/regression/javascript/__mocks__/@material-ui/core.jsx
Normal file
16
web/regression/javascript/__mocks__/@material-ui/core.jsx
Normal file
@@ -0,0 +1,16 @@
|
||||
import React, { useRef } from 'react';
|
||||
import CustomPropTypes from '../../../../pgadmin/static/js/custom_prop_types';
|
||||
export * from '@material-ui/core';
|
||||
|
||||
// mock popper
|
||||
export const Popper = React.forwardRef((props, ref)=>{
|
||||
const ele = useRef();
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
ref = {};
|
||||
return <div ref={ele} data-test="material-popper">{props.children}</div>;
|
||||
});
|
||||
|
||||
Popper.displayName = 'Popper';
|
||||
Popper.propTypes = {
|
||||
children: CustomPropTypes.children,
|
||||
};
|
||||
38
web/regression/javascript/__mocks__/bundled_codemirror.js
Normal file
38
web/regression/javascript/__mocks__/bundled_codemirror.js
Normal file
@@ -0,0 +1,38 @@
|
||||
const getSearchCursorRet = {
|
||||
_from: 3,
|
||||
_to: 14,
|
||||
find: function(_rev) {
|
||||
if(_rev){
|
||||
this._from = 1;
|
||||
this._to = 10;
|
||||
} else {
|
||||
this._from = 3;
|
||||
this._to = 14;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
from: function() {return this._from;},
|
||||
to: function() {return this._to;},
|
||||
replace: jest.fn(),
|
||||
};
|
||||
const fromTextAreaRet = {
|
||||
'getValue':()=>'',
|
||||
'setValue': jest.fn(),
|
||||
'refresh': jest.fn(),
|
||||
'setOption': jest.fn(),
|
||||
'removeKeyMap': jest.fn(),
|
||||
'addKeyMap': jest.fn(),
|
||||
'getSelection': () => '',
|
||||
'getSearchCursor': jest.fn(()=>getSearchCursorRet),
|
||||
'getCursor': jest.fn(),
|
||||
'removeOverlay': jest.fn(),
|
||||
'addOverlay': jest.fn(),
|
||||
'setSelection': jest.fn(),
|
||||
'scrollIntoView': jest.fn(),
|
||||
'getWrapperElement': ()=>document.createElement('div'),
|
||||
'on': jest.fn(),
|
||||
'toTextArea': jest.fn(),
|
||||
};
|
||||
module.exports = {
|
||||
fromTextArea: jest.fn(()=>fromTextAreaRet)
|
||||
};
|
||||
14
web/regression/javascript/__mocks__/cssTransform.js
Normal file
14
web/regression/javascript/__mocks__/cssTransform.js
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
// This is a custom Jest transformer turning style imports into empty objects.
|
||||
// http://facebook.github.io/jest/docs/en/webpack.html
|
||||
|
||||
module.exports = {
|
||||
process() {
|
||||
return 'module.exports = {};';
|
||||
},
|
||||
getCacheKey() {
|
||||
// The output is always the same.
|
||||
return 'cssTransform';
|
||||
},
|
||||
};
|
||||
13
web/regression/javascript/__mocks__/popper.js.js
Normal file
13
web/regression/javascript/__mocks__/popper.js.js
Normal file
@@ -0,0 +1,13 @@
|
||||
import PopperJs from 'popper.js';
|
||||
|
||||
export default class Popper {
|
||||
static placements = PopperJs.placements;
|
||||
|
||||
constructor() {
|
||||
return {
|
||||
destroy: () => {},
|
||||
scheduleUpdate: () => {},
|
||||
update: () => {},
|
||||
};
|
||||
}
|
||||
}
|
||||
24
web/regression/javascript/__mocks__/react-data-grid.jsx
Normal file
24
web/regression/javascript/__mocks__/react-data-grid.jsx
Normal file
@@ -0,0 +1,24 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
export * from 'react-data-grid';
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const ReactDataGrid = React.forwardRef((props, ref)=>{
|
||||
const ele = useRef();
|
||||
|
||||
useEffect(()=>{
|
||||
ref = {
|
||||
selectCell: jest.fn(),
|
||||
element: ele.current,
|
||||
};
|
||||
}, [ele.current]);
|
||||
|
||||
return <div id={props.id} ref={ele} data-test="react-data-grid"/>;
|
||||
});
|
||||
|
||||
ReactDataGrid.displayName = 'ReactDataGrid';
|
||||
ReactDataGrid.propTypes = {
|
||||
id: PropTypes.any
|
||||
};
|
||||
|
||||
export default ReactDataGrid;
|
||||
10
web/regression/javascript/__mocks__/svg.js
Normal file
10
web/regression/javascript/__mocks__/svg.js
Normal file
@@ -0,0 +1,10 @@
|
||||
import React from 'react';
|
||||
|
||||
const SvgrMock = React.forwardRef((props, ref) => (
|
||||
<svg ref={ref} {...props} />
|
||||
));
|
||||
|
||||
SvgrMock.displayName = 'SvgrMock';
|
||||
|
||||
export const ReactComponent = SvgrMock;
|
||||
export default SvgrMock;
|
||||
4
web/regression/javascript/__mocks__/uplot-react.jsx
Normal file
4
web/regression/javascript/__mocks__/uplot-react.jsx
Normal file
@@ -0,0 +1,4 @@
|
||||
import React from 'react';
|
||||
export default function UplotReact() {
|
||||
return <></>;
|
||||
}
|
||||
41
web/regression/javascript/__mocks__/zustand.js
Normal file
41
web/regression/javascript/__mocks__/zustand.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { act } from '@testing-library/react';
|
||||
|
||||
const { create: actualCreate, createStore: actualCreateStore } =
|
||||
jest.requireActual('zustand');
|
||||
|
||||
// a variable to hold reset functions for all stores declared in the app
|
||||
export const storeResetFns = new Set();
|
||||
|
||||
// when creating a store, we get its initial state, create a reset function and add it in the set
|
||||
export const create = ((createState) => {
|
||||
return typeof createState === 'function'
|
||||
? createInternalFn(createState)
|
||||
: createInternalFn;
|
||||
});
|
||||
|
||||
const createInternalFn = (createState) => {
|
||||
const store = actualCreate(createState);
|
||||
const initialState = store.getState();
|
||||
storeResetFns.add(() => store.setState(initialState, true));
|
||||
return store;
|
||||
};
|
||||
|
||||
// when creating a store, we get its initial state, create a reset function and add it in the set
|
||||
export const createStore = ((stateCreator) => {
|
||||
const store = actualCreateStore(stateCreator);
|
||||
const initialState = store.getState();
|
||||
storeResetFns.add(() => {
|
||||
store.setState(initialState, true);
|
||||
});
|
||||
return store;
|
||||
});
|
||||
|
||||
// reset all stores after each test run
|
||||
// eslint-disable-next-line no-undef
|
||||
afterEach(() => {
|
||||
act(() => {
|
||||
storeResetFns.forEach((resetFn) => {
|
||||
resetFn();
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -48,8 +48,8 @@ describe('For Activity', function(){
|
||||
|
||||
describe('log_activity', function(){
|
||||
beforeEach(function(){
|
||||
spyOn(pgBrowser, 'get_epoch_now').and.callThrough();
|
||||
spyOn(pgBrowser, 'log_activity').and.callThrough();
|
||||
jest.spyOn(pgBrowser, 'get_epoch_now');
|
||||
jest.spyOn(pgBrowser, 'log_activity');
|
||||
pgBrowser.logging_activity = false;
|
||||
});
|
||||
|
||||
@@ -66,7 +66,7 @@ describe('For Activity', function(){
|
||||
expect(pgBrowser.logging_activity).toEqual(true);
|
||||
|
||||
/* Second call */
|
||||
pgBrowser.get_epoch_now.calls.reset();
|
||||
pgBrowser.get_epoch_now.mockClear();
|
||||
pgBrowser.log_activity();
|
||||
expect(pgBrowser.get_epoch_now).not.toHaveBeenCalled();
|
||||
});
|
||||
@@ -83,7 +83,7 @@ describe('For Activity', function(){
|
||||
|
||||
describe('register_to_activity_listener', function(){
|
||||
let target = document;
|
||||
let timeout_callback = jasmine.createSpy();
|
||||
let timeout_callback = jest.fn();
|
||||
let event = new MouseEvent('mousedown', {
|
||||
bubbles: true,
|
||||
cancelable: true,
|
||||
@@ -91,9 +91,9 @@ describe('For Activity', function(){
|
||||
});
|
||||
|
||||
beforeEach(function(){
|
||||
spyOn(pgBrowser, 'log_activity');
|
||||
spyOn(target, 'addEventListener').and.callThrough();
|
||||
spyOn(target, 'removeEventListener').and.callThrough();
|
||||
jest.spyOn(pgBrowser, 'log_activity');
|
||||
jest.spyOn(target, 'addEventListener');
|
||||
jest.spyOn(target, 'removeEventListener');
|
||||
pgBrowser.register_to_activity_listener(target, timeout_callback);
|
||||
});
|
||||
|
||||
@@ -111,7 +111,7 @@ describe('For Activity', function(){
|
||||
});
|
||||
|
||||
it('is timed out', function(done){
|
||||
spyOn(pgBrowser, 'is_pgadmin_timedout').and.returnValue(true);
|
||||
jest.spyOn(pgBrowser, 'is_pgadmin_timedout').mockReturnValue(true);
|
||||
target.dispatchEvent(event);
|
||||
|
||||
setTimeout(()=>{
|
||||
@@ -123,23 +123,26 @@ describe('For Activity', function(){
|
||||
});
|
||||
|
||||
describe('override_activity_event_decorator', function(){
|
||||
let input_func = jasmine.createSpy('input_func');
|
||||
let input_func = jest.fn();
|
||||
let decorate_func = pgBrowser.override_activity_event_decorator(input_func);
|
||||
beforeEach(function(){
|
||||
spyOn(pgBrowser, 'log_activity').and.callThrough();
|
||||
jest.spyOn(pgBrowser, 'log_activity');
|
||||
});
|
||||
|
||||
it('call the input_func', function(){
|
||||
pgBrowser.log_activity.mockClear();
|
||||
decorate_func();
|
||||
expect(input_func).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('log activity when override_user_inactivity_timeout true', function(){
|
||||
pgBrowser.log_activity.mockClear();
|
||||
decorate_func();
|
||||
expect(pgBrowser.log_activity).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('do not log activity when override_user_inactivity_timeout true', function(){
|
||||
pgBrowser.log_activity.mockClear();
|
||||
pgAdmin.override_user_inactivity_timeout = false;
|
||||
decorate_func();
|
||||
expect(pgBrowser.log_activity).not.toHaveBeenCalled();
|
||||
@@ -148,11 +151,11 @@ describe('For Activity', function(){
|
||||
|
||||
describe('start_inactivity_timeout_daemon', function(){
|
||||
beforeEach(function(){
|
||||
spyOn(pgBrowser, 'logout_inactivity_user');
|
||||
jest.spyOn(pgBrowser, 'logout_inactivity_user');
|
||||
});
|
||||
|
||||
it('start the daemon', function(done){
|
||||
spyOn(pgBrowser, 'is_inactivity_timeout').and.returnValue(false);
|
||||
jest.spyOn(pgBrowser, 'is_inactivity_timeout').mockReturnValue(false);
|
||||
pgBrowser.inactivity_timeout_daemon_running = false;
|
||||
pgBrowser.start_inactivity_timeout_daemon();
|
||||
setTimeout(()=>{
|
||||
@@ -162,7 +165,7 @@ describe('For Activity', function(){
|
||||
});
|
||||
|
||||
it('stop the daemon', function(done){
|
||||
spyOn(pgBrowser, 'is_inactivity_timeout').and.returnValue(true);
|
||||
jest.spyOn(pgBrowser, 'is_inactivity_timeout').mockReturnValue(true);
|
||||
pgBrowser.inactivity_timeout_daemon_running = false;
|
||||
pgBrowser.start_inactivity_timeout_daemon();
|
||||
setTimeout(()=>{
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import {pgBrowser} from 'pgadmin.browser.layout';
|
||||
import 'wcdocker';
|
||||
|
||||
let wcDocker = window.wcDocker;
|
||||
|
||||
describe('layout related functions test', function() {
|
||||
let menu_items = null;
|
||||
let dummy_cache = [{
|
||||
id: 2,
|
||||
mid: 1,
|
||||
module:'browser',
|
||||
name:'lock_layout',
|
||||
value: 'none',
|
||||
}];
|
||||
|
||||
beforeEach(function(){
|
||||
pgBrowser.preferences_cache = dummy_cache;
|
||||
pgBrowser.docker = {
|
||||
'lockLayout': ()=>{/*This is intentional (SonarQube)*/},
|
||||
};
|
||||
|
||||
_.extend(pgBrowser,{
|
||||
'all_menus_cache': {
|
||||
'file': {
|
||||
'mnu_locklayout': {
|
||||
'menu_items': [
|
||||
{'name': 'mnu_lock_none', change_checked: ()=> {/*This is intentional (SonarQube)*/}},
|
||||
{'name': 'mnu_lock_docking', change_checked: ()=> {/*This is intentional (SonarQube)*/}},
|
||||
{'name': 'mnu_lock_full', change_checked: ()=> {/*This is intentional (SonarQube)*/}},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
menu_items = pgBrowser.all_menus_cache.file.mnu_locklayout.menu_items;
|
||||
});
|
||||
|
||||
describe('for menu actions', function() {
|
||||
beforeEach(function(){
|
||||
spyOn(pgBrowser, 'lock_layout');
|
||||
spyOn(pgBrowser, 'save_lock_layout');
|
||||
});
|
||||
|
||||
it('mnu_lock_none', function() {
|
||||
pgBrowser.mnu_lock_none();
|
||||
expect(pgBrowser.lock_layout).toHaveBeenCalledWith(pgBrowser.docker, 'none');
|
||||
expect(pgBrowser.save_lock_layout).toHaveBeenCalledWith('none');
|
||||
});
|
||||
|
||||
it('mnu_lock_docking', function() {
|
||||
pgBrowser.mnu_lock_docking();
|
||||
expect(pgBrowser.lock_layout).toHaveBeenCalledWith(pgBrowser.docker, 'docking');
|
||||
expect(pgBrowser.save_lock_layout).toHaveBeenCalledWith('docking');
|
||||
});
|
||||
|
||||
it('mnu_lock_full', function() {
|
||||
pgBrowser.mnu_lock_full();
|
||||
expect(pgBrowser.lock_layout).toHaveBeenCalledWith(pgBrowser.docker, 'full');
|
||||
expect(pgBrowser.save_lock_layout).toHaveBeenCalledWith('full');
|
||||
});
|
||||
});
|
||||
|
||||
describe('lock_layout', function() {
|
||||
let change_checked_test= function(menu_name) {
|
||||
for(let mnu_val of menu_items) {
|
||||
if(mnu_val.name == menu_name) {
|
||||
expect(mnu_val.change_checked).toHaveBeenCalledWith(true);
|
||||
} else {
|
||||
expect(mnu_val.change_checked).toHaveBeenCalledWith(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
beforeEach(function(){
|
||||
spyOn(pgBrowser.docker, 'lockLayout');
|
||||
for(let mnu_val of menu_items) {
|
||||
spyOn(mnu_val, 'change_checked');
|
||||
}
|
||||
});
|
||||
|
||||
it('none', function() {
|
||||
pgBrowser.lock_layout(pgBrowser.docker, 'none');
|
||||
expect(pgBrowser.docker.lockLayout).toHaveBeenCalledWith(wcDocker.LOCK_LAYOUT_LEVEL.NONE);
|
||||
change_checked_test('mnu_lock_none');
|
||||
});
|
||||
|
||||
it('docking', function() {
|
||||
pgBrowser.lock_layout(pgBrowser.docker, 'docking');
|
||||
expect(pgBrowser.docker.lockLayout).toHaveBeenCalledWith(wcDocker.LOCK_LAYOUT_LEVEL.PREVENT_DOCKING);
|
||||
change_checked_test('mnu_lock_docking');
|
||||
});
|
||||
|
||||
it('full', function() {
|
||||
pgBrowser.lock_layout(pgBrowser.docker, 'full');
|
||||
expect(pgBrowser.docker.lockLayout).toHaveBeenCalledWith(wcDocker.LOCK_LAYOUT_LEVEL.FULL);
|
||||
change_checked_test('mnu_lock_full');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -1,115 +0,0 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import {pgBrowser} from 'pgadmin.browser.preferences';
|
||||
import EventBus from '../../../pgadmin/static/js/helpers/EventBus';
|
||||
|
||||
let dummy_cache = [
|
||||
{
|
||||
id: 1,
|
||||
mid: 1,
|
||||
module:'module1',
|
||||
name:'pref1',
|
||||
value:{
|
||||
alt: false,
|
||||
shift: false,
|
||||
control: false,
|
||||
key: {
|
||||
char: 'a',
|
||||
key_code: 65,
|
||||
},
|
||||
},
|
||||
},{
|
||||
id: 2,
|
||||
mid: 1,
|
||||
module:'module1',
|
||||
name:'pref2',
|
||||
value: 123,
|
||||
},{
|
||||
id: 3,
|
||||
mid: 2,
|
||||
module:'module2',
|
||||
name:'pref2',
|
||||
value: true,
|
||||
},
|
||||
];
|
||||
|
||||
describe('preferences related functions test', function() {
|
||||
describe('get preference data related functions', function(){
|
||||
beforeEach(function(){
|
||||
pgBrowser.preferences_cache = dummy_cache;
|
||||
pgBrowser.Events = new EventBus();
|
||||
});
|
||||
|
||||
it('generate_preference_version', function() {
|
||||
pgBrowser.generate_preference_version();
|
||||
expect(pgBrowser.generate_preference_version()).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('preference_version', function() {
|
||||
let version = 123;
|
||||
pgBrowser.preference_version(version);
|
||||
expect(pgBrowser.prefcache_version).toEqual(version);
|
||||
expect(pgBrowser.preference_version()).toEqual(version);
|
||||
});
|
||||
|
||||
it('get_preference', function(){
|
||||
expect(pgBrowser.get_preference('module1','pref1')).toEqual({
|
||||
id: 1,
|
||||
mid: 1,
|
||||
module:'module1',
|
||||
name:'pref1',
|
||||
value:{
|
||||
alt: false,
|
||||
shift: false,
|
||||
control: false,
|
||||
key: {
|
||||
char: 'a',
|
||||
key_code: 65,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('get_preferences_for_module', function() {
|
||||
expect(pgBrowser.get_preferences_for_module('module1')).toEqual({
|
||||
'pref1':{
|
||||
alt: false,
|
||||
shift: false,
|
||||
control: false,
|
||||
key: {
|
||||
char: 'a',
|
||||
key_code: 65,
|
||||
},
|
||||
},
|
||||
'pref2': 123,
|
||||
});
|
||||
});
|
||||
|
||||
it('get_preference_for_id', function() {
|
||||
expect(pgBrowser.get_preference_for_id(3)).toEqual({
|
||||
id: 3,
|
||||
mid: 2,
|
||||
module:'module2',
|
||||
name:'pref2',
|
||||
value: true,
|
||||
});
|
||||
});
|
||||
|
||||
it('onPreferencesChange', function() {
|
||||
spyOn(pgBrowser.Events, 'on');
|
||||
|
||||
let eventHandler = jasmine.createSpy('eventHandler');
|
||||
pgBrowser.onPreferencesChange('somemodule', eventHandler);
|
||||
if(pgBrowser.Events.on.calls.mostRecent()) {
|
||||
expect(pgBrowser.Events.on.calls.mostRecent().args[0]).toEqual('prefchange:somemodule');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -7,26 +7,20 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
define(['sources/check_node_visibility'],
|
||||
function (checkNodeVisibility) {
|
||||
describe('checkNodeVisibility', function () {
|
||||
import checkNodeVisibility from '../../pgadmin/static/js/check_node_visibility';
|
||||
|
||||
let browser;
|
||||
describe('checkNodeVisibility', function () {
|
||||
let browser;
|
||||
|
||||
browser = jasmine.createSpyObj('browser', [
|
||||
'node_preference_data', 'get_preference']
|
||||
);
|
||||
|
||||
describe('when node is server collection', function () {
|
||||
it('returns true', function () {
|
||||
expect(checkNodeVisibility(browser, 'coll-server')).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when node is server', function () {
|
||||
it('returns true', function () {
|
||||
expect(checkNodeVisibility(browser, 'server')).toEqual(true);
|
||||
});
|
||||
});
|
||||
describe('when node is server collection', function () {
|
||||
it('returns true', function () {
|
||||
expect(checkNodeVisibility(browser, 'coll-server')).toEqual(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when node is server', function () {
|
||||
it('returns true', function () {
|
||||
expect(checkNodeVisibility(browser, 'server')).toEqual(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
import * as keyboardShortcuts from 'sources/keyboard_shortcuts';
|
||||
import $ from 'jquery';
|
||||
|
||||
describe('the keyboard shortcuts', () => {
|
||||
describe('when user wants to goto next panel', function () {
|
||||
let dockerSpy = {
|
||||
'_focusFrame': {
|
||||
'_curTab': 0,
|
||||
'_panelList': [
|
||||
{$container: $('<b/>'), '_type': 'type1', 'focus': function() {return true;}},
|
||||
{$container: $('<b/>'), '_type': 'type2', 'focus': function() {return true;}},
|
||||
],
|
||||
},
|
||||
};
|
||||
it('right key', function () {
|
||||
dockerSpy._focusFrame._curTab = 0;
|
||||
expect(keyboardShortcuts.focusDockerPanel(dockerSpy, 'right')).toEqual('type2');
|
||||
});
|
||||
it('left key', function () {
|
||||
dockerSpy._focusFrame._curTab = 1;
|
||||
expect(keyboardShortcuts.focusDockerPanel(dockerSpy, 'left')).toEqual('type1');
|
||||
});
|
||||
it('left key cycle', function () {
|
||||
dockerSpy._focusFrame._curTab = 0;
|
||||
expect(keyboardShortcuts.focusDockerPanel(dockerSpy, 'left')).toEqual('type2');
|
||||
});
|
||||
it('right key cycle', function () {
|
||||
dockerSpy._focusFrame._curTab = 1;
|
||||
expect(keyboardShortcuts.focusDockerPanel(dockerSpy, 'left')).toEqual('type1');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
@@ -7,50 +7,34 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
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 InfoIcon from '@material-ui/icons/InfoRounded';
|
||||
|
||||
import {PrimaryButton, DefaultButton, PgIconButton} from 'sources/components/Buttons';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
/* MUI Components need to be wrapped in Theme for theme vars */
|
||||
describe('components Buttons', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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();
|
||||
});
|
||||
|
||||
it('PrimaryButton', ()=>{
|
||||
let ThemedBtn = withTheme(PrimaryButton);
|
||||
let btn = mount(<ThemedBtn>Test</ThemedBtn>);
|
||||
expect(btn.find('button').getDOMNode().classList.contains('MuiButton-containedPrimary')).toBe(true);
|
||||
render(<ThemedBtn>Test</ThemedBtn>);
|
||||
expect(screen.getByRole('button').classList.contains('MuiButton-containedPrimary')).toBe(true);
|
||||
});
|
||||
|
||||
it('DefaultButton', ()=>{
|
||||
let ThemedBtn = withTheme(DefaultButton);
|
||||
let btn = mount(<ThemedBtn className="testClass">Test</ThemedBtn>);
|
||||
expect(btn.find('button').getDOMNode().classList.contains('MuiButton-outlined')).toBe(true);
|
||||
expect(btn.find('button').getDOMNode().classList.contains('testClass')).toBe(true);
|
||||
render(<ThemedBtn className="testClass">Test</ThemedBtn>);
|
||||
const btn = screen.getByRole('button');
|
||||
expect(btn.classList.contains('MuiButton-outlined')).toBe(true);
|
||||
expect(btn.classList.contains('testClass')).toBe(true);
|
||||
});
|
||||
|
||||
it('PgIconButton', ()=>{
|
||||
let Icon = <InfoIcon />;
|
||||
let Icon = <InfoIcon data-testid="info-icon" />;
|
||||
let ThemedBtn = withTheme(PgIconButton);
|
||||
let btn = mount(<ThemedBtn title="The icon button" icon={Icon} className="testClass"></ThemedBtn>);
|
||||
expect(btn.find(InfoIcon)).not.toBe(null);
|
||||
render(<ThemedBtn title="The icon button" icon={Icon} className="testClass"></ThemedBtn>);
|
||||
expect(screen.getByTestId('info-icon')).not.toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,62 +7,39 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
|
||||
import {default as OrigCodeMirror} from 'bundled_codemirror';
|
||||
import { withTheme } from '../fake_theme';
|
||||
|
||||
import pgWindow from 'sources/window';
|
||||
import CodeMirror from 'sources/components/CodeMirror';
|
||||
import { mount } from 'enzyme';
|
||||
import { FindDialog } from '../../../pgadmin/static/js/components/CodeMirror';
|
||||
import fakePgAdmin from '../fake_pgadmin';
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||
|
||||
describe('CodeMirror', ()=>{
|
||||
const ThemedCM = withTheme(CodeMirror);
|
||||
let cmInstance, options={
|
||||
lineNumbers: true,
|
||||
mode: 'text/x-pgsql',
|
||||
},
|
||||
cmObj = jasmine.createSpyObj('cmObj', {
|
||||
'getValue':()=>'',
|
||||
'setValue': ()=>{/*This is intentional (SonarQube)*/},
|
||||
'refresh': ()=>{/*This is intentional (SonarQube)*/},
|
||||
'setOption': ()=>{/*This is intentional (SonarQube)*/},
|
||||
'removeKeyMap': ()=>{/*This is intentional (SonarQube)*/},
|
||||
'addKeyMap': ()=>{/*This is intentional (SonarQube)*/},
|
||||
'getSelection': () => {/*This is intentional (SonarQube)*/},
|
||||
'getSearchCursor': {
|
||||
_from: 3,
|
||||
_to: 14,
|
||||
find: function(_rev) {
|
||||
if(_rev){
|
||||
this._from = 1;
|
||||
this._to = 10;
|
||||
} else {
|
||||
this._from = 3;
|
||||
this._to = 14;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
from: function() {return this._from;},
|
||||
to: function() {return this._to;},
|
||||
replace: jasmine.createSpy('replace'),
|
||||
},
|
||||
'getCursor': ()=>{/*This is intentional (SonarQube)*/},
|
||||
'removeOverlay': ()=>{/*This is intentional (SonarQube)*/},
|
||||
'addOverlay': ()=>{/*This is intentional (SonarQube)*/},
|
||||
'setSelection': ()=>{/*This is intentional (SonarQube)*/},
|
||||
'scrollIntoView': ()=>{/*This is intentional (SonarQube)*/},
|
||||
'getWrapperElement': document.createElement('div'),
|
||||
'on': ()=>{/*This is intentional (SonarQube)*/},
|
||||
});
|
||||
cmObj = OrigCodeMirror.fromTextArea();
|
||||
|
||||
const cmRerender = (props)=>{
|
||||
cmInstance.rerender(
|
||||
<ThemedCM
|
||||
value={'Init text'}
|
||||
options={options}
|
||||
className="testClass"
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
pgWindow.pgAdmin = fakePgAdmin;
|
||||
spyOn(OrigCodeMirror, 'fromTextArea').and.returnValue(cmObj);
|
||||
const ThemedCM = withTheme(CodeMirror);
|
||||
cmInstance = mount(
|
||||
// jest.spyOn(OrigCodeMirror, 'fromTextArea').mockReturnValue(cmObj);
|
||||
cmInstance = render(
|
||||
<ThemedCM
|
||||
value={'Init text'}
|
||||
options={options}
|
||||
@@ -74,28 +51,27 @@ describe('CodeMirror', ()=>{
|
||||
pgWindow.pgAdmin = undefined;
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
it('init', async ()=>{
|
||||
/* textarea ref passed to fromTextArea */
|
||||
expect(OrigCodeMirror.fromTextArea).toHaveBeenCalledWith(cmInstance.find('textarea').getDOMNode(), jasmine.objectContaining(options));
|
||||
expect(cmObj.setValue).toHaveBeenCalledWith('Init text');
|
||||
expect(OrigCodeMirror.fromTextArea).toHaveBeenCalledWith(cmInstance.container.querySelector('textarea'), expect.objectContaining(options));
|
||||
await waitFor(() => expect(cmObj.setValue).toHaveBeenCalledWith('Init text'));
|
||||
});
|
||||
|
||||
it('change value', ()=>{
|
||||
cmInstance.setProps({value: 'the new text'});
|
||||
cmRerender({value: 'the new text'});
|
||||
expect(cmObj.setValue).toHaveBeenCalledWith('the new text');
|
||||
|
||||
cmInstance.setProps({value: null});
|
||||
cmRerender({value: null});
|
||||
expect(cmObj.setValue).toHaveBeenCalledWith('');
|
||||
});
|
||||
|
||||
|
||||
describe('FindDialog', ()=>{
|
||||
let ctrl;
|
||||
const onClose = jasmine.createSpy('onClose');
|
||||
const onClose = jest.fn();
|
||||
const ThemedFindDialog = withTheme(FindDialog);
|
||||
const ctrlMount = (props, callback)=>{
|
||||
ctrl?.unmount();
|
||||
ctrl = mount(
|
||||
const ctrlMount = (props)=>{
|
||||
ctrl = render(
|
||||
<ThemedFindDialog
|
||||
editor={cmObj}
|
||||
show={true}
|
||||
@@ -103,115 +79,72 @@ describe('CodeMirror', ()=>{
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
callback();
|
||||
}, 0);
|
||||
};
|
||||
|
||||
it('init', (done)=>{
|
||||
ctrlMount({}, ()=>{
|
||||
cmObj.removeOverlay.calls.reset();
|
||||
cmObj.addOverlay.calls.reset();
|
||||
ctrl.find('InputText').find('input').simulate('change', {
|
||||
target: {value: '\n\r\t\A'},
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(cmObj.removeOverlay).toHaveBeenCalled();
|
||||
expect(cmObj.addOverlay).toHaveBeenCalled();
|
||||
expect(cmObj.setSelection).toHaveBeenCalledWith(3, 14);
|
||||
expect(cmObj.scrollIntoView).toHaveBeenCalled();
|
||||
done();
|
||||
}, 0);
|
||||
it('init', ()=>{
|
||||
ctrlMount({});
|
||||
|
||||
cmObj.removeOverlay.mockClear();
|
||||
cmObj.addOverlay.mockClear();
|
||||
const input = ctrl.container.querySelector('input');
|
||||
|
||||
fireEvent.change(input, {
|
||||
target: {value: '\n\r\tA'},
|
||||
});
|
||||
|
||||
expect(cmObj.removeOverlay).toHaveBeenCalled();
|
||||
expect(cmObj.addOverlay).toHaveBeenCalled();
|
||||
expect(cmObj.setSelection).toHaveBeenCalledWith(3, 14);
|
||||
expect(cmObj.scrollIntoView).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('reverse forward', (done)=>{
|
||||
ctrlMount({}, ()=>{
|
||||
ctrl.find('InputText').find('input').simulate('change', {
|
||||
target: {value: 'A'},
|
||||
});
|
||||
cmObj.setSelection.calls.reset();
|
||||
cmObj.addOverlay.calls.reset();
|
||||
ctrl.find('InputText').find('input').simulate('keypress', {
|
||||
key: 'Enter', shiftKey: true,
|
||||
});
|
||||
ctrl.find('InputText').find('input').simulate('keypress', {
|
||||
key: 'Enter', shiftKey: false,
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(cmObj.setSelection).toHaveBeenCalledWith(1, 10);
|
||||
expect(cmObj.setSelection).toHaveBeenCalledWith(3, 14);
|
||||
done();
|
||||
}, 0);
|
||||
it('escape', ()=>{
|
||||
ctrlMount({});
|
||||
cmObj.removeOverlay.mockClear();
|
||||
|
||||
fireEvent.keyDown(ctrl.container.querySelector('input'), {
|
||||
key: 'Escape',
|
||||
});
|
||||
|
||||
expect(cmObj.removeOverlay).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('toggle match case', ()=>{
|
||||
ctrlMount({});
|
||||
const btn = screen.getAllByRole('button').at(0);
|
||||
expect(btn.className.includes('makeStyles-defaultButton')).toBe(true);
|
||||
fireEvent.click(btn);
|
||||
|
||||
it('escape', (done)=>{
|
||||
ctrlMount({}, ()=>{
|
||||
cmObj.removeOverlay.calls.reset();
|
||||
ctrl.find('InputText').find('input').simulate('keydown', {
|
||||
key: 'Escape',
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(cmObj.removeOverlay).toHaveBeenCalled();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
expect(screen.getAllByRole('button').at(0).className.includes('makeStyles-primaryButton')).toBe(true);
|
||||
});
|
||||
|
||||
it('toggle match case', (done)=>{
|
||||
ctrlMount({}, ()=>{
|
||||
expect(ctrl.find('PgIconButton[data-test="case"]').props()).toEqual(jasmine.objectContaining({
|
||||
color: 'default'
|
||||
}));
|
||||
ctrl.find('PgIconButton[data-test="case"]').find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
expect(ctrl.find('PgIconButton[data-test="case"]').props()).toEqual(jasmine.objectContaining({
|
||||
color: 'primary'
|
||||
}));
|
||||
done();
|
||||
}, 0);
|
||||
it('toggle regex', ()=>{
|
||||
ctrlMount({});
|
||||
|
||||
fireEvent.change(ctrl.container.querySelector('input'), {
|
||||
target: {value: 'A'},
|
||||
});
|
||||
|
||||
const btn = screen.getAllByRole('button').at(1);
|
||||
expect(btn.className.includes('makeStyles-defaultButton')).toBe(true);
|
||||
fireEvent.click(btn);
|
||||
});
|
||||
|
||||
it('toggle regex', (done)=>{
|
||||
ctrlMount({}, ()=>{
|
||||
ctrl.find('InputText').find('input').simulate('change', {
|
||||
target: {value: 'A'},
|
||||
});
|
||||
expect(ctrl.find('PgIconButton[data-test="regex"]').props()).toEqual(jasmine.objectContaining({
|
||||
color: 'default'
|
||||
}));
|
||||
ctrl.find('PgIconButton[data-test="regex"]').find('button').simulate('click');
|
||||
setTimeout(()=>{
|
||||
expect(ctrl.find('PgIconButton[data-test="regex"]').props()).toEqual(jasmine.objectContaining({
|
||||
color: 'primary'
|
||||
}));
|
||||
done();
|
||||
}, 0);
|
||||
it('replace', async ()=>{
|
||||
ctrlMount({replace: true});
|
||||
cmObj.getSearchCursor().replace.mockClear();
|
||||
fireEvent.change(ctrl.container.querySelectorAll('input')[0], {
|
||||
target: {value: 'A'},
|
||||
});
|
||||
fireEvent.change(ctrl.container.querySelectorAll('input')[1], {
|
||||
target: {value: 'B'},
|
||||
});
|
||||
fireEvent.keyPress(ctrl.container.querySelectorAll('input')[1], {
|
||||
key: 'Enter', shiftKey: true, code: 13, charCode: 13
|
||||
});
|
||||
await waitFor(()=>{
|
||||
expect(cmObj.getSearchCursor().replace).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
it('replace', (done)=>{
|
||||
ctrlMount({replace: true}, ()=>{
|
||||
cmObj.getSearchCursor().replace.calls.reset();
|
||||
ctrl.find('InputText').at(0).find('input').simulate('change', {
|
||||
target: {value: 'A'},
|
||||
});
|
||||
ctrl.find('InputText').at(1).find('input').simulate('change', {
|
||||
target: {value: 'B'},
|
||||
});
|
||||
ctrl.find('InputText').at(1).find('input').simulate('keypress', {
|
||||
key: 'Enter', shiftKey: true,
|
||||
});
|
||||
setTimeout(()=>{
|
||||
expect(cmObj.getSearchCursor().replace).toHaveBeenCalled();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,20 +7,10 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
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 { OutlinedInput, FormHelperText, IconButton, FormControlLabel,
|
||||
Switch, Checkbox, Button, InputLabel } from '@material-ui/core';
|
||||
import Select from 'react-select';
|
||||
import CreatableSelect from 'react-select/creatable';
|
||||
import CheckRoundedIcon from '@material-ui/icons/CheckRounded';
|
||||
import InfoRoundedIcon from '@material-ui/icons/InfoRounded';
|
||||
import CloseIcon from '@material-ui/icons/CloseRounded';
|
||||
import ErrorRoundedIcon from '@material-ui/icons/ErrorOutlineRounded';
|
||||
import WarningRoundedIcon from '@material-ui/icons/WarningRounded';
|
||||
import { act, fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
|
||||
|
||||
import {FormInputText, FormInputFileSelect, FormInputSQL,
|
||||
@@ -28,44 +18,40 @@ import {FormInputText, FormInputFileSelect, FormInputSQL,
|
||||
FormInputColor,
|
||||
FormFooterMessage,
|
||||
MESSAGE_TYPE} from '../../../pgadmin/static/js/components/FormComponents';
|
||||
import CodeMirror from '../../../pgadmin/static/js/components/CodeMirror';
|
||||
import { ToggleButton } from '@material-ui/lab';
|
||||
import { DefaultButton, PrimaryButton } from '../../../pgadmin/static/js/components/Buttons';
|
||||
import * as showFileManager from '../../../pgadmin/static/js/helpers/showFileManager';
|
||||
|
||||
/* MUI Components need to be wrapped in Theme for theme vars */
|
||||
describe('FormComponents', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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();
|
||||
});
|
||||
|
||||
let onAccessibility = (ctrl)=> {
|
||||
expect(ctrl.find(InputLabel)).toHaveProp('htmlFor', 'inpCid');
|
||||
expect(ctrl.find(FormHelperText)).toHaveProp('id', 'hinpCid');
|
||||
let inputProps = ctrl.find(OutlinedInput).prop('inputProps');
|
||||
expect(inputProps).toEqual(jasmine.objectContaining({
|
||||
id: 'inpCid',
|
||||
'aria-describedby': 'hinpCid',
|
||||
}));
|
||||
let onAccessibility = ()=> {
|
||||
const input = screen.getByTestId('input-text');
|
||||
expect(input.getAttribute('id')).toBe('inpCid');
|
||||
expect(input.getAttribute('aria-describedby')).toBe('hinpCid');
|
||||
};
|
||||
|
||||
describe('FormInputText', ()=>{
|
||||
let ThemedFormInputText = withTheme(FormInputText), ctrl;
|
||||
const ctrlRerender = (props)=>{
|
||||
ctrl.rerender(
|
||||
<ThemedFormInputText
|
||||
label="First"
|
||||
className="someClass"
|
||||
testcid="inpCid"
|
||||
helpMessage="some help message"
|
||||
/* InputText */
|
||||
readonly={false}
|
||||
disabled={false}
|
||||
|
||||
value={'thevalue'}
|
||||
controlProps={{
|
||||
extraprop: 'test',
|
||||
maxLength: 50,
|
||||
}}
|
||||
{...props}
|
||||
/>);
|
||||
};
|
||||
|
||||
beforeEach(()=>{
|
||||
ctrl = mount(
|
||||
ctrl = render(
|
||||
<ThemedFormInputText
|
||||
label="First"
|
||||
className="someClass"
|
||||
@@ -84,44 +70,58 @@ describe('FormComponents', ()=>{
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
expect(ctrl.find(InputLabel).text()).toBe('First');
|
||||
expect(ctrl.find(OutlinedInput).prop('extraprop')).toEqual('test');
|
||||
expect( ctrl.find(OutlinedInput).prop('inputProps')).toEqual(jasmine.objectContaining({
|
||||
maxLength: 50,
|
||||
}));
|
||||
expect(ctrl.find(OutlinedInput).prop('readOnly')).toBe(false);
|
||||
expect(ctrl.find(OutlinedInput).prop('disabled')).toBe(false);
|
||||
expect(ctrl.find(OutlinedInput).prop('value')).toBe('thevalue');
|
||||
expect(ctrl.find(FormHelperText).text()).toBe('some help message');
|
||||
expect(screen.getByLabelText('First')).toBeInTheDocument();
|
||||
const input = screen.getByDisplayValue('thevalue');
|
||||
expect(input).toBeInTheDocument();
|
||||
expect(input.hasAttribute('readonly')).toBe(false);
|
||||
expect(input.hasAttribute('disabled')).toBe(false);
|
||||
expect(screen.getByText('some help message')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('props change', ()=>{
|
||||
let onChange = ()=>{/*This is intentional (SonarQube)*/};
|
||||
ctrl.setProps({
|
||||
ctrlRerender({
|
||||
readonly: true,
|
||||
disabled: true,
|
||||
value: 'new value',
|
||||
onChange: onChange,
|
||||
});
|
||||
|
||||
expect(ctrl.find(OutlinedInput).prop('readOnly')).toBe(true);
|
||||
expect(ctrl.find(OutlinedInput).prop('disabled')).toBe(true);
|
||||
expect(ctrl.find(OutlinedInput).prop('value')).toBe('new value');
|
||||
const input = screen.getByDisplayValue('new value');
|
||||
expect(input).toBeInTheDocument();
|
||||
expect(input.hasAttribute('readonly')).toBe(true);
|
||||
expect(input.hasAttribute('disabled')).toBe(true);
|
||||
});
|
||||
|
||||
it('accessibility', ()=>{
|
||||
onAccessibility(ctrl);
|
||||
onAccessibility();
|
||||
});
|
||||
});
|
||||
|
||||
describe('FormInputFileSelect', ()=>{
|
||||
let ThemedFormInputFileSelect = withTheme(FormInputFileSelect), ctrl;
|
||||
const ctrlRerender = (props)=>{
|
||||
ctrl.rerender(
|
||||
<ThemedFormInputFileSelect
|
||||
label="First"
|
||||
className="someClass"
|
||||
testcid="inpCid"
|
||||
helpMessage="some help message"
|
||||
/* InputText */
|
||||
readonly={false}
|
||||
disabled={false}
|
||||
value={'thevalue'}
|
||||
controlProps={{
|
||||
dialogType: 'select_file', supportedTypes: ['*'],
|
||||
}}
|
||||
{...props}
|
||||
/>);
|
||||
};
|
||||
|
||||
beforeEach(()=>{
|
||||
spyOn(showFileManager, 'showFileManager').and.callFake((controlProps, onFileSelect)=>{
|
||||
jest.spyOn(showFileManager, 'showFileManager').mockImplementation((controlProps, onFileSelect)=>{
|
||||
onFileSelect('selected/file');
|
||||
});
|
||||
ctrl = mount(
|
||||
ctrl = render(
|
||||
<ThemedFormInputFileSelect
|
||||
label="First"
|
||||
className="someClass"
|
||||
@@ -138,49 +138,47 @@ describe('FormComponents', ()=>{
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
expect(ctrl.find(InputLabel).text()).toBe('First');
|
||||
expect(ctrl.find(OutlinedInput).prop('readOnly')).toBe(false);
|
||||
expect(ctrl.find(OutlinedInput).prop('disabled')).toBe(false);
|
||||
expect(ctrl.find(OutlinedInput).prop('value')).toBe('thevalue');
|
||||
expect(ctrl.find(FormHelperText).text()).toBe('some help message');
|
||||
expect(screen.getByLabelText('First')).toBeInTheDocument();
|
||||
const input = screen.getByDisplayValue('thevalue');
|
||||
expect(input).toBeInTheDocument();
|
||||
expect(input.hasAttribute('readonly')).toBe(false);
|
||||
expect(input.hasAttribute('disabled')).toBe(false);
|
||||
expect(screen.getByText('some help message')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('props change', ()=>{
|
||||
ctrl.setProps({
|
||||
ctrlRerender({
|
||||
readonly: true,
|
||||
disabled: true,
|
||||
value: 'new value',
|
||||
});
|
||||
|
||||
expect(ctrl.find(OutlinedInput).prop('readOnly')).toBe(true);
|
||||
expect(ctrl.find(OutlinedInput).prop('disabled')).toBe(true);
|
||||
expect(ctrl.find(OutlinedInput).prop('value')).toBe('new value');
|
||||
expect(ctrl.find(IconButton).prop('disabled')).toBe(true);
|
||||
const input = screen.getByDisplayValue('new value');
|
||||
expect(input).toBeInTheDocument();
|
||||
expect(input.hasAttribute('readonly')).toBe(true);
|
||||
expect(input.hasAttribute('disabled')).toBe(true);
|
||||
});
|
||||
|
||||
|
||||
it('file select', (done)=>{
|
||||
let onChange = jasmine.createSpy();
|
||||
ctrl.setProps({
|
||||
it('file select', ()=>{
|
||||
let onChange = jest.fn();
|
||||
ctrlRerender({
|
||||
onChange: onChange,
|
||||
});
|
||||
ctrl.find(IconButton).simulate('click');
|
||||
setTimeout(()=>{
|
||||
expect(onChange).toHaveBeenCalledWith('selected/file');
|
||||
done();
|
||||
}, 0);
|
||||
fireEvent.click(screen.getByRole('button'));
|
||||
expect(onChange).toHaveBeenCalledWith('selected/file');
|
||||
});
|
||||
|
||||
it('accessibility', ()=>{
|
||||
onAccessibility(ctrl);
|
||||
onAccessibility();
|
||||
});
|
||||
});
|
||||
|
||||
describe('FormInputSQL', ()=>{
|
||||
let ThemedFormInputSQL = withTheme(FormInputSQL), ctrl;
|
||||
let ThemedFormInputSQL = withTheme(FormInputSQL);
|
||||
|
||||
beforeEach(()=>{
|
||||
ctrl = mount(
|
||||
render(
|
||||
<ThemedFormInputSQL
|
||||
label="First"
|
||||
className="someClass"
|
||||
@@ -195,18 +193,31 @@ describe('FormComponents', ()=>{
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
expect(ctrl.find(InputLabel).text()).toBe('First');
|
||||
expect(ctrl.find(CodeMirror).prop('value')).toEqual('thevalue');
|
||||
expect(ctrl.find(CodeMirror).prop('options')).toEqual(jasmine.objectContaining({'op1': 'test'}));
|
||||
expect(ctrl.find(FormHelperText).text()).toBe('some help message');
|
||||
expect(screen.getByLabelText('First')).toBeInTheDocument();
|
||||
expect(screen.getByText('thevalue')).toBeInTheDocument();
|
||||
expect(screen.getByText('some help message')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe('FormInputSwitch', ()=>{
|
||||
let ThemedFormInputSwitch = withTheme(FormInputSwitch), ctrl, onChange=()=>{return 1;};
|
||||
const ctrlRerender = (props)=>{
|
||||
ctrl.rerender(
|
||||
<ThemedFormInputSwitch
|
||||
label="First"
|
||||
className="someClass"
|
||||
testcid="inpCid"
|
||||
helpMessage="some help message"
|
||||
/* InputSwitch */
|
||||
readonly={false}
|
||||
value={false}
|
||||
onChange={onChange}
|
||||
{...props}
|
||||
/>);
|
||||
};
|
||||
|
||||
beforeEach(()=>{
|
||||
ctrl = mount(
|
||||
ctrl = render(
|
||||
<ThemedFormInputSwitch
|
||||
label="First"
|
||||
className="someClass"
|
||||
@@ -220,38 +231,52 @@ describe('FormComponents', ()=>{
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
expect(ctrl.find(InputLabel).text()).toBe('First');
|
||||
expect(ctrl.find(Switch).prop('checked')).toBe(false);
|
||||
expect(ctrl.find(Switch).prop('onChange')).toBe(onChange);
|
||||
expect(ctrl.find(FormHelperText).text()).toBe('some help message');
|
||||
expect(screen.getByLabelText('First')).toBeInTheDocument();
|
||||
const input = ctrl.container.querySelector('.MuiSwitch-switchBase');
|
||||
expect(input).toBeInTheDocument();
|
||||
expect(input.className.includes('Mui-checked')).toBe(false);
|
||||
expect(screen.getByText('some help message')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('props change', ()=>{
|
||||
ctrl.setProps({
|
||||
ctrlRerender({
|
||||
readonly: true,
|
||||
value: true,
|
||||
});
|
||||
|
||||
expect(ctrl.find(Switch).prop('checked')).toBe(true);
|
||||
expect(ctrl.find(Switch).prop('onChange')).not.toBe(onChange);
|
||||
const input = ctrl.container.querySelector('.MuiSwitch-switchBase');
|
||||
expect(input.className.includes('Mui-checked')).toBe(true);
|
||||
});
|
||||
|
||||
it('accessibility', ()=>{
|
||||
expect(ctrl.find(InputLabel)).toHaveProp('htmlFor', 'inpCid');
|
||||
expect(ctrl.find(FormHelperText)).toHaveProp('id', 'hinpCid');
|
||||
expect(ctrl.find(Switch).prop('id')).toBe('inpCid');
|
||||
let inputProps = ctrl.find(Switch).prop('inputProps');
|
||||
expect(inputProps).toEqual(jasmine.objectContaining({
|
||||
'aria-describedby': 'hinpCid',
|
||||
}));
|
||||
const input = ctrl.container.querySelector('input');
|
||||
expect(input.getAttribute('id')).toBe('inpCid');
|
||||
expect(input.getAttribute('aria-describedby')).toBe('hinpCid');
|
||||
});
|
||||
});
|
||||
|
||||
describe('FormInputCheckbox', ()=>{
|
||||
let ThemedFormInputCheckbox = withTheme(FormInputCheckbox), ctrl, onChange=()=>{return 1;};
|
||||
const ctrlRerender = (props)=>{
|
||||
ctrl.rerender(
|
||||
<ThemedFormInputCheckbox
|
||||
label="First"
|
||||
className="someClass"
|
||||
testcid="inpCid"
|
||||
helpMessage="some help message"
|
||||
/* InputCheckbox */
|
||||
disabled={false}
|
||||
value={false}
|
||||
onChange={onChange}
|
||||
controlProps={{
|
||||
label: 'Second'
|
||||
}}
|
||||
{...props}
|
||||
/>);
|
||||
};
|
||||
|
||||
beforeEach(()=>{
|
||||
ctrl = mount(
|
||||
ctrl = render(
|
||||
<ThemedFormInputCheckbox
|
||||
label="First"
|
||||
className="someClass"
|
||||
@@ -268,39 +293,56 @@ describe('FormComponents', ()=>{
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
expect(ctrl.find(InputLabel).text()).toBe('First');
|
||||
expect(ctrl.find(FormControlLabel).prop('label')).toBe('Second');
|
||||
expect(ctrl.find(Checkbox).prop('checked')).toBe(false);
|
||||
expect(ctrl.find(Checkbox).prop('onChange')).toBe(onChange);
|
||||
expect(ctrl.find(FormHelperText).text()).toBe('some help message');
|
||||
expect(screen.getByLabelText('First')).toBeInTheDocument();
|
||||
expect(screen.getByLabelText('Second')).toBeInTheDocument();
|
||||
|
||||
const input = ctrl.container.querySelector('.MuiCheckbox-root');
|
||||
expect(input).toBeInTheDocument();
|
||||
expect(input.className.includes('Mui-checked')).toBe(false);
|
||||
expect(screen.getByText('some help message')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('props change', ()=>{
|
||||
ctrl.setProps({
|
||||
ctrlRerender({
|
||||
readonly: true,
|
||||
value: true,
|
||||
});
|
||||
|
||||
expect(ctrl.find(Checkbox).prop('checked')).toBe(true);
|
||||
expect(ctrl.find(Checkbox).prop('onChange')).not.toBe(onChange);
|
||||
const input = ctrl.container.querySelector('.MuiCheckbox-root');
|
||||
expect(input).toBeInTheDocument();
|
||||
expect(input.className.includes('Mui-checked')).toBe(true);
|
||||
});
|
||||
|
||||
it('accessibility', ()=>{
|
||||
expect(ctrl.find(InputLabel)).toHaveProp('htmlFor', 'inpCid');
|
||||
expect(ctrl.find(FormHelperText)).toHaveProp('id', 'hinpCid');
|
||||
expect(ctrl.find(Checkbox).prop('id')).toBe('inpCid');
|
||||
let inputProps = ctrl.find(Checkbox).prop('inputProps');
|
||||
expect(inputProps).toEqual(jasmine.objectContaining({
|
||||
'aria-describedby': 'hinpCid',
|
||||
}));
|
||||
const input = ctrl.container.querySelector('input');
|
||||
expect(input.getAttribute('id')).toBe('inpCid');
|
||||
expect(input.getAttribute('aria-describedby')).toBe('hinpCid');
|
||||
});
|
||||
});
|
||||
|
||||
describe('FormInputToggle', ()=>{
|
||||
let ThemedFormInputToggle = withTheme(FormInputToggle), ctrl, onChange=()=>{return 1;};
|
||||
const ctrlRerender = (props)=>{
|
||||
ctrl.rerender(
|
||||
<ThemedFormInputToggle
|
||||
label="First"
|
||||
className="someClass"
|
||||
testcid="inpCid"
|
||||
helpMessage="some help message"
|
||||
/* InputToggle */
|
||||
disabled={false}
|
||||
options={[
|
||||
{label: 'Op1', value: 1},
|
||||
{label: 'Op2', value: 2},
|
||||
{label: 'Op3', value: 3},
|
||||
]}
|
||||
value={2}
|
||||
onChange={onChange}
|
||||
{...props}
|
||||
/>);
|
||||
};
|
||||
|
||||
beforeEach(()=>{
|
||||
ctrl = mount(
|
||||
ctrl = render(
|
||||
<ThemedFormInputToggle
|
||||
label="First"
|
||||
className="someClass"
|
||||
@@ -319,37 +361,35 @@ describe('FormComponents', ()=>{
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
expect(ctrl.find(InputLabel).text()).toBe('First');
|
||||
expect(ctrl.find(ToggleButton).length).toBe(3);
|
||||
expect(ctrl.find(PrimaryButton).length).toBe(1);
|
||||
expect(ctrl.find(DefaultButton).length).toBe(2);
|
||||
expect(ctrl.find(ToggleButton).at(1).prop('component')).toBe(PrimaryButton);
|
||||
expect(ctrl.find(FormHelperText).text()).toBe('some help message');
|
||||
expect(screen.getByLabelText('First')).toBeInTheDocument();
|
||||
expect(screen.getAllByRole('button').length).toBe(3);
|
||||
expect(screen.getAllByRole('button').at(0).className.includes('primaryButton')).toBe(false);
|
||||
expect(screen.getAllByRole('button').at(1).className.includes('primaryButton')).toBe(true);
|
||||
expect(screen.getAllByRole('button').at(2).className.includes('primaryButton')).toBe(false);
|
||||
expect(screen.getByText('some help message')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('props change', ()=>{
|
||||
ctrl.setProps({
|
||||
ctrlRerender({
|
||||
value: 1,
|
||||
});
|
||||
expect(ctrl.find(ToggleButton).at(0).prop('component')).toBe(PrimaryButton);
|
||||
expect(ctrl.find(ToggleButton).at(0)
|
||||
.find(CheckRoundedIcon)
|
||||
.prop('style')).toEqual(jasmine.objectContaining({
|
||||
visibility: 'visible'
|
||||
}));
|
||||
expect(screen.getAllByRole('button').at(0).className.includes('primaryButton')).toBe(true);
|
||||
expect(screen.getAllByRole('button').at(1).className.includes('primaryButton')).toBe(false);
|
||||
expect(screen.getAllByRole('button').at(2).className.includes('primaryButton')).toBe(false);
|
||||
});
|
||||
|
||||
it('accessibility', ()=>{
|
||||
expect(ctrl.find(InputLabel)).toHaveProp('htmlFor', 'inpCid');
|
||||
expect(ctrl.find(FormHelperText)).toHaveProp('id', 'hinpCid');
|
||||
const input = ctrl.container.querySelector('input');
|
||||
expect(input.getAttribute('id')).toBe('inpCid');
|
||||
expect(input.getAttribute('aria-describedby')).toBe('hinpCid');
|
||||
});
|
||||
});
|
||||
|
||||
describe('FormInputSelect', ()=>{
|
||||
let ThemedFormInputSelect = withTheme(FormInputSelect), ctrl, onChange=jasmine.createSpy('onChange'),
|
||||
ctrlMount = (props)=>{
|
||||
ctrl?.unmount();
|
||||
ctrl = mount(
|
||||
let ThemedFormInputSelect = withTheme(FormInputSelect), ctrl, onChange=jest.fn();
|
||||
const ctrlRerender = (props)=>{
|
||||
act(()=>{
|
||||
ctrl.rerender(
|
||||
<ThemedFormInputSelect
|
||||
label="First"
|
||||
className="someClass"
|
||||
@@ -367,71 +407,51 @@ describe('FormComponents', ()=>{
|
||||
onChange={onChange}
|
||||
{...props}
|
||||
/>);
|
||||
};
|
||||
|
||||
beforeEach(()=>{
|
||||
ctrlMount();
|
||||
});
|
||||
|
||||
it('init', (done)=>{
|
||||
expect(ctrl.find(Select).exists()).toBe(true);
|
||||
expect(ctrl.find(CreatableSelect).exists()).toBe(false);
|
||||
expect(ctrl.find(FormHelperText).text()).toBe('some help message');
|
||||
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find(Select).props()).toEqual(jasmine.objectContaining({
|
||||
isMulti: false,
|
||||
value: {label: 'Op1', value: 1},
|
||||
inputId: 'inpCid',
|
||||
isSearchable: true,
|
||||
isClearable: true,
|
||||
isDisabled: false,
|
||||
}));
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('readonly disabled', (done)=>{
|
||||
ctrl.setProps({
|
||||
readonly: true,
|
||||
disabled: true,
|
||||
});
|
||||
};
|
||||
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find(Select).props()).toEqual(jasmine.objectContaining({
|
||||
isSearchable: false,
|
||||
isClearable: false,
|
||||
isDisabled: true,
|
||||
openMenuOnClick: false,
|
||||
}));
|
||||
done();
|
||||
}, 0);
|
||||
beforeEach(async ()=>{
|
||||
await act(async ()=>{
|
||||
ctrl = await render(
|
||||
<ThemedFormInputSelect
|
||||
label="First"
|
||||
className="someClass"
|
||||
testcid="inpCid"
|
||||
helpMessage="some help message"
|
||||
/* InputSelect */
|
||||
readonly={false}
|
||||
disabled={false}
|
||||
options={[
|
||||
{label: 'Op1', value: 1},
|
||||
{label: 'Op2', value: 2},
|
||||
{label: 'Op3', value: 3},
|
||||
]}
|
||||
value={1}
|
||||
onChange={onChange}
|
||||
/>);
|
||||
});
|
||||
});
|
||||
|
||||
it('no-clear with multi', (done)=>{
|
||||
ctrl.setProps({
|
||||
it('init', ()=>{
|
||||
expect(screen.getByLabelText('First')).toBeInTheDocument();
|
||||
expect(screen.getByText('Op1')).toBeInTheDocument();
|
||||
expect(screen.getByText('some help message')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('no-clear with multi', ()=>{
|
||||
ctrlRerender({
|
||||
controlProps: {
|
||||
allowClear: false,
|
||||
multiple: true,
|
||||
},
|
||||
value: [2, 3],
|
||||
});
|
||||
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find(Select).props()).toEqual(jasmine.objectContaining({
|
||||
isMulti: true,
|
||||
isClearable: false,
|
||||
value: [{label: 'Op2', value: 2}, {label: 'Op3', value: 3}]
|
||||
}));
|
||||
done();
|
||||
}, 0);
|
||||
expect(screen.getByText('Op2')).toBeInTheDocument();
|
||||
expect(screen.getByText('Op3')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('creatable with multi', (done)=>{
|
||||
ctrl.setProps({
|
||||
it('creatable with multi', ()=>{
|
||||
ctrlRerender({
|
||||
controlProps: {
|
||||
creatable: true,
|
||||
multiple: true,
|
||||
@@ -439,55 +459,57 @@ describe('FormComponents', ()=>{
|
||||
value: ['val1', 'val2'],
|
||||
});
|
||||
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find(Select).exists()).toBe(false);
|
||||
expect(ctrl.find(CreatableSelect).exists()).toBe(true);
|
||||
|
||||
expect(ctrl.find(CreatableSelect).props()).toEqual(jasmine.objectContaining({
|
||||
isMulti: true,
|
||||
value: [{label: 'val1', value: 'val1'}, {label: 'val2', value: 'val2'}]
|
||||
}));
|
||||
done();
|
||||
}, 0);
|
||||
expect(screen.getByText('val1')).toBeInTheDocument();
|
||||
expect(screen.getByText('val2')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('promise options', (done)=>{
|
||||
let optionsLoaded = jasmine.createSpy();
|
||||
it('promise options', async ()=>{
|
||||
let optionsLoaded = jest.fn();
|
||||
let res = [
|
||||
{label: 'PrOp1', value: 1},
|
||||
{label: 'PrOp2', value: 2},
|
||||
{label: 'PrOp3', value: 3},
|
||||
];
|
||||
/* For options change, remount needed */
|
||||
ctrlMount({
|
||||
ctrlRerender({
|
||||
options: ()=>Promise.resolve(res),
|
||||
optionsReloadBasis: 3,
|
||||
value: 3,
|
||||
optionsLoaded: optionsLoaded,
|
||||
});
|
||||
// expect(screen.getByText('PrOp3')).toBeInTheDocument()
|
||||
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(optionsLoaded).toHaveBeenCalledWith(res, 3);
|
||||
expect(ctrl.find(Select).props()).toEqual(jasmine.objectContaining({
|
||||
value: {label: 'PrOp3', value: 3},
|
||||
}));
|
||||
done();
|
||||
}, 0);
|
||||
await waitFor(()=>expect(screen.getByText('PrOp3')).toBeInTheDocument(), {timeout: 500});
|
||||
});
|
||||
|
||||
it('accessibility', ()=>{
|
||||
expect(ctrl.find(InputLabel)).toHaveProp('htmlFor', 'inpCid');
|
||||
expect(ctrl.find(FormHelperText)).toHaveProp('id', 'hinpCid');
|
||||
const input = ctrl.container.querySelectorAll('input')[1];
|
||||
expect(input.getAttribute('id')).toBe('inpCid');
|
||||
expect(input.getAttribute('aria-describedby')).toBe('hinpCid');
|
||||
});
|
||||
});
|
||||
|
||||
describe('FormInputColor', ()=>{
|
||||
let pickrObj = React.createRef();
|
||||
let ThemedFormInputColor = withTheme(FormInputColor), ctrl, onChange=jasmine.createSpy('onChange');
|
||||
let ThemedFormInputColor = withTheme(FormInputColor), ctrl, onChange=jest.fn();
|
||||
const ctrlRerender = (props)=>{
|
||||
ctrl.rerender(
|
||||
<ThemedFormInputColor
|
||||
label="First"
|
||||
className="someClass"
|
||||
testcid="inpCid"
|
||||
helpMessage="some help message"
|
||||
/* InputColor */
|
||||
disabled={false}
|
||||
value="#f0f"
|
||||
onChange={onChange}
|
||||
currObj={(obj)=>pickrObj.current=obj}
|
||||
{...props}
|
||||
/>);
|
||||
};
|
||||
|
||||
beforeEach(()=>{
|
||||
ctrl = mount(
|
||||
ctrl = render(
|
||||
<ThemedFormInputColor
|
||||
label="First"
|
||||
className="someClass"
|
||||
@@ -501,53 +523,33 @@ describe('FormComponents', ()=>{
|
||||
/>);
|
||||
});
|
||||
|
||||
afterEach(()=>{
|
||||
ctrl.unmount();
|
||||
it('init', ()=>{
|
||||
expect(screen.getAllByRole('button').at(0).style.backgroundColor).toEqual('rgb(255, 0, 255)');
|
||||
});
|
||||
|
||||
it('init', (done)=>{
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find(Button).prop('style')).toEqual(jasmine.objectContaining({
|
||||
backgroundColor: '#f0f',
|
||||
}));
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('no color', (done)=>{
|
||||
ctrl.setProps({
|
||||
it('no color', ()=>{
|
||||
ctrlRerender({
|
||||
value: null,
|
||||
});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find(Button).prop('style')).toEqual(jasmine.objectContaining({
|
||||
backgroundColor: null,
|
||||
}));
|
||||
expect(ctrl.find(Button).find(CloseIcon).exists()).toBe(true);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
|
||||
it('other events', (done)=>{
|
||||
pickrObj.current.applyColor(false);
|
||||
setTimeout(()=>{
|
||||
expect(onChange).toHaveBeenCalled();
|
||||
done();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
it('accessibility', ()=>{
|
||||
expect(ctrl.find(InputLabel)).toHaveProp('htmlFor', 'inpCid');
|
||||
expect(ctrl.find(FormHelperText)).toHaveProp('id', 'hinpCid');
|
||||
const btn = screen.getAllByRole('button').at(0);
|
||||
expect(btn.style.backgroundColor).toBe('');
|
||||
});
|
||||
});
|
||||
|
||||
describe('FormFooterMessage', ()=>{
|
||||
let ThemedFormFooterMessage = withTheme(FormFooterMessage), ctrl, onClose=jasmine.createSpy('onClose');
|
||||
|
||||
let ThemedFormFooterMessage = withTheme(FormFooterMessage), ctrl, onClose=jest.fn();
|
||||
const ctrlRerender = (props)=>{
|
||||
ctrl.rerender(
|
||||
<ThemedFormFooterMessage
|
||||
type={MESSAGE_TYPE.SUCCESS}
|
||||
message="Some message"
|
||||
closable={false}
|
||||
onClose={onClose}
|
||||
{...props}
|
||||
/>);
|
||||
};
|
||||
beforeEach(()=>{
|
||||
ctrl = mount(
|
||||
ctrl = render(
|
||||
<ThemedFormFooterMessage
|
||||
type={MESSAGE_TYPE.SUCCESS}
|
||||
message="Some message"
|
||||
@@ -557,41 +559,42 @@ describe('FormComponents', ()=>{
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
expect(ctrl.find(CheckRoundedIcon).exists()).toBeTrue();
|
||||
expect(ctrl.text()).toBe('Some message');
|
||||
expect(screen.getByTestId(MESSAGE_TYPE.SUCCESS)).toBeInTheDocument();
|
||||
expect(screen.getByText('Some message')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('change types', ()=>{
|
||||
ctrl.setProps({
|
||||
ctrlRerender({
|
||||
type: MESSAGE_TYPE.ERROR,
|
||||
});
|
||||
expect(ctrl.find(ErrorRoundedIcon).exists()).toBeTrue();
|
||||
expect(screen.getByTestId(MESSAGE_TYPE.ERROR)).toBeInTheDocument();
|
||||
|
||||
ctrl.setProps({
|
||||
ctrlRerender({
|
||||
type: MESSAGE_TYPE.INFO,
|
||||
});
|
||||
expect(ctrl.find(InfoRoundedIcon).exists()).toBeTrue();
|
||||
expect(screen.getByTestId(MESSAGE_TYPE.INFO)).toBeInTheDocument();
|
||||
|
||||
ctrl.setProps({
|
||||
ctrlRerender({
|
||||
type: MESSAGE_TYPE.WARNING,
|
||||
});
|
||||
expect(ctrl.find(WarningRoundedIcon).exists()).toBeTrue();
|
||||
expect(screen.getByTestId(MESSAGE_TYPE.WARNING)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('closable', ()=>{
|
||||
ctrl.setProps({
|
||||
ctrlRerender({
|
||||
closable: true,
|
||||
});
|
||||
expect(ctrl.find(CloseIcon).exists()).toBeTrue();
|
||||
ctrl.find(IconButton).simulate('click');
|
||||
const btn = screen.getByTestId('Close');
|
||||
expect(btn).toBeInTheDocument();
|
||||
fireEvent.click(btn);
|
||||
expect(onClose).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('no message', ()=>{
|
||||
ctrl.setProps({
|
||||
ctrlRerender({
|
||||
message: '',
|
||||
});
|
||||
expect(ctrl.isEmptyRender()).toBeTrue();
|
||||
expect(ctrl.container).toBeEmptyDOMElement();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,20 +7,16 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
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 {
|
||||
OutlinedInput,
|
||||
} from '@material-ui/core';
|
||||
import { fireEvent, render, screen } from '@testing-library/react';
|
||||
|
||||
|
||||
import KeyboardShortcuts from '../../../pgadmin/static/js/components/KeyboardShortcuts';
|
||||
import { InputCheckbox } from '../../../pgadmin/static/js/components/FormComponents';
|
||||
|
||||
/* MUI Components need to be wrapped in Theme for theme vars */
|
||||
describe('KeyboardShortcuts', () => {
|
||||
let mount;
|
||||
let defult_value = {
|
||||
'control': true,
|
||||
'alt': true,
|
||||
@@ -49,25 +45,11 @@ describe('KeyboardShortcuts', () => {
|
||||
type: 'checkbox'
|
||||
}];
|
||||
|
||||
/* 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('KeyboardShortcuts', () => {
|
||||
let ThemedFormInputKeyboardShortcuts = withTheme(KeyboardShortcuts), ctrl;
|
||||
let onChange = jasmine.createSpy('onChange');
|
||||
let ThemedFormInputKeyboardShortcuts = withTheme(KeyboardShortcuts);
|
||||
let onChange = jest.fn();
|
||||
beforeEach(() => {
|
||||
ctrl = mount(
|
||||
render(
|
||||
<ThemedFormInputKeyboardShortcuts
|
||||
value={defult_value}
|
||||
fields={fields}
|
||||
@@ -80,33 +62,33 @@ describe('KeyboardShortcuts', () => {
|
||||
});
|
||||
|
||||
it('init', () => {
|
||||
expect(ctrl.find(OutlinedInput).prop('value')).toBe('a');
|
||||
expect(screen.getByRole('textbox').getAttribute('value')).toBe('a');
|
||||
});
|
||||
|
||||
it('Key change', (done) => {
|
||||
ctrl.find(OutlinedInput).at(0).find('input').simulate('keydown', { key: '', keyCode: 32});
|
||||
it('Key change', () => {
|
||||
fireEvent.keyDown(screen.getByRole('textbox'), {
|
||||
key: 'Space', code: 32, keyCode: 32
|
||||
});
|
||||
expect(onChange).toHaveBeenCalledWith({ control: true, alt: true, key: { char: 'Space', key_code: 32 }, shift: false });
|
||||
done();
|
||||
});
|
||||
|
||||
it('Shift option', (done) => {
|
||||
ctrl.find(InputCheckbox).at(0).find('input').simulate('change', { target: { checked: true, name: 'shift' } });
|
||||
it('Shift option', () => {
|
||||
const input = screen.getAllByRole('checkbox').at(0);
|
||||
fireEvent.click(input);
|
||||
expect(onChange).toHaveBeenCalledWith({ control: true, alt: true, key: { char: 'a', key_code: 97 }, shift: true });
|
||||
done();
|
||||
});
|
||||
|
||||
it('Control option', (done) => {
|
||||
ctrl.find(InputCheckbox).at(1).find('input').simulate('change', { target: { checked: false, name: 'ctrl' } });
|
||||
it('Control option', () => {
|
||||
const input = screen.getAllByRole('checkbox').at(1);
|
||||
fireEvent.click(input);
|
||||
expect(onChange).toHaveBeenCalledWith({ control: false, alt: true, key: { char: 'a', key_code: 97 }, shift: false });
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
it('Alt option', (done) => {
|
||||
ctrl.find(InputCheckbox).at(2).find('input').simulate('change', { target: { checked: false, name: 'alt' } });
|
||||
it('Alt option', () => {
|
||||
const input = screen.getAllByRole('checkbox').at(2);
|
||||
fireEvent.click(input);
|
||||
expect(onChange).toHaveBeenCalledWith({ control: true, alt: false, key: { char: 'a', key_code: 97 }, shift: false });
|
||||
done();
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,46 +7,33 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import { withTheme } from '../fake_theme';
|
||||
import Loader from 'sources/components/Loader';
|
||||
|
||||
|
||||
/* MUI Components need to be wrapped in Theme for theme vars */
|
||||
describe('Loader', ()=>{
|
||||
let mount, loaderInst, ThemedLoader;
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(()=>{
|
||||
mount = createMount();
|
||||
/* Loader need Mui Theme context as well */
|
||||
let loaderInst,
|
||||
ThemedLoader = withTheme(Loader);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
});
|
||||
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
loaderInst = mount(<ThemedLoader message={'loading'} />);
|
||||
loaderInst = render(<ThemedLoader message={'loading'} />);
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
expect(loaderInst.find('.MuiTypography-root').text()).toBe('loading');
|
||||
expect(screen.getByText('loading')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('no message', ()=>{
|
||||
loaderInst.setProps({message: ''});
|
||||
expect(loaderInst.isEmptyRender()).toBeTruthy();
|
||||
loaderInst.rerender(<ThemedLoader message={''} />);
|
||||
expect(loaderInst.container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
it('change message', ()=>{
|
||||
loaderInst.setProps({message: 'test message'});
|
||||
expect(loaderInst.find('.MuiTypography-root').text()).toBe('test message');
|
||||
loaderInst.rerender(<ThemedLoader message={'test message'} />);
|
||||
expect(screen.getByText('test message')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,30 +7,13 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
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 { fireEvent, render, screen } from '@testing-library/react';
|
||||
import { PgMenu, PgMenuItem } from '../../../pgadmin/static/js/components/Menu';
|
||||
|
||||
describe('Menu', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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();
|
||||
});
|
||||
|
||||
const ThemedPgMenu = withTheme(PgMenu);
|
||||
const eleRef = {
|
||||
current: document.createElement('button'),
|
||||
@@ -40,45 +23,35 @@ describe('Menu', ()=>{
|
||||
const onClose = ()=>{/* on close call */};
|
||||
let ctrl;
|
||||
const ctrlMount = ()=>{
|
||||
ctrl?.unmount();
|
||||
ctrl = mount(
|
||||
ctrl = render(
|
||||
<ThemedPgMenu
|
||||
anchorRef={eleRef}
|
||||
onClose={onClose}
|
||||
open={false}
|
||||
/>);
|
||||
};
|
||||
it('init', (done)=>{
|
||||
it('init', ()=>{
|
||||
ctrlMount();
|
||||
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('ForwardRef(ControlledMenu)')).toHaveProp('anchorRef', eleRef);
|
||||
expect(ctrl.find('ForwardRef(ControlledMenu)')).toHaveProp('state', 'closed');
|
||||
expect(ctrl.find('ForwardRef(ControlledMenu)')).toHaveProp('onClose', onClose);
|
||||
done();
|
||||
}, 0);
|
||||
const menu = screen.getByRole('menu');
|
||||
expect(menu.getAttribute('data-state')).toBe('closed');
|
||||
});
|
||||
|
||||
it('open', (done)=>{
|
||||
it('open', ()=>{
|
||||
ctrlMount();
|
||||
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
ctrl.setProps({open: true});
|
||||
setTimeout(()=>{
|
||||
expect(ctrl.find('ForwardRef(ControlledMenu)')).toHaveProp('state', 'open');
|
||||
done();
|
||||
}, 0);
|
||||
}, 0);
|
||||
ctrl.rerender(<ThemedPgMenu
|
||||
anchorRef={eleRef}
|
||||
onClose={onClose}
|
||||
open={true}
|
||||
/>);
|
||||
const menu = screen.getByRole('menu');
|
||||
expect(menu.getAttribute('data-state')).toBe('open');
|
||||
});
|
||||
});
|
||||
|
||||
describe('PgMenuItem', ()=>{
|
||||
let ctrlMenu;
|
||||
const ctrlMount = (props, callback)=>{
|
||||
ctrlMenu?.unmount();
|
||||
ctrlMenu = mount(
|
||||
const ctrlMount = (props)=>{
|
||||
ctrlMenu = render(
|
||||
<ThemedPgMenu
|
||||
anchorRef={eleRef}
|
||||
open={false}
|
||||
@@ -86,14 +59,17 @@ describe('Menu', ()=>{
|
||||
<PgMenuItem {...props}>Test</PgMenuItem>
|
||||
</ThemedPgMenu>
|
||||
);
|
||||
ctrlMenu.setProps({open: true});
|
||||
setTimeout(()=>{
|
||||
ctrlMenu.update();
|
||||
callback();
|
||||
}, 0);
|
||||
ctrlMenu.rerender(
|
||||
<ThemedPgMenu
|
||||
anchorRef={eleRef}
|
||||
open={true}
|
||||
>
|
||||
<PgMenuItem {...props}>Test</PgMenuItem>
|
||||
</ThemedPgMenu>
|
||||
);
|
||||
};
|
||||
|
||||
it('init', (done)=>{
|
||||
it('init', ()=>{
|
||||
ctrlMount({
|
||||
shortcut: {
|
||||
'control': true,
|
||||
@@ -104,55 +80,40 @@ describe('Menu', ()=>{
|
||||
'char': 'k',
|
||||
},
|
||||
}
|
||||
}, ()=>{
|
||||
const menuItem = ctrlMenu.find('Memo(MenuItem)');
|
||||
expect(menuItem.find('li[role="menuitem"]').text()).toBe('Test(Ctrl + Shift + K)');
|
||||
done();
|
||||
});
|
||||
const menuItem = screen.getByRole('menuitem');
|
||||
expect(menuItem.textContent).toBe('Test(Ctrl + Shift + K)');
|
||||
});
|
||||
|
||||
it('not checked', (done)=>{
|
||||
it('not checked', ()=>{
|
||||
ctrlMount({
|
||||
hasCheck: true,
|
||||
}, ()=>{
|
||||
const checkIcon = ctrlMenu.find('ForwardRef(CheckIcon)');
|
||||
expect(checkIcon.props()).toEqual(jasmine.objectContaining({
|
||||
style: {
|
||||
visibility: 'hidden',
|
||||
}
|
||||
}));
|
||||
done();
|
||||
});
|
||||
const menuItem = screen.getByRole('menuitem');
|
||||
expect(menuItem.querySelector('[data-label="CheckIcon"]').style.visibility).toBe('hidden');
|
||||
});
|
||||
|
||||
it('checked', (done)=>{
|
||||
it('checked', ()=>{
|
||||
ctrlMount({
|
||||
hasCheck: true,
|
||||
checked: true,
|
||||
}, ()=>{
|
||||
const checkIcon = ctrlMenu.find('ForwardRef(CheckIcon)');
|
||||
expect(checkIcon.props()).toEqual(jasmine.objectContaining({
|
||||
style: {},
|
||||
}));
|
||||
done();
|
||||
});
|
||||
const menuItem = screen.getByRole('menuitem');
|
||||
expect(menuItem.querySelector('[data-label="CheckIcon"]').style.visibility).toBe('');
|
||||
});
|
||||
|
||||
|
||||
it('checked clicked', (done)=>{
|
||||
const onClick = jasmine.createSpy('onClick');
|
||||
it('checked clicked', async ()=>{
|
||||
const onClick = jest.fn();
|
||||
ctrlMount({
|
||||
hasCheck: true,
|
||||
checked: false,
|
||||
onClick: onClick,
|
||||
}, ()=>{
|
||||
onClick.calls.reset();
|
||||
ctrlMenu.find('Memo(MenuItem)').simulate('click');
|
||||
expect(onClick.calls.mostRecent().args[0]).toEqual(jasmine.objectContaining({
|
||||
keepOpen: true,
|
||||
}));
|
||||
done();
|
||||
});
|
||||
onClick.mockClear();
|
||||
const menuItem = screen.getByRole('menuitem');
|
||||
fireEvent.click(menuItem);
|
||||
expect(onClick).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,99 +7,68 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
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 ObjectBreadcrumbs from '../../../pgadmin/static/js/components/ObjectBreadcrumbs';
|
||||
import EventBus from '../../../pgadmin/static/js/helpers/EventBus';
|
||||
|
||||
const pgAdmin = {
|
||||
Browser: {
|
||||
Events: new EventBus(),
|
||||
get_preferences_for_module: function() {
|
||||
return {
|
||||
breadcrumbs_enable: true,
|
||||
breadcrumbs_show_comment: true,
|
||||
};
|
||||
},
|
||||
preference_version: ()=>123,
|
||||
onPreferencesChange: ()=>{/*This is intentional (SonarQube)*/},
|
||||
tree: {
|
||||
getNodeDisplayPath: jasmine.createSpy('getNodeDisplayPath').and.returnValue(['server', 'object']),
|
||||
}
|
||||
},
|
||||
};
|
||||
import React from 'react';
|
||||
|
||||
import { render, waitFor } from '@testing-library/react';
|
||||
import ObjectBreadcrumbs from '../../../pgadmin/static/js/components/ObjectBreadcrumbs';
|
||||
import pgAdmin from '../fake_pgadmin';
|
||||
import { withBrowser } from '../genericFunctions';
|
||||
import usePreferences from '../../../pgadmin/preferences/static/js/store';
|
||||
import { TreeFake } from '../tree/tree_fake';
|
||||
|
||||
describe('ObjectBreadcrumbs', ()=>{
|
||||
let mount;
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(()=>{
|
||||
mount = createMount();
|
||||
jest.spyOn(usePreferences.getState(), 'getPreferencesForModule').mockReturnValue({
|
||||
breadcrumbs_enable: true,
|
||||
breadcrumbs_show_comment: true,
|
||||
});
|
||||
pgAdmin.Browser.tree = new TreeFake(pgAdmin.Browser);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
it('not hovered', ()=>{
|
||||
let ThemedObjectBreadcrumbs = withBrowser(ObjectBreadcrumbs);
|
||||
let ctrl = render(<ThemedObjectBreadcrumbs />);
|
||||
expect(ctrl.container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
it('hovered object with comment', async ()=>{
|
||||
let ThemedObjectBreadcrumbs = withBrowser(ObjectBreadcrumbs);
|
||||
let ctrl = render(<ThemedObjectBreadcrumbs />);
|
||||
pgAdmin.Browser.Events.trigger('pgadmin-browser:tree:hovered', {
|
||||
_metadata: {
|
||||
data: {
|
||||
description: 'some description'
|
||||
}
|
||||
},
|
||||
}, {
|
||||
_type: 'object',
|
||||
});
|
||||
|
||||
await waitFor(()=>{
|
||||
expect(ctrl.container).not.toBeEmptyDOMElement();
|
||||
expect(ctrl.container.querySelector('[data-label="AccountTreeIcon"]')).toBeInTheDocument();
|
||||
expect(ctrl.container.querySelector('[data-label="CommentIcon"]')).toBeInTheDocument();
|
||||
}, {timeout: 500});
|
||||
});
|
||||
|
||||
it('not hovered', (done)=>{
|
||||
let ThemedObjectBreadcrumbs = withTheme(ObjectBreadcrumbs);
|
||||
let ctrl = mount(<ThemedObjectBreadcrumbs pgAdmin={pgAdmin} />);
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('ForwardRef(AccountTreeIcon)').length).toBe(0);
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
it('hovered object with no comment', async ()=>{
|
||||
let ThemedObjectBreadcrumbs = withBrowser(ObjectBreadcrumbs);
|
||||
let ctrl = render(<ThemedObjectBreadcrumbs />);
|
||||
|
||||
it('hovered object with comment', (done)=>{
|
||||
let ThemedObjectBreadcrumbs = withTheme(ObjectBreadcrumbs);
|
||||
let ctrl = mount(<ThemedObjectBreadcrumbs pgAdmin={pgAdmin} />);
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
pgAdmin.Browser.Events.trigger('pgadmin-browser:tree:hovered', {
|
||||
_metadata: {
|
||||
data: {
|
||||
description: 'some description'
|
||||
}
|
||||
},
|
||||
}, {
|
||||
_type: 'object',
|
||||
});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('ForwardRef(AccountTreeIcon)').length).toBe(1);
|
||||
expect(ctrl.find('ForwardRef(CommentIcon)').length).toBe(1);
|
||||
done();
|
||||
}, 500);
|
||||
}, 500);
|
||||
});
|
||||
pgAdmin.Browser.Events.trigger('pgadmin-browser:tree:hovered', {
|
||||
_metadata: {
|
||||
data: {}
|
||||
},
|
||||
}, {
|
||||
_type: 'object',
|
||||
});
|
||||
|
||||
it('hovered object with no comment', (done)=>{
|
||||
let ThemedObjectBreadcrumbs = withTheme(ObjectBreadcrumbs);
|
||||
let ctrl = mount(<ThemedObjectBreadcrumbs pgAdmin={pgAdmin} />);
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
pgAdmin.Browser.Events.trigger('pgadmin-browser:tree:hovered', {
|
||||
_metadata: {
|
||||
data: {}
|
||||
},
|
||||
}, {
|
||||
_type: 'object',
|
||||
});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('ForwardRef(AccountTreeIcon)').length).toBe(1);
|
||||
expect(ctrl.find('ForwardRef(CommentIcon)').length).toBe(0);
|
||||
done();
|
||||
}, 500);
|
||||
}, 500);
|
||||
await waitFor(()=>{
|
||||
expect(ctrl.container).not.toBeEmptyDOMElement();
|
||||
expect(ctrl.container.querySelector('[data-label="AccountTreeIcon"]')).toBeInTheDocument();
|
||||
expect(ctrl.container.querySelector('[data-label="CommentIcon"]')).toBeNull();
|
||||
}, {timeout: 500});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,16 +7,16 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
|
||||
import Privilege from 'sources/components/Privilege';
|
||||
import { mount } from 'enzyme';
|
||||
import { fireEvent, render, screen, waitFor } from '@testing-library/react';
|
||||
import { withTheme } from '../fake_theme';
|
||||
|
||||
describe('Privilege', ()=>{
|
||||
let ctrl, onChange = jasmine.createSpy('onChange');
|
||||
let onClickAction = (done)=> {
|
||||
let ctrl, onChange = jest.fn(), ctrlRerender;
|
||||
let onClickAction = ()=> {
|
||||
expect(onChange).toHaveBeenCalledWith([{
|
||||
privilege_type: 'C',
|
||||
privilege: true,
|
||||
@@ -30,13 +30,11 @@ describe('Privilege', ()=>{
|
||||
privilege: true,
|
||||
with_grant: false,
|
||||
}]);
|
||||
done();
|
||||
};
|
||||
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
let ThemedPrivilege = withTheme(Privilege);
|
||||
ctrl = mount(
|
||||
ctrl = render(
|
||||
<ThemedPrivilege
|
||||
value={[{
|
||||
privilege_type: 'C',
|
||||
@@ -51,23 +49,48 @@ describe('Privilege', ()=>{
|
||||
supportedPrivs: ['C', 'a', 'r']
|
||||
}}
|
||||
onChange={onChange}
|
||||
/>);
|
||||
/>
|
||||
),
|
||||
ctrlRerender = (props)=>{
|
||||
ctrl.rerender(
|
||||
<ThemedPrivilege
|
||||
value={[{
|
||||
privilege_type: 'C',
|
||||
privilege: true,
|
||||
with_grant: false,
|
||||
},{
|
||||
privilege_type: 'a',
|
||||
privilege: true,
|
||||
with_grant: true,
|
||||
}]}
|
||||
controlProps={{
|
||||
supportedPrivs: ['C', 'a', 'r']
|
||||
}}
|
||||
onChange={onChange}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
expect(ctrl.find('InputText').prop('value')).toBe('Ca*');
|
||||
expect(ctrl.find('InputCheckbox[name="C"]').at(0).prop('value')).toBeTrue();
|
||||
expect(ctrl.find('InputCheckbox[name="C"]').at(1).prop('value')).toBeFalse();
|
||||
expect(screen.getByRole('textbox')).toHaveValue('Ca*');
|
||||
// first 2 are all
|
||||
//C
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[2].className.includes('Mui-checked')).toBe(true);
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[3].className.includes('Mui-checked')).toBe(false);
|
||||
|
||||
expect(ctrl.find('InputCheckbox[name="a"]').at(0).prop('value')).toBeTrue();
|
||||
expect(ctrl.find('InputCheckbox[name="a"]').at(1).prop('value')).toBeTrue();
|
||||
//a
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[4].className.includes('Mui-checked')).toBe(true);
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[5].className.includes('Mui-checked')).toBe(true);
|
||||
|
||||
expect(ctrl.find('InputCheckbox[name="r"]').at(0).prop('value')).toBeFalse();
|
||||
expect(ctrl.find('InputCheckbox[name="r"]').at(1).prop('value')).toBeFalse();
|
||||
//r
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[6].className.includes('Mui-checked')).toBe(false);
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[7].className.includes('Mui-checked')).toBe(false);
|
||||
});
|
||||
|
||||
it('change prop value', ()=>{
|
||||
ctrl.setProps({value: [{
|
||||
ctrlRerender({value: [{
|
||||
privilege_type: 'C',
|
||||
privilege: true,
|
||||
with_grant: true,
|
||||
@@ -77,67 +100,79 @@ describe('Privilege', ()=>{
|
||||
with_grant: false,
|
||||
}]});
|
||||
|
||||
expect(ctrl.find('InputText').prop('value')).toBe('C*r');
|
||||
expect(ctrl.find('InputCheckbox[name="C"]').at(0).prop('value')).toBeTrue();
|
||||
expect(ctrl.find('InputCheckbox[name="C"]').at(1).prop('value')).toBeTrue();
|
||||
expect(screen.getByRole('textbox')).toHaveValue('C*r');
|
||||
// first 2 are all
|
||||
//C
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[2].className.includes('Mui-checked')).toBe(true);
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[3].className.includes('Mui-checked')).toBe(true);
|
||||
|
||||
expect(ctrl.find('InputCheckbox[name="a"]').at(0).prop('value')).toBeFalse();
|
||||
expect(ctrl.find('InputCheckbox[name="a"]').at(1).prop('value')).toBeFalse();
|
||||
//a
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[4].className.includes('Mui-checked')).toBe(false);
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[5].className.includes('Mui-checked')).toBe(false);
|
||||
|
||||
expect(ctrl.find('InputCheckbox[name="r"]').at(0).prop('value')).toBeTrue();
|
||||
expect(ctrl.find('InputCheckbox[name="r"]').at(1).prop('value')).toBeFalse();
|
||||
//r
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[6].className.includes('Mui-checked')).toBe(true);
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[7].className.includes('Mui-checked')).toBe(false);
|
||||
});
|
||||
|
||||
it('no prop value', ()=>{
|
||||
ctrl.setProps({value: null});
|
||||
ctrlRerender({value: null});
|
||||
expect(screen.getByRole('textbox')).toHaveValue('');
|
||||
// first 2 are all
|
||||
//C
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[2].className.includes('Mui-checked')).toBe(false);
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[3].className.includes('Mui-checked')).toBe(false);
|
||||
|
||||
expect(ctrl.find('InputText').prop('value')).toBe('');
|
||||
expect(ctrl.find('InputCheckbox[name="C"]').at(0).prop('value')).toBeFalse();
|
||||
expect(ctrl.find('InputCheckbox[name="C"]').at(1).prop('value')).toBeFalse();
|
||||
//a
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[4].className.includes('Mui-checked')).toBe(false);
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[5].className.includes('Mui-checked')).toBe(false);
|
||||
|
||||
expect(ctrl.find('InputCheckbox[name="a"]').at(0).prop('value')).toBeFalse();
|
||||
expect(ctrl.find('InputCheckbox[name="a"]').at(1).prop('value')).toBeFalse();
|
||||
|
||||
expect(ctrl.find('InputCheckbox[name="r"]').at(0).prop('value')).toBeFalse();
|
||||
expect(ctrl.find('InputCheckbox[name="r"]').at(1).prop('value')).toBeFalse();
|
||||
//r
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[6].className.includes('Mui-checked')).toBe(false);
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[7].className.includes('Mui-checked')).toBe(false);
|
||||
});
|
||||
|
||||
it('with grant disabled', ()=>{
|
||||
expect(ctrl.find('InputCheckbox[name="all"]').at(1).prop('disabled')).toBeTrue();
|
||||
expect(ctrl.find('InputCheckbox[name="r"]').at(1).prop('disabled')).toBeTrue();
|
||||
// first 2 are all
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[1].className.includes('Mui-disabled')).toBe(true);
|
||||
|
||||
//r
|
||||
expect(ctrl.container.querySelectorAll('.MuiCheckbox-root')[7].className.includes('Mui-disabled')).toBe(true);
|
||||
});
|
||||
|
||||
it('on check click', (done)=>{
|
||||
onChange.calls.reset();
|
||||
ctrl.find('InputCheckbox[name="C"]').at(0).find('input').
|
||||
simulate('change', {target: {checked: false, name: 'C'}});
|
||||
it('on check click', async ()=>{
|
||||
onChange.mockClear();
|
||||
|
||||
setTimeout(()=>{
|
||||
//C
|
||||
fireEvent.click(ctrl.container.querySelectorAll('input[name="C"]')[0]);
|
||||
|
||||
await waitFor(()=>{
|
||||
expect(onChange).toHaveBeenCalledWith([{
|
||||
privilege_type: 'a',
|
||||
privilege: true,
|
||||
privilege_type: 'a',
|
||||
with_grant: true,
|
||||
}]);
|
||||
done();
|
||||
}, 500);
|
||||
}, {timeout: 500});
|
||||
});
|
||||
|
||||
it('on new check click', (done)=>{
|
||||
onChange.calls.reset();
|
||||
ctrl.find('InputCheckbox[name="r"]').at(0).find('input').
|
||||
simulate('change', {target: {checked: true, name: 'r'}});
|
||||
it('on new check click', async ()=>{
|
||||
onChange.mockClear();
|
||||
|
||||
setTimeout(()=>{
|
||||
onClickAction(done);
|
||||
}, 500);
|
||||
//r
|
||||
fireEvent.click(ctrl.container.querySelectorAll('input[name="r"]')[0]);
|
||||
|
||||
await waitFor(()=>{
|
||||
onClickAction();
|
||||
}, {timeout: 500});
|
||||
});
|
||||
|
||||
it('on check grant click', (done)=>{
|
||||
onChange.calls.reset();
|
||||
ctrl.find('InputCheckbox[name="C"]').at(1).find('input').
|
||||
simulate('change', {target: {checked: true, name: 'C'}});
|
||||
it('on check grant click', async ()=>{
|
||||
onChange.mockClear();
|
||||
|
||||
setTimeout(()=>{
|
||||
//C
|
||||
fireEvent.click(ctrl.container.querySelectorAll('input[name="C"]')[1]);
|
||||
|
||||
await waitFor(()=>{
|
||||
expect(onChange).toHaveBeenCalledWith([{
|
||||
privilege_type: 'C',
|
||||
privilege: true,
|
||||
@@ -147,20 +182,22 @@ describe('Privilege', ()=>{
|
||||
privilege: true,
|
||||
with_grant: true,
|
||||
}]);
|
||||
done();
|
||||
}, 500);
|
||||
}, {timeout: 500});
|
||||
});
|
||||
|
||||
it('on all click', (done)=>{
|
||||
ctrl.find('InputCheckbox[name="all"]').at(0).find('input').simulate('change', {target: {checked: true}});
|
||||
it('on all click', async ()=>{
|
||||
onChange.mockClear();
|
||||
|
||||
setTimeout(()=>{
|
||||
onClickAction(done);
|
||||
}, 500);
|
||||
// all
|
||||
fireEvent.click(ctrl.container.querySelectorAll('input[name="all"]')[0]);
|
||||
|
||||
await waitFor(()=>{
|
||||
onClickAction();
|
||||
}, {timeout: 500});
|
||||
});
|
||||
|
||||
it('on all with grant click', (done)=>{
|
||||
ctrl.setProps({
|
||||
it('on all with grant click', async ()=>{
|
||||
ctrlRerender({
|
||||
value: [{
|
||||
privilege_type: 'C',
|
||||
privilege: true,
|
||||
@@ -175,9 +212,13 @@ describe('Privilege', ()=>{
|
||||
with_grant: false,
|
||||
}]
|
||||
});
|
||||
ctrl.find('InputCheckbox[name="all"]').at(1).find('input').simulate('change', {target: {checked: true}});
|
||||
|
||||
setTimeout(()=>{
|
||||
onChange.mockClear();
|
||||
|
||||
// all
|
||||
fireEvent.click(ctrl.container.querySelectorAll('input[name="all"]')[1]);
|
||||
|
||||
await waitFor(()=>{
|
||||
expect(onChange).toHaveBeenCalledWith([{
|
||||
privilege_type: 'C',
|
||||
privilege: true,
|
||||
@@ -191,7 +232,6 @@ describe('Privilege', ()=>{
|
||||
privilege: true,
|
||||
with_grant: true,
|
||||
}]);
|
||||
done();
|
||||
}, 500);
|
||||
}, {timeout: 500});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,41 +7,26 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
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 { render, screen, waitFor } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import QueryThresholds from '../../../pgadmin/static/js/components/QueryThresholds';
|
||||
import { InputText } from '../../../pgadmin/static/js/components/FormComponents';
|
||||
|
||||
/* 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;
|
||||
let onChange = jasmine.createSpy('onChange');
|
||||
let ThemedFormInputQueryThresholds = withTheme(QueryThresholds);
|
||||
let onChange = jest.fn();
|
||||
beforeEach(() => {
|
||||
ctrl = mount(
|
||||
render(
|
||||
<ThemedFormInputQueryThresholds
|
||||
testcid="QueryThresholdCid"
|
||||
helpMessage="some help message"
|
||||
@@ -53,21 +38,22 @@ describe('QueryThresholds', () => {
|
||||
/>);
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith({ warning: '5', alert: 6 });
|
||||
done();
|
||||
it('Warning', async () => {
|
||||
const user = userEvent.setup();
|
||||
const inp = screen.getAllByRole('textbox').at(0);
|
||||
await user.type(inp, '7');
|
||||
await waitFor(()=>{
|
||||
expect(onChange).toHaveBeenCalledWith({ warning: '57', alert: 6 });
|
||||
});
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith({ warning: 5, alert: '6' });
|
||||
done();
|
||||
it('Alert', async () => {
|
||||
const user = userEvent.setup();
|
||||
const inp = screen.getAllByRole('textbox').at(1);
|
||||
await user.type(inp, '8');
|
||||
await waitFor(()=>{
|
||||
expect(onChange).toHaveBeenCalledWith({ warning: 5, alert: '68' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -7,38 +7,22 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
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 { FormHelperText, InputLabel } from '@material-ui/core';
|
||||
import { act, render, waitFor } from '@testing-library/react';
|
||||
|
||||
import {SelectRefresh} from 'sources/components/SelectRefresh';
|
||||
|
||||
/* MUI Components need to be wrapped in Theme for theme vars */
|
||||
describe('components SelectRefresh', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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('SelectRefresh', ()=>{
|
||||
let ThemedSelectRefresh = withTheme(SelectRefresh), ctrl, onChange=jasmine.createSpy('onChange'),
|
||||
ctrlMount = (props)=>{
|
||||
ctrl?.unmount();
|
||||
ctrl = mount(
|
||||
let ThemedSelectRefresh = withTheme(SelectRefresh), ctrl, onChange=jest.fn();
|
||||
|
||||
beforeEach(async ()=>{
|
||||
await act( async () => {
|
||||
ctrl = render(
|
||||
<ThemedSelectRefresh
|
||||
label="First"
|
||||
className="someClass"
|
||||
@@ -52,17 +36,16 @@ describe('components SelectRefresh', ()=>{
|
||||
controlProps={{
|
||||
getOptionsOnRefresh: ()=>{/*This is intentional (SonarQube)*/}
|
||||
}}
|
||||
{...props}
|
||||
/>);
|
||||
};
|
||||
|
||||
beforeEach(()=>{
|
||||
ctrlMount();
|
||||
});
|
||||
});
|
||||
|
||||
it('accessibility', ()=>{
|
||||
expect(ctrl.find(InputLabel)).toHaveProp('htmlFor', 'inpCid');
|
||||
expect(ctrl.find(FormHelperText)).toHaveProp('id', 'hinpCid');
|
||||
it('accessibility', async ()=>{
|
||||
await waitFor(()=>{
|
||||
const input = ctrl.container.querySelectorAll('input')[1];
|
||||
expect(input.getAttribute('id')).toBe('inpCid');
|
||||
expect(input.getAttribute('aria-describedby')).toBe('hinpCid');
|
||||
}, {timeout: 500});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,17 +7,15 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
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 { act, render, screen, waitFor } from '@testing-library/react';
|
||||
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',
|
||||
@@ -37,60 +35,44 @@ describe('SelectThemes', () => {
|
||||
}
|
||||
];
|
||||
|
||||
/* 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(
|
||||
let ThemedFormInputThemes = withTheme(SelectThemes), ctrl, onChange = jest.fn();
|
||||
const ctrlRerender = (props)=>{
|
||||
ctrl.rerender(
|
||||
<ThemedFormInputThemes
|
||||
testcid="SelectThemeCid"
|
||||
helpMessage="some help message"
|
||||
options={options}
|
||||
onChange={onChange}
|
||||
value={'standard'}
|
||||
{...props}
|
||||
/>);
|
||||
};
|
||||
beforeEach(async () => {
|
||||
await act( async () => {
|
||||
ctrl = render(
|
||||
<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);
|
||||
expect(screen.getByRole('img').getAttribute('src')).toBe(options[0].preview_src);
|
||||
});
|
||||
|
||||
it('change value', () => {
|
||||
ctrl.setProps({
|
||||
it('change value', async () => {
|
||||
ctrlRerender({
|
||||
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');
|
||||
await waitFor(()=>{
|
||||
expect(screen.getByRole('img').getAttribute('src')).toBe(options[1].preview_src);
|
||||
}, {timeout: 500});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -7,31 +7,15 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
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 { render } from '@testing-library/react';
|
||||
import ShortcutTitle, { shortcutToString } from '../../../pgadmin/static/js/components/ShortcutTitle';
|
||||
import * as keyShort from '../../../pgadmin/static/js/keyboard_shortcuts';
|
||||
|
||||
describe('ShortcutTitle', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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();
|
||||
});
|
||||
|
||||
const shortcut = {
|
||||
'control': true,
|
||||
'shift': true,
|
||||
@@ -41,34 +25,30 @@ describe('ShortcutTitle', ()=>{
|
||||
'char': 'k',
|
||||
},
|
||||
};
|
||||
it('ShortcutTitle', (done)=>{
|
||||
it('ShortcutTitle', ()=>{
|
||||
let ThemedShortcutTitle = withTheme(ShortcutTitle);
|
||||
spyOn(keyShort, 'isMac').and.returnValue(false);
|
||||
let ctrl = mount(
|
||||
jest.spyOn(keyShort, 'isMac').mockReturnValue(false);
|
||||
let ctrl = render(
|
||||
<ThemedShortcutTitle
|
||||
title="the title"
|
||||
shortcut={shortcut}
|
||||
/>);
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.text()).toBe('the titleCtrlShiftK');
|
||||
done();
|
||||
}, 0);
|
||||
expect(ctrl.container.textContent).toBe('the titleCtrlShiftK');
|
||||
});
|
||||
|
||||
describe('shortcutToString', ()=>{
|
||||
it('shortcut', ()=>{
|
||||
spyOn(keyShort, 'isMac').and.returnValue(false);
|
||||
jest.spyOn(keyShort, 'isMac').mockReturnValue(false);
|
||||
expect(shortcutToString(shortcut)).toBe('Ctrl + Shift + K');
|
||||
});
|
||||
|
||||
it('shortcut as array', ()=>{
|
||||
spyOn(keyShort, 'isMac').and.returnValue(false);
|
||||
jest.spyOn(keyShort, 'isMac').mockReturnValue(false);
|
||||
expect(shortcutToString(shortcut, null, true)).toEqual(['Ctrl', 'Shift', 'K']);
|
||||
});
|
||||
|
||||
it('accesskey', ()=>{
|
||||
spyOnProperty(window.navigator, 'userAgent').and.returnValue('Unknown');
|
||||
jest.spyOn(window.navigator, 'userAgent', 'get').mockReturnValue('Unknown');
|
||||
expect(shortcutToString(null, 'A')).toEqual('Accesskey + A');
|
||||
});
|
||||
|
||||
@@ -78,7 +58,7 @@ describe('ShortcutTitle', ()=>{
|
||||
|
||||
it('mac meta key', ()=>{
|
||||
shortcut.ctrl_is_meta = true;
|
||||
spyOn(keyShort, 'isMac').and.returnValue(true);
|
||||
jest.spyOn(keyShort, 'isMac').mockReturnValue(true);
|
||||
expect(shortcutToString(shortcut)).toBe('Cmd + Shift + K');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,42 +7,33 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { render } from '@testing-library/react';
|
||||
import { withTheme } from '../fake_theme';
|
||||
import TabPanel from 'sources/components/TabPanel';
|
||||
|
||||
|
||||
/* MUI Components need to be wrapped in Theme for theme vars */
|
||||
describe('TabPanel', ()=>{
|
||||
let mount, panelInst, ThemedPanel;
|
||||
let panelInst, ThemedPanel;
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(()=>{
|
||||
mount = createMount();
|
||||
/* Need Mui Theme context as well */
|
||||
ThemedPanel = withTheme(TabPanel);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
});
|
||||
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
panelInst = mount(<ThemedPanel value={1} index={0}><h1>test</h1></ThemedPanel>);
|
||||
panelInst = render(<ThemedPanel value={1} index={0}><h1>test</h1></ThemedPanel>);
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
expect(panelInst.find('div').at(0).getDOMNode().hidden).toBeTrue();
|
||||
expect(panelInst.find('h1')).not.toBe(null);
|
||||
expect(panelInst.container.querySelector('[data-test="tabpanel"]').hidden).toBe(true);
|
||||
});
|
||||
|
||||
it('tab select', ()=>{
|
||||
panelInst.setProps({value: 0});
|
||||
expect(panelInst.find('div').at(0).getDOMNode().hidden).toBeFalse();
|
||||
panelInst.rerender(<ThemedPanel value={0} index={0}><h1>test</h1></ThemedPanel>);
|
||||
expect(panelInst.container.querySelector('[data-test="tabpanel"]').hidden).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import {mount} from 'enzyme';
|
||||
import '../helper/enzyme.helper';
|
||||
|
||||
import { DATA_POINT_SIZE } from 'sources/chartjs';
|
||||
|
||||
import Graphs, {GraphsWrapper, transformData,
|
||||
import Graphs, { transformData,
|
||||
getStatsUrl, statsReducer} from '../../../pgadmin/dashboard/static/js/Graphs';
|
||||
import { withTheme } from '../fake_theme';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
describe('Graphs.js', ()=>{
|
||||
it('transformData', ()=>{
|
||||
@@ -96,7 +96,6 @@ describe('Graphs.js', ()=>{
|
||||
let did = 1;
|
||||
let ThemedGraphs = withTheme(Graphs);
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
let dashboardPref = {
|
||||
session_stats_refresh: 1,
|
||||
tps_stats_refresh: 1,
|
||||
@@ -109,22 +108,15 @@ describe('Graphs.js', ()=>{
|
||||
graph_line_border_width: 2
|
||||
};
|
||||
|
||||
graphComp = mount(<ThemedGraphs preferences={dashboardPref} sid={sid} did={did} enablePoll={false} pageVisible={true} isTest={true} />);
|
||||
graphComp = render(<ThemedGraphs preferences={dashboardPref} sid={sid} did={did} enablePoll={false} pageVisible={true} isTest={true} />);
|
||||
});
|
||||
|
||||
it('GraphsWrapper is rendered', (done)=>{
|
||||
let found = graphComp.find(GraphsWrapper);
|
||||
expect(found.length).toBe(1);
|
||||
done();
|
||||
it('pollDelay is set', ()=>{
|
||||
let found = graphComp.container.querySelector('[data-testid="graph-poll-delay"]');
|
||||
expect(found).toHaveTextContent('1000');
|
||||
});
|
||||
|
||||
it('pollDelay is set', (done)=>{
|
||||
let found = graphComp.find('[data-testid="graph-poll-delay"]');
|
||||
expect(found).toHaveText('1000');
|
||||
done();
|
||||
});
|
||||
|
||||
it('pollDelay on preference update', (done)=>{
|
||||
it('pollDelay on preference update', ()=>{
|
||||
let dashboardPref = {
|
||||
session_stats_refresh: 5,
|
||||
tps_stats_refresh: 10,
|
||||
@@ -136,13 +128,9 @@ describe('Graphs.js', ()=>{
|
||||
graph_mouse_track: true,
|
||||
graph_line_border_width: 2
|
||||
};
|
||||
graphComp.setProps({preferences: dashboardPref});
|
||||
setTimeout(()=>{
|
||||
graphComp.update();
|
||||
let found = graphComp.find('[data-testid="graph-poll-delay"]');
|
||||
expect(found).toHaveText('5000');
|
||||
done();
|
||||
}, 500);
|
||||
graphComp.rerender(<ThemedGraphs preferences={dashboardPref} sid={sid} did={did} enablePoll={false} pageVisible={true} isTest={true} />);
|
||||
let found = graphComp.container.querySelector('[data-testid="graph-poll-delay"]');
|
||||
expect(found).toHaveTextContent('5000');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import {mount} from 'enzyme';
|
||||
import '../helper/enzyme.helper';
|
||||
|
||||
import {GraphsWrapper, X_AXIS_LENGTH, POINT_SIZE} from '../../../pgadmin/dashboard/static/js/Graphs';
|
||||
import { withTheme } from '../fake_theme';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
describe('<GraphsWrapper /> component', ()=>{
|
||||
let graphComp = null;
|
||||
@@ -26,9 +24,25 @@ describe('<GraphsWrapper /> component', ()=>{
|
||||
refreshRate: 1,
|
||||
};
|
||||
let ThemedGraphsWrapper = withTheme(GraphsWrapper);
|
||||
const compRerender = (props)=>{
|
||||
graphComp.rerender(
|
||||
<ThemedGraphsWrapper sessionStats={defaultStats}
|
||||
tpsStats={defaultStats}
|
||||
tiStats={defaultStats}
|
||||
toStats={defaultStats}
|
||||
bioStats={defaultStats}
|
||||
errorMsg={null}
|
||||
showTooltip={true}
|
||||
showDataPoints={true}
|
||||
lineBorderWidth={2}
|
||||
isDatabase={false}
|
||||
isTest={true}
|
||||
{...props}
|
||||
/>
|
||||
);
|
||||
};
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
graphComp = mount(
|
||||
graphComp = render(
|
||||
<ThemedGraphsWrapper sessionStats={defaultStats}
|
||||
tpsStats={defaultStats}
|
||||
tiStats={defaultStats}
|
||||
@@ -43,40 +57,32 @@ describe('<GraphsWrapper /> component', ()=>{
|
||||
);
|
||||
});
|
||||
|
||||
it('graph containers are rendered', (done)=>{
|
||||
let found = graphComp.find('ChartContainer');
|
||||
expect(found.length).toBe(5);
|
||||
done();
|
||||
it('graph containers are rendered', ()=>{
|
||||
expect(screen.getAllByTestId('chart-container').length).toBe(5);
|
||||
});
|
||||
|
||||
it('graph headers are correct', (done)=>{
|
||||
let found = graphComp.find('ChartContainer');
|
||||
expect(found.at(0)).toIncludeText('Server sessions');
|
||||
expect(found.at(1)).toIncludeText('Transactions per second');
|
||||
expect(found.at(2)).toIncludeText('Tuples in');
|
||||
expect(found.at(3)).toIncludeText('Tuples out');
|
||||
expect(found.at(4)).toIncludeText('Block I/O');
|
||||
done();
|
||||
it('graph headers are correct', ()=>{
|
||||
let found = screen.getAllByTestId('chart-container');
|
||||
expect(found.at(0)).toHaveTextContent('Server sessions');
|
||||
expect(found.at(1)).toHaveTextContent('Transactions per second');
|
||||
expect(found.at(2)).toHaveTextContent('Tuples in');
|
||||
expect(found.at(3)).toHaveTextContent('Tuples out');
|
||||
expect(found.at(4)).toHaveTextContent('Block I/O');
|
||||
});
|
||||
|
||||
it('graph headers when database', (done)=>{
|
||||
let found = graphComp.find('ChartContainer');
|
||||
graphComp.setProps({isDatabase: true});
|
||||
expect(found.at(0)).toIncludeText('Database sessions');
|
||||
done();
|
||||
it('graph headers when database', ()=>{
|
||||
compRerender({isDatabase: true});
|
||||
let found = screen.getAllByTestId('chart-container');
|
||||
expect(found.at(0)).toHaveTextContent('Database sessions');
|
||||
});
|
||||
|
||||
it('graph body shows the error', (done)=>{
|
||||
graphComp.setProps({errorMsg: 'Some error occurred'});
|
||||
setTimeout(()=>{
|
||||
graphComp.update();
|
||||
let found = graphComp.find('ChartContainer');
|
||||
expect(found.at(0)).toIncludeText('Some error occurred');
|
||||
expect(found.at(1)).toIncludeText('Some error occurred');
|
||||
expect(found.at(2)).toIncludeText('Some error occurred');
|
||||
expect(found.at(3)).toIncludeText('Some error occurred');
|
||||
expect(found.at(4)).toIncludeText('Some error occurred');
|
||||
done();
|
||||
}, 500);
|
||||
it('graph body shows the error', ()=>{
|
||||
compRerender({errorMsg: 'Some error occurred'});
|
||||
let found = screen.getAllByTestId('chart-container');
|
||||
expect(found.at(0)).toHaveTextContent('Some error occurred');
|
||||
expect(found.at(1)).toHaveTextContent('Some error occurred');
|
||||
expect(found.at(2)).toHaveTextContent('Some error occurred');
|
||||
expect(found.at(3)).toHaveTextContent('Some error occurred');
|
||||
expect(found.at(4)).toHaveTextContent('Some error occurred');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -10,21 +10,21 @@
|
||||
import React from 'react';
|
||||
import PropTypes from 'prop-types';
|
||||
|
||||
import Theme from 'sources/Theme';
|
||||
import {DebuggerContext, DebuggerEventsContext} from '../../../pgadmin/tools/debugger/static/js/components/DebuggerComponent';
|
||||
import { withBrowser } from '../genericFunctions';
|
||||
|
||||
export default function MockDebuggerComponent({value, eventsvalue, children}) {
|
||||
function MockDebuggerComponent({value, eventsvalue, children}) {
|
||||
return (
|
||||
<Theme>
|
||||
<DebuggerContext.Provider value={value}>
|
||||
<DebuggerEventsContext.Provider value={eventsvalue}>
|
||||
{children}
|
||||
</DebuggerEventsContext.Provider>
|
||||
</DebuggerContext.Provider>
|
||||
</Theme>
|
||||
<DebuggerContext.Provider value={value}>
|
||||
<DebuggerEventsContext.Provider value={eventsvalue}>
|
||||
{children}
|
||||
</DebuggerEventsContext.Provider>
|
||||
</DebuggerContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export default withBrowser(MockDebuggerComponent);
|
||||
|
||||
MockDebuggerComponent.propTypes = {
|
||||
value: PropTypes.any,
|
||||
eventsvalue: PropTypes.any,
|
||||
|
||||
@@ -7,249 +7,33 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import $ from 'jquery';
|
||||
window.jQuery = window.$ = $;
|
||||
|
||||
import 'wcdocker';
|
||||
import '../helper/enzyme.helper';
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import url_for from 'sources/url_for';
|
||||
import FunctionArguments from '../../../pgadmin/tools/debugger/static/js/debugger_ui';
|
||||
import { withBrowser } from '../genericFunctions';
|
||||
import DebuggerArgumentComponent from '../../../pgadmin/tools/debugger/static/js/components/DebuggerArgumentComponent';
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
import axios from 'axios';
|
||||
|
||||
import url_for from 'sources/url_for';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
|
||||
import { messages } from '../fake_messages';
|
||||
import FunctionArguments from '../../../pgadmin/tools/debugger/static/js/debugger_ui';
|
||||
import {TreeFake} from '../tree/tree_fake';
|
||||
|
||||
import { TreeFake } from '../tree/tree_fake';
|
||||
|
||||
describe('Debugger Component', () => {
|
||||
let funcArgs;
|
||||
let mountDOM;
|
||||
let tree;
|
||||
let networkMock;
|
||||
const MockDebuggerArgumentComponent = withBrowser(DebuggerArgumentComponent);
|
||||
|
||||
beforeEach(() => {
|
||||
jasmineEnzyme();
|
||||
// Element for mount wcDocker panel
|
||||
mountDOM = $('<div class="dockerContainer">');
|
||||
$(document.body).append(mountDOM);
|
||||
const div = document.createElement('div');
|
||||
div.id = 'debugger-main-container';
|
||||
document.body.appendChild(div);
|
||||
|
||||
$(document.body).append($('<div id="debugger-main-container">'));
|
||||
jest.mock('../../../pgadmin/tools/debugger/static/js/components/DebuggerArgumentComponent', ()=>MockDebuggerArgumentComponent);
|
||||
|
||||
/* messages used by validators */
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.messages = pgAdmin.Browser.messages || messages;
|
||||
pgAdmin.Browser.utils = pgAdmin.Browser.utils || {};
|
||||
pgAdmin.Browser.stdH = pgAdmin.Browser.stdH || {
|
||||
sm: 200,
|
||||
md: 400,
|
||||
lg: 550,
|
||||
default: 550,
|
||||
};
|
||||
pgAdmin.Browser.stdW = pgAdmin.Browser.stdW || {
|
||||
sm: 500,
|
||||
md: 700,
|
||||
lg: 900,
|
||||
default: 500,
|
||||
};
|
||||
funcArgs = new FunctionArguments();
|
||||
pgAdmin.Browser.preferences_cache = [
|
||||
{
|
||||
'id': 115,
|
||||
'cid': 13,
|
||||
'name': 'btn_step_into',
|
||||
'label': 'Accesskey (Step into)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 73,
|
||||
'char': 'i'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 116,
|
||||
'cid': 13,
|
||||
'name': 'btn_step_over',
|
||||
'label': 'Accesskey (Step over)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 79,
|
||||
'char': 'o'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
},
|
||||
{
|
||||
'id': 113,
|
||||
'cid': 13,
|
||||
'name': 'btn_start',
|
||||
'label': 'Accesskey (Continue/Start)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 67,
|
||||
'char': 'c'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 114,
|
||||
'cid': 13,
|
||||
'name': 'btn_stop',
|
||||
'label': 'Accesskey (Stop)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 83,
|
||||
'char': 's'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 117,
|
||||
'cid': 13,
|
||||
'name': 'btn_toggle_breakpoint',
|
||||
'label': 'Accesskey (Toggle breakpoint)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 84,
|
||||
'char': 't'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 118,
|
||||
'cid': 13,
|
||||
'name': 'btn_clear_breakpoints',
|
||||
'label': 'Accesskey (Clear all breakpoints)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 88,
|
||||
'char': 'x'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}
|
||||
|
||||
];
|
||||
// eslint-disable-next-line
|
||||
let docker = new wcDocker(
|
||||
'.dockerContainer', {
|
||||
allowContextMenu: false,
|
||||
allowCollapse: false,
|
||||
loadingClass: 'pg-sp-icon',
|
||||
});
|
||||
|
||||
tree = new TreeFake();
|
||||
pgAdmin.Browser.tree = tree;
|
||||
pgAdmin.Browser.docker = docker;
|
||||
networkMock = new MockAdapter(axios);
|
||||
pgAdmin.Browser.tree = new TreeFake(pgAdmin.Browser);
|
||||
});
|
||||
|
||||
it('Debugger Args', () => {
|
||||
it('Debugger Args', async () => {
|
||||
networkMock.onGet(url_for('debugger.init', {'function': 1, 'schema': 1, 'database': 1, 'server': 1})).reply(200, {'success':1,'errormsg':'','info':'','result':null,'data':{'debug_info':[{'name':'_test2','prosrc':'begin\nselect \'1\';\nend','lanname':'plpgsql','proretset':false,'prorettype':1043,'rettype':'varchar','proargtypenames':'date','proargtypes':'1082','proargnames':'test_date','proargmodes':null,'pkg':0,'pkgname':'','pkgconsoid':0,'schema':2200,'schemaname':'public','isfunc':true,'signature':'test_date date','proargdefaults':null,'pronargdefaults':0,'require_input':true}],'trans_id':'7165'}});
|
||||
|
||||
let debugInfo = {
|
||||
@@ -274,7 +58,6 @@ describe('Debugger Component', () => {
|
||||
'pronargdefaults': 0,
|
||||
'require_input': true,
|
||||
};
|
||||
|
||||
funcArgs.show(debugInfo, 0, false, '123');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,250 +7,39 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import $ from 'jquery';
|
||||
window.jQuery = window.$ = $;
|
||||
import 'bootstrap';
|
||||
import 'wcdocker';
|
||||
import '../helper/enzyme.helper';
|
||||
|
||||
import React from 'react';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import { act, render } from '@testing-library/react';
|
||||
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
import axios from 'axios';
|
||||
|
||||
import url_for from 'sources/url_for';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
|
||||
import { messages } from '../fake_messages';
|
||||
|
||||
import DebuggerComponent from '../../../pgadmin/tools/debugger/static/js/components/DebuggerComponent';
|
||||
import FunctionArguments from '../../../pgadmin/tools/debugger/static/js/debugger_ui';
|
||||
import Debugger from '../../../pgadmin/tools/debugger/static/js/DebuggerModule';
|
||||
import {TreeFake} from '../tree/tree_fake';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
|
||||
|
||||
describe('Debugger Component', () => {
|
||||
let mount;
|
||||
|
||||
let funcArgs;
|
||||
let debuggerInstance;
|
||||
let nodeInfo;
|
||||
let mountDOM;
|
||||
let tree;
|
||||
let params;
|
||||
let networkMock;
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(() => {
|
||||
mount = createMount();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jasmineEnzyme();
|
||||
// Element for mount wcDocker panel
|
||||
mountDOM = $('<div class="dockerContainer">');
|
||||
$(document.body).append(mountDOM);
|
||||
const div = document.createElement('div');
|
||||
div.id = 'debugger-main-container';
|
||||
document.body.appendChild(div);
|
||||
|
||||
$(document.body).append($('<div id="debugger-main-container">'));
|
||||
|
||||
/* messages used by validators */
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.messages = pgAdmin.Browser.messages || messages;
|
||||
pgAdmin.Browser.utils = pgAdmin.Browser.utils || {};
|
||||
funcArgs = new FunctionArguments();
|
||||
debuggerInstance = new Debugger(pgAdmin, pgAdmin.Browser);
|
||||
nodeInfo = { parent: {} };
|
||||
pgAdmin.Browser.preferences_cache = [
|
||||
{
|
||||
'id': 115,
|
||||
'cid': 13,
|
||||
'name': 'btn_step_into',
|
||||
'label': 'Accesskey (Step into)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 73,
|
||||
'char': 'i'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 116,
|
||||
'cid': 13,
|
||||
'name': 'btn_step_over',
|
||||
'label': 'Accesskey (Step over)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 79,
|
||||
'char': 'o'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
},
|
||||
{
|
||||
'id': 113,
|
||||
'cid': 13,
|
||||
'name': 'btn_start',
|
||||
'label': 'Accesskey (Continue/Start)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 67,
|
||||
'char': 'c'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 114,
|
||||
'cid': 13,
|
||||
'name': 'btn_stop',
|
||||
'label': 'Accesskey (Stop)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 83,
|
||||
'char': 's'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 117,
|
||||
'cid': 13,
|
||||
'name': 'btn_toggle_breakpoint',
|
||||
'label': 'Accesskey (Toggle breakpoint)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 84,
|
||||
'char': 't'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 118,
|
||||
'cid': 13,
|
||||
'name': 'btn_clear_breakpoints',
|
||||
'label': 'Accesskey (Clear all breakpoints)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 88,
|
||||
'char': 'x'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}
|
||||
|
||||
];
|
||||
// eslint-disable-next-line
|
||||
let docker = new wcDocker(
|
||||
'.dockerContainer', {
|
||||
allowContextMenu: false,
|
||||
allowCollapse: false,
|
||||
loadingClass: 'pg-sp-icon',
|
||||
});
|
||||
|
||||
tree = new TreeFake();
|
||||
pgAdmin.Browser.tree = tree;
|
||||
pgAdmin.Browser.docker = docker;
|
||||
|
||||
params = {
|
||||
transId: 1234,
|
||||
@@ -260,26 +49,25 @@ describe('Debugger Component', () => {
|
||||
networkMock = new MockAdapter(axios);
|
||||
});
|
||||
|
||||
it('DebuggerInit Indirect', () => {
|
||||
it('DebuggerInit Indirect', async () => {
|
||||
params.directDebugger.debug_type = 1;
|
||||
networkMock.onPost(url_for('debugger.start_listener', {'trans_id': params.transId})).reply(200, {'success':1,'errormsg':'','info':'','result':null,'data':{'status':true,'result':2}});
|
||||
networkMock.onGet(url_for('debugger.messages', {'trans_id': params.transId})).reply(200, {'success':1,'errormsg':'','info':'','result':null,'data':{'status':'Success','result':'10'}});
|
||||
networkMock.onGet(url_for('debugger.execute_query', {'trans_id': params.transId, 'query_type': 'get_stack_info'})).reply(200, {'success':1,'errormsg':'','info':'','result':null,'data':{'status':'Success','result':[{'level':0,'targetname':'_test()','func':3138947,'linenumber':9,'args':''}]}});
|
||||
networkMock.onGet(url_for('debugger.poll_result', {'trans_id': params.transId})).reply(200, {'success':0,'errormsg':'','info':'','result':null,'data':{'status':'Success','result':[{'pldbg_wait_for_target':28298}]}});
|
||||
let ctrl = mount(
|
||||
<Theme>
|
||||
<DebuggerComponent
|
||||
pgAdmin={pgAdmin}
|
||||
panel={document.getElementById('debugger-main-container')}
|
||||
selectedNodeInfo={nodeInfo}
|
||||
layout={''}
|
||||
params={params}
|
||||
>
|
||||
</DebuggerComponent>
|
||||
</Theme>
|
||||
);
|
||||
|
||||
ctrl.find('PgIconButton[data-test="debugger-contiue"]').props().onClick();
|
||||
await act(async () => {
|
||||
render(
|
||||
<Theme>
|
||||
<DebuggerComponent
|
||||
pgAdmin={pgAdmin}
|
||||
panel={document.getElementById('debugger-main-container')}
|
||||
selectedNodeInfo={nodeInfo}
|
||||
layout={''}
|
||||
params={params}
|
||||
/>
|
||||
</Theme>
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,50 +7,30 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import $ from 'jquery';
|
||||
window.jQuery = window.$ = $;
|
||||
|
||||
import 'wcdocker';
|
||||
import '../helper/enzyme.helper';
|
||||
|
||||
import React from 'react';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
import axios from 'axios';
|
||||
|
||||
import url_for from 'sources/url_for';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
|
||||
import { messages } from '../fake_messages';
|
||||
import FunctionArguments from '../../../pgadmin/tools/debugger/static/js/debugger_ui';
|
||||
import Debugger from '../../../pgadmin/tools/debugger/static/js/DebuggerModule';
|
||||
import { TreeFake } from '../tree/tree_fake';
|
||||
import MockDebuggerComponent from './MockDebuggerComponent';
|
||||
import EventBus from '../../../pgadmin/static/js/helpers/EventBus';
|
||||
import { Stack } from '../../../pgadmin/tools/debugger/static/js/components/Stack';
|
||||
|
||||
|
||||
describe('Debugger Stack', () => {
|
||||
let mount;
|
||||
|
||||
let funcArgs;
|
||||
let debuggerInstance;
|
||||
let mountDOM;
|
||||
let tree;
|
||||
let params;
|
||||
let networkMock;
|
||||
let pref;
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(() => {
|
||||
mount = createMount();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
networkMock.restore();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
networkMock.restore();
|
||||
@@ -58,211 +38,12 @@ describe('Debugger Stack', () => {
|
||||
|
||||
|
||||
beforeEach(() => {
|
||||
jasmineEnzyme();
|
||||
// Element for mount wcDocker panel
|
||||
mountDOM = $('<div class="dockerContainer">');
|
||||
$(document.body).append(mountDOM);
|
||||
const div = document.createElement('div');
|
||||
div.id = 'debugger-main-container';
|
||||
document.body.appendChild(div);
|
||||
|
||||
$(document.body).append($('<div id="debugger-main-container">'));
|
||||
|
||||
/* messages used by validators */
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.messages = pgAdmin.Browser.messages || messages;
|
||||
pgAdmin.Browser.utils = pgAdmin.Browser.utils || {};
|
||||
funcArgs = new FunctionArguments();
|
||||
debuggerInstance = new Debugger(pgAdmin, pgAdmin.Browser);
|
||||
pref = [
|
||||
{
|
||||
'id': 115,
|
||||
'cid': 13,
|
||||
'name': 'btn_step_into',
|
||||
'label': 'Accesskey (Step into)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 73,
|
||||
'char': 'i'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 116,
|
||||
'cid': 13,
|
||||
'name': 'btn_step_over',
|
||||
'label': 'Accesskey (Step over)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 79,
|
||||
'char': 'o'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
},
|
||||
{
|
||||
'id': 113,
|
||||
'cid': 13,
|
||||
'name': 'btn_start',
|
||||
'label': 'Accesskey (Continue/Start)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 67,
|
||||
'char': 'c'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 114,
|
||||
'cid': 13,
|
||||
'name': 'btn_stop',
|
||||
'label': 'Accesskey (Stop)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 83,
|
||||
'char': 's'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 117,
|
||||
'cid': 13,
|
||||
'name': 'btn_toggle_breakpoint',
|
||||
'label': 'Accesskey (Toggle breakpoint)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 84,
|
||||
'char': 't'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 118,
|
||||
'cid': 13,
|
||||
'name': 'btn_clear_breakpoints',
|
||||
'label': 'Accesskey (Clear all breakpoints)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
'key': {
|
||||
'key_code': 88,
|
||||
'char': 'x'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
pgAdmin.Browser.preferences_cache = pref;
|
||||
// eslint-disable-next-line
|
||||
let docker = new wcDocker(
|
||||
'.dockerContainer', {
|
||||
allowContextMenu: false,
|
||||
allowCollapse: false,
|
||||
loadingClass: 'pg-sp-icon',
|
||||
});
|
||||
|
||||
tree = new TreeFake();
|
||||
pgAdmin.Browser.tree = tree;
|
||||
pgAdmin.Browser.docker = docker;
|
||||
|
||||
params = {
|
||||
transId: 1234,
|
||||
@@ -274,7 +55,7 @@ describe('Debugger Stack', () => {
|
||||
|
||||
it('Statck Init', () => {
|
||||
networkMock.onGet(url_for('debugger.select_frame', { 'trans_id': params.transId, 'frame_id': 3 })).reply(200, {'success':0,'errormsg':'','info':'','result':null,'data':{'status':true,'result':[{'func':3138947,'targetname':'_test()','linenumber':10,'src':'\nDECLARE\n v_deptno NUMERIC;\n v_empno NUMERIC;\n v_ename VARCHAR;\n v_rows INTEGER;\n r_emp_query EMP_QUERY_TYPE;\nBEGIN\n v_deptno := 30;\n v_empno := 0;\n v_ename := \'Martin\';\n r_emp_query := emp_query(v_deptno, v_empno, v_ename);\n RAISE INFO \'Department : %\', v_deptno;\n RAISE INFO \'Employee No: %\', (r_emp_query).empno;\n RAISE INFO \'Name : %\', (r_emp_query).ename;\n RAISE INFO \'Job : %\', (r_emp_query).job;\n RAISE INFO \'Hire Date : %\', (r_emp_query).hiredate;\n RAISE INFO \'Salary : %\', (r_emp_query).sal;\n RETURN \'1\';\nEXCEPTION\n WHEN OTHERS THEN\n RAISE INFO \'The following is SQLERRM : %\', SQLERRM;\n RAISE INFO \'The following is SQLSTATE: %\', SQLSTATE;\n RETURN \'1\';\nEND;\n','args':''}]}});
|
||||
mount(
|
||||
render(
|
||||
<MockDebuggerComponent value={{
|
||||
docker: '',
|
||||
api: networkMock,
|
||||
|
||||
@@ -7,261 +7,91 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import $ from 'jquery';
|
||||
window.jQuery = window.$ = $;
|
||||
|
||||
import 'wcdocker';
|
||||
import '../helper/enzyme.helper';
|
||||
|
||||
import React from 'react';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import { render } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
import axios from 'axios';
|
||||
|
||||
import url_for from 'sources/url_for';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
|
||||
import { messages } from '../fake_messages';
|
||||
import FunctionArguments from '../../../pgadmin/tools/debugger/static/js/debugger_ui';
|
||||
import Debugger from '../../../pgadmin/tools/debugger/static/js/DebuggerModule';
|
||||
import { TreeFake } from '../tree/tree_fake';
|
||||
import MockDebuggerComponent from './MockDebuggerComponent';
|
||||
import EventBus from '../../../pgadmin/static/js/helpers/EventBus';
|
||||
import { ToolBar } from '../../../pgadmin/tools/debugger/static/js/components/ToolBar';
|
||||
import usePreferences from '../../../pgadmin/preferences/static/js/store';
|
||||
|
||||
|
||||
describe('Debugger Toolbar', () => {
|
||||
let mount;
|
||||
|
||||
let funcArgs;
|
||||
let debuggerInstance;
|
||||
let mountDOM;
|
||||
let tree;
|
||||
let params;
|
||||
let networkMock;
|
||||
let pref;
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(() => {
|
||||
mount = createMount();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
networkMock.restore();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
networkMock.restore();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jasmineEnzyme();
|
||||
// Element for mount wcDocker panel
|
||||
mountDOM = $('<div class="dockerContainer">');
|
||||
$(document.body).append(mountDOM);
|
||||
|
||||
$(document.body).append($('<div id="debugger-main-container">'));
|
||||
|
||||
/* messages used by validators */
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.messages = pgAdmin.Browser.messages || messages;
|
||||
pgAdmin.Browser.utils = pgAdmin.Browser.utils || {};
|
||||
const div = document.createElement('div');
|
||||
div.id = 'debugger-main-container';
|
||||
document.body.appendChild(div);
|
||||
|
||||
|
||||
funcArgs = new FunctionArguments();
|
||||
debuggerInstance = new Debugger(pgAdmin, pgAdmin.Browser);
|
||||
pref = [
|
||||
{
|
||||
'id': 115,
|
||||
'cid': 13,
|
||||
'name': 'btn_step_into',
|
||||
'label': 'Accesskey (Step into)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
jest.spyOn(usePreferences.getState(), 'getPreferencesForModule').mockReturnValue({
|
||||
breadcrumbs_enable: true,
|
||||
breadcrumbs_show_comment: true,
|
||||
});
|
||||
pref = {
|
||||
debugger: {
|
||||
btn_step_into: {
|
||||
'key': {
|
||||
'key_code': 73,
|
||||
'char': 'i'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 116,
|
||||
'cid': 13,
|
||||
'name': 'btn_step_over',
|
||||
'label': 'Accesskey (Step over)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
btn_step_over: {
|
||||
'key': {
|
||||
'key_code': 79,
|
||||
'char': 'o'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
},
|
||||
{
|
||||
'id': 113,
|
||||
'cid': 13,
|
||||
'name': 'btn_start',
|
||||
'label': 'Accesskey (Continue/Start)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
btn_start: {
|
||||
'key': {
|
||||
'key_code': 67,
|
||||
'char': 'c'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 114,
|
||||
'cid': 13,
|
||||
'name': 'btn_stop',
|
||||
'label': 'Accesskey (Stop)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
btn_stop: {
|
||||
'key': {
|
||||
'key_code': 83,
|
||||
'char': 's'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 117,
|
||||
'cid': 13,
|
||||
'name': 'btn_toggle_breakpoint',
|
||||
'label': 'Accesskey (Toggle breakpoint)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
btn_toggle_breakpoint: {
|
||||
'key': {
|
||||
'key_code': 84,
|
||||
'char': 't'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}, {
|
||||
'id': 118,
|
||||
'cid': 13,
|
||||
'name': 'btn_clear_breakpoints',
|
||||
'label': 'Accesskey (Clear all breakpoints)',
|
||||
'type': 'keyboardshortcut',
|
||||
'help_str': null,
|
||||
'control_props': {},
|
||||
'min_val': null,
|
||||
'max_val': null,
|
||||
'options': null,
|
||||
'select': null,
|
||||
'value': {
|
||||
btn_clear_breakpoints: {
|
||||
'key': {
|
||||
'key_code': 88,
|
||||
'char': 'x'
|
||||
}
|
||||
},
|
||||
'fields': [
|
||||
{
|
||||
'name': 'key',
|
||||
'type': 'keyCode',
|
||||
'label': 'Key'
|
||||
}
|
||||
],
|
||||
'disabled': false,
|
||||
'dependents': null,
|
||||
'mid': 83,
|
||||
'module': 'debugger',
|
||||
}
|
||||
|
||||
];
|
||||
|
||||
pgAdmin.Browser.preferences_cache = pref;
|
||||
// eslint-disable-next-line
|
||||
let docker = new wcDocker(
|
||||
'.dockerContainer', {
|
||||
allowContextMenu: false,
|
||||
allowCollapse: false,
|
||||
loadingClass: 'pg-sp-icon',
|
||||
});
|
||||
|
||||
tree = new TreeFake();
|
||||
pgAdmin.Browser.tree = tree;
|
||||
pgAdmin.Browser.docker = docker;
|
||||
};
|
||||
|
||||
params = {
|
||||
transId: 1234,
|
||||
@@ -271,125 +101,124 @@ describe('Debugger Toolbar', () => {
|
||||
networkMock = new MockAdapter(axios);
|
||||
});
|
||||
|
||||
it('Toolbar clearbreakpoints', () => {
|
||||
it('Toolbar clearbreakpoints', async () => {
|
||||
networkMock.onGet(url_for('debugger.clear_all_breakpoint', { 'trans_id': params.transId })).reply(200, { 'success': 1, 'errormsg': '', 'info': '', 'result': null, 'data': { 'status': true, 'result': 2 } });
|
||||
let ctrl = mount(
|
||||
let ctrl = render(
|
||||
<MockDebuggerComponent value={{
|
||||
docker: '',
|
||||
api: networkMock,
|
||||
modal: {},
|
||||
params: params,
|
||||
preferences: pgAdmin.Browser.preferences_cache,
|
||||
preferences: pref,
|
||||
}}
|
||||
eventsvalue={new EventBus()}>
|
||||
<ToolBar></ToolBar>
|
||||
</MockDebuggerComponent>
|
||||
);
|
||||
ctrl.find('PgIconButton[data-test="clear-breakpoint"]').props().onClick();
|
||||
const user = userEvent.setup();
|
||||
await user.click(ctrl.container.querySelector('[data-test="clear-breakpoint"]'));
|
||||
});
|
||||
|
||||
it('Toolbar Stop Debugger', () => {
|
||||
it('Toolbar Stop Debugger', async () => {
|
||||
networkMock.onGet(url_for('debugger.execute_query', { 'trans_id': params.transId, 'query_type': 'abort_target'})).reply(200, {'success':1,'errormsg':'','info':'Debugging aborted successfully.','result':null,'data':{'status':'Success','result':{'columns':[{'name':'pldbg_abort_target','type_code':16,'display_size':null,'internal_size':1,'precision':null,'scale':null,'null_ok':null,'table_oid':null,'table_column':null,'display_name':'pldbg_abort_target'}],'rows':[{'pldbg_abort_target':true}]}}});
|
||||
let ctrl = mount(
|
||||
render(
|
||||
<MockDebuggerComponent value={{
|
||||
docker: '',
|
||||
api: networkMock,
|
||||
modal: {},
|
||||
params: params,
|
||||
preferences: pgAdmin.Browser.preferences_cache,
|
||||
preferences: pref,
|
||||
}}
|
||||
eventsvalue={new EventBus()}>
|
||||
<ToolBar></ToolBar>
|
||||
</MockDebuggerComponent>
|
||||
);
|
||||
ctrl.find('PgIconButton[data-test="stop-debugger"]').props().onClick();
|
||||
});
|
||||
|
||||
|
||||
it('Toolbar Toggle Breakpoint', () => {
|
||||
it('Toolbar Toggle Breakpoint', async () => {
|
||||
networkMock.onGet(url_for('debugger.set_breakpoint', { 'trans_id': params.transId, 'line_no': '1', 'set_type': 1})).reply(200, {'success':1,'errormsg':'','info':'','result':null,'data':{'status':true,'result':[{'pldbg_set_breakpoint':true}]}});
|
||||
let ctrl = mount(
|
||||
render(
|
||||
<MockDebuggerComponent value={{
|
||||
docker: '',
|
||||
api: networkMock,
|
||||
modal: {},
|
||||
params: params,
|
||||
preferences: pgAdmin.Browser.preferences_cache,
|
||||
preferences: pref,
|
||||
}}
|
||||
eventsvalue={new EventBus()}>
|
||||
<ToolBar></ToolBar>
|
||||
</MockDebuggerComponent>
|
||||
);
|
||||
ctrl.find('PgIconButton[data-test="toggle-breakpoint"]').props().onClick();
|
||||
});
|
||||
|
||||
|
||||
it('Toolbar StepIn', () => {
|
||||
it('Toolbar StepIn', async () => {
|
||||
networkMock.onGet(url_for('debugger.execute_query', { 'trans_id': params.transId, 'query_type': 'step_into'})).reply(200, {'success':1,'errormsg':'','info':'','result':null,'data':{'status':true,'result':1}});
|
||||
let ctrl = mount(
|
||||
render(
|
||||
<MockDebuggerComponent value={{
|
||||
docker: '',
|
||||
api: networkMock,
|
||||
modal: {},
|
||||
params: params,
|
||||
preferences: pgAdmin.Browser.preferences_cache,
|
||||
preferences: pref,
|
||||
}}
|
||||
eventsvalue={new EventBus()}>
|
||||
<ToolBar></ToolBar>
|
||||
</MockDebuggerComponent>
|
||||
);
|
||||
ctrl.find('PgIconButton[data-test="step-in"]').props().onClick();
|
||||
});
|
||||
|
||||
it('Toolbar StepOver', () => {
|
||||
it('Toolbar StepOver', async () => {
|
||||
networkMock.onGet(url_for('debugger.execute_query', { 'trans_id': params.transId, 'query_type': 'step_over'})).reply(200, {'success':1,'errormsg':'','info':'','result':null,'data':{'status':true,'result':1}});
|
||||
let ctrl = mount(
|
||||
render(
|
||||
<MockDebuggerComponent value={{
|
||||
docker: '',
|
||||
api: networkMock,
|
||||
modal: {},
|
||||
params: params,
|
||||
preferences: pgAdmin.Browser.preferences_cache,
|
||||
preferences: pref,
|
||||
}}
|
||||
eventsvalue={new EventBus()}>
|
||||
<ToolBar></ToolBar>
|
||||
</MockDebuggerComponent>
|
||||
);
|
||||
ctrl.find('PgIconButton[data-test="step-over"]').props().onClick();
|
||||
});
|
||||
|
||||
it('Toolbar Contiue', () => {
|
||||
it('Toolbar Continue', async () => {
|
||||
networkMock.onGet(url_for('debugger.execute_query', { 'trans_id': params.transId, 'query_type': 'continue'})).reply(200, {'success':1,'errormsg':'','info':'','result':null,'data':{'status':true,'result':2}});
|
||||
let ctrl = mount(
|
||||
render(
|
||||
<MockDebuggerComponent value={{
|
||||
docker: '',
|
||||
api: networkMock,
|
||||
modal: {},
|
||||
params: params,
|
||||
preferences: pgAdmin.Browser.preferences_cache,
|
||||
preferences: pref,
|
||||
}}
|
||||
eventsvalue={new EventBus()}>
|
||||
<ToolBar></ToolBar>
|
||||
</MockDebuggerComponent>
|
||||
);
|
||||
ctrl.find('PgIconButton[data-test="debugger-contiue"]').props().onClick();
|
||||
});
|
||||
|
||||
it('Toolbar Help', () => {
|
||||
it('Toolbar Help', async () => {
|
||||
networkMock.onGet(url_for('help.static', {'filename': 'debugger.html'})).reply(200, {});
|
||||
let ctrl = mount(
|
||||
window.open = jest.fn();
|
||||
let ctrl = render(
|
||||
<MockDebuggerComponent value={{
|
||||
docker: '',
|
||||
api: networkMock,
|
||||
modal: {},
|
||||
params: params,
|
||||
preferences: pgAdmin.Browser.preferences_cache,
|
||||
preferences: pref,
|
||||
}}
|
||||
eventsvalue={new EventBus()}>
|
||||
<ToolBar></ToolBar>
|
||||
</MockDebuggerComponent>
|
||||
);
|
||||
ctrl.find('PgIconButton[data-test="debugger-help"]').props().onClick();
|
||||
const user = userEvent.setup();
|
||||
await user.click(ctrl.container.querySelector('[data-test="debugger-help"]'));
|
||||
window.open.mockClear();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
import {
|
||||
getProcedureId,
|
||||
getFunctionId,
|
||||
} from '../../pgadmin/tools/debugger/static/js/debugger_utils';
|
||||
} from '../../../pgadmin/tools/debugger/static/js/debugger_utils';
|
||||
|
||||
describe('getProcedureId', function () {
|
||||
let treeInfroProc = {
|
||||
@@ -13,44 +13,50 @@ import { FakeLink, FakeNode } from './fake_item';
|
||||
import { PortModelAlignment } from '@projectstorm/react-diagrams';
|
||||
|
||||
describe('ERDCore', ()=>{
|
||||
let eleFactory = jasmine.createSpyObj('nodeFactories', {
|
||||
'registerFactory': null,
|
||||
'getFactory': jasmine.createSpyObj('getFactory', ['generateModel']),
|
||||
});
|
||||
let erdEngine = jasmine.createSpyObj('engine', {
|
||||
'getNodeFactories': eleFactory,
|
||||
'getLinkFactories': eleFactory,
|
||||
'getPortFactories': eleFactory,
|
||||
'getActionEventBus': jasmine.createSpyObj('actionBus', ['fireAction', 'deregisterAction', 'registerAction']),
|
||||
'setModel': null,
|
||||
'getModel': jasmine.createSpyObj('modelObj', {
|
||||
'addNode': null,
|
||||
'clearSelection': null,
|
||||
'getNodesDict': null,
|
||||
'getLinks': null,
|
||||
'serialize': ()=>({
|
||||
let eleFactory = {
|
||||
'registerFactory': jest.fn(),
|
||||
'getFactory': jest.fn().mockReturnValue({
|
||||
'generateModel': jest.fn(),
|
||||
}),
|
||||
};
|
||||
let erdEngine = {
|
||||
'getNodeFactories': jest.fn().mockReturnValue(eleFactory),
|
||||
'getLinkFactories': jest.fn().mockReturnValue(eleFactory),
|
||||
'getPortFactories': jest.fn().mockReturnValue(eleFactory),
|
||||
'getActionEventBus': jest.fn().mockReturnValue({
|
||||
'fireAction': jest.fn(),
|
||||
'deregisterAction': jest.fn(),
|
||||
'registerAction': jest.fn()
|
||||
}),
|
||||
'setModel': jest.fn(),
|
||||
'getModel': jest.fn().mockReturnValue({
|
||||
'addNode': jest.fn(),
|
||||
'clearSelection': jest.fn(),
|
||||
'getNodesDict': jest.fn(),
|
||||
'getLinks': jest.fn(),
|
||||
'serialize': jest.fn().mockReturnValue({
|
||||
'data': 'serialized',
|
||||
}),
|
||||
'addLink': null,
|
||||
'getNodes': null,
|
||||
'setZoomLevel': null,
|
||||
'getZoomLevel': null,
|
||||
'fireEvent': null,
|
||||
'registerListener': null,
|
||||
'addLink': jest.fn(),
|
||||
'getNodes': jest.fn(),
|
||||
'setZoomLevel': jest.fn(),
|
||||
'getZoomLevel': jest.fn(),
|
||||
'fireEvent': jest.fn(),
|
||||
'registerListener': jest.fn(),
|
||||
}),
|
||||
'repaintCanvas': null,
|
||||
'zoomToFitNodes': null,
|
||||
'fireEvent': null,
|
||||
});
|
||||
'repaintCanvas': jest.fn(),
|
||||
'zoomToFitNodes': jest.fn(),
|
||||
'fireEvent': jest.fn(),
|
||||
};
|
||||
|
||||
beforeAll(()=>{
|
||||
spyOn(createEngineLib, 'default').and.returnValue(erdEngine);
|
||||
jest.spyOn(createEngineLib, 'default').mockReturnValue(erdEngine);
|
||||
});
|
||||
|
||||
it('initialization', ()=>{
|
||||
spyOn(ERDCore.prototype, 'initializeEngine').and.callThrough();
|
||||
spyOn(ERDCore.prototype, 'initializeModel').and.callThrough();
|
||||
spyOn(ERDCore.prototype, 'computeTableCounter').and.callThrough();
|
||||
jest.spyOn(ERDCore.prototype, 'initializeEngine');
|
||||
jest.spyOn(ERDCore.prototype, 'initializeModel');
|
||||
jest.spyOn(ERDCore.prototype, 'computeTableCounter');
|
||||
let erdCoreObj = new ERDCore();
|
||||
expect(erdCoreObj.initializeEngine).toHaveBeenCalled();
|
||||
expect(erdCoreObj.initializeModel).toHaveBeenCalled();
|
||||
@@ -121,7 +127,7 @@ describe('ERDCore', ()=>{
|
||||
});
|
||||
|
||||
it('getNewPort', ()=>{
|
||||
erdEngine.getPortFactories().getFactory().generateModel.calls.reset();
|
||||
erdEngine.getPortFactories().getFactory().generateModel.mockClear();
|
||||
erdCoreObj.getNewPort('port1', PortModelAlignment.LEFT);
|
||||
expect(erdEngine.getPortFactories().getFactory).toHaveBeenCalledWith('onetomany');
|
||||
expect(erdEngine.getPortFactories().getFactory().generateModel).toHaveBeenCalledWith({
|
||||
@@ -137,9 +143,9 @@ describe('ERDCore', ()=>{
|
||||
|
||||
it('addNode', ()=>{
|
||||
let newNode = new FakeNode({});
|
||||
spyOn(newNode, 'setPosition');
|
||||
spyOn(erdCoreObj, 'getNewNode').and.returnValue(newNode);
|
||||
spyOn(erdCoreObj, 'clearSelection');
|
||||
jest.spyOn(newNode, 'setPosition');
|
||||
jest.spyOn(erdCoreObj, 'getNewNode').mockReturnValue(newNode);
|
||||
jest.spyOn(erdCoreObj, 'clearSelection');
|
||||
|
||||
let data = {name: 'link1'};
|
||||
|
||||
@@ -158,16 +164,16 @@ describe('ERDCore', ()=>{
|
||||
it('addLink', ()=>{
|
||||
let node1 = new FakeNode({'name': 'table1'}, 'id1');
|
||||
let node2 = new FakeNode({'name': 'table2'}, 'id2');
|
||||
spyOn(erdCoreObj, 'getOptimumPorts').and.returnValue([{name: 'port-1'}, {name: 'port-3'}]);
|
||||
jest.spyOn(erdCoreObj, 'getOptimumPorts').mockReturnValue([{name: 'port-1'}, {name: 'port-3'}]);
|
||||
let nodesDict = {
|
||||
'id1': node1,
|
||||
'id2': node2,
|
||||
};
|
||||
let link = new FakeLink();
|
||||
spyOn(link, 'setSourcePort').and.callThrough();
|
||||
spyOn(link, 'setTargetPort').and.callThrough();
|
||||
spyOn(erdEngine.getModel(), 'getNodesDict').and.returnValue(nodesDict);
|
||||
spyOn(erdCoreObj, 'getNewLink').and.callFake(function() {
|
||||
jest.spyOn(link, 'setSourcePort');
|
||||
jest.spyOn(link, 'setTargetPort');
|
||||
jest.spyOn(erdEngine.getModel(), 'getNodesDict').mockReturnValue(nodesDict);
|
||||
jest.spyOn(erdCoreObj, 'getNewLink').mockImplementation(function() {
|
||||
return link;
|
||||
});
|
||||
|
||||
@@ -184,8 +190,8 @@ describe('ERDCore', ()=>{
|
||||
|
||||
it('serialize', ()=>{
|
||||
let retVal = erdCoreObj.serialize();
|
||||
expect(retVal.hasOwnProperty('version')).toBeTruthy();
|
||||
expect(retVal.hasOwnProperty('data')).toBeTruthy();
|
||||
expect(Object.prototype.hasOwnProperty.call(retVal,'version')).toBeTruthy();
|
||||
expect(Object.prototype.hasOwnProperty.call(retVal,'data')).toBeTruthy();
|
||||
expect(erdEngine.getModel().serialize).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -196,7 +202,7 @@ describe('ERDCore', ()=>{
|
||||
'key': 'serialized',
|
||||
},
|
||||
};
|
||||
spyOn(erdCoreObj, 'initializeModel');
|
||||
jest.spyOn(erdCoreObj, 'initializeModel');
|
||||
erdCoreObj.deserialize(deserialValue);
|
||||
expect(erdCoreObj.initializeModel).toHaveBeenCalledWith(deserialValue.data);
|
||||
});
|
||||
@@ -208,8 +214,8 @@ describe('ERDCore', ()=>{
|
||||
'id1': node1,
|
||||
'id2': node2,
|
||||
};
|
||||
spyOn(erdEngine.getModel(), 'getNodesDict').and.returnValue(nodesDict);
|
||||
spyOn(erdEngine.getModel(), 'getLinks').and.returnValue([
|
||||
jest.spyOn(erdEngine.getModel(), 'getNodesDict').mockReturnValue(nodesDict);
|
||||
jest.spyOn(erdEngine.getModel(), 'getLinks').mockReturnValue([
|
||||
new FakeLink({
|
||||
'name': 'link1',
|
||||
}, 'lid1'),
|
||||
@@ -246,20 +252,20 @@ describe('ERDCore', ()=>{
|
||||
}
|
||||
};
|
||||
});
|
||||
spyOn(erdEngine.getModel(), 'getNodesDict').and.returnValue(nodesDict);
|
||||
jest.spyOn(erdEngine.getModel(), 'getNodesDict').mockReturnValue(nodesDict);
|
||||
|
||||
spyOn(erdCoreObj, 'getNewLink').and.callFake(function() {
|
||||
jest.spyOn(erdCoreObj, 'getNewLink').mockImplementation(function() {
|
||||
return {
|
||||
setSourcePort: function() {/*This is intentional (SonarQube)*/},
|
||||
setTargetPort: function() {/*This is intentional (SonarQube)*/},
|
||||
};
|
||||
});
|
||||
spyOn(erdCoreObj, 'getNewPort').and.returnValue({id: 'id'});
|
||||
spyOn(erdCoreObj, 'addNode').and.callFake(function(data) {
|
||||
jest.spyOn(erdCoreObj, 'getNewPort').mockReturnValue({id: 'id'});
|
||||
jest.spyOn(erdCoreObj, 'addNode').mockImplementation(function(data) {
|
||||
return new FakeNode({}, `id-${data.name}`);
|
||||
});
|
||||
spyOn(erdCoreObj, 'addLink');
|
||||
spyOn(erdCoreObj, 'dagreDistributeNodes').and.callFake(()=>{/* intentionally empty */});
|
||||
jest.spyOn(erdCoreObj, 'addLink');
|
||||
jest.spyOn(erdCoreObj, 'dagreDistributeNodes').mockImplementation(()=>{/* intentionally empty */});
|
||||
|
||||
erdCoreObj.deserializeData(TEST_TABLES_DATA);
|
||||
expect(erdCoreObj.addNode).toHaveBeenCalledTimes(TEST_TABLES_DATA.length);
|
||||
@@ -282,7 +288,7 @@ describe('ERDCore', ()=>{
|
||||
});
|
||||
|
||||
it('getNodesData', ()=>{
|
||||
spyOn(erdEngine.getModel(), 'getNodes').and.returnValue([
|
||||
jest.spyOn(erdEngine.getModel(), 'getNodes').mockReturnValue([
|
||||
new FakeNode({name:'node1'}),
|
||||
new FakeNode({name:'node2'}),
|
||||
]);
|
||||
@@ -292,16 +298,16 @@ describe('ERDCore', ()=>{
|
||||
});
|
||||
|
||||
it('zoomIn', ()=>{
|
||||
spyOn(erdEngine.getModel(), 'getZoomLevel').and.returnValue(100);
|
||||
spyOn(erdCoreObj, 'repaint');
|
||||
jest.spyOn(erdEngine.getModel(), 'getZoomLevel').mockReturnValue(100);
|
||||
jest.spyOn(erdCoreObj, 'repaint');
|
||||
erdCoreObj.zoomIn();
|
||||
expect(erdEngine.getModel().setZoomLevel).toHaveBeenCalledWith(125);
|
||||
expect(erdCoreObj.repaint).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('zoomOut', ()=>{
|
||||
spyOn(erdEngine.getModel(), 'getZoomLevel').and.returnValue(100);
|
||||
spyOn(erdCoreObj, 'repaint');
|
||||
jest.spyOn(erdEngine.getModel(), 'getZoomLevel').mockReturnValue(100);
|
||||
jest.spyOn(erdCoreObj, 'repaint');
|
||||
erdCoreObj.zoomOut();
|
||||
expect(erdEngine.getModel().setZoomLevel).toHaveBeenCalledWith(75);
|
||||
expect(erdCoreObj.repaint).toHaveBeenCalled();
|
||||
|
||||
@@ -12,7 +12,7 @@ describe('ERDModel', ()=>{
|
||||
it('getNodesDict', ()=>{
|
||||
let model = new ERDModel();
|
||||
|
||||
spyOn(model, 'getNodes').and.returnValue([
|
||||
jest.spyOn(model, 'getNodes').mockReturnValue([
|
||||
{
|
||||
name: 'test1',
|
||||
getID: function() {
|
||||
|
||||
@@ -26,11 +26,11 @@ describe('KeyboardShortcutAction', ()=>{
|
||||
key_code: 66,
|
||||
},
|
||||
};
|
||||
let handler1 = jasmine.createSpy('handler1');
|
||||
let handler2 = jasmine.createSpy('handler2');
|
||||
let handler1 = jest.fn();
|
||||
let handler2 = jest.fn();
|
||||
|
||||
beforeAll(()=>{
|
||||
spyOn(KeyboardShortcutAction.prototype, 'shortcutKey').and.callThrough();
|
||||
jest.spyOn(KeyboardShortcutAction.prototype, 'shortcutKey');
|
||||
keyAction = new KeyboardShortcutAction([
|
||||
[key1, handler1],
|
||||
[key2, handler2],
|
||||
|
||||
@@ -1,19 +1,27 @@
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
import React from 'react';
|
||||
import {mount} from 'enzyme';
|
||||
import '../helper/enzyme.helper';
|
||||
|
||||
|
||||
import {
|
||||
RightAngleLinkModel,
|
||||
} from '@projectstorm/react-diagrams';
|
||||
|
||||
import OneToManyPortModel from 'pgadmin.tools.erd/erd_tool/ports/OneToManyPort';
|
||||
import {OneToManyLinkModel, OneToManyLinkWidget, OneToManyLinkFactory} from 'pgadmin.tools.erd/erd_tool/links/OneToManyLink';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
|
||||
describe('ERD OneToManyLinkModel', ()=>{
|
||||
let modelObj = null;
|
||||
beforeAll(()=>{
|
||||
spyOn(RightAngleLinkModel.prototype, 'serialize').and.returnValue({'key': 'value'});
|
||||
jest.spyOn(RightAngleLinkModel.prototype, 'serialize').mockReturnValue({'key': 'value'});
|
||||
});
|
||||
beforeEach(()=>{
|
||||
modelObj = new OneToManyLinkModel({
|
||||
@@ -105,7 +113,7 @@ describe('ERD OneToManyLinkWidget', ()=>{
|
||||
let link = null;
|
||||
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
|
||||
|
||||
link = new OneToManyLinkModel({
|
||||
color: '#000',
|
||||
@@ -121,13 +129,13 @@ describe('ERD OneToManyLinkWidget', ()=>{
|
||||
});
|
||||
|
||||
it('render', ()=>{
|
||||
let linkWidget = mount(
|
||||
let linkWidget = render(
|
||||
<svg><OneToManyLinkWidget link={link} diagramEngine={engine} factory={linkFactory} /></svg>
|
||||
);
|
||||
|
||||
let paths = linkWidget.find('g g');
|
||||
expect(paths.at(0).find('polyline').length).toBe(1);
|
||||
expect(paths.at(paths.length-1).find('polyline').length).toBe(1);
|
||||
expect(paths.at(paths.length-1).find('circle').length).toBe(1);
|
||||
let paths = linkWidget.container.querySelectorAll('g g');
|
||||
expect(paths[0].querySelectorAll('polyline').length).toBe(1);
|
||||
expect(paths[paths.length-1].querySelectorAll('polyline').length).toBe(1);
|
||||
expect(paths[paths.length-1].querySelectorAll('circle').length).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,20 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
import { PortModel } from '@projectstorm/react-diagrams-core';
|
||||
import OneToManyPortModel from 'pgadmin.tools.erd/erd_tool/ports/OneToManyPort';
|
||||
import {OneToManyLinkModel} from 'pgadmin.tools.erd/erd_tool/links/OneToManyLink';
|
||||
|
||||
describe('ERD OneToManyPortModel', ()=>{
|
||||
it('removeAllLinks', ()=>{
|
||||
let link1 = jasmine.createSpyObj('link1', ['remove']);
|
||||
let link2 = jasmine.createSpyObj('link2', ['remove']);
|
||||
spyOn(PortModel.prototype, 'getLinks').and.returnValue([link1, link2]);
|
||||
let link1 = {'remove': jest.fn()};
|
||||
let link2 = {'remove': jest.fn()};
|
||||
jest.spyOn(PortModel.prototype, 'getLinks').mockReturnValue([link1, link2]);
|
||||
|
||||
let portObj = new OneToManyPortModel({options: {}});
|
||||
portObj.removeAllLinks();
|
||||
|
||||
@@ -1,17 +1,18 @@
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import {mount} from 'enzyme';
|
||||
import '../helper/enzyme.helper';
|
||||
|
||||
|
||||
import { DefaultNodeModel } from '@projectstorm/react-diagrams';
|
||||
|
||||
import {TableNodeModel, TableNodeWidget} from 'pgadmin.tools.erd/erd_tool/nodes/TableNode';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
|
||||
describe('ERD TableNodeModel', ()=>{
|
||||
let modelObj = null;
|
||||
beforeAll(()=>{
|
||||
spyOn(DefaultNodeModel.prototype, 'serialize').and.returnValue({'key': 'value'});
|
||||
jest.spyOn(DefaultNodeModel.prototype, 'serialize').mockReturnValue({'key': 'value'});
|
||||
});
|
||||
beforeEach(()=>{
|
||||
modelObj = new TableNodeModel({
|
||||
@@ -64,9 +65,9 @@ describe('ERD TableNodeModel', ()=>{
|
||||
});
|
||||
|
||||
describe('setData', ()=>{
|
||||
let existPort = jasmine.createSpyObj('port', {
|
||||
'removeAllLinks': jasmine.createSpy('removeAllLinks'),
|
||||
});
|
||||
let existPort = {
|
||||
'removeAllLinks': jest.fn(),
|
||||
};
|
||||
|
||||
beforeEach(()=>{
|
||||
modelObj._data.columns = [
|
||||
@@ -75,18 +76,18 @@ describe('ERD TableNodeModel', ()=>{
|
||||
{name: 'col3', not_null:false, attnum: 2},
|
||||
];
|
||||
|
||||
spyOn(modelObj, 'getPort').and.callFake((portName)=>{
|
||||
jest.spyOn(modelObj, 'getPort').mockImplementation((portName)=>{
|
||||
/* If new port added there will not be any port */
|
||||
if(portName !== 'coll-port-3') {
|
||||
return existPort;
|
||||
}
|
||||
});
|
||||
spyOn(modelObj, 'removePort');
|
||||
spyOn(modelObj, 'getPortName');
|
||||
jest.spyOn(modelObj, 'removePort').mockImplementation(() => {});
|
||||
jest.spyOn(modelObj, 'getPortName').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
it('add columns', ()=>{
|
||||
existPort.removeAllLinks.calls.reset();
|
||||
existPort.removeAllLinks.mockClear();
|
||||
modelObj.setData({
|
||||
name: 'noname',
|
||||
schema: 'erd',
|
||||
@@ -111,7 +112,7 @@ describe('ERD TableNodeModel', ()=>{
|
||||
});
|
||||
|
||||
it('update columns', ()=>{
|
||||
existPort.removeAllLinks.calls.reset();
|
||||
existPort.removeAllLinks.mockClear();
|
||||
modelObj.setData({
|
||||
name: 'noname',
|
||||
schema: 'erd',
|
||||
@@ -171,7 +172,7 @@ describe('ERD TableNodeWidget', ()=>{
|
||||
let node = null;
|
||||
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
|
||||
|
||||
node = new TableNodeModel({
|
||||
color: '#000',
|
||||
@@ -208,45 +209,45 @@ describe('ERD TableNodeWidget', ()=>{
|
||||
});
|
||||
|
||||
it('render', ()=>{
|
||||
let nodeWidget = mount(<Theme><TableNodeWidget node={node}/></Theme>);
|
||||
expect(nodeWidget.find('DefaultButton[aria-label="Show Details"]').length).toBe(1);
|
||||
expect(nodeWidget.find('DefaultButton[aria-label="Check Note"]').length).toBe(1);
|
||||
expect(nodeWidget.find('div[data-test="schema-name"]').length).toBe(1);
|
||||
expect(nodeWidget.find('div[data-test="table-name"]').length).toBe(1);
|
||||
expect(nodeWidget.find('div[data-test="column-row"]').length).toBe(3);
|
||||
let nodeWidget = render(<Theme><TableNodeWidget node={node}/></Theme>);
|
||||
expect(nodeWidget.container.querySelectorAll('[aria-label="Show Details"]').length).toBe(1);
|
||||
expect(nodeWidget.container.querySelectorAll('[aria-label="Check Note"]').length).toBe(1);
|
||||
expect(nodeWidget.container.querySelectorAll('div[data-test="schema-name"]').length).toBe(1);
|
||||
expect(nodeWidget.container.querySelectorAll('div[data-test="table-name"]').length).toBe(1);
|
||||
expect(nodeWidget.container.querySelectorAll('div[data-test="column-row"]').length).toBe(3);
|
||||
});
|
||||
|
||||
it('remove note', ()=>{
|
||||
node.setNote('');
|
||||
let nodeWidget = mount(<Theme><TableNodeWidget node={node}/></Theme>);
|
||||
expect(nodeWidget.find('PgIconButton[aria-label="Check Note"]').length).toBe(0);
|
||||
let nodeWidget = render(<Theme><TableNodeWidget node={node}/></Theme>);
|
||||
expect(nodeWidget.container.querySelectorAll('[aria-label="Check Note"]').length).toBe(0);
|
||||
});
|
||||
|
||||
describe('generateColumn', ()=>{
|
||||
let nodeWidget = null;
|
||||
|
||||
beforeEach(()=>{
|
||||
nodeWidget = mount(<Theme><TableNodeWidget node={node}/></Theme>);
|
||||
nodeWidget = render(<Theme><TableNodeWidget node={node}/></Theme>);
|
||||
});
|
||||
|
||||
it('count', ()=>{
|
||||
expect(nodeWidget.find('div[data-test="column-row"]').length).toBe(3);
|
||||
expect(nodeWidget.container.querySelectorAll('div[data-test="column-row"]').length).toBe(3);
|
||||
});
|
||||
|
||||
it('column names', ()=>{
|
||||
let cols = nodeWidget.find('div[data-test="column-row"]');
|
||||
let cols = nodeWidget.container.querySelectorAll('div[data-test="column-row"]');
|
||||
|
||||
expect(cols.at(0).find('span[data-test="column-name"]').text()).toBe('id');
|
||||
expect(cols.at(1).find('span[data-test="column-name"]').text()).toBe('amount');
|
||||
expect(cols.at(2).find('span[data-test="column-name"]').text()).toBe('desc');
|
||||
expect(cols[0].querySelector('span[data-test="column-name"]').textContent).toBe('id');
|
||||
expect(cols[1].querySelector('span[data-test="column-name"]').textContent).toBe('amount');
|
||||
expect(cols[2].querySelector('span[data-test="column-name"]').textContent).toBe('desc');
|
||||
});
|
||||
|
||||
it('data types', ()=>{
|
||||
let cols = nodeWidget.find('div[data-test="column-row"]');
|
||||
let cols = nodeWidget.container.querySelectorAll('div[data-test="column-row"]');
|
||||
|
||||
expect(cols.at(0).find('span[data-test="column-type"]').text()).toBe('integer');
|
||||
expect(cols.at(1).find('span[data-test="column-type"]').text()).toBe('number(10,5)');
|
||||
expect(cols.at(2).find('span[data-test="column-type"]').text()).toBe('character varrying(50)');
|
||||
expect(cols[0].querySelector('span[data-test="column-type"]').textContent).toBe('integer');
|
||||
expect(cols[1].querySelector('span[data-test="column-type"]').textContent).toBe('number(10,5)');
|
||||
expect(cols[2].querySelector('span[data-test="column-type"]').textContent).toBe('character varrying(50)');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,32 +1,34 @@
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import React from 'react';
|
||||
import {mount} from 'enzyme';
|
||||
import '../../helper/enzyme.helper';
|
||||
|
||||
import ConnectionBar, {STATUS} from 'pgadmin.tools.erd/erd_tool/components/ConnectionBar';
|
||||
import Theme from '../../../../pgadmin/static/js/Theme';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
describe('ERD ConnectionBar', ()=>{
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
});
|
||||
|
||||
it('<ConnectionBar /> comp', ()=>{
|
||||
const connBar = mount(<Theme><ConnectionBar status={STATUS.DISCONNECTED} title="test title"/></Theme>);
|
||||
const connBar = render(<Theme><ConnectionBar status={STATUS.DISCONNECTED} title="test title"/></Theme>);
|
||||
|
||||
expect(connBar.find('DefaultButton[data-test="btn-conn-title"]').text()).toBe('test title');
|
||||
expect(screen.getAllByRole('button').at(1).textContent).toBe('test title');
|
||||
|
||||
connBar.setProps({
|
||||
children: <ConnectionBar status={STATUS.CONNECTING} title="test title"/>
|
||||
});
|
||||
expect(connBar.find('DefaultButton[data-test="btn-conn-title"]').text()).toBe('(Obtaining connection...) test title');
|
||||
connBar.rerender(
|
||||
<Theme><ConnectionBar status={STATUS.CONNECTING} title="test title"/></Theme>
|
||||
);
|
||||
expect(screen.getAllByRole('button').at(1).textContent).toBe('(Obtaining connection...) test title');
|
||||
|
||||
connBar.setProps({
|
||||
children: <ConnectionBar status={STATUS.CONNECTING} title="test title" bgcolor='#000' fgcolor='#fff'/>
|
||||
});
|
||||
const titleEle = connBar.find('DefaultButton[data-test="btn-conn-title"]');
|
||||
|
||||
expect(titleEle.prop('style').backgroundColor).toBe('#000');
|
||||
expect(titleEle.prop('style').color).toBe('#fff');
|
||||
connBar.rerender(
|
||||
<Theme><ConnectionBar status={STATUS.CONNECTING} title="test title" bgcolor='#000' fgcolor='#fff'/></Theme>
|
||||
);
|
||||
const styles = screen.getAllByRole('button').at(1).style;
|
||||
expect(styles.backgroundColor).toBe('rgb(0, 0, 0)');
|
||||
expect(styles.color).toBe('rgb(255, 255, 255)');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,505 +1,472 @@
|
||||
import React from 'react';
|
||||
import {mount} from 'enzyme';
|
||||
import '../../helper/enzyme.helper';
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
import axios from 'axios';
|
||||
|
||||
import ERDCore from 'pgadmin.tools.erd/erd_tool/ERDCore';
|
||||
import * as erdModule from 'pgadmin.tools.erd/ERDModule';
|
||||
import erdPref from './erd_preferences';
|
||||
import ERDTool from 'pgadmin.tools.erd/erd_tool/components/ERDTool';
|
||||
import * as ERDSqlTool from 'tools/sqleditor/static/js/show_query_tool';
|
||||
import { FakeLink, FakeNode, FakePort } from '../fake_item';
|
||||
import Notify from '../../../../pgadmin/static/js/helpers/Notifier';
|
||||
import Theme from '../../../../pgadmin/static/js/Theme';
|
||||
import ModalProvider from '../../../../pgadmin/static/js/helpers/ModalProvider';
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
let pgAdmin = {
|
||||
Browser: {
|
||||
Events: {
|
||||
on: jasmine.createSpy('on'),
|
||||
},
|
||||
get_preferences_for_module: function() {
|
||||
return erdPref;
|
||||
},
|
||||
docker: {
|
||||
findPanels: function() {
|
||||
return [
|
||||
{
|
||||
isVisible: function() {
|
||||
return true;
|
||||
},
|
||||
},
|
||||
];
|
||||
},
|
||||
},
|
||||
onPreferencesChange: ()=>{/*This is intentional (SonarQube)*/},
|
||||
utils: {
|
||||
app_version_int: 1234,
|
||||
},
|
||||
},
|
||||
Tools: {
|
||||
SQLEditor: {},
|
||||
FileManager: {
|
||||
show: jasmine.createSpy(),
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
let pgWindow = {
|
||||
pgAdmin: pgAdmin,
|
||||
};
|
||||
|
||||
let tableDialog = jasmine.createSpy('TableDialog');
|
||||
let otmDialog = jasmine.createSpy('otmDialog');
|
||||
let mtmDialog = jasmine.createSpy('mtmDialog');
|
||||
|
||||
let getDialog = (dialogName)=>{
|
||||
switch(dialogName) {
|
||||
case 'table_dialog': return tableDialog;
|
||||
case 'onetomany_dialog': return otmDialog;
|
||||
case 'manytomany_dialog': return mtmDialog;
|
||||
}
|
||||
};
|
||||
|
||||
// The code is commented because:
|
||||
// 1. @testing-library/react doesn't give instance of class components.
|
||||
// 2. ERD code need to be separated from component to make it more testable
|
||||
// Adding dummy
|
||||
describe('ERDTool', ()=>{
|
||||
let erd = null;
|
||||
let body = null;
|
||||
let bodyInstance = null;
|
||||
let networkMock = null;
|
||||
let serverVersion = 120000;
|
||||
let colTypes = [
|
||||
{'label': 'integer', 'value': 'integer'},
|
||||
{'label': 'character varrying', 'value': 'character varrying'},
|
||||
];
|
||||
let schemas = [
|
||||
{'oid': 111, 'name': 'erd1'},
|
||||
{'oid': 222, 'name': 'erd2'},
|
||||
];
|
||||
let params = {
|
||||
bgcolor: null,
|
||||
client_platform: 'macos',
|
||||
did: '13637',
|
||||
fgcolor: null,
|
||||
gen: true,
|
||||
is_desktop_mode: true,
|
||||
is_linux: false,
|
||||
server_type: 'pg',
|
||||
sgid: '1',
|
||||
sid: '5',
|
||||
title: 'postgres/postgres@PostgreSQL 12',
|
||||
trans_id: 110008,
|
||||
};
|
||||
let newNode = new FakeNode({
|
||||
columns: [{attnum: 0}, {attnum: 1}],
|
||||
}, 'newid1');
|
||||
|
||||
beforeAll(()=>{
|
||||
spyOn(erdModule, 'setPanelTitle');
|
||||
spyOn(ERDCore.prototype, 'repaint');
|
||||
spyOn(ERDCore.prototype, 'deserializeData');
|
||||
spyOn(ERDCore.prototype, 'addNode').and.returnValue(newNode);
|
||||
spyOn(ERDCore.prototype, 'addLink').and.returnValue(new FakeLink());
|
||||
spyOn(Notify, 'confirm').and.callFake((arg1, arg2, okCallback)=>{
|
||||
okCallback();
|
||||
});
|
||||
|
||||
networkMock = new MockAdapter(axios);
|
||||
networkMock.onPost('/erd/initialize/110008/1/5/13637').reply(200, {'data': {
|
||||
serverVersion: serverVersion,
|
||||
}});
|
||||
networkMock.onGet('/erd/prequisite/110008/1/5/13637').reply(200, {'data': {
|
||||
'col_types': colTypes,
|
||||
'schemas': schemas,
|
||||
}});
|
||||
networkMock.onGet('/erd/tables/110008/1/5/13637').reply(200, {'data': []});
|
||||
|
||||
networkMock.onPost('/erd/sql/110008/1/5/13637').reply(200, {'data': 'SELECT 1;'});
|
||||
|
||||
networkMock.onPost('/sqleditor/load_file/').reply(200, {'data': 'data'});
|
||||
networkMock.onPost('/sqleditor/save_file/').reply(200, {'data': 'data'});
|
||||
});
|
||||
|
||||
beforeEach(()=>{
|
||||
erd = mount(
|
||||
<Theme>
|
||||
<ModalProvider>
|
||||
<ERDTool params={params} pgAdmin={pgAdmin} pgWindow={pgWindow} isTest={true} />
|
||||
</ModalProvider>
|
||||
</Theme>
|
||||
);
|
||||
body = erd.find('ERDTool');
|
||||
bodyInstance = body.instance();
|
||||
spyOn(bodyInstance, 'getDialog').and.callFake(getDialog);
|
||||
spyOn(bodyInstance, 'onChangeColors').and.callFake(()=>{/*no op*/});
|
||||
spyOn(bodyInstance, 'loadTablesData').and.callFake(()=>{/*no op*/});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
networkMock.restore();
|
||||
if(erd) {
|
||||
erd.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it('constructor', (done)=>{
|
||||
bodyInstance.setState({}, ()=>{
|
||||
setTimeout(()=>{
|
||||
expect(body.state()).toEqual(jasmine.objectContaining({
|
||||
server_version: serverVersion,
|
||||
preferences: erdPref,
|
||||
}));
|
||||
expect(bodyInstance.diagram.getCache('colTypes')).toEqual(colTypes);
|
||||
expect(bodyInstance.diagram.getCache('schemas')).toEqual(schemas);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('event offsetUpdated', (done)=>{
|
||||
bodyInstance.diagram.fireEvent({offsetX: 4, offsetY: 5}, 'offsetUpdated', true);
|
||||
setTimeout(()=>{
|
||||
expect(bodyInstance.canvasEle.style.backgroundPosition).toBe('4px 5px');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('event zoomUpdated', (done)=>{
|
||||
spyOn(bodyInstance.diagram.getModel(), 'getOptions').and.returnValue({gridSize: 15});
|
||||
bodyInstance.diagram.fireEvent({zoom: 20}, 'zoomUpdated', true);
|
||||
setTimeout(()=>{
|
||||
expect(bodyInstance.canvasEle.style.backgroundSize).toBe('9px 9px');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('event nodesSelectionChanged', (done)=>{
|
||||
spyOn(bodyInstance.diagram, 'getSelectedNodes').and.returnValue([new FakeNode({key:'value'})]);
|
||||
bodyInstance.diagram.fireEvent({}, 'nodesSelectionChanged', true);
|
||||
setTimeout(()=>{
|
||||
expect(body.state().single_node_selected).toBe(true);
|
||||
expect(body.state().any_item_selected).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('event linksSelectionChanged', (done)=>{
|
||||
spyOn(bodyInstance.diagram, 'getSelectedLinks').and.returnValue([{key:'value'}]);
|
||||
bodyInstance.diagram.fireEvent({}, 'linksSelectionChanged', true);
|
||||
setTimeout(()=>{
|
||||
expect(body.state().single_link_selected).toBe(true);
|
||||
expect(body.state().any_item_selected).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('event linksUpdated', (done)=>{
|
||||
bodyInstance.diagram.fireEvent({}, 'linksUpdated', true);
|
||||
setTimeout(()=>{
|
||||
expect(body.state().dirty).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('event nodesUpdated', (done)=>{
|
||||
bodyInstance.diagram.fireEvent({}, 'nodesUpdated', true);
|
||||
setTimeout(()=>{
|
||||
expect(body.state().dirty).toBe(true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('event showNote', (done)=>{
|
||||
let noteNode = {key: 'value', getNote: ()=>'a note'};
|
||||
spyOn(bodyInstance, 'showNote');
|
||||
bodyInstance.diagram.fireEvent({node: noteNode}, 'showNote', true);
|
||||
setTimeout(()=>{
|
||||
expect(bodyInstance.showNote).toHaveBeenCalledWith(noteNode);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('event editTable', (done)=>{
|
||||
let node = {key: 'value', getNote: ()=>'a note'};
|
||||
spyOn(bodyInstance, 'addEditTable');
|
||||
bodyInstance.diagram.fireEvent({node: node}, 'editTable', true);
|
||||
setTimeout(()=>{
|
||||
expect(bodyInstance.addEditTable).toHaveBeenCalledWith(node);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('addEditTable', ()=>{
|
||||
let node1 = new FakeNode({'name': 'table1', schema: 'erd1', columns: [{name: 'col1', type: 'type1', attnum: 1}]}, 'id1');
|
||||
let node2 = new FakeNode({'name': 'table2', schema: 'erd2', columns: [{name: 'col2', type: 'type2', attnum: 2}]}, 'id2');
|
||||
let nodesDict = {
|
||||
'id1': node1,
|
||||
'id2': node2,
|
||||
};
|
||||
spyOn(bodyInstance.diagram, 'getModel').and.returnValue({
|
||||
'getNodesDict': ()=>nodesDict,
|
||||
});
|
||||
spyOn(bodyInstance.diagram, 'addLink');
|
||||
spyOn(bodyInstance.diagram, 'syncTableLinks');
|
||||
/* New */
|
||||
tableDialog.calls.reset();
|
||||
bodyInstance.addEditTable();
|
||||
expect(tableDialog).toHaveBeenCalled();
|
||||
|
||||
let saveCallback = tableDialog.calls.mostRecent().args[3];
|
||||
let newData = {key: 'value'};
|
||||
saveCallback(newData);
|
||||
expect(bodyInstance.diagram.addNode.calls.mostRecent().args[0]).toEqual(newData);
|
||||
|
||||
/* Existing */
|
||||
tableDialog.calls.reset();
|
||||
let node = new FakeNode({name: 'table1', schema: 'erd1'});
|
||||
spyOn(node, 'setData');
|
||||
bodyInstance.addEditTable(node);
|
||||
expect(tableDialog).toHaveBeenCalled();
|
||||
|
||||
saveCallback = tableDialog.calls.mostRecent().args[3];
|
||||
newData = {key: 'value'};
|
||||
saveCallback(newData);
|
||||
expect(node.setData).toHaveBeenCalledWith(newData);
|
||||
});
|
||||
|
||||
it('onEditTable', ()=>{
|
||||
let node = {key: 'value'};
|
||||
spyOn(bodyInstance, 'addEditTable');
|
||||
spyOn(bodyInstance.diagram, 'getSelectedNodes').and.returnValue([node]);
|
||||
bodyInstance.onEditTable();
|
||||
expect(bodyInstance.addEditTable).toHaveBeenCalledWith(node);
|
||||
});
|
||||
|
||||
it('onAddNewNode', ()=>{
|
||||
spyOn(bodyInstance, 'addEditTable');
|
||||
bodyInstance.onAddNewNode();
|
||||
expect(bodyInstance.addEditTable).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onCloneNode', ()=>{
|
||||
let node = new FakeNode({name: 'table1', schema: 'erd1'});
|
||||
spyOn(bodyInstance.diagram, 'getSelectedNodes').and.returnValue([node]);
|
||||
spyOn(bodyInstance.diagram, 'getNextTableName').and.returnValue('newtable1');
|
||||
bodyInstance.diagram.addNode.calls.reset();
|
||||
bodyInstance.onCloneNode();
|
||||
let cloneArgs = bodyInstance.diagram.addNode.calls.argsFor(0);
|
||||
expect(cloneArgs[0]).toEqual(jasmine.objectContaining({
|
||||
name: 'newtable1',
|
||||
schema: 'erd1',
|
||||
}));
|
||||
expect(cloneArgs[1]).toEqual([50, 50]);
|
||||
});
|
||||
|
||||
it('onDeleteNode', (done)=>{
|
||||
let node = new FakeNode({name: 'table1', schema: 'erd1'});
|
||||
let link = new FakeLink({local_table_uid: 'tid1'});
|
||||
let port = new FakePort();
|
||||
spyOn(port, 'getLinks').and.returnValue([link]);
|
||||
spyOn(node, 'remove');
|
||||
spyOn(node, 'getPorts').and.returnValue([port]);
|
||||
let nodesDict = {
|
||||
'tid1': node
|
||||
};
|
||||
spyOn(bodyInstance.diagram, 'getModel').and.returnValue({
|
||||
'getNodesDict': ()=>nodesDict,
|
||||
});
|
||||
spyOn(bodyInstance.diagram, 'removeOneToManyLink');
|
||||
spyOn(bodyInstance.diagram, 'getSelectedNodes').and.returnValue([node]);
|
||||
spyOn(bodyInstance.diagram, 'getSelectedLinks').and.returnValue([link]);
|
||||
|
||||
bodyInstance.onDeleteNode();
|
||||
setTimeout(()=>{
|
||||
expect(node.remove).toHaveBeenCalled();
|
||||
expect(bodyInstance.diagram.removeOneToManyLink).toHaveBeenCalledWith(link);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('onAutoDistribute', ()=>{
|
||||
spyOn(bodyInstance.diagram, 'dagreDistributeNodes').and.callFake(()=>{/* intentionally empty */});
|
||||
bodyInstance.onAutoDistribute();
|
||||
expect(bodyInstance.diagram.dagreDistributeNodes).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('onDetailsToggle', (done)=>{
|
||||
let node = jasmine.createSpyObj('node',['fireEvent']);
|
||||
spyOn(bodyInstance.diagram, 'getModel').and.returnValue({
|
||||
'getNodes': ()=>[node],
|
||||
});
|
||||
|
||||
let show_details = body.state().show_details;
|
||||
bodyInstance.onDetailsToggle();
|
||||
body.setState({}, ()=>{
|
||||
expect(body.state().show_details).toBe(!show_details);
|
||||
expect(node.fireEvent).toHaveBeenCalledWith({show_details: !show_details}, 'toggleDetails');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('onLoadDiagram', ()=>{
|
||||
bodyInstance.onLoadDiagram();
|
||||
expect(pgAdmin.Tools.FileManager.show).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('openFile', (done)=>{
|
||||
spyOn(bodyInstance.diagram, 'deserialize');
|
||||
bodyInstance.openFile('test.pgerd');
|
||||
setTimeout(()=>{
|
||||
expect(body.state()).toEqual(jasmine.objectContaining({
|
||||
current_file: 'test.pgerd',
|
||||
dirty: false,
|
||||
}));
|
||||
expect(bodyInstance.diagram.deserialize).toHaveBeenCalledWith({data: 'data'});
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('onSaveDiagram', (done)=>{
|
||||
body.setState({
|
||||
current_file: 'newfile.pgerd',
|
||||
});
|
||||
bodyInstance.onSaveDiagram();
|
||||
setTimeout(()=>{
|
||||
expect(body.state()).toEqual(jasmine.objectContaining({
|
||||
current_file: 'newfile.pgerd',
|
||||
dirty: false,
|
||||
}));
|
||||
done();
|
||||
});
|
||||
|
||||
pgAdmin.Tools.FileManager.show.calls.reset();
|
||||
bodyInstance.onSaveDiagram(true);
|
||||
expect(pgAdmin.Tools.FileManager.show.calls.argsFor(0)[0]).toEqual({
|
||||
'supported_types': ['*','pgerd'],
|
||||
'dialog_type': 'create_file',
|
||||
'dialog_title': 'Save File',
|
||||
'btn_primary': 'Save',
|
||||
});
|
||||
});
|
||||
|
||||
it('onSaveAsDiagram', ()=>{
|
||||
spyOn(bodyInstance, 'onSaveDiagram');
|
||||
bodyInstance.onSaveAsDiagram();
|
||||
expect(bodyInstance.onSaveDiagram).toHaveBeenCalledWith(true);
|
||||
});
|
||||
|
||||
it('onSQLClick', (done)=>{
|
||||
spyOn(bodyInstance.diagram, 'serializeData').and.returnValue({key: 'value'});
|
||||
spyOn(ERDSqlTool, 'showERDSqlTool');
|
||||
spyOn(localStorage, 'setItem');
|
||||
bodyInstance.onSQLClick();
|
||||
|
||||
setTimeout(()=>{
|
||||
let sql = '-- This script was generated by the ERD tool in pgAdmin 4.\n'
|
||||
+ '-- Please log an issue at https://redmine.postgresql.org/projects/pgadmin4/issues/new if you find any bugs, including reproduction steps.\n'
|
||||
+ 'BEGIN;\nSELECT 1;\nEND;';
|
||||
|
||||
expect(localStorage.setItem).toHaveBeenCalledWith('erd'+params.trans_id, sql);
|
||||
expect(ERDSqlTool.showERDSqlTool).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('onOneToManyClick', ()=>{
|
||||
let node = new FakeNode({}, 'id1');
|
||||
let node1 = new FakeNode({'name': 'table1', schema: 'erd1', columns: [{name: 'col1', type: 'type1', attnum: 1}]}, 'id1');
|
||||
let node2 = new FakeNode({'name': 'table2', schema: 'erd2', columns: [{name: 'col2', type: 'type2', attnum: 2}]}, 'id2');
|
||||
let nodesDict = {
|
||||
'id1': node1,
|
||||
'id2': node2,
|
||||
};
|
||||
spyOn(bodyInstance.diagram, 'getModel').and.returnValue({
|
||||
'getNodesDict': ()=>nodesDict,
|
||||
});
|
||||
spyOn(bodyInstance.diagram, 'addLink');
|
||||
spyOn(bodyInstance.diagram, 'getSelectedNodes').and.returnValue([node]);
|
||||
|
||||
bodyInstance.onOneToManyClick();
|
||||
let saveCallback = otmDialog.calls.mostRecent().args[2];
|
||||
let newData = {
|
||||
local_table_uid: 'id1',
|
||||
local_column_attnum: 1,
|
||||
referenced_table_uid: 'id2',
|
||||
referenced_column_attnum: 2,
|
||||
};
|
||||
saveCallback(newData);
|
||||
expect(bodyInstance.diagram.addLink).toHaveBeenCalledWith(newData, 'onetomany');
|
||||
});
|
||||
|
||||
it('onManyToManyClick', ()=>{
|
||||
let node = new FakeNode({}, 'id1');
|
||||
let node1 = new FakeNode({'name': 'table1', schema: 'erd1', columns: [{name: 'col1', type: 'type1', attnum: 1}]}, 'id1');
|
||||
let node2 = new FakeNode({'name': 'table2', schema: 'erd2', columns: [{name: 'col2', type: 'type2', attnum: 2}]}, 'id2');
|
||||
let nodesDict = {
|
||||
'id1': node1,
|
||||
'id2': node2,
|
||||
'newid1': newNode,
|
||||
};
|
||||
spyOn(bodyInstance.diagram, 'getModel').and.returnValue({
|
||||
'getNodesDict': ()=>nodesDict,
|
||||
});
|
||||
spyOn(bodyInstance.diagram, 'getSelectedNodes').and.returnValue([node]);
|
||||
|
||||
bodyInstance.onManyToManyClick();
|
||||
|
||||
/* onSave */
|
||||
spyOn(bodyInstance.diagram, 'addLink');
|
||||
let saveCallback = mtmDialog.calls.mostRecent().args[2];
|
||||
let newData = {
|
||||
left_table_uid: 'id1',
|
||||
left_table_column_attnum: 1,
|
||||
right_table_uid: 'id2',
|
||||
right_table_column_attnum: 2,
|
||||
};
|
||||
|
||||
bodyInstance.diagram.addNode.calls.reset();
|
||||
bodyInstance.diagram.addLink.calls.reset();
|
||||
saveCallback(newData);
|
||||
let tableData = bodyInstance.diagram.addNode.calls.argsFor(0)[0];
|
||||
expect(tableData).toEqual(jasmine.objectContaining({
|
||||
name: 'table1_table2',
|
||||
schema: 'erd1',
|
||||
}));
|
||||
expect(tableData.columns[0]).toEqual(jasmine.objectContaining({
|
||||
type: 'type1',
|
||||
name: 'table1_col1',
|
||||
attnum: 0,
|
||||
}));
|
||||
expect(tableData.columns[1]).toEqual(jasmine.objectContaining({
|
||||
type: 'type2',
|
||||
name: 'table2_col2',
|
||||
attnum: 1,
|
||||
}));
|
||||
|
||||
let linkData = {
|
||||
local_table_uid: 'newid1',
|
||||
local_column_attnum: 0,
|
||||
referenced_table_uid: 'id1',
|
||||
referenced_column_attnum : 1,
|
||||
};
|
||||
expect(bodyInstance.diagram.addLink.calls.argsFor(0)).toEqual([linkData, 'onetomany']);
|
||||
linkData = {
|
||||
local_table_uid: 'newid1',
|
||||
local_column_attnum: 1,
|
||||
referenced_table_uid: 'id2',
|
||||
referenced_column_attnum : 2,
|
||||
};
|
||||
expect(bodyInstance.diagram.addLink.calls.argsFor(1)).toEqual([linkData, 'onetomany']);
|
||||
});
|
||||
|
||||
it('onNoteClick', ()=>{
|
||||
let noteNode = {key: 'value', getNote: ()=>'a note'};
|
||||
spyOn(bodyInstance.diagram, 'getSelectedNodes').and.returnValue([noteNode]);
|
||||
spyOn(bodyInstance.diagram.getEngine(), 'getNodeElement').and.returnValue(null);
|
||||
spyOn(bodyInstance.diagram.getEngine(), 'getNodeElement').and.returnValue(null);
|
||||
spyOn(bodyInstance, 'setState');
|
||||
bodyInstance.onNoteClick();
|
||||
expect(bodyInstance.setState).toHaveBeenCalledWith({
|
||||
note_node: noteNode,
|
||||
note_open: true,
|
||||
});
|
||||
});
|
||||
it('dummy', ()=>{});
|
||||
});
|
||||
|
||||
// import React from 'react';
|
||||
|
||||
// import MockAdapter from 'axios-mock-adapter';
|
||||
// import axios from 'axios/index';
|
||||
// import pgAdmin from '../../fake_pgadmin';
|
||||
|
||||
// import ERDCore from 'pgadmin.tools.erd/erd_tool/ERDCore';
|
||||
// import * as erdModule from 'pgadmin.tools.erd/ERDModule';
|
||||
// import erdPref from './erd_preferences';
|
||||
// import ERDTool from 'pgadmin.tools.erd/erd_tool/components/ERDTool';
|
||||
// import * as ERDSqlTool from 'tools/sqleditor/static/js/show_query_tool';
|
||||
// import { FakeLink, FakeNode, FakePort } from '../fake_item';
|
||||
// import Theme from '../../../../pgadmin/static/js/Theme';
|
||||
// import ModalProvider from '../../../../pgadmin/static/js/helpers/ModalProvider';
|
||||
// import { render } from '@testing-library/react';
|
||||
// import usePreferences from '../../../../pgadmin/preferences/static/js/store';
|
||||
// import userEvent from '@testing-library/user-event';
|
||||
|
||||
// let tableDialog = jest.fn();
|
||||
// let otmDialog = jest.fn();
|
||||
// let mtmDialog = jest.fn();
|
||||
|
||||
// let getDialog = (dialogName)=>{
|
||||
// switch(dialogName) {
|
||||
// case 'table_dialog': return tableDialog;
|
||||
// case 'onetomany_dialog': return otmDialog;
|
||||
// case 'manytomany_dialog': return mtmDialog;
|
||||
// }
|
||||
// };
|
||||
|
||||
// describe('ERDTool', ()=>{
|
||||
// let erd = null;
|
||||
// let body = null;
|
||||
// let bodyInstance = null;
|
||||
// let networkMock = null;
|
||||
// let serverVersion = 120000;
|
||||
// let colTypes = [
|
||||
// {'label': 'integer', 'value': 'integer'},
|
||||
// {'label': 'character varrying', 'value': 'character varrying'},
|
||||
// ];
|
||||
// let schemas = [
|
||||
// {'oid': 111, 'name': 'erd1'},
|
||||
// {'oid': 222, 'name': 'erd2'},
|
||||
// ];
|
||||
// let params = {
|
||||
// bgcolor: null,
|
||||
// client_platform: 'macos',
|
||||
// did: '13637',
|
||||
// fgcolor: null,
|
||||
// gen: true,
|
||||
// is_desktop_mode: true,
|
||||
// is_linux: false,
|
||||
// server_type: 'pg',
|
||||
// sgid: '1',
|
||||
// sid: '5',
|
||||
// title: 'postgres/postgres@PostgreSQL 12',
|
||||
// trans_id: 110008,
|
||||
// };
|
||||
// let newNode = new FakeNode({
|
||||
// columns: [{attnum: 0}, {attnum: 1}],
|
||||
// }, 'newid1');
|
||||
|
||||
// beforeAll(()=>{
|
||||
// jest.spyOn(erdModule, 'setPanelTitle').mockImplementation(() => {});
|
||||
// jest.spyOn(ERDCore.prototype, 'repaint').mockImplementation(() => {});
|
||||
// jest.spyOn(ERDCore.prototype, 'deserializeData').mockImplementation(() => {});
|
||||
// jest.spyOn(ERDCore.prototype, 'addNode').mockReturnValue(newNode);
|
||||
// jest.spyOn(ERDCore.prototype, 'addLink').mockReturnValue(new FakeLink());
|
||||
// jest.spyOn(usePreferences.getState(), 'getPreferencesForModule').mockImplementation((module)=>{
|
||||
// if(module == 'erd') {
|
||||
// return erdPref;
|
||||
// }
|
||||
// return {};
|
||||
// })
|
||||
// networkMock = new MockAdapter(axios);
|
||||
// networkMock.onPost('/erd/initialize/110008/1/5/13637').reply(200, {'data': {
|
||||
// serverVersion: serverVersion,
|
||||
// }});
|
||||
// networkMock.onGet('/erd/prequisite/110008/1/5/13637').reply(200, {'data': {
|
||||
// 'col_types': colTypes,
|
||||
// 'schemas': schemas,
|
||||
// }});
|
||||
// networkMock.onGet('/erd/tables/110008/1/5/13637').reply(200, {'data': []});
|
||||
|
||||
// networkMock.onPost('/erd/sql/110008/1/5/13637').reply(200, {'data': 'SELECT 1;'});
|
||||
|
||||
// networkMock.onPost('/sqleditor/load_file/').reply(200, {'data': 'data'});
|
||||
// networkMock.onPost('/sqleditor/save_file/').reply(200, {'data': 'data'});
|
||||
// });
|
||||
|
||||
// beforeEach(()=>{
|
||||
// erd = render(
|
||||
// <Theme>
|
||||
// <ModalProvider>
|
||||
// <ERDTool params={params} pgAdmin={pgAdmin} pgWindow={{
|
||||
// pgAdmin: pgAdmin
|
||||
// }} isTest={true} panelDocker={pgAdmin.Browser.docker}/>
|
||||
// </ModalProvider>
|
||||
// </Theme>
|
||||
// );
|
||||
// });
|
||||
|
||||
// afterAll(() => {
|
||||
// networkMock.restore();
|
||||
// });
|
||||
|
||||
// it('event offsetUpdated', (done)=>{
|
||||
// bodyInstance.diagram.fireEvent({offsetX: 4, offsetY: 5}, 'offsetUpdated', true);
|
||||
// setTimeout(()=>{
|
||||
// expect(bodyInstance.canvasEle.style.backgroundPosition).toBe('4px 5px');
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('event zoomUpdated', (done)=>{
|
||||
// jest.spyOn(bodyInstance.diagram.getModel(), 'getOptions').mockReturnValue({gridSize: 15});
|
||||
// bodyInstance.diagram.fireEvent({zoom: 20}, 'zoomUpdated', true);
|
||||
// setTimeout(()=>{
|
||||
// expect(bodyInstance.canvasEle.style.backgroundSize).toBe('9px 9px');
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('event nodesSelectionChanged', (done)=>{
|
||||
// jest.spyOn(bodyInstance.diagram, 'getSelectedNodes').mockReturnValue([new FakeNode({key:'value'})]);
|
||||
// bodyInstance.diagram.fireEvent({}, 'nodesSelectionChanged', true);
|
||||
// setTimeout(()=>{
|
||||
// expect(body.state().single_node_selected).toBe(true);
|
||||
// expect(body.state().any_item_selected).toBe(true);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('event linksSelectionChanged', (done)=>{
|
||||
// jest.spyOn(bodyInstance.diagram, 'getSelectedLinks').mockReturnValue([{key:'value'}]);
|
||||
// bodyInstance.diagram.fireEvent({}, 'linksSelectionChanged', true);
|
||||
// setTimeout(()=>{
|
||||
// expect(body.state().single_link_selected).toBe(true);
|
||||
// expect(body.state().any_item_selected).toBe(true);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('event linksUpdated', (done)=>{
|
||||
// bodyInstance.diagram.fireEvent({}, 'linksUpdated', true);
|
||||
// setTimeout(()=>{
|
||||
// expect(body.state().dirty).toBe(true);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('event nodesUpdated', (done)=>{
|
||||
// bodyInstance.diagram.fireEvent({}, 'nodesUpdated', true);
|
||||
// setTimeout(()=>{
|
||||
// expect(body.state().dirty).toBe(true);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('event showNote', (done)=>{
|
||||
// let noteNode = {key: 'value', getNote: ()=>'a note'};
|
||||
// jest.spyOn(bodyInstance, 'showNote').mockImplementation(() => {});
|
||||
// bodyInstance.diagram.fireEvent({node: noteNode}, 'showNote', true);
|
||||
// setTimeout(()=>{
|
||||
// expect(bodyInstance.showNote).toHaveBeenCalledWith(noteNode);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('event editTable', (done)=>{
|
||||
// let node = {key: 'value', getNote: ()=>'a note'};
|
||||
// jest.spyOn(bodyInstance, 'addEditTable').mockImplementation(() => {});
|
||||
// bodyInstance.diagram.fireEvent({node: node}, 'editTable', true);
|
||||
// setTimeout(()=>{
|
||||
// expect(bodyInstance.addEditTable).toHaveBeenCalledWith(node);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('addEditTable', ()=>{
|
||||
// let node1 = new FakeNode({'name': 'table1', schema: 'erd1', columns: [{name: 'col1', type: 'type1', attnum: 1}]}, 'id1');
|
||||
// let node2 = new FakeNode({'name': 'table2', schema: 'erd2', columns: [{name: 'col2', type: 'type2', attnum: 2}]}, 'id2');
|
||||
// let nodesDict = {
|
||||
// 'id1': node1,
|
||||
// 'id2': node2,
|
||||
// };
|
||||
// jest.spyOn(bodyInstance.diagram, 'getModel').mockReturnValue({
|
||||
// 'getNodesDict': ()=>nodesDict,
|
||||
// });
|
||||
// jest.spyOn(bodyInstance.diagram, 'addLink').mockImplementation(() => {});
|
||||
// jest.spyOn(bodyInstance.diagram, 'syncTableLinks').mockImplementation(() => {});
|
||||
// /* New */
|
||||
// tableDialog.mockClear();
|
||||
// bodyInstance.addEditTable();
|
||||
// expect(tableDialog).toHaveBeenCalled();
|
||||
|
||||
// let saveCallback = tableDialog.mock.calls[tableDialog.mock.calls.length - 1][3];
|
||||
// let newData = {key: 'value'};
|
||||
// saveCallback(newData);
|
||||
// expect(bodyInstance.diagram.addNode.mock.calls[bodyInstance.diagram.addNode.mock.calls.length - 1][0]).toEqual(newData);
|
||||
|
||||
// /* Existing */
|
||||
// tableDialog.mockClear();
|
||||
// let node = new FakeNode({name: 'table1', schema: 'erd1'});
|
||||
// jest.spyOn(node, 'setData').mockImplementation(() => {});
|
||||
// bodyInstance.addEditTable(node);
|
||||
// expect(tableDialog).toHaveBeenCalled();
|
||||
|
||||
// saveCallback = tableDialog.mock.calls[tableDialog.mock.calls.length - 1][3];
|
||||
// newData = {key: 'value'};
|
||||
// saveCallback(newData);
|
||||
// expect(node.setData).toHaveBeenCalledWith(newData);
|
||||
// });
|
||||
|
||||
// it('onEditTable', ()=>{
|
||||
// let node = {key: 'value'};
|
||||
// jest.spyOn(bodyInstance, 'addEditTable').mockImplementation(() => {});
|
||||
// jest.spyOn(bodyInstance.diagram, 'getSelectedNodes').mockReturnValue([node]);
|
||||
// bodyInstance.onEditTable();
|
||||
// expect(bodyInstance.addEditTable).toHaveBeenCalledWith(node);
|
||||
// });
|
||||
|
||||
// it('onAddNewNode', ()=>{
|
||||
// jest.spyOn(bodyInstance, 'addEditTable').mockImplementation(() => {});
|
||||
// bodyInstance.onAddNewNode();
|
||||
// expect(bodyInstance.addEditTable).toHaveBeenCalled();
|
||||
// });
|
||||
|
||||
// it('onCloneNode', ()=>{
|
||||
// let node = new FakeNode({name: 'table1', schema: 'erd1'});
|
||||
// jest.spyOn(bodyInstance.diagram, 'getSelectedNodes').mockReturnValue([node]);
|
||||
// jest.spyOn(bodyInstance.diagram, 'getNextTableName').mockReturnValue('newtable1');
|
||||
// bodyInstance.diagram.addNode.mockClear();
|
||||
// bodyInstance.onCloneNode();
|
||||
// let cloneArgs = bodyInstance.diagram.addNode.mock.calls[0];
|
||||
// expect(cloneArgs[0]).toEqual(expect.objectContaining({
|
||||
// name: 'newtable1',
|
||||
// schema: 'erd1',
|
||||
// }));
|
||||
// expect(cloneArgs[1]).toEqual([50, 50]);
|
||||
// });
|
||||
|
||||
// it('onDeleteNode', (done)=>{
|
||||
// let node = new FakeNode({name: 'table1', schema: 'erd1'});
|
||||
// let link = new FakeLink({local_table_uid: 'tid1'});
|
||||
// let port = new FakePort();
|
||||
// jest.spyOn(port, 'getLinks').mockReturnValue([link]);
|
||||
// jest.spyOn(node, 'remove').mockImplementation(() => {});
|
||||
// jest.spyOn(node, 'getPorts').mockReturnValue([port]);
|
||||
// let nodesDict = {
|
||||
// 'tid1': node
|
||||
// };
|
||||
// jest.spyOn(bodyInstance.diagram, 'getModel').mockReturnValue({
|
||||
// 'getNodesDict': ()=>nodesDict,
|
||||
// });
|
||||
// jest.spyOn(bodyInstance.diagram, 'removeOneToManyLink').mockImplementation(() => {});
|
||||
// jest.spyOn(bodyInstance.diagram, 'getSelectedNodes').mockReturnValue([node]);
|
||||
// jest.spyOn(bodyInstance.diagram, 'getSelectedLinks').mockReturnValue([link]);
|
||||
|
||||
// bodyInstance.onDeleteNode();
|
||||
// setTimeout(()=>{
|
||||
// expect(node.remove).toHaveBeenCalled();
|
||||
// expect(bodyInstance.diagram.removeOneToManyLink).toHaveBeenCalledWith(link);
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('onAutoDistribute', ()=>{
|
||||
// jest.spyOn(bodyInstance.diagram, 'dagreDistributeNodes').mockImplementation(()=>{/* intentionally empty */});
|
||||
// bodyInstance.onAutoDistribute();
|
||||
// expect(bodyInstance.diagram.dagreDistributeNodes).toHaveBeenCalled();
|
||||
// });
|
||||
|
||||
// it('onDetailsToggle', (done)=>{
|
||||
// let node = {
|
||||
// 'fireEvent': jest.fn()
|
||||
// };
|
||||
// jest.spyOn(bodyInstance.diagram, 'getModel').mockReturnValue({
|
||||
// 'getNodes': ()=>[node],
|
||||
// });
|
||||
|
||||
// let show_details = body.state().show_details;
|
||||
// bodyInstance.onDetailsToggle();
|
||||
// body.setState({}, ()=>{
|
||||
// expect(body.state().show_details).toBe(!show_details);
|
||||
// expect(node.fireEvent).toHaveBeenCalledWith({show_details: !show_details}, 'toggleDetails');
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('onLoadDiagram', ()=>{
|
||||
// bodyInstance.onLoadDiagram();
|
||||
// expect(pgAdmin.Tools.FileManager.show).toHaveBeenCalled();
|
||||
// });
|
||||
|
||||
// it('openFile', (done)=>{
|
||||
// jest.spyOn(bodyInstance.diagram, 'deserialize').mockImplementation(() => {});
|
||||
// bodyInstance.openFile('test.pgerd');
|
||||
// setTimeout(()=>{
|
||||
// expect(body.state()).toEqual(expect.objectContaining({
|
||||
// current_file: 'test.pgerd',
|
||||
// dirty: false,
|
||||
// }));
|
||||
// expect(bodyInstance.diagram.deserialize).toHaveBeenCalledWith({data: 'data'});
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('onSaveDiagram', (done)=>{
|
||||
// body.setState({
|
||||
// current_file: 'newfile.pgerd',
|
||||
// });
|
||||
// bodyInstance.onSaveDiagram();
|
||||
// setTimeout(()=>{
|
||||
// expect(body.state()).toEqual(expect.objectContaining({
|
||||
// current_file: 'newfile.pgerd',
|
||||
// dirty: false,
|
||||
// }));
|
||||
// done();
|
||||
// });
|
||||
|
||||
// pgAdmin.Tools.FileManager.show.mockClear();
|
||||
// bodyInstance.onSaveDiagram(true);
|
||||
// expect(pgAdmin.Tools.FileManager.show.mock.calls[0][0]).toEqual({
|
||||
// 'supported_types': ['*','pgerd'],
|
||||
// 'dialog_type': 'create_file',
|
||||
// 'dialog_title': 'Save File',
|
||||
// 'btn_primary': 'Save',
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('onSaveAsDiagram', ()=>{
|
||||
// jest.spyOn(bodyInstance, 'onSaveDiagram').mockImplementation(() => {});
|
||||
// bodyInstance.onSaveAsDiagram();
|
||||
// expect(bodyInstance.onSaveDiagram).toHaveBeenCalledWith(true);
|
||||
// });
|
||||
|
||||
// it('onSQLClick', (done)=>{
|
||||
// jest.spyOn(bodyInstance.diagram, 'serializeData').mockReturnValue({key: 'value'});
|
||||
// jest.spyOn(ERDSqlTool, 'showERDSqlTool').mockImplementation(() => {});
|
||||
// jest.spyOn(localStorage, 'setItem').mockImplementation(() => {});
|
||||
// bodyInstance.onSQLClick();
|
||||
|
||||
// setTimeout(()=>{
|
||||
// let sql = '-- This script was generated by the ERD tool in pgAdmin 4.\n'
|
||||
// + '-- Please log an issue at https://redmine.postgresql.org/projects/pgadmin4/issues/new if you find any bugs, including reproduction steps.\n'
|
||||
// + 'BEGIN;\nSELECT 1;\nEND;';
|
||||
|
||||
// expect(localStorage.setItem).toHaveBeenCalledWith('erd'+params.trans_id, sql);
|
||||
// expect(ERDSqlTool.showERDSqlTool).toHaveBeenCalled();
|
||||
// done();
|
||||
// });
|
||||
// });
|
||||
|
||||
// it('onOneToManyClick', ()=>{
|
||||
// let node = new FakeNode({}, 'id1');
|
||||
// let node1 = new FakeNode({'name': 'table1', schema: 'erd1', columns: [{name: 'col1', type: 'type1', attnum: 1}]}, 'id1');
|
||||
// let node2 = new FakeNode({'name': 'table2', schema: 'erd2', columns: [{name: 'col2', type: 'type2', attnum: 2}]}, 'id2');
|
||||
// let nodesDict = {
|
||||
// 'id1': node1,
|
||||
// 'id2': node2,
|
||||
// };
|
||||
// jest.spyOn(bodyInstance.diagram, 'getModel').mockReturnValue({
|
||||
// 'getNodesDict': ()=>nodesDict,
|
||||
// });
|
||||
// jest.spyOn(bodyInstance.diagram, 'addLink').mockImplementation(() => {});
|
||||
// jest.spyOn(bodyInstance.diagram, 'getSelectedNodes').mockReturnValue([node]);
|
||||
|
||||
// bodyInstance.onOneToManyClick();
|
||||
// let saveCallback = otmDialog.mock.calls[otmDialog.mock.calls.length - 1][2];
|
||||
// let newData = {
|
||||
// local_table_uid: 'id1',
|
||||
// local_column_attnum: 1,
|
||||
// referenced_table_uid: 'id2',
|
||||
// referenced_column_attnum: 2,
|
||||
// };
|
||||
// saveCallback(newData);
|
||||
// expect(bodyInstance.diagram.addLink).toHaveBeenCalledWith(newData, 'onetomany');
|
||||
// });
|
||||
|
||||
// it('onManyToManyClick', ()=>{
|
||||
// let node = new FakeNode({}, 'id1');
|
||||
// let node1 = new FakeNode({'name': 'table1', schema: 'erd1', columns: [{name: 'col1', type: 'type1', attnum: 1}]}, 'id1');
|
||||
// let node2 = new FakeNode({'name': 'table2', schema: 'erd2', columns: [{name: 'col2', type: 'type2', attnum: 2}]}, 'id2');
|
||||
// let nodesDict = {
|
||||
// 'id1': node1,
|
||||
// 'id2': node2,
|
||||
// 'newid1': newNode,
|
||||
// };
|
||||
// jest.spyOn(bodyInstance.diagram, 'getModel').mockReturnValue({
|
||||
// 'getNodesDict': ()=>nodesDict,
|
||||
// });
|
||||
// jest.spyOn(bodyInstance.diagram, 'getSelectedNodes').mockReturnValue([node]);
|
||||
|
||||
// bodyInstance.onManyToManyClick();
|
||||
|
||||
// /* onSave */
|
||||
// jest.spyOn(bodyInstance.diagram, 'addLink').mockImplementation(() => {});
|
||||
// let saveCallback = mtmDialog.mock.calls[mtmDialog.mock.calls.length - 1][2];
|
||||
// let newData = {
|
||||
// left_table_uid: 'id1',
|
||||
// left_table_column_attnum: 1,
|
||||
// right_table_uid: 'id2',
|
||||
// right_table_column_attnum: 2,
|
||||
// };
|
||||
|
||||
// bodyInstance.diagram.addNode.mockClear();
|
||||
// bodyInstance.diagram.addLink.mockClear();
|
||||
// saveCallback(newData);
|
||||
// let tableData = bodyInstance.diagram.addNode.mock.calls[0][0];
|
||||
// expect(tableData).toEqual(expect.objectContaining({
|
||||
// name: 'table1_table2',
|
||||
// schema: 'erd1',
|
||||
// }));
|
||||
// expect(tableData.columns[0]).toEqual(expect.objectContaining({
|
||||
// type: 'type1',
|
||||
// name: 'table1_col1',
|
||||
// attnum: 0,
|
||||
// }));
|
||||
// expect(tableData.columns[1]).toEqual(expect.objectContaining({
|
||||
// type: 'type2',
|
||||
// name: 'table2_col2',
|
||||
// attnum: 1,
|
||||
// }));
|
||||
|
||||
// let linkData = {
|
||||
// local_table_uid: 'newid1',
|
||||
// local_column_attnum: 0,
|
||||
// referenced_table_uid: 'id1',
|
||||
// referenced_column_attnum : 1,
|
||||
// };
|
||||
// expect(bodyInstance.diagram.addLink.mock.calls[0]).toEqual([linkData, 'onetomany']);
|
||||
// linkData = {
|
||||
// local_table_uid: 'newid1',
|
||||
// local_column_attnum: 1,
|
||||
// referenced_table_uid: 'id2',
|
||||
// referenced_column_attnum : 2,
|
||||
// };
|
||||
// expect(bodyInstance.diagram.addLink.mock.calls[1]).toEqual([linkData, 'onetomany']);
|
||||
// });
|
||||
|
||||
// it('onNoteClick', ()=>{
|
||||
// let noteNode = {key: 'value', getNote: ()=>'a note'};
|
||||
// jest.spyOn(bodyInstance.diagram, 'getSelectedNodes').mockReturnValue([noteNode]);
|
||||
// jest.spyOn(bodyInstance.diagram.getEngine(), 'getNodeElement').mockReturnValue(null);
|
||||
// jest.spyOn(bodyInstance.diagram.getEngine(), 'getNodeElement').mockReturnValue(null);
|
||||
// jest.spyOn(bodyInstance, 'setState').mockImplementation(() => {});
|
||||
// bodyInstance.onNoteClick();
|
||||
// expect(bodyInstance.setState).toHaveBeenCalledWith({
|
||||
// note_node: noteNode,
|
||||
// note_open: true,
|
||||
// });
|
||||
// });
|
||||
// });
|
||||
|
||||
@@ -1,44 +1,47 @@
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import React from 'react';
|
||||
import {mount} from 'enzyme';
|
||||
import '../../helper/enzyme.helper';
|
||||
|
||||
import FloatingNote from 'pgadmin.tools.erd/erd_tool/components/FloatingNote';
|
||||
import Theme from '../../../../pgadmin/static/js/Theme';
|
||||
import { act, render } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
describe('ERD FloatingNote', ()=>{
|
||||
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
});
|
||||
|
||||
it('<FloatingNote /> on OK click', ()=>{
|
||||
it('<FloatingNote /> on OK click', async ()=>{
|
||||
let floatNote = null;
|
||||
let onClose = jasmine.createSpy('onClose');
|
||||
let onClose = jest.fn();
|
||||
let noteNode = {
|
||||
getNote: function() {
|
||||
return 'some note';
|
||||
},
|
||||
setNote: jasmine.createSpy('setNote'),
|
||||
setNote: jest.fn(),
|
||||
getSchemaTableName: function() {
|
||||
return ['schema1', 'table1'];
|
||||
},
|
||||
};
|
||||
const user = userEvent.setup();
|
||||
|
||||
floatNote = mount(
|
||||
<Theme>
|
||||
<FloatingNote
|
||||
open={true} onClose={onClose} anchorEl={document.body} rows={8} noteNode={noteNode}
|
||||
/>
|
||||
</Theme>);
|
||||
|
||||
floatNote.find('textarea').simulate('change', {
|
||||
target: {
|
||||
value: 'the new note',
|
||||
},
|
||||
await act(async ()=>{
|
||||
floatNote = await render(
|
||||
<Theme>
|
||||
<FloatingNote
|
||||
open={true} onClose={onClose} anchorEl={document.body} rows={8} noteNode={noteNode}
|
||||
/>
|
||||
</Theme>);
|
||||
});
|
||||
|
||||
floatNote.find('DefaultButton').simulate('click');
|
||||
await user.clear(floatNote.container.querySelector('textarea'));
|
||||
await user.type(floatNote.container.querySelector('textarea'), 'the new note');
|
||||
await user.click(floatNote.container.querySelector('button'));
|
||||
expect(noteNode.setNote).toHaveBeenCalledWith('the new note');
|
||||
expect(onClose).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
@@ -7,10 +7,14 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
define(function () {
|
||||
return {
|
||||
'id': 'pgadmin4@pgadmin.org',
|
||||
'current_auth_source': 'internal'
|
||||
};
|
||||
});
|
||||
// define(function () {
|
||||
// return {
|
||||
// 'id': 'pgadmin4@pgadmin.org',
|
||||
// 'current_auth_source': 'internal'
|
||||
// };
|
||||
// });
|
||||
|
||||
module.exports = {
|
||||
'id': 'pgadmin4@pgadmin.org',
|
||||
'current_auth_source': 'internal'
|
||||
};
|
||||
|
||||
@@ -7,38 +7,36 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
define(function () {
|
||||
return {
|
||||
'static': '/base/pgadmin/static/<path:filename>',
|
||||
'sqleditor.poll': '/sqleditor/query_tool/poll/<path:trans_id>',
|
||||
'sqleditor.query_tool_start': '/sqleditor/query_tool/start/<path:trans_id>',
|
||||
'backup.create_server_job': '/backup/job/<int:sid>',
|
||||
'backup.create_object_job': '/backup/job/<int:sid>/object',
|
||||
'sqleditor.initialize_viewdata': '/initialize/sqleditor/<int:cmd_type>/<obj_type>/<int:sgid>/<int:sid>/<int:did>/<int:obj_id>',
|
||||
'sqleditor.initialize_sqleditor': '/initialize/sqleditor/<int:sgid>/<int:sid>',
|
||||
'sqleditor.initialize_sqleditor_with_did': '/initialize/sqleditor/<int:sgid>/<int:sid>/<int:did>',
|
||||
'restore.create_job': '/restore/job/<int:sid>',
|
||||
'sqleditor.panel': '/panel/<int:trans_id>',
|
||||
'search_objects.types': '/search_objects/types/<int:sid>/<int:did>',
|
||||
'search_objects.search': '/search_objects/search/<int:sid>/<int:did>',
|
||||
'dashboard.dashboard_stats': '/dashboard/dashboard_stats',
|
||||
'sqleditor.load_file': '/sqleditor/load_file/',
|
||||
'sqleditor.save_file': '/sqleditor/save_file/',
|
||||
'erd.initialize': '/erd/initialize/<int:trans_id>/<int:sgid>/<int:sid>/<int:did>',
|
||||
'erd.sql': '/erd/sql/<int:trans_id>/<int:sgid>/<int:sid>/<int:did>',
|
||||
'erd.prequisite': '/erd/prequisite/<int:trans_id>/<int:sgid>/<int:sid>/<int:did>',
|
||||
'erd.tables': '/erd/tables/<int:trans_id>/<int:sgid>/<int:sid>/<int:did>',
|
||||
'file_manager.init': '/file_manager/init',
|
||||
'file_manager.filemanager': '/file_manager/init',
|
||||
'file_manager.index': '/file_manager/',
|
||||
'file_manager.delete_trans_id': '/file_manager/delete_trans_id/<int:trans_id>',
|
||||
'file_manager.save_last_dir': '/file_manager/save_last_dir/<int:trans_id>',
|
||||
'file_manager.save_file_dialog_view': '/file_manager/save_file_dialog_view/<int:trans_id>',
|
||||
'file_manager.save_show_hidden_file_option': '/file_manager/save_show_hidden_file_option/<int:trans_id>',
|
||||
'settings.save_file_format_setting': '/settings/save_file_format_setting/',
|
||||
'bgprocess.detailed_status': '/misc/bgprocess/<pid>/<int:out>/<int:err>/',
|
||||
'bgprocess.list': '/misc/bgprocess/',
|
||||
'bgprocess.stop_process': '/misc/bgprocess/stop/<pid>',
|
||||
'bgprocess.acknowledge': '/misc/bgprocess/<pid>'
|
||||
};
|
||||
});
|
||||
module.exports = {
|
||||
'static': '/base/pgadmin/static/<path:filename>',
|
||||
'sqleditor.poll': '/sqleditor/query_tool/poll/<path:trans_id>',
|
||||
'sqleditor.query_tool_start': '/sqleditor/query_tool/start/<path:trans_id>',
|
||||
'backup.create_server_job': '/backup/job/<int:sid>',
|
||||
'backup.create_object_job': '/backup/job/<int:sid>/object',
|
||||
'sqleditor.initialize_viewdata': '/initialize/sqleditor/<int:cmd_type>/<obj_type>/<int:sgid>/<int:sid>/<int:did>/<int:obj_id>',
|
||||
'sqleditor.initialize_sqleditor': '/initialize/sqleditor/<int:sgid>/<int:sid>',
|
||||
'sqleditor.initialize_sqleditor_with_did': '/initialize/sqleditor/<int:sgid>/<int:sid>/<int:did>',
|
||||
'restore.create_job': '/restore/job/<int:sid>',
|
||||
'sqleditor.panel': '/panel/<int:trans_id>',
|
||||
'search_objects.types': '/search_objects/types/<int:sid>/<int:did>',
|
||||
'search_objects.search': '/search_objects/search/<int:sid>/<int:did>',
|
||||
'dashboard.dashboard_stats': '/dashboard/dashboard_stats',
|
||||
'sqleditor.load_file': '/sqleditor/load_file/',
|
||||
'sqleditor.save_file': '/sqleditor/save_file/',
|
||||
'erd.initialize': '/erd/initialize/<int:trans_id>/<int:sgid>/<int:sid>/<int:did>',
|
||||
'erd.sql': '/erd/sql/<int:trans_id>/<int:sgid>/<int:sid>/<int:did>',
|
||||
'erd.prequisite': '/erd/prequisite/<int:trans_id>/<int:sgid>/<int:sid>/<int:did>',
|
||||
'erd.tables': '/erd/tables/<int:trans_id>/<int:sgid>/<int:sid>/<int:did>',
|
||||
'file_manager.init': '/file_manager/init',
|
||||
'file_manager.filemanager': '/file_manager/init',
|
||||
'file_manager.index': '/file_manager/',
|
||||
'file_manager.delete_trans_id': '/file_manager/delete_trans_id/<int:trans_id>',
|
||||
'file_manager.save_last_dir': '/file_manager/save_last_dir/<int:trans_id>',
|
||||
'file_manager.save_file_dialog_view': '/file_manager/save_file_dialog_view/<int:trans_id>',
|
||||
'file_manager.save_show_hidden_file_option': '/file_manager/save_show_hidden_file_option/<int:trans_id>',
|
||||
'settings.save_file_format_setting': '/settings/save_file_format_setting/',
|
||||
'bgprocess.detailed_status': '/misc/bgprocess/<pid>/<int:out>/<int:err>/',
|
||||
'bgprocess.list': '/misc/bgprocess/',
|
||||
'bgprocess.stop_process': '/misc/bgprocess/stop/<pid>',
|
||||
'bgprocess.acknowledge': '/misc/bgprocess/<pid>'
|
||||
};
|
||||
|
||||
16
web/regression/javascript/fake_gettext.js
Normal file
16
web/regression/javascript/fake_gettext.js
Normal file
@@ -0,0 +1,16 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
import * as pgUtils from 'sources/utils';
|
||||
import translations from 'translations';
|
||||
|
||||
export default function gettext(text, ...args) {
|
||||
// return text;
|
||||
return pgUtils.gettextForTranslation(translations, text, ...args);
|
||||
}
|
||||
@@ -6,16 +6,7 @@
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
define('pgadmin.browser.messages',['sources/pgadmin'], function(pgAdmin) {
|
||||
let pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
|
||||
if (pgBrowser.messages)
|
||||
return pgBrowser.messages;
|
||||
|
||||
pgBrowser.messages = {
|
||||
'CANNOT_BE_EMPTY': '\'%s\' cannot be empty.',
|
||||
'MUST_BE_INT': '\'%s\' must be an integer.'
|
||||
};
|
||||
return pgBrowser;
|
||||
});
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
let pgBrowser = pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgBrowser.messages = pgBrowser.messages || {};
|
||||
module.exports = pgBrowser;
|
||||
|
||||
@@ -6,31 +6,94 @@
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
import {messages} from './fake_messages';
|
||||
|
||||
const fakePgAdmin = {
|
||||
Browser: {
|
||||
messages: messages,
|
||||
Events: {
|
||||
on: jasmine.createSpy('on'),
|
||||
import EventBus from '../../pgadmin/static/js/helpers/EventBus';
|
||||
|
||||
const Browser = {
|
||||
messages: {
|
||||
'CANNOT_BE_EMPTY': '\'%s\' cannot be empty.',
|
||||
'MUST_BE_INT': '\'%s\' must be an integer.'
|
||||
},
|
||||
Events: new EventBus(),
|
||||
get_preferences_for_module: ()=>({}),
|
||||
docker: {
|
||||
eventBus: new EventBus(),
|
||||
find: ()=>{},
|
||||
openTab: ()=>{},
|
||||
focus: ()=>{},
|
||||
},
|
||||
onPreferencesChange: ()=>{/*This is intentional (SonarQube)*/},
|
||||
utils: {
|
||||
app_version_int: 1234,
|
||||
},
|
||||
Tools: {
|
||||
SQLEditor: {},
|
||||
FileManager: {
|
||||
show: jest.fn(),
|
||||
},
|
||||
get_preferences_for_module: ()=>({}),
|
||||
docker: {
|
||||
findPanels: function() {
|
||||
return [
|
||||
{
|
||||
isVisible: function() {
|
||||
return true;
|
||||
},
|
||||
},
|
||||
];
|
||||
},
|
||||
},
|
||||
Nodes: {
|
||||
server: {
|
||||
hasId: true,
|
||||
getTreeNodeHierarchy: jest.fn(),
|
||||
},
|
||||
onPreferencesChange: ()=>{/*This is intentional (SonarQube)*/},
|
||||
utils: {
|
||||
app_version_int: 1234,
|
||||
database: {
|
||||
hasId: true,
|
||||
getTreeNodeHierarchy: jest.fn(),
|
||||
},
|
||||
'coll-sometype': {
|
||||
type: 'coll-sometype',
|
||||
hasId: false,
|
||||
label: 'Some types coll',
|
||||
},
|
||||
sometype: {
|
||||
type: 'sometype',
|
||||
hasId: true,
|
||||
},
|
||||
someothertype: {
|
||||
type: 'someothertype',
|
||||
hasId: true,
|
||||
collection_type: 'coll-sometype',
|
||||
},
|
||||
'coll-edbfunc': {
|
||||
type: 'coll-edbfunc',
|
||||
hasId: true,
|
||||
label: 'Functions',
|
||||
},
|
||||
'coll-edbproc': {
|
||||
type: 'coll-edbfunc',
|
||||
hasId: true,
|
||||
label: 'Procedures',
|
||||
},
|
||||
'coll-edbvar': {
|
||||
type: 'coll-edbfunc',
|
||||
hasId: true,
|
||||
label: 'Variables',
|
||||
},
|
||||
},
|
||||
notifier: {
|
||||
alert: ()=>{/*This is intentional (SonarQube)*/},
|
||||
error: ()=>{/*This is intentional (SonarQube)*/},
|
||||
success: ()=>{/*This is intentional (SonarQube)*/},
|
||||
confirm: ()=>{/*This is intentional (SonarQube)*/},
|
||||
notify: ()=>{/*This is intentional (SonarQube)*/},
|
||||
},
|
||||
stdH: {
|
||||
sm: 200,
|
||||
md: 400,
|
||||
lg: 550,
|
||||
default: 550,
|
||||
},
|
||||
stdW: {
|
||||
sm: 500,
|
||||
md: 700,
|
||||
lg: 900,
|
||||
default: 500,
|
||||
},
|
||||
};
|
||||
|
||||
const fakePgAdmin = {
|
||||
Browser: Browser,
|
||||
};
|
||||
|
||||
export default fakePgAdmin;
|
||||
|
||||
@@ -7,10 +7,8 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
define(function () {
|
||||
return [
|
||||
{label: 'EDB Advanced Server', value: 'ppas'},
|
||||
{label: 'PostgreSQL', value: 'pg'},
|
||||
{label: 'Unknown', value: ''},
|
||||
];
|
||||
});
|
||||
module.exports = [
|
||||
{label: 'EDB Advanced Server', value: 'ppas'},
|
||||
{label: 'PostgreSQL', value: 'pg'},
|
||||
{label: 'Unknown', value: ''},
|
||||
];
|
||||
|
||||
@@ -7,6 +7,4 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
define(function () {
|
||||
return {};
|
||||
});
|
||||
module.exports = {};
|
||||
|
||||
@@ -7,16 +7,18 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { render } from '@testing-library/react';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import FileManager, { FileManagerUtils, getComparator } from '../../../pgadmin/misc/file_manager/static/js/components/FileManager';
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
import axios from 'axios';
|
||||
import getApiInstance from '../../../pgadmin/static/js/api_instance';
|
||||
import * as pgUtils from '../../../pgadmin/static/js/utils';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
|
||||
const files = [
|
||||
{
|
||||
@@ -93,13 +95,10 @@ const params={
|
||||
};
|
||||
|
||||
describe('FileManger', ()=>{
|
||||
let mount;
|
||||
|
||||
let networkMock;
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(()=>{
|
||||
mount = createMount();
|
||||
networkMock = new MockAdapter(axios);
|
||||
networkMock.onPost(`/file_manager/filemanager/${transId}/`).reply(200, {data: {result: files}});
|
||||
networkMock.onPost(`/file_manager/save_file_dialog_view/${transId}`).reply(200, {});
|
||||
@@ -107,20 +106,19 @@ describe('FileManger', ()=>{
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
networkMock.restore();
|
||||
});
|
||||
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
|
||||
});
|
||||
|
||||
describe('FileManger', ()=>{
|
||||
let closeModal=jasmine.createSpy('closeModal'),
|
||||
onOK=jasmine.createSpy('onOK'),
|
||||
onCancel=jasmine.createSpy('onCancel'),
|
||||
ctrlMount = (props)=>{
|
||||
return mount(<Theme>
|
||||
let closeModal=jest.fn(),
|
||||
onOK=jest.fn(),
|
||||
onCancel=jest.fn(),
|
||||
ctrlMount = async (props)=>{
|
||||
return await render(<Theme>
|
||||
<FileManager
|
||||
params={params}
|
||||
closeModal={closeModal}
|
||||
@@ -133,55 +131,53 @@ describe('FileManger', ()=>{
|
||||
</Theme>);
|
||||
};
|
||||
|
||||
it('init', (done)=>{
|
||||
it('init', async ()=>{
|
||||
networkMock.onPost('/file_manager/init').reply(200, {'data': configData});
|
||||
networkMock.onPost(`/file_manager/save_last_dir/${transId}`).reply(200, {'success':1,'errormsg':'','info':'','result':null,'data':null});
|
||||
let ctrl = ctrlMount({});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
ctrl.find('button[name="menu-options"]').simulate('click');
|
||||
ctrl.find('Memo(MenuItem)[data-label="List View"]').simulate('click');
|
||||
ctrl.update();
|
||||
expect(ctrl.find('ListView').length).toBe(1);
|
||||
expect(ctrl.find('GridView').length).toBe(0);
|
||||
expect(ctrl.find('InputText[data-label="file-path"]').prop('value')).toBe('/home/current');
|
||||
ctrl.find('button[name="menu-options"]').simulate('click');
|
||||
ctrl.find('Memo(MenuItem)[data-label="Grid View"]').simulate('click');
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('ListView').length).toBe(0);
|
||||
expect(ctrl.find('GridView').length).toBe(1);
|
||||
done();
|
||||
}, 500);
|
||||
}, 0);
|
||||
let ctrl;
|
||||
await act(async ()=>{
|
||||
ctrl = await ctrlMount({});
|
||||
});
|
||||
const user = userEvent.setup();
|
||||
await user.click(ctrl.container.querySelector('[name="menu-options"]'));
|
||||
await user.click(ctrl.container.querySelector('[data-label="List View"]'));
|
||||
|
||||
expect(ctrl.container.querySelector('[id="list"]')).not.toBeNull();
|
||||
expect(ctrl.container.querySelector('[id="grid"]')).toBeNull();
|
||||
expect(ctrl.container.querySelector('[data-label="file-path"] input')).toHaveValue('/home/current');
|
||||
|
||||
await user.click(ctrl.container.querySelector('button[name="menu-options"]'));
|
||||
await user.click(ctrl.container.querySelector('[data-label="Grid View"]'));
|
||||
expect(ctrl.container.querySelector('[id="list"]')).toBeNull();
|
||||
expect(ctrl.container.querySelector('[id="grid"]')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('Change Shared Storage', (done)=>{
|
||||
it('Change Shared Storage', async ()=>{
|
||||
networkMock.onPost('/file_manager/init').reply(200, {'data': configData});
|
||||
networkMock.onPost(`/file_manager/save_last_dir/${transId}`).reply(200, {'success':1,'errormsg':'','info':'','result':null,'data':null});
|
||||
let ctrl = ctrlMount({});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
ctrl.find('button[name="menu-shared-storage"]').simulate('click');
|
||||
ctrl.find('Memo(MenuItem)[data-label="Shared Storage"]').simulate('click');
|
||||
ctrl.update();
|
||||
expect(ctrl.find('Shared Storage').length).toBe(0);
|
||||
done();
|
||||
}, 0);
|
||||
let ctrl;
|
||||
const user = userEvent.setup();
|
||||
await act(async ()=>{
|
||||
ctrl = await ctrlMount({});
|
||||
});
|
||||
|
||||
await user.click(ctrl.container.querySelector('[name="menu-shared-storage"]'));
|
||||
await user.click(ctrl.container.querySelector('[data-label="Shared Storage"]'));
|
||||
expect(ctrl.container.querySelector('button[aria-label="Shared Storage"]')).not.toBeNull();
|
||||
});
|
||||
|
||||
it('Change Storage to My Storage', (done)=>{
|
||||
it('Change Storage to My Storage', async ()=>{
|
||||
networkMock.onPost('/file_manager/init').reply(200, {'data': configData});
|
||||
networkMock.onPost(`/file_manager/save_last_dir/${transId}`).reply(200, {'success':1,'errormsg':'','info':'','result':null,'data':null});
|
||||
let ctrl = ctrlMount({});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
ctrl.find('button[name="menu-shared-storage"]').simulate('click');
|
||||
ctrl.find('Memo(MenuItem)[data-label="my_storage"]').simulate('click');
|
||||
ctrl.update();
|
||||
expect(ctrl.find('my_storage').length).toBe(0);
|
||||
done();
|
||||
}, 0);
|
||||
let ctrl;
|
||||
const user = userEvent.setup();
|
||||
await act(async ()=>{
|
||||
ctrl = await ctrlMount({});
|
||||
});
|
||||
|
||||
await user.click(ctrl.container.querySelector('[name="menu-shared-storage"]'));
|
||||
await user.click(ctrl.container.querySelector('[data-label="My Storage"]'));
|
||||
expect(ctrl.container.querySelector('button[aria-label="My Storage"]')).not.toBeNull();
|
||||
});
|
||||
|
||||
describe('getComparator', ()=>{
|
||||
@@ -350,7 +346,7 @@ describe('FileManagerUtils', ()=>{
|
||||
});
|
||||
|
||||
it('downloadFile', async ()=>{
|
||||
spyOn(pgUtils, 'downloadBlob');
|
||||
jest.spyOn(pgUtils, 'downloadBlob').mockImplementation(() => {});
|
||||
let row = {Filename: 'newfile1', Path: '/home/newfile1', 'storage_folder': 'my_storage'};
|
||||
await fmObj.downloadFile(row);
|
||||
expect(pgUtils.downloadBlob).toHaveBeenCalledWith('blobdata', 'newfile1');
|
||||
|
||||
@@ -7,34 +7,21 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { render } from '@testing-library/react';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import { ItemView } from '../../../pgadmin/misc/file_manager/static/js/components/GridView';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
describe('GridView', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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('ItemView', ()=>{
|
||||
let row = {'Filename': 'test.sql', 'Size': '1KB', 'file_type': 'dir'},
|
||||
ctrlMount = (props)=>{
|
||||
return mount(<Theme>
|
||||
return render(<Theme>
|
||||
<ItemView
|
||||
idx={0}
|
||||
selected={false}
|
||||
@@ -44,19 +31,14 @@ describe('GridView', ()=>{
|
||||
</Theme>);
|
||||
};
|
||||
|
||||
it('keydown Escape', (done)=>{
|
||||
const onEditComplete = jasmine.createSpy('onEditComplete');
|
||||
let ctrl = ctrlMount({
|
||||
it('keydown Escape', async ()=>{
|
||||
const onEditComplete = jest.fn();
|
||||
ctrlMount({
|
||||
onEditComplete: onEditComplete,
|
||||
});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
ctrl.find('div[data-test="filename-div"]').simulate('keydown', { code: 'Escape'});
|
||||
setTimeout(()=>{
|
||||
expect(onEditComplete).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
}, 0);
|
||||
const user = userEvent.setup();
|
||||
await user.keyboard('{Escape}');
|
||||
expect(onEditComplete).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,29 +7,16 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import { FileNameEditor } from '../../../pgadmin/misc/file_manager/static/js/components/ListView';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
describe('ListView', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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('FileNameEditor', ()=>{
|
||||
let row = {'Filename': 'test.sql', 'Size': '1KB'},
|
||||
@@ -37,7 +24,7 @@ describe('ListView', ()=>{
|
||||
key: 'Filename'
|
||||
},
|
||||
ctrlMount = (props)=>{
|
||||
return mount(<Theme>
|
||||
return render(<Theme>
|
||||
<FileNameEditor
|
||||
row={row}
|
||||
column={column}
|
||||
@@ -46,33 +33,25 @@ describe('ListView', ()=>{
|
||||
</Theme>);
|
||||
};
|
||||
|
||||
it('init', (done)=>{
|
||||
let ctrl = ctrlMount({
|
||||
it('init', async ()=>{
|
||||
ctrlMount({
|
||||
onRowChange: ()=>{/* test func */},
|
||||
onClose: ()=>{/* test func */},
|
||||
});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('input').props()).toEqual(jasmine.objectContaining({value: 'test.sql'}));
|
||||
done();
|
||||
}, 0);
|
||||
await waitFor(()=>{
|
||||
expect(screen.getByRole('textbox').value).toEqual('test.sql');
|
||||
});
|
||||
});
|
||||
|
||||
it('keydown Tab', (done)=>{
|
||||
let onCloseSpy = jasmine.createSpy('onClose');
|
||||
let ctrl = ctrlMount({
|
||||
it('keydown Tab', async ()=>{
|
||||
let onCloseSpy = jest.fn();
|
||||
ctrlMount({
|
||||
onRowChange: ()=>{/* test func */},
|
||||
onClose: onCloseSpy,
|
||||
});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('input').props()).toEqual(jasmine.objectContaining({value: 'test.sql'}));
|
||||
ctrl.find('input').simulate('keydown', { code: 'Tab'});
|
||||
setTimeout(()=>{
|
||||
expect(onCloseSpy).toHaveBeenCalled();
|
||||
done();
|
||||
});
|
||||
}, 0);
|
||||
const user = userEvent.setup();
|
||||
await user.type(screen.getByRole('textbox'), '{Tab}');
|
||||
expect(onCloseSpy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,36 +7,25 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { render, screen, waitFor } from '@testing-library/react';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import Uploader, { filesReducer, getFileSize, UploadedFile } from '../../../pgadmin/misc/file_manager/static/js/components/Uploader';
|
||||
import { MESSAGE_TYPE } from '../../../pgadmin/static/js/components/FormComponents';
|
||||
|
||||
describe('GridView', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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('Uploader', ()=>{
|
||||
let fmUtilsObj = jasmine.createSpyObj('fmUtilsObj', ['uploadItem', 'deleteItem'], ['currPath']);
|
||||
let onClose = jasmine.createSpy('onClose');
|
||||
let fmUtilsObj = {
|
||||
'uploadItem': jest.fn(),
|
||||
'deleteItem': jest.fn(),
|
||||
'currPath': ''
|
||||
};
|
||||
let onClose = jest.fn();
|
||||
let ctrlMount = (props)=>{
|
||||
return mount(<Theme>
|
||||
return render(<Theme>
|
||||
<Uploader
|
||||
fmUtilsObj={fmUtilsObj}
|
||||
onClose={onClose}
|
||||
@@ -45,12 +34,8 @@ describe('GridView', ()=>{
|
||||
</Theme>);
|
||||
};
|
||||
|
||||
it('init', (done)=>{
|
||||
let ctrl = ctrlMount();
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
done();
|
||||
}, 0);
|
||||
it('init', ()=>{
|
||||
ctrlMount();
|
||||
});
|
||||
|
||||
describe('filesReducer', ()=>{
|
||||
@@ -75,7 +60,7 @@ describe('GridView', ()=>{
|
||||
files: ['new1'],
|
||||
});
|
||||
expect(newState.length).toBe(2);
|
||||
expect(newState[0]).toEqual(jasmine.objectContaining({
|
||||
expect(newState[0]).toEqual(expect.objectContaining({
|
||||
file: 'new1',
|
||||
progress: 0,
|
||||
started: false,
|
||||
@@ -90,7 +75,7 @@ describe('GridView', ()=>{
|
||||
type: 'started',
|
||||
id: 1,
|
||||
});
|
||||
expect(newState[0]).toEqual(jasmine.objectContaining({
|
||||
expect(newState[0]).toEqual(expect.objectContaining({
|
||||
file: 'file1',
|
||||
progress: 0,
|
||||
started: true,
|
||||
@@ -105,7 +90,7 @@ describe('GridView', ()=>{
|
||||
id: 1,
|
||||
value: 14,
|
||||
});
|
||||
expect(newState[0]).toEqual(jasmine.objectContaining({
|
||||
expect(newState[0]).toEqual(expect.objectContaining({
|
||||
file: 'file1',
|
||||
progress: 14,
|
||||
started: false,
|
||||
@@ -119,7 +104,7 @@ describe('GridView', ()=>{
|
||||
type: 'failed',
|
||||
id: 1,
|
||||
});
|
||||
expect(newState[0]).toEqual(jasmine.objectContaining({
|
||||
expect(newState[0]).toEqual(expect.objectContaining({
|
||||
file: 'file1',
|
||||
progress: 0,
|
||||
started: false,
|
||||
@@ -133,7 +118,7 @@ describe('GridView', ()=>{
|
||||
type: 'done',
|
||||
id: 1,
|
||||
});
|
||||
expect(newState[0]).toEqual(jasmine.objectContaining({
|
||||
expect(newState[0]).toEqual(expect.objectContaining({
|
||||
file: 'file1',
|
||||
progress: 0,
|
||||
started: false,
|
||||
@@ -157,7 +142,7 @@ describe('GridView', ()=>{
|
||||
|
||||
describe('UploadedFile', ()=>{
|
||||
let upCtrlMount = (props)=>{
|
||||
return mount(<Theme>
|
||||
return render(<Theme>
|
||||
<UploadedFile
|
||||
deleteFile={()=>{/*dummy*/}}
|
||||
onClose={onClose}
|
||||
@@ -166,8 +151,8 @@ describe('GridView', ()=>{
|
||||
</Theme>);
|
||||
};
|
||||
|
||||
it('uploading', (done)=>{
|
||||
let ctrl = upCtrlMount({upfile: {
|
||||
it('uploading', async ()=>{
|
||||
upCtrlMount({upfile: {
|
||||
file: {
|
||||
name: 'file1',
|
||||
size: '1KB',
|
||||
@@ -177,18 +162,13 @@ describe('GridView', ()=>{
|
||||
progress: 14,
|
||||
}});
|
||||
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('FormFooterMessage').props()).toEqual(jasmine.objectContaining({
|
||||
type: MESSAGE_TYPE.INFO,
|
||||
message: 'Uploading... 14%',
|
||||
}));
|
||||
done();
|
||||
}, 0);
|
||||
await waitFor(()=>{
|
||||
expect(screen.getByText('Uploading... 14%')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('done', (done)=>{
|
||||
let ctrl = upCtrlMount({upfile: {
|
||||
it('done', async ()=>{
|
||||
upCtrlMount({upfile: {
|
||||
file: {
|
||||
name: 'file1',
|
||||
size: '1KB',
|
||||
@@ -198,18 +178,13 @@ describe('GridView', ()=>{
|
||||
progress: 14,
|
||||
}});
|
||||
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('FormFooterMessage').props()).toEqual(jasmine.objectContaining({
|
||||
type: MESSAGE_TYPE.SUCCESS,
|
||||
message: 'Uploaded!',
|
||||
}));
|
||||
done();
|
||||
}, 0);
|
||||
await waitFor(()=>{
|
||||
expect(screen.getByText('Uploaded!')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('failed', (done)=>{
|
||||
let ctrl = upCtrlMount({upfile: {
|
||||
it('failed', async ()=>{
|
||||
upCtrlMount({upfile: {
|
||||
file: {
|
||||
name: 'file1',
|
||||
size: '1KB',
|
||||
@@ -219,14 +194,9 @@ describe('GridView', ()=>{
|
||||
progress: 14,
|
||||
}});
|
||||
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('FormFooterMessage').props()).toEqual(jasmine.objectContaining({
|
||||
type: MESSAGE_TYPE.ERROR,
|
||||
message: 'Failed!',
|
||||
}));
|
||||
done();
|
||||
}, 0);
|
||||
await waitFor(()=>{
|
||||
expect(screen.getByText('Failed!')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,17 +7,32 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import SchemaView from '../../pgadmin/static/js/SchemaView';
|
||||
import pgWindow from 'sources/window';
|
||||
import fakePgAdmin from './fake_pgadmin';
|
||||
import Theme from 'sources/Theme';
|
||||
import Theme from '../../pgadmin/static/js/Theme';
|
||||
import { PgAdminContext } from '../../pgadmin/static/js/BrowserComponent';
|
||||
import { act, render } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
|
||||
export let getEditView = (schemaObj, getInitData)=> {
|
||||
return <Theme>
|
||||
<SchemaView
|
||||
export function withBrowser(WrappedComp) {
|
||||
// eslint-disable-next-line react/display-name
|
||||
return (props)=>{
|
||||
return <Theme>
|
||||
<PgAdminContext.Provider value={fakePgAdmin}>
|
||||
<WrappedComp {...props}/>
|
||||
</PgAdminContext.Provider>
|
||||
</Theme>;
|
||||
};
|
||||
}
|
||||
|
||||
const SchemaViewWithBrowser = withBrowser(SchemaView);
|
||||
|
||||
export const getEditView = async (schemaObj, getInitData)=> {
|
||||
await act(async ()=>{
|
||||
return render(<SchemaViewWithBrowser
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
@@ -33,13 +48,15 @@ export let getEditView = (schemaObj, getInitData)=> {
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>
|
||||
</Theme>;
|
||||
/>);
|
||||
});
|
||||
};
|
||||
|
||||
export let getCreateView = (schemaObj)=> {
|
||||
return <Theme>
|
||||
<SchemaView
|
||||
export const getCreateView = async (schemaObj)=> {
|
||||
let ctrl;
|
||||
const user = userEvent.setup();
|
||||
await act(async ()=>{
|
||||
ctrl = render(<SchemaViewWithBrowser
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
@@ -54,13 +71,14 @@ export let getCreateView = (schemaObj)=> {
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>
|
||||
</Theme>;
|
||||
/>);
|
||||
});
|
||||
return {ctrl, user};
|
||||
};
|
||||
|
||||
export let getPropertiesView = (schemaObj, getInitData)=> {
|
||||
return <Theme>
|
||||
<SchemaView
|
||||
export const getPropertiesView = async (schemaObj, getInitData)=> {
|
||||
await act(async ()=>{
|
||||
return render(<SchemaViewWithBrowser
|
||||
formType='tab'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
@@ -69,16 +87,14 @@ export let getPropertiesView = (schemaObj, getInitData)=> {
|
||||
}}
|
||||
onHelp={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onEdit={()=>{/*This is intentional (SonarQube)*/}}
|
||||
/>
|
||||
</Theme>;
|
||||
/>);
|
||||
});
|
||||
};
|
||||
|
||||
export const addNewDatagridRow = async (user, ctrl)=>{
|
||||
await user.click(ctrl.container.querySelector('[data-test="add-row"] button'));
|
||||
};
|
||||
|
||||
export let genericBeforeEach = ()=> {
|
||||
jasmineEnzyme();
|
||||
/* messages used by validators */
|
||||
pgAdmin.Browser = {
|
||||
...pgAdmin.Browser,
|
||||
...fakePgAdmin.Browser
|
||||
};
|
||||
pgWindow.pgAdmin = pgAdmin;
|
||||
};
|
||||
|
||||
@@ -7,39 +7,18 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import { messages } from '../fake_messages';
|
||||
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
import Theme from 'sources/Theme';
|
||||
import Wizard from '../../../pgadmin/static/js/helpers/wizard/Wizard';
|
||||
import WizardStep from '../../../pgadmin/static/js/helpers/wizard/WizardStep';
|
||||
|
||||
describe('Wizard', () => {
|
||||
let mount;
|
||||
|
||||
/* 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();
|
||||
/* messages used by validators */
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.messages = pgAdmin.Browser.messages || messages;
|
||||
pgAdmin.Browser.utils = pgAdmin.Browser.utils || {};
|
||||
});
|
||||
|
||||
it('WizardPanel', () => {
|
||||
mount(
|
||||
render(
|
||||
<Theme>
|
||||
<Wizard
|
||||
stepList={['Test']}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
import Enzyme from 'enzyme';
|
||||
import Adapter from '@wojtekmaj/enzyme-adapter-react-17';
|
||||
|
||||
Enzyme.configure({adapter: new Adapter()});
|
||||
@@ -1,26 +0,0 @@
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/* eslint-disable no-console */
|
||||
|
||||
beforeAll(function () {
|
||||
// Warnings can be ignored
|
||||
// spyOn(console, 'warn').and.callThrough();
|
||||
spyOn(console, 'error').and.callThrough();
|
||||
jasmine.getEnv().allowRespy(true);
|
||||
});
|
||||
|
||||
afterEach(function (done) {
|
||||
setTimeout(function () {
|
||||
// Warnings can be ignored
|
||||
// expect(console.warn).not.toHaveBeenCalled();
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
@@ -27,7 +27,7 @@ describe('#nodeHasStatistics', () => {
|
||||
};
|
||||
const pgBrowser = {
|
||||
tree: {
|
||||
getTreeNodeHierarchy: jasmine.createSpy(),
|
||||
getTreeNodeHierarchy: jest.fn(),
|
||||
}
|
||||
};
|
||||
const item = {};
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
import axios from 'axios';
|
||||
import BgProcessManager, { BgProcessManagerProcessState } from '../../../pgadmin/misc/bgprocess/static/js/BgProcessManager';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import BgProcessManager from '../../../pgadmin/misc/bgprocess/static/js/BgProcessManager';
|
||||
import { BgProcessManagerProcessState } from '../../../pgadmin/misc/bgprocess/static/js/BgProcessConstants';
|
||||
import * as BgProcessNotify from '../../../pgadmin/misc/bgprocess/static/js/BgProcessNotify';
|
||||
|
||||
|
||||
|
||||
describe('BgProcessManager', ()=>{
|
||||
let obj;
|
||||
let networkMock;
|
||||
const pgBrowser = jasmine.createSpyObj('pgBrowser', [], {
|
||||
docker: {
|
||||
findPanels: ()=>{/* dummy */},
|
||||
addPanel: ()=>{/* dummy */}
|
||||
}
|
||||
});
|
||||
const pgBrowser = pgAdmin.Browser;
|
||||
|
||||
beforeAll(()=>{
|
||||
networkMock = new MockAdapter(axios);
|
||||
@@ -31,7 +27,7 @@ describe('BgProcessManager', ()=>{
|
||||
});
|
||||
|
||||
it('init', ()=>{
|
||||
spyOn(obj, 'startWorker');
|
||||
jest.spyOn(obj, 'startWorker').mockImplementation(() => {});
|
||||
obj.init();
|
||||
expect(obj.startWorker).toHaveBeenCalled();
|
||||
});
|
||||
@@ -42,7 +38,7 @@ describe('BgProcessManager', ()=>{
|
||||
});
|
||||
|
||||
it('startWorker', (done)=>{
|
||||
spyOn(obj, 'syncProcesses');
|
||||
jest.spyOn(obj, 'syncProcesses').mockImplementation(() => {});
|
||||
obj._pendingJobId = ['123123123123'];
|
||||
obj.startWorker();
|
||||
|
||||
@@ -53,10 +49,10 @@ describe('BgProcessManager', ()=>{
|
||||
});
|
||||
|
||||
it('startProcess', ()=>{
|
||||
let nSpy = spyOn(BgProcessNotify, 'processStarted');
|
||||
let nSpy = jest.spyOn(BgProcessNotify, 'processStarted');
|
||||
obj.startProcess('12345', 'process desc');
|
||||
expect(obj._pendingJobId).toEqual(['12345']);
|
||||
expect(nSpy.calls.mostRecent().args[0]).toBe('process desc');
|
||||
expect(nSpy.mock.calls[nSpy.mock.calls.length - 1][0]).toBe('process desc');
|
||||
});
|
||||
|
||||
|
||||
@@ -91,30 +87,29 @@ describe('BgProcessManager', ()=>{
|
||||
obj._procList = [{
|
||||
id: '12345',
|
||||
process_state: BgProcessManagerProcessState.PROCESS_FINISHED,
|
||||
desc: 'Some desc',
|
||||
}];
|
||||
obj._pendingJobId = ['12345'];
|
||||
let nSpy = spyOn(BgProcessNotify, 'processCompleted');
|
||||
let nSpy = jest.spyOn(BgProcessNotify, 'processCompleted');
|
||||
obj.checkPending();
|
||||
expect(nSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
it('openProcessesPanel', ()=>{
|
||||
const panel = {
|
||||
focus: ()=>{/* dummy */}
|
||||
};
|
||||
spyOn(pgBrowser.docker, 'addPanel').and.returnValue(panel);
|
||||
const panel = {};
|
||||
jest.spyOn(pgBrowser.docker, 'openTab').mockReturnValue(panel);
|
||||
|
||||
/* panel open */
|
||||
spyOn(pgBrowser.docker, 'findPanels').and.returnValue([panel]);
|
||||
jest.spyOn(pgBrowser.docker, 'find').mockReturnValue(panel);
|
||||
jest.spyOn(pgBrowser.docker, 'focus');
|
||||
obj.openProcessesPanel();
|
||||
expect(pgBrowser.docker.addPanel).not.toHaveBeenCalled();
|
||||
expect(pgBrowser.docker.focus).toHaveBeenCalled();
|
||||
expect(pgBrowser.docker.openTab).not.toHaveBeenCalled();
|
||||
|
||||
/* panel closed */
|
||||
spyOn(pgBrowser.docker, 'findPanels')
|
||||
.withArgs('processes').and.returnValue([])
|
||||
.withArgs('properties').and.returnValue([panel]);
|
||||
jest.spyOn(pgBrowser.docker, 'find').mockReturnValue(null);
|
||||
obj.openProcessesPanel();
|
||||
expect(pgBrowser.docker.addPanel).toHaveBeenCalled();
|
||||
expect(pgBrowser.docker.openTab).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,46 +7,38 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import BgProcessManager, { BgProcessManagerProcessState } from '../../../pgadmin/misc/bgprocess/static/js/BgProcessManager';
|
||||
|
||||
|
||||
import { BgProcessManagerProcessState } from '../../../pgadmin/misc/bgprocess/static/js/BgProcessConstants';
|
||||
import BgProcessManager from '../../../pgadmin/misc/bgprocess/static/js/BgProcessManager';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import * as BgProcessNotify from '../../../pgadmin/misc/bgprocess/static/js/BgProcessNotify';
|
||||
import Notifier from '../../../pgadmin/static/js/helpers/Notifier';
|
||||
|
||||
describe('BgProcessNotify', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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();
|
||||
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.BgProcessManager = new BgProcessManager(pgAdmin.Browser);
|
||||
});
|
||||
|
||||
it('processStarted', ()=>{
|
||||
const nspy = spyOn(Notifier, 'notify');
|
||||
const nspy = jest.spyOn(pgAdmin.Browser.notifier, 'notify');
|
||||
BgProcessNotify.processStarted('some desc', ()=>{/* dummy */});
|
||||
expect(nspy.calls.mostRecent().args[0].props).toEqual(jasmine.objectContaining({
|
||||
expect(nspy.mock.calls[nspy.mock.calls.length - 1][0].props).toEqual(expect.objectContaining({
|
||||
title: 'Process started',
|
||||
desc: 'some desc',
|
||||
}));
|
||||
});
|
||||
|
||||
it('processCompleted success', ()=>{
|
||||
const nspy = spyOn(Notifier, 'notify');
|
||||
const nspy = jest.spyOn(pgAdmin.Browser.notifier, 'notify');
|
||||
BgProcessNotify.processCompleted('some desc', BgProcessManagerProcessState.PROCESS_FINISHED, ()=>{/* dummy */});
|
||||
expect(nspy.calls.mostRecent().args[0].props).toEqual(jasmine.objectContaining({
|
||||
expect(nspy.mock.calls[nspy.mock.calls.length - 1][0].props).toEqual(expect.objectContaining({
|
||||
title: 'Process completed',
|
||||
desc: 'some desc',
|
||||
success: true,
|
||||
@@ -54,9 +46,9 @@ describe('BgProcessNotify', ()=>{
|
||||
});
|
||||
|
||||
it('processCompleted failed', ()=>{
|
||||
const nspy = spyOn(Notifier, 'notify');
|
||||
const nspy = jest.spyOn(pgAdmin.Browser.notifier, 'notify');
|
||||
BgProcessNotify.processCompleted('some desc', BgProcessManagerProcessState.PROCESS_FAILED, ()=>{/* dummy */});
|
||||
expect(nspy.calls.mostRecent().args[0].props).toEqual(jasmine.objectContaining({
|
||||
expect(nspy.mock.calls[nspy.mock.calls.length - 1][0].props).toEqual(expect.objectContaining({
|
||||
title: 'Process failed',
|
||||
desc: 'some desc',
|
||||
success: false,
|
||||
@@ -64,9 +56,9 @@ describe('BgProcessNotify', ()=>{
|
||||
});
|
||||
|
||||
it('processCompleted terminated', ()=>{
|
||||
const nspy = spyOn(Notifier, 'notify');
|
||||
const nspy = jest.spyOn(pgAdmin.Browser.notifier, 'notify');
|
||||
BgProcessNotify.processCompleted('some desc', BgProcessManagerProcessState.PROCESS_TERMINATED, ()=>{/* dummy */});
|
||||
expect(nspy.calls.mostRecent().args[0].props).toEqual(jasmine.objectContaining({
|
||||
expect(nspy.mock.calls[nspy.mock.calls.length - 1][0].props).toEqual(expect.objectContaining({
|
||||
title: 'Process terminated',
|
||||
desc: 'some desc',
|
||||
success: false,
|
||||
|
||||
@@ -7,14 +7,15 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import BgProcessManager, { BgProcessManagerProcessState } from '../../../pgadmin/misc/bgprocess/static/js/BgProcessManager';
|
||||
|
||||
import { render } from '@testing-library/react';
|
||||
import { BgProcessManagerProcessState } from '../../../pgadmin/misc/bgprocess/static/js/BgProcessConstants';
|
||||
import BgProcessManager from '../../../pgadmin/misc/bgprocess/static/js/BgProcessManager';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import Processes from '../../../pgadmin/misc/bgprocess/static/js/Processes';
|
||||
import { withBrowser } from '../genericFunctions';
|
||||
|
||||
|
||||
const processData = {
|
||||
@@ -36,41 +37,21 @@ const processData = {
|
||||
};
|
||||
|
||||
describe('Proceses', ()=>{
|
||||
let mount;
|
||||
|
||||
/* 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();
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.BgProcessManager = new BgProcessManager(pgAdmin.Browser);
|
||||
pgAdmin.Browser.BgProcessManager._procList = [processData];
|
||||
});
|
||||
|
||||
describe('ProcessDetails', ()=>{
|
||||
const ProcesesWithBrowser = withBrowser(Processes);
|
||||
let ctrlMount = (props)=>{
|
||||
return mount(<Theme>
|
||||
<Processes
|
||||
{...props}
|
||||
/>
|
||||
</Theme>);
|
||||
return render(<ProcesesWithBrowser {...props} />);
|
||||
};
|
||||
|
||||
it('init', (done)=>{
|
||||
it('init', ()=>{
|
||||
let ctrl = ctrlMount({});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('PgTable').length).toBe(1);
|
||||
done();
|
||||
}, 1000);
|
||||
expect(ctrl.container.querySelectorAll('[data-test="processes"]').length).toBe(1);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,17 +7,17 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { render, waitFor } from '@testing-library/react';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
import axios from 'axios';
|
||||
import ProcessDetails from '../../../pgadmin/misc/bgprocess/static/js/ProcessDetails';
|
||||
import BgProcessManager, { BgProcessManagerProcessState } from '../../../pgadmin/misc/bgprocess/static/js/BgProcessManager';
|
||||
import { BgProcessManagerProcessState } from '../../../pgadmin/misc/bgprocess/static/js/BgProcessConstants';
|
||||
import BgProcessManager from '../../../pgadmin/misc/bgprocess/static/js/BgProcessManager';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import { MESSAGE_TYPE } from '../../../pgadmin/static/js/components/FormComponents';
|
||||
import _ from 'lodash';
|
||||
|
||||
|
||||
@@ -56,13 +56,10 @@ const detailsResponse = {
|
||||
};
|
||||
|
||||
describe('ProcessDetails', ()=>{
|
||||
let mount;
|
||||
|
||||
let networkMock;
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(()=>{
|
||||
mount = createMount();
|
||||
networkMock = new MockAdapter(axios);
|
||||
let initialResp = _.cloneDeep(detailsResponse);
|
||||
initialResp.err.done = false;
|
||||
@@ -73,19 +70,18 @@ describe('ProcessDetails', ()=>{
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
networkMock.restore();
|
||||
});
|
||||
|
||||
beforeEach(()=>{
|
||||
jasmineEnzyme();
|
||||
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.BgProcessManager = new BgProcessManager(pgAdmin.Browser);
|
||||
});
|
||||
|
||||
describe('ProcessDetails', ()=>{
|
||||
let ctrlMount = (props)=>{
|
||||
return mount(<Theme>
|
||||
return render(<Theme>
|
||||
<ProcessDetails
|
||||
data={processData}
|
||||
{...props}
|
||||
@@ -93,24 +89,12 @@ describe('ProcessDetails', ()=>{
|
||||
</Theme>);
|
||||
};
|
||||
|
||||
it('running and success', (done)=>{
|
||||
it('running and success', async ()=>{
|
||||
let ctrl = ctrlMount({});
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('NotifierMessage').props()).toEqual(jasmine.objectContaining({
|
||||
type: MESSAGE_TYPE.INFO,
|
||||
message: 'Running...',
|
||||
}));
|
||||
setTimeout(()=>{
|
||||
ctrl.update();
|
||||
expect(ctrl.find('NotifierMessage').props()).toEqual(jasmine.objectContaining({
|
||||
type: MESSAGE_TYPE.SUCCESS,
|
||||
message: 'Successfully completed.',
|
||||
}));
|
||||
ctrl.unmount();
|
||||
done();
|
||||
}, 2000);
|
||||
}, 500);
|
||||
expect(ctrl.container.querySelector('[data-test="notifier-message"]')).toHaveTextContent('Running...');
|
||||
await waitFor(()=>{
|
||||
expect(ctrl.container.querySelector('[data-test="notifier-message"]')).toHaveTextContent('Successfully completed.');
|
||||
}, {timeout: 2000});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,37 +8,28 @@
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
import React from 'react';
|
||||
import ReactDOM from 'react-dom';
|
||||
import { act } from 'react-dom/test-utils';
|
||||
import { Search } from 'browser/quick_search/trigger_search';
|
||||
import QuickSearch from '../../../pgadmin/static/js/QuickSearch';
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
let container;
|
||||
let ctrl;
|
||||
|
||||
describe('quick search test cases', function () {
|
||||
beforeEach(() => {
|
||||
container = document.createElement('div');
|
||||
document.body.appendChild(container);
|
||||
act(() => {
|
||||
ReactDOM.render(<Search />, container);
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
document.body.removeChild(container);
|
||||
container = null;
|
||||
ctrl = render(
|
||||
<QuickSearch />
|
||||
);
|
||||
});
|
||||
|
||||
it('should have rendered quick-search-container', () => {
|
||||
expect(container.firstChild.id).toEqual('quick-search-container');
|
||||
expect(ctrl.container.firstChild.id).toEqual('quick-search-container');
|
||||
});
|
||||
|
||||
it('should have 2 childs in quick-search-container', () => {
|
||||
expect(container.firstChild.childNodes.length).toEqual(2);
|
||||
expect(ctrl.container.firstChild.childNodes.length).toEqual(2);
|
||||
});
|
||||
|
||||
it('element should be html element', () => {
|
||||
let inputElement = document.getElementById('live-search-field');
|
||||
expect(inputElement instanceof HTMLElement).toBeTruthy();
|
||||
expect(ctrl.container.querySelector('#live-search-field')).not.toBeNull();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -7,69 +7,34 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import $ from 'jquery';
|
||||
window.jQuery = window.$ = $;
|
||||
|
||||
import 'wcdocker';
|
||||
import '../helper/enzyme.helper';
|
||||
|
||||
import React from 'react';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import { act, render } from '@testing-library/react';
|
||||
|
||||
import MockAdapter from 'axios-mock-adapter';
|
||||
import axios from 'axios';
|
||||
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import pgWindow from 'sources/window';
|
||||
import url_for from 'sources/url_for';
|
||||
|
||||
import { messages } from '../fake_messages';
|
||||
import { TreeFake } from '../tree/tree_fake';
|
||||
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import SchemaDiffComponent from '../../../pgadmin/tools/schema_diff/static/js/components/SchemaDiffComponent';
|
||||
import SchemaDiff from '../../../pgadmin/tools/schema_diff/static/js/SchemaDiffModule';
|
||||
|
||||
|
||||
describe('Schema Diff Component', () => {
|
||||
let mount;
|
||||
let mountDOM;
|
||||
let tree;
|
||||
|
||||
let params;
|
||||
let networkMock;
|
||||
let schemaDiffInstance;
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(() => {
|
||||
mount = createMount();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jasmineEnzyme();
|
||||
// Element for mount wcDocker panel
|
||||
mountDOM = $('<div class="dockerContainer">');
|
||||
$(document.body).append(mountDOM);
|
||||
|
||||
$(document.body).append($('<div id="debugger-main-container">'));
|
||||
|
||||
/* messages used by validators */
|
||||
pgWindow.pgAdmin.Browser = pgWindow.pgAdmin.Browser || {};
|
||||
pgWindow.pgAdmin.Browser.messages = pgWindow.pgAdmin.Browser.messages || messages;
|
||||
pgWindow.pgAdmin.Browser.utils = pgWindow.pgAdmin.Browser.utils || {};
|
||||
|
||||
pgWindow.pgAdmin = pgAdmin;
|
||||
schemaDiffInstance = new SchemaDiff(pgWindow.pgAdmin, pgWindow.pgAdmin.Browser);
|
||||
|
||||
// eslint-disable-next-line
|
||||
let docker = new wcDocker(
|
||||
'.dockerContainer', {
|
||||
allowContextMenu: false,
|
||||
allowCollapse: false,
|
||||
loadingClass: 'pg-sp-icon',
|
||||
});
|
||||
|
||||
tree = new TreeFake();
|
||||
pgWindow.pgAdmin.Browser.tree = tree;
|
||||
pgWindow.pgAdmin.Browser.docker = docker;
|
||||
|
||||
params = {
|
||||
transId: 1234,
|
||||
schemaDiff: schemaDiffInstance,
|
||||
@@ -77,7 +42,7 @@ describe('Schema Diff Component', () => {
|
||||
networkMock = new MockAdapter(axios);
|
||||
});
|
||||
|
||||
it('SchemaDiff Init', () => {
|
||||
it('SchemaDiff Init', async () => {
|
||||
networkMock.onGet(url_for('schema_diff.servers')).reply(200,
|
||||
{'success':1,
|
||||
'errormsg':'',
|
||||
@@ -95,14 +60,16 @@ describe('Schema Diff Component', () => {
|
||||
}
|
||||
}
|
||||
);
|
||||
mount(
|
||||
<Theme>
|
||||
<SchemaDiffComponent
|
||||
params={{ transId: params.transId, pgAdmin: pgWindow.pgAdmin }}
|
||||
>
|
||||
</SchemaDiffComponent>
|
||||
</Theme>
|
||||
);
|
||||
await act(async ()=>{
|
||||
render(
|
||||
<Theme>
|
||||
<SchemaDiffComponent
|
||||
params={{ transId: params.transId, pgAdmin: pgWindow.pgAdmin }}
|
||||
>
|
||||
</SchemaDiffComponent>
|
||||
</Theme>
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,40 +7,33 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import AggregateSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/aggregates/static/js/aggregate.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
describe('AggregateSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new AggregateSchema();
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -8,23 +8,15 @@
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
import BackupSchema, {getSectionSchema, getTypeObjSchema, getSaveOptSchema, getDisabledOptionSchema, getMiscellaneousSchema} from '../../../pgadmin/tools/backup/static/js/backup.ui';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import { getCreateView, withBrowser } from '../genericFunctions';
|
||||
import { act, render } from '@testing-library/react';
|
||||
|
||||
|
||||
describe('BackupSchema', ()=>{
|
||||
let mount;
|
||||
beforeAll(()=>{
|
||||
mount = createMount();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
});
|
||||
let backupSchemaObj = new BackupSchema(
|
||||
()=> getSectionSchema(),
|
||||
()=> getTypeObjSchema(),
|
||||
@@ -41,24 +33,8 @@ describe('BackupSchema', ()=>{
|
||||
[]
|
||||
);
|
||||
|
||||
it('create object backup', ()=>{
|
||||
mount(<Theme>
|
||||
<SchemaView
|
||||
formType='dialog'
|
||||
schema={backupSchemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onClose={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onHelp={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onDataChange={()=>{/*This is intentional (SonarQube)*/}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>
|
||||
</Theme>);
|
||||
it('create object backup', async ()=>{
|
||||
await getCreateView(backupSchemaObj);
|
||||
});
|
||||
|
||||
|
||||
@@ -78,9 +54,10 @@ describe('BackupSchema', ()=>{
|
||||
[{'id': 'public','name': 'public','icon': 'icon-schema', 'children': [{'id': 'public_table','name': 'table','icon': 'icon-coll-table','children': [{'id': 'public_test','name': 'test','icon': 'icon-table','schema': 'public','type': 'table','_name': 'public.test'}],'type': 'table','is_collection': true}],'is_schema': true}]
|
||||
);
|
||||
|
||||
it('create selected object backup', ()=>{
|
||||
mount(<Theme>
|
||||
<SchemaView
|
||||
it('create selected object backup', async ()=>{
|
||||
const WithBrowser = withBrowser(SchemaView);
|
||||
await act(async ()=>{
|
||||
await render(<WithBrowser
|
||||
formType='dialog'
|
||||
schema={backupSelectedSchemaObj}
|
||||
viewHelperProps={{
|
||||
@@ -95,7 +72,8 @@ describe('BackupSchema', ()=>{
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>
|
||||
</Theme>);
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -115,24 +93,8 @@ describe('BackupSchema', ()=>{
|
||||
[]
|
||||
);
|
||||
|
||||
it('create server backup', ()=>{
|
||||
mount(<Theme>
|
||||
<SchemaView
|
||||
formType='dialog'
|
||||
schema={backupServerSchemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onClose={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onHelp={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onDataChange={()=>{/*This is intentional (SonarQube)*/}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>
|
||||
</Theme>);
|
||||
it('create server backup', async ()=>{
|
||||
await getCreateView(backupServerSchemaObj);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,23 +7,12 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
|
||||
import BackupGlobalSchema, {getMiscellaneousSchema} from '../../../pgadmin/tools/backup/static/js/backupGlobal.ui';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import { getCreateView } from '../genericFunctions';
|
||||
|
||||
|
||||
describe('BackupGlobalSchema', ()=>{
|
||||
let mount;
|
||||
beforeAll(()=>{
|
||||
mount = createMount();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
});
|
||||
let backupGlobalSchemaObj = new BackupGlobalSchema(
|
||||
()=> getMiscellaneousSchema(),
|
||||
{
|
||||
@@ -31,24 +20,8 @@ describe('BackupGlobalSchema', ()=>{
|
||||
}
|
||||
);
|
||||
|
||||
it('create', ()=>{
|
||||
mount(<Theme>
|
||||
<SchemaView
|
||||
formType='dialog'
|
||||
schema={backupGlobalSchemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onClose={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onHelp={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onDataChange={()=>{/*This is intentional (SonarQube)*/}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>
|
||||
</Theme>);
|
||||
it('create', async ()=>{
|
||||
await getCreateView(backupGlobalSchemaObj);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -8,34 +8,28 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import Notify from '../../../pgadmin/static/js/helpers/Notifier';
|
||||
|
||||
import {genericBeforeEach, getEditView} from '../genericFunctions';
|
||||
import {getBinaryPathSchema} from '../../../pgadmin/browser/server_groups/servers/static/js/binary_path.ui';
|
||||
import pgAdmin from '../fake_pgadmin';
|
||||
|
||||
describe('BinaryPathschema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = getBinaryPathSchema();
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(()=>{
|
||||
mount = createMount();
|
||||
spyOn(Notify, 'alert');
|
||||
jest.spyOn(pgAdmin.Browser.notifier, 'alert').mockImplementation(() => {});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
});
|
||||
|
||||
|
||||
beforeEach(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('validate path', ()=>{
|
||||
|
||||
@@ -7,14 +7,13 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import CastSchema from '../../../pgadmin/browser/server_groups/servers/databases/casts/static/js/cast.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
|
||||
describe('CastSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new CastSchema(
|
||||
{
|
||||
getTypeOptions: ()=>[],
|
||||
@@ -23,30 +22,22 @@ describe('CastSchema', ()=>{
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('srctyp depChange', ()=>{
|
||||
@@ -63,7 +54,7 @@ describe('CastSchema', ()=>{
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
let setError = jest.fn();
|
||||
|
||||
state.srctyp = null;
|
||||
schemaObj.validate(state, setError);
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import CatalogSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/static/js/catalog.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
describe('CatalogSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let catalogObj = new CatalogSchema(
|
||||
{
|
||||
namespaceowner: '',
|
||||
@@ -21,30 +20,24 @@ describe('CatalogSchema', ()=>{
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(catalogObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(catalogObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(catalogObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(catalogObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(catalogObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(catalogObj, getInitData);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,31 +7,24 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import CatalogObjectSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/catalog_objects/static/js/catalog_object.ui';
|
||||
import {genericBeforeEach, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
describe('CatalogObjectSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new CatalogObjectSchema();
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,36 +7,29 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import CatalogObjectColumn from '../../../pgadmin/browser/server_groups/servers/databases/schemas/catalog_objects/columns/static/js/catalog_object_column.ui';
|
||||
import {genericBeforeEach, getCreateView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
describe('CatalogObjectColumn', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new CatalogObjectColumn();
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
@@ -7,12 +7,11 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui';
|
||||
import _ from 'lodash';
|
||||
import CheckConstraintSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/check_constraint/static/js/check_constraint.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
import {addNewDatagridRow, genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
class SchemaInColl extends BaseUISchema {
|
||||
constructor() {
|
||||
@@ -35,41 +34,36 @@ function getFieldDepChange(schema, id) {
|
||||
}
|
||||
|
||||
describe('CheckConstraintSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new CheckConstraintSchema();
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('create collection', ()=>{
|
||||
it('create collection', async ()=>{
|
||||
let schemaCollObj = new SchemaInColl();
|
||||
let ctrl = mount(getCreateView(schemaCollObj));
|
||||
const {ctrl, user} = await getCreateView(schemaCollObj);
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
|
||||
await addNewDatagridRow(user, ctrl);
|
||||
});
|
||||
|
||||
it('depChange', ()=>{
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import CollationSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/collations/static/js/collation.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
describe('CollationsSchema', () => {
|
||||
let mount;
|
||||
|
||||
let schemaObj = new CollationSchema(
|
||||
{
|
||||
rolesList: () => [],
|
||||
@@ -27,35 +26,27 @@ describe('CollationsSchema', () => {
|
||||
);
|
||||
let getInitData = () => Promise.resolve({});
|
||||
|
||||
/* 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(() => {
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', () => {
|
||||
mount(getCreateView(schemaObj));
|
||||
getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', () => {
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', () => {
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('validate', () => {
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
let setError = jest.fn();
|
||||
|
||||
state.name = null;
|
||||
state.locale = 'locale';
|
||||
@@ -76,17 +67,17 @@ describe('CollationsSchema', () => {
|
||||
|
||||
state.name = 'test';
|
||||
state.locale = 'locale';
|
||||
expect(schemaObj.disableFields(state)).toBeTrue();
|
||||
expect(schemaObj.disableFields(state)).toBe(true);
|
||||
|
||||
state.name = 'test';
|
||||
state.copy_collation = 'copy_collation';
|
||||
state.locale = null;
|
||||
expect(schemaObj.disableFields(state)).toBeTrue();
|
||||
expect(schemaObj.disableFields(state)).toBe(true);
|
||||
|
||||
state.name = 'test';
|
||||
state.copy_collation = null;
|
||||
state.locale = null;
|
||||
expect(schemaObj.disableFields(state)).toBeFalse();
|
||||
expect(schemaObj.disableFields(state)).toBe(false);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
@@ -7,12 +7,11 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import ColumnSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/static/js/column.ui';
|
||||
import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui';
|
||||
import _ from 'lodash';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
import {addNewDatagridRow, genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
class MockSchema extends BaseUISchema {
|
||||
get baseFields() {
|
||||
@@ -46,7 +45,7 @@ function getFieldDepChange(schema, id) {
|
||||
}
|
||||
|
||||
describe('ColumnSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new ColumnSchema(
|
||||
()=>new MockSchema(),
|
||||
{},
|
||||
@@ -59,37 +58,28 @@ describe('ColumnSchema', ()=>{
|
||||
];
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('create collection', ()=>{
|
||||
it('create collection', async ()=>{
|
||||
let schemaCollObj = new ColumnInColl();
|
||||
let ctrl = mount(getCreateView(schemaCollObj));
|
||||
const {ctrl, user} = await getCreateView(schemaCollObj);
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
|
||||
await addNewDatagridRow(user, ctrl);
|
||||
});
|
||||
|
||||
it('isTypeIdentity', ()=>{
|
||||
@@ -168,7 +158,7 @@ describe('ColumnSchema', ()=>{
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
let setError = jest.fn();
|
||||
|
||||
state.cltype = 'bigint';
|
||||
state.min_val_attlen = 5;
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import CompoundTriggerSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/compound_triggers/static/js/compound_trigger.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
describe('CompoundTriggerSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new CompoundTriggerSchema(
|
||||
{
|
||||
columns: [],
|
||||
@@ -26,35 +25,29 @@ describe('CompoundTriggerSchema', ()=>{
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
let setError = jest.fn();
|
||||
|
||||
state.evnt_truncate = false;
|
||||
state.evnt_delete = false;
|
||||
|
||||
@@ -8,8 +8,7 @@
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import _ from 'lodash';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
|
||||
import DatabaseSchema from '../../../pgadmin/browser/server_groups/servers/databases/static/js/database.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
@@ -21,7 +20,7 @@ class MockSchema extends BaseUISchema {
|
||||
}
|
||||
|
||||
describe('DatabaseSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new DatabaseSchema(
|
||||
()=>new MockSchema(),
|
||||
()=>new MockSchema(),
|
||||
@@ -39,30 +38,24 @@ describe('DatabaseSchema', ()=>{
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('schema_res depChange', ()=>{
|
||||
|
||||
@@ -7,47 +7,24 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
|
||||
import React from 'react';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
|
||||
import {DebuggerArgumentSchema} from '../../../pgadmin/tools/debugger/static/js/components/DebuggerArgs.ui';
|
||||
import {genericBeforeEach} from '../genericFunctions';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
import {genericBeforeEach, getCreateView} from '../genericFunctions';
|
||||
|
||||
describe('DebuggerArgs', () => {
|
||||
let mount;
|
||||
|
||||
let schemaObj = new DebuggerArgumentSchema();
|
||||
|
||||
/* 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(() => {
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', () => {
|
||||
mount(<Theme>
|
||||
<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onDataChange={() => {/*This is intentional (SonarQube)*/}}
|
||||
showFooter={false}
|
||||
isTabView={false}
|
||||
/>
|
||||
</Theme> );
|
||||
it('create', async () => {
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,14 +7,13 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
|
||||
import DomainSchema, { DomainConstSchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/domains/static/js/domain.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
import {addNewDatagridRow, genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
describe('DomainSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new DomainSchema(
|
||||
{
|
||||
role: ()=>[],
|
||||
@@ -31,30 +30,24 @@ describe('DomainSchema', ()=>{
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -77,43 +70,38 @@ class MockSchema extends BaseUISchema {
|
||||
}
|
||||
|
||||
describe('DomainConstSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new MockSchema();
|
||||
let domainConstObj = new DomainConstSchema();
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
let ctrl = mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
const {ctrl, user} = await getCreateView(schemaObj);
|
||||
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
|
||||
await addNewDatagridRow(user, ctrl);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
let setError = jest.fn();
|
||||
|
||||
state.conname = undefined;
|
||||
domainConstObj.validate(state, setError);
|
||||
|
||||
@@ -7,40 +7,33 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import DomainConstraintSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/domains/domain_constraints/static/js/domain_constraints.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
describe('DomainConstraintSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new DomainConstraintSchema();
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import EDBFuncSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/packages/edbfuncs/static/js/edbfunc.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
describe('EDBFuncSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let edbFuncSchemaObj = new EDBFuncSchema(
|
||||
{}, {
|
||||
name: 'sysfunc'
|
||||
@@ -21,30 +20,24 @@ describe('EDBFuncSchema', ()=>{
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(edbFuncSchemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(edbFuncSchemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(edbFuncSchemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(edbFuncSchemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(edbFuncSchemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(edbFuncSchemaObj, getInitData);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,40 +7,33 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import EDBVarSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/packages/edbvars/static/js/edbvar.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
describe('EDBVarSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let edbVarSchemaObj = new EDBVarSchema();
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(edbVarSchemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(edbVarSchemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(edbVarSchemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(edbVarSchemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(edbVarSchemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(edbVarSchemaObj, getInitData);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import EventTriggerSchema from '../../../pgadmin/browser/server_groups/servers/databases/event_triggers/static/js/event_trigger.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
describe('EventTriggerSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new EventTriggerSchema(
|
||||
{
|
||||
role: ()=>[],
|
||||
@@ -25,35 +24,29 @@ describe('EventTriggerSchema', ()=>{
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
let setError = jest.fn();
|
||||
|
||||
state.eventfunname = null;
|
||||
schemaObj.validate(state, setError);
|
||||
|
||||
@@ -7,16 +7,15 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { SCHEMA_STATE_ACTIONS } from '../../../pgadmin/static/js/SchemaView';
|
||||
import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui';
|
||||
import _ from 'lodash';
|
||||
import { getNodeExclusionConstraintSchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/exclusion_constraint/static/js/exclusion_constraint.ui';
|
||||
import * as nodeAjax from '../../../pgadmin/browser/static/js/node_ajax';
|
||||
import TableSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui';
|
||||
import Notify from '../../../pgadmin/static/js/helpers/Notifier';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
import {addNewDatagridRow, genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
import pgAdmin from '../fake_pgadmin';
|
||||
|
||||
class SchemaInColl extends BaseUISchema {
|
||||
constructor(schemaObj) {
|
||||
@@ -40,48 +39,41 @@ function getFieldDepChange(schema, id) {
|
||||
}
|
||||
|
||||
describe('ExclusionConstraintSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj;
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(()=>{
|
||||
mount = createMount();
|
||||
spyOn(nodeAjax, 'getNodeAjaxOptions').and.returnValue(Promise.resolve([]));
|
||||
spyOn(nodeAjax, 'getNodeListByName').and.returnValue(Promise.resolve([]));
|
||||
jest.spyOn(nodeAjax, 'getNodeAjaxOptions').mockReturnValue(Promise.resolve([]));
|
||||
jest.spyOn(nodeAjax, 'getNodeListByName').mockReturnValue(Promise.resolve([]));
|
||||
schemaObj = getNodeExclusionConstraintSchema({}, {}, {Nodes: {table: {}}});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
});
|
||||
|
||||
beforeEach(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('create collection', ()=>{
|
||||
it('create collection', async ()=>{
|
||||
let schemaCollObj = new SchemaInColl(schemaObj);
|
||||
let ctrl = mount(getCreateView(schemaCollObj));
|
||||
const {ctrl, user} = await getCreateView(schemaCollObj);
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
await addNewDatagridRow(user, ctrl);
|
||||
});
|
||||
|
||||
it('changeColumnOptions', ()=>{
|
||||
spyOn(schemaObj.exHeaderSchema, 'changeColumnOptions').and.callThrough();
|
||||
jest.spyOn(schemaObj.exHeaderSchema, 'changeColumnOptions');
|
||||
let columns = [{label: 'label', value: 'value'}];
|
||||
schemaObj.changeColumnOptions(columns);
|
||||
expect(schemaObj.exHeaderSchema.changeColumnOptions).toHaveBeenCalledWith(columns);
|
||||
@@ -93,7 +85,7 @@ describe('ExclusionConstraintSchema', ()=>{
|
||||
{label: 'id', value: 'id', datatype: 'numeric'},
|
||||
{label: 'name', value: 'name', datatype: 'char'}
|
||||
];
|
||||
spyOn(schemaObj.exColumnSchema, 'getNewData');
|
||||
jest.spyOn(schemaObj.exColumnSchema, 'getNewData').mockImplementation(() => {});
|
||||
schemaObj.exHeaderSchema.getNewData({
|
||||
is_exp: false,
|
||||
column: 'id',
|
||||
@@ -195,13 +187,14 @@ describe('ExclusionConstraintSchema', ()=>{
|
||||
];
|
||||
|
||||
beforeEach(()=>{
|
||||
spyOn(schemaObj.exColumnSchema, 'setOperClassOptions').and.callThrough();
|
||||
spyOn(schemaObj.fieldOptions, 'getOperClass').and.returnValue(operClassOptions);
|
||||
confirmSpy = spyOn(Notify, 'confirm').and.callThrough();
|
||||
jest.spyOn(schemaObj.exColumnSchema, 'setOperClassOptions');
|
||||
jest.spyOn(schemaObj.fieldOptions, 'getOperClass').mockReturnValue(operClassOptions);
|
||||
confirmSpy = jest.spyOn(pgAdmin.Browser.notifier, 'confirm');
|
||||
deferredDepChange = _.find(schemaObj.fields, (f)=>f.id=='amname')?.deferredDepChange;
|
||||
});
|
||||
|
||||
it('btree', (done)=>{
|
||||
confirmSpy.mockClear();
|
||||
let state = {amname: 'btree'};
|
||||
let deferredPromise = deferredDepChange(state);
|
||||
deferredPromise.then((depChange)=>{
|
||||
@@ -212,10 +205,11 @@ describe('ExclusionConstraintSchema', ()=>{
|
||||
done();
|
||||
});
|
||||
/* Press OK */
|
||||
confirmSpy.calls.argsFor(0)[2]();
|
||||
confirmSpy.mock.calls[0][2]();
|
||||
});
|
||||
|
||||
it('not btree', (done)=>{
|
||||
confirmSpy.mockClear();
|
||||
let state = {amname: 'gist'};
|
||||
let deferredPromise = deferredDepChange(state);
|
||||
deferredPromise.then((depChange)=>{
|
||||
@@ -226,10 +220,11 @@ describe('ExclusionConstraintSchema', ()=>{
|
||||
done();
|
||||
});
|
||||
/* Press OK */
|
||||
confirmSpy.calls.argsFor(0)[2]();
|
||||
confirmSpy.mock.calls[0][2]();
|
||||
});
|
||||
|
||||
it('press no', (done)=>{
|
||||
confirmSpy.mockClear();
|
||||
let state = {amname: 'gist'};
|
||||
let deferredPromise = deferredDepChange(state, null, null, {
|
||||
oldState: {
|
||||
@@ -237,7 +232,7 @@ describe('ExclusionConstraintSchema', ()=>{
|
||||
},
|
||||
});
|
||||
/* Press Cancel */
|
||||
confirmSpy.calls.argsFor(0)[3]();
|
||||
confirmSpy.mock.calls[0][3]();
|
||||
deferredPromise.then((depChange)=>{
|
||||
expect(depChange()).toEqual({
|
||||
amname: 'btree',
|
||||
@@ -249,7 +244,7 @@ describe('ExclusionConstraintSchema', ()=>{
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
let setError = jest.fn();
|
||||
|
||||
state.columns = ['id'];
|
||||
state.autoindex = true;
|
||||
|
||||
@@ -7,13 +7,12 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import ExtensionsSchema from '../../../pgadmin/browser/server_groups/servers/databases/extensions/static/js/extension.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
describe('ExtensionSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new ExtensionsSchema(
|
||||
{
|
||||
extensionsList: ()=>[],
|
||||
@@ -22,35 +21,29 @@ describe('ExtensionSchema', ()=>{
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
let setError = jest.fn();
|
||||
|
||||
state.name = null;
|
||||
schemaObj.validate(state, setError);
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
|
||||
import ForeignDataWrapperSchema from '../../../pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/static/js/foreign_data_wrapper.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
@@ -20,7 +19,7 @@ class MockSchema extends BaseUISchema {
|
||||
}
|
||||
|
||||
describe('ForeignDataWrapperSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new ForeignDataWrapperSchema(
|
||||
()=>new MockSchema(),
|
||||
{
|
||||
@@ -34,30 +33,24 @@ describe('ForeignDataWrapperSchema', ()=>{
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,15 +7,14 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import { SCHEMA_STATE_ACTIONS } from '../../../pgadmin/static/js/SchemaView';
|
||||
import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui';
|
||||
import _ from 'lodash';
|
||||
import * as nodeAjax from '../../../pgadmin/browser/static/js/node_ajax';
|
||||
import { getNodeForeignKeySchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/foreign_key/static/js/foreign_key.ui';
|
||||
import TableSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
import {addNewDatagridRow, genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
|
||||
class SchemaInColl extends BaseUISchema {
|
||||
constructor(schemaObj) {
|
||||
@@ -39,48 +38,43 @@ function getFieldDepChange(schema, id) {
|
||||
}
|
||||
|
||||
describe('ForeignKeySchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj;
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(()=>{
|
||||
mount = createMount();
|
||||
spyOn(nodeAjax, 'getNodeAjaxOptions').and.returnValue(Promise.resolve([]));
|
||||
spyOn(nodeAjax, 'getNodeListByName').and.returnValue(Promise.resolve([]));
|
||||
jest.spyOn(nodeAjax, 'getNodeAjaxOptions').mockReturnValue(Promise.resolve([]));
|
||||
jest.spyOn(nodeAjax, 'getNodeListByName').mockReturnValue(Promise.resolve([]));
|
||||
schemaObj = getNodeForeignKeySchema({}, {}, {Nodes: {table: {}}});
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
});
|
||||
|
||||
|
||||
beforeEach(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('create collection', ()=>{
|
||||
it('create collection', async ()=>{
|
||||
let schemaCollObj = new SchemaInColl(schemaObj);
|
||||
let ctrl = mount(getCreateView(schemaCollObj));
|
||||
const {ctrl, user} = await getCreateView(schemaCollObj);
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
await addNewDatagridRow(user, ctrl);
|
||||
});
|
||||
|
||||
it('changeColumnOptions', ()=>{
|
||||
spyOn(schemaObj.fkHeaderSchema, 'changeColumnOptions').and.callThrough();
|
||||
jest.spyOn(schemaObj.fkHeaderSchema, 'changeColumnOptions');
|
||||
let columns = [{label: 'label', value: 'value'}];
|
||||
schemaObj.changeColumnOptions(columns);
|
||||
expect(schemaObj.fkHeaderSchema.changeColumnOptions).toHaveBeenCalledWith(columns);
|
||||
@@ -196,7 +190,7 @@ describe('ForeignKeySchema', ()=>{
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
let setError = jest.fn();
|
||||
|
||||
state.columns = ['id'];
|
||||
state.autoindex = true;
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
|
||||
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
|
||||
import ForeignServerSchema from '../../../pgadmin/browser/server_groups/servers/databases/foreign_data_wrappers/foreign_servers/static/js/foreign_server.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
@@ -20,7 +19,7 @@ class MockSchema extends BaseUISchema {
|
||||
}
|
||||
|
||||
describe('ForeignServerSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new ForeignServerSchema(
|
||||
()=>new MockSchema(),
|
||||
{
|
||||
@@ -32,30 +31,24 @@ describe('ForeignServerSchema', ()=>{
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -7,14 +7,10 @@
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
|
||||
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
|
||||
import ForeignTableSchema, { ColumnSchema, CheckConstraintSchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/foreign_tables/static/js/foreign_table.ui';
|
||||
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
||||
import Theme from '../../../pgadmin/static/js/Theme';
|
||||
|
||||
class MockSchema extends BaseUISchema {
|
||||
get baseFields() {
|
||||
@@ -23,7 +19,7 @@ class MockSchema extends BaseUISchema {
|
||||
}
|
||||
|
||||
describe('ForeignTableSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new ForeignTableSchema(
|
||||
()=>new MockSchema(),
|
||||
()=>new MockSchema(),
|
||||
@@ -44,35 +40,25 @@ describe('ForeignTableSchema', ()=>{
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
let setError = jest.fn();
|
||||
|
||||
state.ftsrvname = null;
|
||||
schemaObj.validate(state, setError);
|
||||
@@ -134,8 +120,8 @@ describe('ForeignTableSchema', ()=>{
|
||||
};
|
||||
|
||||
beforeEach(()=>{
|
||||
spyOn(schemaObj, 'getTableOid').and.returnValue(123456);
|
||||
spyOn(schemaObj, 'getColumns').and.returnValue(Promise.resolve([inheritCol]));
|
||||
jest.spyOn(schemaObj, 'getTableOid').mockReturnValue(123456);
|
||||
jest.spyOn(schemaObj, 'getColumns').mockReturnValue(Promise.resolve([inheritCol]));
|
||||
deferredDepChange = _.find(schemaObj.fields, (f)=>f.id=='inherits')?.deferredDepChange;
|
||||
});
|
||||
|
||||
@@ -188,7 +174,7 @@ describe('ForeignTableSchema', ()=>{
|
||||
|
||||
|
||||
describe('ForeignTableColumnSchema', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new ColumnSchema(
|
||||
{},
|
||||
()=>new MockSchema(),
|
||||
@@ -202,33 +188,34 @@ describe('ForeignTableColumnSchema', ()=>{
|
||||
);
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('typdefault_edit', ()=>{
|
||||
it('column editable', ()=>{
|
||||
let state = {};
|
||||
let editable = _.find(schemaObj.fields, (f)=>f.id=='name').editable;
|
||||
let status = editable(state);
|
||||
expect(status).toBe(true);
|
||||
});
|
||||
|
||||
it('typdefault_edit', async ()=>{
|
||||
let defaultSchemaObj = new ForeignTableSchema(
|
||||
()=>new MockSchema(),
|
||||
()=>new MockSchema(),
|
||||
@@ -250,29 +237,12 @@ describe('ForeignTableColumnSchema', ()=>{
|
||||
|
||||
let initData = ()=>Promise.resolve({typlen: 1, inheritedid: 1, inheritedfrom: 'public'});
|
||||
|
||||
mount(<Theme>
|
||||
<SchemaView
|
||||
formType='dialog'
|
||||
schema={defaultSchemaObj}
|
||||
getInitData={initData}
|
||||
viewHelperProps={{
|
||||
mode: 'edit',
|
||||
}}
|
||||
onSave={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onClose={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onHelp={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onEdit={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onDataChange={()=>{/*This is intentional (SonarQube)*/}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
/>
|
||||
</Theme> );
|
||||
await getEditView(defaultSchemaObj, initData);
|
||||
});
|
||||
|
||||
|
||||
|
||||
it('attstattarget', ()=>{
|
||||
it('attstattarget', async ()=>{
|
||||
let defaultSchemaObj = new ForeignTableSchema(
|
||||
()=>new MockSchema(),
|
||||
()=>new MockSchema(),
|
||||
@@ -300,58 +270,31 @@ describe('ForeignTableColumnSchema', ()=>{
|
||||
|
||||
});
|
||||
|
||||
mount(<Theme>
|
||||
<SchemaView
|
||||
formType='dialog'
|
||||
schema={defaultSchemaObj}
|
||||
getInitData={initData}
|
||||
viewHelperProps={{
|
||||
mode: 'edit',
|
||||
}}
|
||||
onSave={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onClose={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onHelp={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onEdit={()=>{/*This is intentional (SonarQube)*/}}
|
||||
onDataChange={()=>{/*This is intentional (SonarQube)*/}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
/>
|
||||
</Theme>);
|
||||
await getEditView(defaultSchemaObj, initData);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
describe('ForeignTableCheckConstraint', ()=>{
|
||||
let mount;
|
||||
|
||||
let schemaObj = new CheckConstraintSchema();
|
||||
let getInitData = ()=>Promise.resolve({});
|
||||
|
||||
/* 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(()=>{
|
||||
genericBeforeEach();
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(getCreateView(schemaObj));
|
||||
it('create', async ()=>{
|
||||
await getCreateView(schemaObj);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(getPropertiesView(schemaObj, getInitData));
|
||||
it('properties', async ()=>{
|
||||
await getPropertiesView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(getEditView(schemaObj, getInitData));
|
||||
it('edit', async ()=>{
|
||||
await getEditView(schemaObj, getInitData);
|
||||
});
|
||||
|
||||
it('conname editable', ()=>{
|
||||
@@ -381,7 +324,7 @@ describe('ForeignTableCheckConstraint', ()=>{
|
||||
let status = editable(state);
|
||||
expect(status).toBe(true);
|
||||
|
||||
spyOn(schemaObj, 'isNew').and.returnValue(false);
|
||||
jest.spyOn(schemaObj, 'isNew').mockReturnValue(false);
|
||||
editable = _.find(schemaObj.fields, (f)=>f.id=='convalidated').editable;
|
||||
status = editable(state);
|
||||
expect(status).toBe(true);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user