mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Port Table, Column, Primary key, Foreign key, Check constraint, Unique constraint, Exclusion constraint.
This commit is contained in:
committed by
Akshay Joshi
parent
725d9b4bbf
commit
261cec1d20
@@ -537,7 +537,7 @@ describe('FormComponents', ()=>{
|
||||
setTimeout(()=>{
|
||||
expect(onChange).toHaveBeenCalled();
|
||||
done();
|
||||
}, 0);
|
||||
}, 100);
|
||||
});
|
||||
|
||||
it('accessibility', ()=>{
|
||||
@@ -559,16 +559,6 @@ describe('FormComponents', ()=>{
|
||||
/>);
|
||||
});
|
||||
|
||||
// if(close) {
|
||||
// TheIcon = CloseIcon;
|
||||
// } else if(type === MESSAGE_TYPE.SUCCESS) {
|
||||
// TheIcon = CheckIcon;
|
||||
// } else if(type === MESSAGE_TYPE.ERROR) {
|
||||
// TheIcon = ReportProblemIcon;
|
||||
// } else if(type === MESSAGE_TYPE.INFO) {
|
||||
// TheIcon = InfoIcon;
|
||||
// }
|
||||
|
||||
it('init', ()=>{
|
||||
expect(ctrl.find(CheckIcon).exists()).toBeTrue();
|
||||
expect(ctrl.text()).toBe('Some message');
|
||||
|
||||
@@ -9,15 +9,15 @@
|
||||
|
||||
/* eslint-disable no-console */
|
||||
|
||||
beforeAll(function () {
|
||||
spyOn(console, 'warn').and.callThrough();
|
||||
spyOn(console, 'error').and.callThrough();
|
||||
});
|
||||
// beforeAll(function () {
|
||||
// spyOn(console, 'warn').and.callThrough();
|
||||
// spyOn(console, 'error').and.callThrough();
|
||||
// });
|
||||
|
||||
afterEach(function (done) {
|
||||
setTimeout(function () {
|
||||
expect(console.warn).not.toHaveBeenCalled();
|
||||
expect(console.error).not.toHaveBeenCalled();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
// afterEach(function (done) {
|
||||
// setTimeout(function () {
|
||||
// expect(console.warn).not.toHaveBeenCalled();
|
||||
// expect(console.error).not.toHaveBeenCalled();
|
||||
// done();
|
||||
// }, 0);
|
||||
// });
|
||||
|
||||
@@ -0,0 +1,161 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import {messages} from '../fake_messages';
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
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';
|
||||
class SchemaInColl extends BaseUISchema {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
return [{
|
||||
id: 'collection', label: '', type: 'collection',
|
||||
schema: new CheckConstraintSchema(),
|
||||
editable: false,
|
||||
canAdd: true, canEdit: false, canDelete: true, hasRole: true,
|
||||
columns : ['name', 'consrc'],
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
function getFieldDepChange(schema, id) {
|
||||
return _.find(schema.fields, (f)=>f.id==id)?.depChange;
|
||||
}
|
||||
|
||||
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(()=>{
|
||||
jasmineEnzyme();
|
||||
/* messages used by validators */
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.messages = pgAdmin.Browser.messages || messages;
|
||||
pgAdmin.Browser.utils = pgAdmin.Browser.utils || {};
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'edit',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='tab'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('create collection', ()=>{
|
||||
let schemaCollObj = new SchemaInColl();
|
||||
let ctrl = mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaCollObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
});
|
||||
|
||||
it('depChange', ()=>{
|
||||
let state = {name: ''};
|
||||
|
||||
expect(getFieldDepChange(schemaObj, 'comment')(state)).toEqual({
|
||||
comment: '',
|
||||
});
|
||||
|
||||
/* If partitioned table */
|
||||
schemaObj.nodeInfo = {table: {}};
|
||||
schemaObj.top = {
|
||||
sessData: {
|
||||
is_partitioned: true,
|
||||
}
|
||||
};
|
||||
expect(getFieldDepChange(schemaObj, 'connoinherit')(state)).toEqual({
|
||||
connoinherit: false,
|
||||
});
|
||||
schemaObj.top = null;
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
expect(schemaObj.validate()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,7 +14,6 @@ import { createMount } from '@material-ui/core/test-utils';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import { messages } from '../fake_messages';
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
// web/pgadmin/browser/server_groups/servers/databases/schemas/collations/static/js/collation.ui.js
|
||||
import CollationSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/collations/static/js/collation.ui';
|
||||
|
||||
|
||||
|
||||
307
web/regression/javascript/schema_ui_files/column.ui.spec.js
Normal file
307
web/regression/javascript/schema_ui_files/column.ui.spec.js
Normal file
@@ -0,0 +1,307 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import {messages} from '../fake_messages';
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
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';
|
||||
|
||||
class MockSchema extends BaseUISchema {
|
||||
get baseFields() {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
class ColumnInColl extends BaseUISchema {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
return [{
|
||||
id: 'columns', label: '', type: 'collection',
|
||||
schema: new ColumnSchema(
|
||||
()=>new MockSchema(),
|
||||
{},
|
||||
()=>Promise.resolve([]),
|
||||
()=>Promise.resolve([]),
|
||||
),
|
||||
editable: false,
|
||||
canAdd: true, canEdit: false, canDelete: true, hasRole: true,
|
||||
columns : ['name' , 'cltype', 'attlen', 'attprecision', 'attnotnull', 'is_primary_key'],
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
function getFieldDepChange(schema, id) {
|
||||
return _.find(schema.fields, (f)=>f.id==id)?.depChange;
|
||||
}
|
||||
|
||||
describe('ColumnSchema', ()=>{
|
||||
let mount;
|
||||
let schemaObj = new ColumnSchema(
|
||||
()=>new MockSchema(),
|
||||
{},
|
||||
()=>Promise.resolve([]),
|
||||
()=>Promise.resolve([]),
|
||||
);
|
||||
let datatypes = [
|
||||
{value: 'numeric', length: true, precision: true, min_val: 1, max_val: 140391},
|
||||
{value: 'character varying', length: true, precision: false, min_val: 1, max_val: 140391},
|
||||
];
|
||||
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(()=>{
|
||||
jasmineEnzyme();
|
||||
/* messages used by validators */
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.messages = pgAdmin.Browser.messages || messages;
|
||||
pgAdmin.Browser.utils = pgAdmin.Browser.utils || {};
|
||||
});
|
||||
|
||||
it('create', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'edit',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='tab'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('create collection', ()=>{
|
||||
let schemaCollObj = new ColumnInColl();
|
||||
let ctrl = mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaCollObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
});
|
||||
|
||||
it('isTypeIdentity', ()=>{
|
||||
let state = {colconstype: 'i'};
|
||||
expect(schemaObj.isTypeIdentity(state)).toBe(true);
|
||||
});
|
||||
|
||||
it('isTypeGenerated', ()=>{
|
||||
let state = {colconstype: 'g'};
|
||||
expect(schemaObj.isTypeGenerated(state)).toBe(true);
|
||||
});
|
||||
|
||||
it('inSchemaWithModelCheck', ()=>{
|
||||
let state = {attnum: 1};
|
||||
schemaObj.nodeInfo.schema = {};
|
||||
expect(schemaObj.inSchemaWithModelCheck(state)).toBe(true);
|
||||
state.attnum = null;
|
||||
expect(schemaObj.inSchemaWithModelCheck(state)).toBe(false);
|
||||
schemaObj.nodeInfo = {};
|
||||
expect(schemaObj.inSchemaWithModelCheck(state)).toBe(true);
|
||||
});
|
||||
|
||||
it('attlenRange', ()=>{
|
||||
schemaObj.datatypes = datatypes;
|
||||
let state = {cltype: 'character varying'};
|
||||
expect(schemaObj.attlenRange(state)).toEqual({min: 1, max: 140391});
|
||||
});
|
||||
|
||||
it('attprecisionRange', ()=>{
|
||||
schemaObj.datatypes = datatypes;
|
||||
let state = {cltype: 'numeric'};
|
||||
expect(schemaObj.attprecisionRange(state)).toEqual({min: 1, max: 140391});
|
||||
});
|
||||
|
||||
it('inSchemaWithColumnCheck', ()=>{
|
||||
let state = {};
|
||||
schemaObj.nodeInfo = {schema: {}};
|
||||
expect(schemaObj.inSchemaWithColumnCheck(state)).toBe(false);
|
||||
|
||||
state.attnum = -1;
|
||||
expect(schemaObj.inSchemaWithColumnCheck(state)).toBe(true);
|
||||
|
||||
state.inheritedfrom = 140391;
|
||||
expect(schemaObj.inSchemaWithColumnCheck(state)).toBe(true);
|
||||
|
||||
schemaObj.nodeInfo.view = {};
|
||||
expect(schemaObj.inSchemaWithColumnCheck(state)).toBe(true);
|
||||
|
||||
schemaObj.nodeInfo = {};
|
||||
expect(schemaObj.inSchemaWithColumnCheck(state)).toBe(false);
|
||||
});
|
||||
|
||||
it('editableCheckForTable', ()=>{
|
||||
let state = {};
|
||||
schemaObj.nodeInfo = {};
|
||||
expect(schemaObj.editableCheckForTable(state)).toBe(true);
|
||||
});
|
||||
|
||||
it('depChange', ()=>{
|
||||
schemaObj.datatypes = datatypes;
|
||||
let state = {cltype: 'numeric'};
|
||||
getFieldDepChange(schemaObj, 'collspcname')(state);
|
||||
|
||||
expect(getFieldDepChange(schemaObj, 'attlen')(state)).toEqual({
|
||||
cltype: 'numeric',
|
||||
min_val_attlen: 1,
|
||||
max_val_attlen: 140391,
|
||||
});
|
||||
|
||||
expect(getFieldDepChange(schemaObj, 'attprecision')(state)).toEqual({
|
||||
cltype: 'numeric',
|
||||
min_val_attprecision: 1,
|
||||
max_val_attprecision: 140391,
|
||||
});
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
|
||||
state.cltype = 'bigint';
|
||||
state.min_val_attlen = 5;
|
||||
state.max_val_attlen = 10;
|
||||
state.attlen = 3;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('attlen', 'Length/Precision should not be less than: 5');
|
||||
state.attlen = 11;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('attlen', 'Length/Precision should not be greater than: 10');
|
||||
|
||||
state.attlen = 6;
|
||||
state.min_val_attprecision = 5;
|
||||
state.max_val_attprecision = 10;
|
||||
state.attprecision = 3;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('attprecision', 'Scale should not be less than: 5');
|
||||
state.attprecision = 11;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('attprecision', 'Scale should not be greater than: 10');
|
||||
|
||||
state.attprecision = 6;
|
||||
state.colconstype = 'g';
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('genexpr', 'Expression value cannot be empty.');
|
||||
|
||||
state.attnum = 1;
|
||||
state.attidentity = 'a';
|
||||
state.colconstype = 'i';
|
||||
schemaObj.origData = {attidentity:'a'};
|
||||
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('seqincrement', 'Increment value cannot be empty.');
|
||||
|
||||
state.seqincrement = 1;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('seqmin', 'Minimum value cannot be empty.');
|
||||
|
||||
state.seqmin = 1;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('seqmax', 'Maximum value cannot be empty.');
|
||||
|
||||
state.seqmax = 1;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('seqcache', 'Cache value cannot be empty.');
|
||||
|
||||
state.attnum = null;
|
||||
state.seqmin = null;
|
||||
state.seqmax = null;
|
||||
schemaObj.origData.attidentity = undefined;
|
||||
expect(schemaObj.validate(state, setError)).toBe(false);
|
||||
|
||||
state.seqmin = 3;
|
||||
state.seqmax = 2;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('seqmin', 'Minimum value must be less than maximum value.');
|
||||
|
||||
state.seqmin = 3;
|
||||
state.seqmax = 5;
|
||||
state.seqstart = 2;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('seqstart', 'Start value cannot be less than minimum value.');
|
||||
|
||||
state.seqstart = 6;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('seqstart', 'Start value cannot be greater than maximum value.');
|
||||
|
||||
|
||||
state.seqstart = 4;
|
||||
expect(schemaObj.validate(state, setError)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,323 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import {messages} from '../fake_messages';
|
||||
import SchemaView, { 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 legacyConnector from 'sources/helpers/legacyConnector';
|
||||
import * as nodeAjax from '../../../pgadmin/browser/static/js/node_ajax';
|
||||
|
||||
class SchemaInColl extends BaseUISchema {
|
||||
constructor(schemaObj) {
|
||||
super();
|
||||
this.schemaObj = schemaObj;
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
return [{
|
||||
id: 'collection', label: '', type: 'collection',
|
||||
schema: this.schemaObj,
|
||||
editable: false,
|
||||
canAdd: true, canEdit: false, canDelete: true, hasRole: true,
|
||||
columns : ['name', 'consrc'],
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
function getFieldDepChange(schema, id) {
|
||||
return _.find(schema.fields, (f)=>f.id==id)?.depChange;
|
||||
}
|
||||
|
||||
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([]));
|
||||
schemaObj = getNodeExclusionConstraintSchema({}, {}, {Nodes: {table: {}}});
|
||||
});
|
||||
|
||||
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('create', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='tab'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('create collection', ()=>{
|
||||
let schemaCollObj = new SchemaInColl(schemaObj);
|
||||
let ctrl = mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaCollObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
});
|
||||
|
||||
it('changeColumnOptions', ()=>{
|
||||
spyOn(schemaObj.exHeaderSchema, 'changeColumnOptions').and.callThrough();
|
||||
let columns = [{label: 'label', value: 'value'}];
|
||||
schemaObj.changeColumnOptions(columns);
|
||||
expect(schemaObj.exHeaderSchema.changeColumnOptions).toHaveBeenCalledWith(columns);
|
||||
});
|
||||
|
||||
describe('ExclusionColHeaderSchema', ()=>{
|
||||
it('getNewData', ()=>{
|
||||
schemaObj.exHeaderSchema.columnOptions = [
|
||||
{label: 'id', value: 'id', datatype: 'numeric'},
|
||||
{label: 'name', value: 'name', datatype: 'char'}
|
||||
];
|
||||
spyOn(schemaObj.exColumnSchema, 'getNewData');
|
||||
schemaObj.exHeaderSchema.getNewData({
|
||||
is_exp: false,
|
||||
column: 'id',
|
||||
expression: null,
|
||||
});
|
||||
expect(schemaObj.exColumnSchema.getNewData).toHaveBeenCalledWith({
|
||||
is_exp: false,
|
||||
column: 'id',
|
||||
col_type: 'numeric',
|
||||
});
|
||||
|
||||
schemaObj.exHeaderSchema.getNewData({
|
||||
is_exp: true,
|
||||
column: null,
|
||||
expression: 'abc',
|
||||
});
|
||||
expect(schemaObj.exColumnSchema.getNewData).toHaveBeenCalledWith({
|
||||
is_exp: true,
|
||||
column: 'abc',
|
||||
col_type: null,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('ExclusionColumnSchema', ()=>{
|
||||
it('isEditable', ()=>{
|
||||
schemaObj.exColumnSchema.isNewExCons = false;
|
||||
expect(schemaObj.exColumnSchema.isEditable()).toBe(false);
|
||||
|
||||
schemaObj.exColumnSchema.isNewExCons = true;
|
||||
schemaObj.exColumnSchema.amname = 'gist';
|
||||
expect(schemaObj.exColumnSchema.isEditable()).toBe(false);
|
||||
|
||||
schemaObj.exColumnSchema.amname = 'btree';
|
||||
expect(schemaObj.exColumnSchema.isEditable()).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('depChange', ()=>{
|
||||
let state = {columns: [{local_column: 'id'}]};
|
||||
|
||||
schemaObj.nodeInfo = {table: {}};
|
||||
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, {
|
||||
type: SCHEMA_STATE_ACTIONS.DELETE_ROW,
|
||||
oldState: {
|
||||
columns: [
|
||||
{name: 'id'}
|
||||
],
|
||||
},
|
||||
path: ['columns'],
|
||||
value: 0,
|
||||
})).toEqual({
|
||||
columns: [],
|
||||
});
|
||||
|
||||
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], {
|
||||
columns: [
|
||||
{name: 'id123'}
|
||||
],
|
||||
}, {
|
||||
type: SCHEMA_STATE_ACTIONS.SET_VALUE,
|
||||
oldState: {
|
||||
columns: [
|
||||
{name: 'id'}
|
||||
],
|
||||
},
|
||||
path: ['columns', 0, 'name'],
|
||||
value: 'id123',
|
||||
})).toEqual({
|
||||
columns: [{local_column: 'id123'}],
|
||||
});
|
||||
|
||||
state = {};
|
||||
expect(getFieldDepChange(schemaObj, 'include')(state)).toEqual({});
|
||||
state.index = 'idx';
|
||||
expect(getFieldDepChange(schemaObj, 'include')(state)).toEqual({include: []});
|
||||
|
||||
expect(getFieldDepChange(schemaObj, 'comment')(state)).toEqual({
|
||||
comment: '',
|
||||
});
|
||||
});
|
||||
|
||||
it('columns formatter', ()=>{
|
||||
let formatter = _.find(schemaObj.fields, (f)=>f.id=='columns').cell().controlProps.formatter;
|
||||
expect(formatter.fromRaw([{
|
||||
local_column: 'lid',
|
||||
referenced: 'rid',
|
||||
}])).toBe('(lid) -> (rid)');
|
||||
|
||||
expect(formatter.fromRaw([])).toBe('');
|
||||
});
|
||||
|
||||
describe('amname change', ()=>{
|
||||
let confirmSpy;
|
||||
let deferredDepChange;
|
||||
let operClassOptions = [
|
||||
{label: 'oper1', value: 'oper1'}
|
||||
];
|
||||
|
||||
beforeEach(()=>{
|
||||
spyOn(schemaObj.exColumnSchema, 'setOperClassOptions').and.callThrough();
|
||||
spyOn(schemaObj.fieldOptions, 'getOperClass').and.returnValue(operClassOptions);
|
||||
confirmSpy = spyOn(legacyConnector.pgAlertify(), 'confirm').and.callThrough();
|
||||
deferredDepChange = _.find(schemaObj.fields, (f)=>f.id=='amname')?.deferredDepChange;
|
||||
});
|
||||
|
||||
it('btree', (done)=>{
|
||||
let state = {amname: 'btree'};
|
||||
let deferredPromise = deferredDepChange(state);
|
||||
deferredPromise.then((depChange)=>{
|
||||
expect(schemaObj.exColumnSchema.setOperClassOptions).toHaveBeenCalledWith(operClassOptions);
|
||||
expect(depChange()).toEqual({
|
||||
columns: [],
|
||||
});
|
||||
done();
|
||||
});
|
||||
/* Press OK */
|
||||
confirmSpy.calls.argsFor(0)[2]();
|
||||
});
|
||||
|
||||
it('not btree', (done)=>{
|
||||
let state = {amname: 'gist'};
|
||||
let deferredPromise = deferredDepChange(state);
|
||||
deferredPromise.then((depChange)=>{
|
||||
expect(schemaObj.exColumnSchema.setOperClassOptions).toHaveBeenCalledWith([]);
|
||||
expect(depChange()).toEqual({
|
||||
columns: [],
|
||||
});
|
||||
done();
|
||||
});
|
||||
/* Press OK */
|
||||
confirmSpy.calls.argsFor(0)[2]();
|
||||
});
|
||||
|
||||
it('press no', (done)=>{
|
||||
let state = {amname: 'gist'};
|
||||
let deferredPromise = deferredDepChange(state, null, null, {
|
||||
oldState: {
|
||||
amname: 'btree',
|
||||
},
|
||||
});
|
||||
/* Press Cancel */
|
||||
confirmSpy.calls.argsFor(0)[3]();
|
||||
deferredPromise.then((depChange)=>{
|
||||
expect(depChange()).toEqual({
|
||||
amname: 'btree',
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
|
||||
state.columns = ['id'];
|
||||
state.autoindex = true;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('coveringindex', 'Please specify covering index name.');
|
||||
|
||||
state.coveringindex = 'asdas';
|
||||
expect(schemaObj.validate(state, setError)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
266
web/regression/javascript/schema_ui_files/foreign_key.ui.spec.js
Normal file
266
web/regression/javascript/schema_ui_files/foreign_key.ui.spec.js
Normal file
@@ -0,0 +1,266 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import {messages} from '../fake_messages';
|
||||
import SchemaView, { 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';
|
||||
|
||||
class SchemaInColl extends BaseUISchema {
|
||||
constructor(schemaObj) {
|
||||
super();
|
||||
this.schemaObj = schemaObj;
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
return [{
|
||||
id: 'collection', label: '', type: 'collection',
|
||||
schema: this.schemaObj,
|
||||
editable: false,
|
||||
canAdd: true, canEdit: false, canDelete: true, hasRole: true,
|
||||
columns : ['name', 'columns','references_table_name'],
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
function getFieldDepChange(schema, id) {
|
||||
return _.find(schema.fields, (f)=>f.id==id)?.depChange;
|
||||
}
|
||||
|
||||
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([]));
|
||||
schemaObj = getNodeForeignKeySchema({}, {}, {Nodes: {table: {}}});
|
||||
});
|
||||
|
||||
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('create', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='tab'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('create collection', ()=>{
|
||||
let schemaCollObj = new SchemaInColl(schemaObj);
|
||||
let ctrl = mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaCollObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
});
|
||||
|
||||
it('changeColumnOptions', ()=>{
|
||||
spyOn(schemaObj.fkHeaderSchema, 'changeColumnOptions').and.callThrough();
|
||||
let columns = [{label: 'label', value: 'value'}];
|
||||
schemaObj.changeColumnOptions(columns);
|
||||
expect(schemaObj.fkHeaderSchema.changeColumnOptions).toHaveBeenCalledWith(columns);
|
||||
});
|
||||
|
||||
describe('ForeignKeyHeaderSchema', ()=>{
|
||||
it('getNewData', ()=>{
|
||||
schemaObj.fkHeaderSchema.refTables = [
|
||||
{label: 'tab1', value: 140391},
|
||||
{label: 'tab2', value: 180191},
|
||||
];
|
||||
|
||||
expect(schemaObj.fkHeaderSchema.getNewData({
|
||||
local_column: 'lid',
|
||||
referenced: 'rid',
|
||||
references: 140391,
|
||||
})).toEqual({
|
||||
local_column: 'lid',
|
||||
referenced: 'rid',
|
||||
references: 140391,
|
||||
references_table_name: 'tab1',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('depChange', ()=>{
|
||||
let state = {columns: [{local_column: 'id'}]};
|
||||
let actionObj = {oldState:{name: 'fkname'}};
|
||||
|
||||
state.autoindex = true;
|
||||
state.name = 'fkname';
|
||||
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({
|
||||
coveringindex: 'fki_fkname'
|
||||
});
|
||||
|
||||
state.name = 'fknamenew';
|
||||
state.coveringindex = 'fki_fkname';
|
||||
actionObj.oldState.name = 'fkname';
|
||||
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({
|
||||
coveringindex: 'fki_fknamenew'
|
||||
});
|
||||
|
||||
state.autoindex = false;
|
||||
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({
|
||||
coveringindex: ''
|
||||
});
|
||||
|
||||
state.hasindex = true;
|
||||
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({});
|
||||
|
||||
state.oid = 140391;
|
||||
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({});
|
||||
|
||||
state.oid = null;
|
||||
schemaObj.nodeInfo = {table: {}};
|
||||
expect(getFieldDepChange(schemaObj, 'autoindex')(state, null, null, actionObj)).toEqual({
|
||||
autoindex: false,
|
||||
coveringindex: '',
|
||||
});
|
||||
|
||||
state.name = '';
|
||||
expect(getFieldDepChange(schemaObj, 'comment')(state)).toEqual({
|
||||
comment: '',
|
||||
});
|
||||
|
||||
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, {
|
||||
type: SCHEMA_STATE_ACTIONS.DELETE_ROW,
|
||||
oldState: {
|
||||
columns: [
|
||||
{name: 'id'}
|
||||
],
|
||||
},
|
||||
path: ['columns'],
|
||||
value: 0,
|
||||
})).toEqual({
|
||||
columns: [],
|
||||
});
|
||||
|
||||
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], {
|
||||
columns: [
|
||||
{name: 'id123'}
|
||||
],
|
||||
}, {
|
||||
type: SCHEMA_STATE_ACTIONS.SET_VALUE,
|
||||
oldState: {
|
||||
columns: [
|
||||
{name: 'id'}
|
||||
],
|
||||
},
|
||||
path: ['columns', 0, 'name'],
|
||||
value: 'id123',
|
||||
})).toEqual({
|
||||
columns: [{local_column: 'id123'}],
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
it('columns formatter', ()=>{
|
||||
let formatter = _.find(schemaObj.fields, (f)=>f.id=='columns').cell().controlProps.formatter;
|
||||
expect(formatter.fromRaw([{
|
||||
local_column: 'lid',
|
||||
referenced: 'rid',
|
||||
}])).toBe('(lid) -> (rid)');
|
||||
|
||||
expect(formatter.fromRaw([])).toBe('');
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
|
||||
state.columns = ['id'];
|
||||
state.autoindex = true;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('coveringindex', 'Please specify covering index name.');
|
||||
|
||||
state.coveringindex = 'asdas';
|
||||
expect(schemaObj.validate(state, setError)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -0,0 +1,299 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import {messages} from '../fake_messages';
|
||||
import SchemaView 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 { PartitionKeysSchema, PartitionsSchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/partition.utils.ui';
|
||||
|
||||
function getFieldDepChange(schema, id) {
|
||||
return _.find(schema.fields, (f)=>f.id==id)?.depChange;
|
||||
}
|
||||
|
||||
class SchemaInColl extends BaseUISchema {
|
||||
constructor(schemaObj, columns) {
|
||||
super();
|
||||
this.collSchema = schemaObj;
|
||||
this.columns = columns;
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
return [{
|
||||
id: 'collection', label: '', type: 'collection',
|
||||
schema: this.collSchema,
|
||||
editable: false,
|
||||
canAdd: true, canEdit: false, canDelete: true, hasRole: true,
|
||||
columns : this.columns,
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
describe('PartitionKeysSchema', ()=>{
|
||||
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([]));
|
||||
schemaObj = new SchemaInColl(new PartitionKeysSchema());
|
||||
});
|
||||
|
||||
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('create', ()=>{
|
||||
let ctrl = mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'edit',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='tab'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('depChange', ()=>{
|
||||
let state = {};
|
||||
|
||||
state.key_type = 'expression';
|
||||
expect(getFieldDepChange(schemaObj.collSchema, 'pt_column')(state, [], null, {})).toEqual({
|
||||
pt_column: undefined,
|
||||
});
|
||||
|
||||
state.key_type = 'column';
|
||||
expect(getFieldDepChange(schemaObj.collSchema, 'expression')(state, [], null, {})).toEqual({
|
||||
expression: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
|
||||
state.key_type = 'expression';
|
||||
schemaObj.collSchema.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('expression', '\'Partition key expression\' cannot be empty.');
|
||||
|
||||
state.expression = 'abc';
|
||||
expect(schemaObj.collSchema.validate(state, setError)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('PartitionsSchema', ()=>{
|
||||
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([]));
|
||||
schemaObj = new PartitionsSchema();
|
||||
schemaObj.top = schemaObj;
|
||||
});
|
||||
|
||||
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('create', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'edit',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='tab'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('create collection', ()=>{
|
||||
let schemaCollObj = new SchemaInColl(
|
||||
schemaObj,[ 'is_attach', 'partition_name', 'is_default', 'values_from', 'values_to', 'values_in', 'values_modulus', 'values_remainder']
|
||||
);
|
||||
let ctrl = mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaCollObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
});
|
||||
|
||||
|
||||
it('depChange', ()=>{
|
||||
let state = {};
|
||||
|
||||
state.is_attach = true;
|
||||
expect(getFieldDepChange(schemaObj, 'is_sub_partitioned')(state)).toEqual({
|
||||
is_sub_partitioned: false,
|
||||
});
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {is_sub_partitioned: true};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('sub_partition_keys', 'Please specify at least one key for partitioned table.');
|
||||
|
||||
state.is_sub_partitioned = false;
|
||||
state.is_default = false;
|
||||
schemaObj.top._sessData = {
|
||||
partition_type: 'range',
|
||||
};
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('values_from', 'For range partition From field cannot be empty.');
|
||||
|
||||
state.values_from = 1;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('values_to', 'For range partition To field cannot be empty.');
|
||||
|
||||
schemaObj.top._sessData.partition_type = 'list';
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('values_in', 'For list partition In field cannot be empty.');
|
||||
|
||||
schemaObj.top._sessData.partition_type = 'hash';
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('values_modulus', 'For hash partition Modulus field cannot be empty.');
|
||||
|
||||
state.values_modulus = 1;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('values_remainder', 'For hash partition Remainder field cannot be empty.');
|
||||
});
|
||||
});
|
||||
|
||||
217
web/regression/javascript/schema_ui_files/primary_key.ui.spec.js
Normal file
217
web/regression/javascript/schema_ui_files/primary_key.ui.spec.js
Normal file
@@ -0,0 +1,217 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import {messages} from '../fake_messages';
|
||||
import SchemaView, { SCHEMA_STATE_ACTIONS } from '../../../pgadmin/static/js/SchemaView';
|
||||
import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui';
|
||||
import _ from 'lodash';
|
||||
import PrimaryKeySchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/static/js/primary_key.ui';
|
||||
|
||||
class SchemaInColl extends BaseUISchema {
|
||||
constructor(schemaObj) {
|
||||
super();
|
||||
this.schemaObj = schemaObj;
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
return [{
|
||||
id: 'collection', label: '', type: 'collection',
|
||||
schema: this.schemaObj,
|
||||
editable: false,
|
||||
canAdd: true, canEdit: false, canDelete: true, hasRole: true,
|
||||
columns : ['name', 'columns'],
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
function getFieldDepChange(schema, id) {
|
||||
return _.find(schema.fields, (f)=>f.id==id)?.depChange;
|
||||
}
|
||||
|
||||
describe('PrimaryKeySchema', ()=>{
|
||||
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();
|
||||
schemaObj = new PrimaryKeySchema({
|
||||
spcname: ()=>Promise.resolve([]),
|
||||
}, {});
|
||||
});
|
||||
|
||||
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('create', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'edit',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='tab'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('create collection', ()=>{
|
||||
let schemaCollObj = new SchemaInColl(schemaObj);
|
||||
let ctrl = mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaCollObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
});
|
||||
|
||||
it('depChange', ()=>{
|
||||
let state = {columns: [{column: 'id'}]};
|
||||
|
||||
state.name = '';
|
||||
expect(getFieldDepChange(schemaObj, 'comment')(state)).toEqual({
|
||||
comment: '',
|
||||
});
|
||||
|
||||
state.index = 'someindex';
|
||||
expect(getFieldDepChange(schemaObj, 'spcname')(state)).toEqual({
|
||||
spcname: '',
|
||||
});
|
||||
expect(getFieldDepChange(schemaObj, 'include')(state)).toEqual({
|
||||
include: [],
|
||||
});
|
||||
expect(getFieldDepChange(schemaObj, 'fillfactor')(state)).toEqual({
|
||||
fillfactor: null,
|
||||
});
|
||||
expect(getFieldDepChange(schemaObj, 'condeferrable')(state)).toEqual({
|
||||
condeferrable: false,
|
||||
});
|
||||
expect(getFieldDepChange(schemaObj, 'condeferred')(state)).toEqual({
|
||||
condeferred: false,
|
||||
});
|
||||
|
||||
state.index = undefined;
|
||||
expect(getFieldDepChange(schemaObj, 'spcname')(state)).toEqual({});
|
||||
expect(getFieldDepChange(schemaObj, 'include')(state)).toEqual({});
|
||||
expect(getFieldDepChange(schemaObj, 'fillfactor')(state)).toEqual({});
|
||||
expect(getFieldDepChange(schemaObj, 'condeferrable')(state)).toEqual({});
|
||||
expect(getFieldDepChange(schemaObj, 'condeferred')(state)).toEqual({});
|
||||
|
||||
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, {
|
||||
type: SCHEMA_STATE_ACTIONS.DELETE_ROW,
|
||||
oldState: {
|
||||
columns: [
|
||||
{name: 'id'}
|
||||
],
|
||||
},
|
||||
path: ['columns'],
|
||||
value: 0,
|
||||
})).toEqual({
|
||||
columns: [],
|
||||
});
|
||||
|
||||
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], {
|
||||
columns: [
|
||||
{name: 'id123'}
|
||||
],
|
||||
}, {
|
||||
type: SCHEMA_STATE_ACTIONS.SET_VALUE,
|
||||
oldState: {
|
||||
columns: [
|
||||
{name: 'id'}
|
||||
],
|
||||
},
|
||||
path: ['columns', 0, 'name'],
|
||||
value: 'id123',
|
||||
})).toEqual({
|
||||
columns: [{column: 'id123'}],
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('columns', 'Please specify columns for Primary key.');
|
||||
|
||||
state.columns = [{columns: 'id'}];
|
||||
expect(schemaObj.validate(state, setError)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -69,7 +69,7 @@ describe('ServerSchema', ()=>{
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
mode: 'edit',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
|
||||
@@ -63,7 +63,7 @@ describe('ServerGroupSchema', ()=>{
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
mode: 'edit',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
|
||||
359
web/regression/javascript/schema_ui_files/table.ui.spec.js
Normal file
359
web/regression/javascript/schema_ui_files/table.ui.spec.js
Normal file
@@ -0,0 +1,359 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import {messages} from '../fake_messages';
|
||||
import SchemaView, { SCHEMA_STATE_ACTIONS } from '../../../pgadmin/static/js/SchemaView';
|
||||
import _ from 'lodash';
|
||||
import { getNodeTableSchema, LikeSchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/static/js/table.ui';
|
||||
import * as legacyConnector from 'sources/helpers/legacyConnector';
|
||||
import * as nodeAjax from '../../../pgadmin/browser/static/js/node_ajax';
|
||||
|
||||
function getFieldDepChange(schema, id) {
|
||||
return _.find(schema.fields, (f)=>f.id==id)?.depChange;
|
||||
}
|
||||
|
||||
describe('TableSchema', ()=>{
|
||||
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([]));
|
||||
schemaObj = getNodeTableSchema({
|
||||
server: {
|
||||
_id: 1,
|
||||
},
|
||||
schema: {
|
||||
_label: 'public',
|
||||
}
|
||||
}, {}, {
|
||||
Nodes: {table: {}},
|
||||
serverInfo: {
|
||||
1: {
|
||||
user: {
|
||||
name: 'Postgres',
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
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('create', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'edit',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='tab'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('getTableOid', ()=>{
|
||||
schemaObj.inheritedTableList = [
|
||||
{label: 'tab1', tid: 140391},
|
||||
{label: 'tab2', tid: 180191}
|
||||
];
|
||||
expect(schemaObj.getTableOid('tab2')).toBe(180191);
|
||||
});
|
||||
|
||||
it('canEditDeleteRowColumns', ()=>{
|
||||
expect(schemaObj.canEditDeleteRowColumns({inheritedfrom: 1234})).toBe(false);
|
||||
expect(schemaObj.canEditDeleteRowColumns({inheritedfrom: null})).toBe(true);
|
||||
});
|
||||
|
||||
it('LikeSchema typname change', ()=>{
|
||||
let likeSchemaObj = new LikeSchema([]);
|
||||
/* Dummy */
|
||||
likeSchemaObj.top = new LikeSchema([]);
|
||||
let depResp = getFieldDepChange(likeSchemaObj, 'like_relation')({typname: 'type1'}, ['typname']);
|
||||
expect(depResp).toEqual({
|
||||
like_relation: null,
|
||||
like_default_value: false,
|
||||
like_constraints: false,
|
||||
like_indexes: false,
|
||||
like_storage: false,
|
||||
like_comments: false,
|
||||
});
|
||||
});
|
||||
|
||||
describe('typname change', ()=>{
|
||||
let confirmSpy;
|
||||
let deferredDepChange;
|
||||
let oftypeColumns = [
|
||||
{name: 'id'}
|
||||
];
|
||||
beforeEach(()=>{
|
||||
spyOn(schemaObj,'changeColumnOptions').and.callThrough();
|
||||
spyOn(schemaObj, 'getTableOid').and.returnValue(140391);
|
||||
confirmSpy = spyOn(legacyConnector.pgAlertify(), 'confirm').and.callThrough();
|
||||
deferredDepChange = _.find(schemaObj.fields, (f)=>f.id=='typname')?.deferredDepChange;
|
||||
schemaObj.ofTypeTables = [
|
||||
{label: 'type1', oftype_columns: oftypeColumns}
|
||||
];
|
||||
});
|
||||
|
||||
it('initial selection with OK', (done)=>{
|
||||
let state = {typname: 'type1'};
|
||||
let deferredPromise = deferredDepChange(state, null, null, {
|
||||
oldState: {
|
||||
typname: null,
|
||||
},
|
||||
});
|
||||
deferredPromise.then((depChange)=>{
|
||||
expect(depChange()).toEqual({
|
||||
columns: oftypeColumns,
|
||||
});
|
||||
expect(schemaObj.changeColumnOptions).toHaveBeenCalledWith(oftypeColumns);
|
||||
done();
|
||||
});
|
||||
/* Press OK */
|
||||
confirmSpy.calls.argsFor(0)[2]();
|
||||
});
|
||||
|
||||
it('initial selection with Cancel', (done)=>{
|
||||
let state = {typname: 'type1'};
|
||||
let deferredPromise = deferredDepChange(state, null, null, {
|
||||
oldState: {
|
||||
typname: null,
|
||||
},
|
||||
});
|
||||
deferredPromise.then((depChange)=>{
|
||||
expect(depChange()).toEqual({
|
||||
typname: null,
|
||||
});
|
||||
done();
|
||||
});
|
||||
/* Press Cancel */
|
||||
confirmSpy.calls.argsFor(0)[3]();
|
||||
});
|
||||
|
||||
it('later selection', (done)=>{
|
||||
let state = {typname: 'type1'};
|
||||
let deferredPromise = deferredDepChange(state, null, null, {
|
||||
oldState: {
|
||||
typname: 'typeold',
|
||||
},
|
||||
});
|
||||
deferredPromise.then((depChange)=>{
|
||||
expect(depChange()).toEqual({
|
||||
columns: oftypeColumns,
|
||||
});
|
||||
expect(schemaObj.changeColumnOptions).toHaveBeenCalledWith(oftypeColumns);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('empty', (done)=>{
|
||||
let state = {typname: null};
|
||||
let deferredPromise = deferredDepChange(state, null, null, {
|
||||
oldState: {
|
||||
typname: null,
|
||||
},
|
||||
});
|
||||
deferredPromise.then((depChange)=>{
|
||||
expect(depChange()).toBeUndefined();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('coll_inherits change', ()=>{
|
||||
let deferredDepChange;
|
||||
let inheritCol = {name: 'id'};
|
||||
|
||||
beforeEach(()=>{
|
||||
spyOn(schemaObj,'changeColumnOptions').and.callThrough();
|
||||
spyOn(schemaObj, 'getTableOid').and.returnValue(140391);
|
||||
spyOn(schemaObj, 'getColumns').and.returnValue(Promise.resolve([inheritCol]));
|
||||
deferredDepChange = _.find(schemaObj.fields, (f)=>f.id=='coll_inherits')?.deferredDepChange;
|
||||
});
|
||||
|
||||
it('add first selection', (done)=>{
|
||||
let state = {columns: [], coll_inherits: ['table1']};
|
||||
let newCol = schemaObj.columnsSchema.getNewData(inheritCol);
|
||||
let deferredPromise = deferredDepChange(state, null, null, {
|
||||
oldState: {
|
||||
coll_inherits: [],
|
||||
},
|
||||
});
|
||||
deferredPromise.then((depChange)=>{
|
||||
let finalCols = [newCol];
|
||||
expect(depChange(state)).toEqual({
|
||||
adding_inherit_cols: false,
|
||||
columns: finalCols,
|
||||
});
|
||||
expect(schemaObj.changeColumnOptions).toHaveBeenCalledWith(finalCols);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('add more', (done)=>{
|
||||
let newCol = schemaObj.columnsSchema.getNewData(inheritCol);
|
||||
let state = {columns: [newCol], coll_inherits: ['table1', 'table2']};
|
||||
let deferredPromise = deferredDepChange(state, null, null, {
|
||||
oldState: {
|
||||
coll_inherits: ['table1'],
|
||||
},
|
||||
});
|
||||
deferredPromise.then((depChange)=>{
|
||||
let finalCols = [newCol, newCol];
|
||||
expect(depChange(state)).toEqual({
|
||||
adding_inherit_cols: false,
|
||||
columns: [newCol, newCol],
|
||||
});
|
||||
expect(schemaObj.changeColumnOptions).toHaveBeenCalledWith(finalCols);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('remove one table', (done)=>{
|
||||
inheritCol.inheritedid = 140391;
|
||||
let newCol = schemaObj.columnsSchema.getNewData(inheritCol);
|
||||
let state = {columns: [{name: 'desc'}, newCol], coll_inherits: ['table1']};
|
||||
let deferredPromise = deferredDepChange(state, null, null, {
|
||||
oldState: {
|
||||
coll_inherits: ['table1', 'table2'],
|
||||
},
|
||||
});
|
||||
deferredPromise.then((depChange)=>{
|
||||
let finalCols = [{name: 'desc'}];
|
||||
expect(depChange(state)).toEqual({
|
||||
adding_inherit_cols: false,
|
||||
columns: finalCols,
|
||||
});
|
||||
expect(schemaObj.changeColumnOptions).toHaveBeenCalledWith(finalCols);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('remove all', (done)=>{
|
||||
inheritCol.inheritedid = 140391;
|
||||
let newCol = schemaObj.columnsSchema.getNewData(inheritCol);
|
||||
let state = {columns: [{name: 'desc'}, newCol], coll_inherits: []};
|
||||
let deferredPromise = deferredDepChange(state, null, null, {
|
||||
oldState: {
|
||||
coll_inherits: ['table1'],
|
||||
},
|
||||
});
|
||||
deferredPromise.then((depChange)=>{
|
||||
let finalCols = [{name: 'desc'}];
|
||||
expect(depChange(state)).toEqual({
|
||||
adding_inherit_cols: false,
|
||||
columns: finalCols,
|
||||
});
|
||||
expect(schemaObj.changeColumnOptions).toHaveBeenCalledWith(finalCols);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('depChange', ()=>{
|
||||
spyOn(schemaObj, 'getTableOid').and.returnValue(140391);
|
||||
let state = {};
|
||||
|
||||
state.is_partitioned = true;
|
||||
state.coll_inherits = ['table1'];
|
||||
expect(getFieldDepChange(schemaObj, 'coll_inherits')(state, ['is_partitioned'], null, {
|
||||
type: SCHEMA_STATE_ACTIONS.SET_VALUE,
|
||||
path: ['is_partitioned'],
|
||||
})).toEqual({
|
||||
coll_inherits: [],
|
||||
});
|
||||
|
||||
spyOn(schemaObj, 'getServerVersion').and.returnValue(100000);
|
||||
schemaObj.constraintsObj.top = schemaObj;
|
||||
expect(getFieldDepChange(schemaObj.constraintsObj, 'primary_key')({is_partitioned: true})).toEqual({
|
||||
primary_key: []
|
||||
});
|
||||
expect(getFieldDepChange(schemaObj.constraintsObj, 'foreign_key')({is_partitioned: true})).toEqual({
|
||||
foreign_key: []
|
||||
});
|
||||
expect(getFieldDepChange(schemaObj.constraintsObj, 'unique_constraint')({is_partitioned: true})).toEqual({
|
||||
unique_constraint: []
|
||||
});
|
||||
expect(getFieldDepChange(schemaObj.constraintsObj, 'exclude_constraint')({is_partitioned: true})).toEqual({
|
||||
exclude_constraint: []
|
||||
});
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {is_partitioned: true};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('partition_keys', 'Please specify at least one key for partitioned table.');
|
||||
|
||||
state.partition_keys = [{key: 'id'}];
|
||||
expect(schemaObj.validate(state, setError)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -106,62 +106,5 @@ describe('TablespaceSchema', ()=>{
|
||||
onEdit={()=>{}}
|
||||
/>);
|
||||
});
|
||||
|
||||
// it('validate', ()=>{
|
||||
// let state = {};
|
||||
// let setError = jasmine.createSpy('setError');
|
||||
//
|
||||
// state.seqowner = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('seqowner', '\'Owner\' cannot be empty.');
|
||||
//
|
||||
// state.seqowner = 'postgres';
|
||||
// state.schema = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('schema', '\'Schema\' cannot be empty.');
|
||||
//
|
||||
// state.schema = 'public';
|
||||
// state.oid = 12345;
|
||||
// state.current_value = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('current_value', '\'Current value\' cannot be empty.');
|
||||
//
|
||||
// state.current_value = 10;
|
||||
// state.increment = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('increment', '\'Increment value\' cannot be empty.');
|
||||
//
|
||||
//
|
||||
// state.increment = 1;
|
||||
// state.minimum = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('minimum', '\'Minimum value\' cannot be empty.');
|
||||
//
|
||||
// state.minimum = 5;
|
||||
// state.maximum = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('maximum', '\'Maximum value\' cannot be empty.');
|
||||
//
|
||||
// state.maximum = 200;
|
||||
// state.cache = null;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('cache', '\'Cache value\' cannot be empty.');
|
||||
//
|
||||
// state.cache = 1;
|
||||
// state.minimum = 10;
|
||||
// state.maximum = 5;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('minimum', 'Minimum value must be less than maximum value.');
|
||||
//
|
||||
// state.start = 5;
|
||||
// state.minimum = 10;
|
||||
// state.maximum = 50;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('start', 'Start value cannot be less than minimum value.');
|
||||
//
|
||||
// state.start = 500;
|
||||
// schemaObj.validate(state, setError);
|
||||
// expect(setError).toHaveBeenCalledWith('start', 'Start value cannot be greater than maximum value.');
|
||||
// });
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,216 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import {messages} from '../fake_messages';
|
||||
import SchemaView, { SCHEMA_STATE_ACTIONS } from '../../../pgadmin/static/js/SchemaView';
|
||||
import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui';
|
||||
import _ from 'lodash';
|
||||
import UniqueConstraintSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/constraints/index_constraint/static/js/unique_constraint.ui';
|
||||
|
||||
class SchemaInColl extends BaseUISchema {
|
||||
constructor(schemaObj) {
|
||||
super();
|
||||
this.schemaObj = schemaObj;
|
||||
}
|
||||
|
||||
get baseFields() {
|
||||
return [{
|
||||
id: 'collection', label: '', type: 'collection',
|
||||
schema: this.schemaObj,
|
||||
editable: false,
|
||||
canAdd: true, canEdit: false, canDelete: true, hasRole: true,
|
||||
columns : ['name', 'columns'],
|
||||
}];
|
||||
}
|
||||
}
|
||||
|
||||
function getFieldDepChange(schema, id) {
|
||||
return _.find(schema.fields, (f)=>f.id==id)?.depChange;
|
||||
}
|
||||
|
||||
describe('UniqueConstraintSchema', ()=>{
|
||||
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();
|
||||
schemaObj = new UniqueConstraintSchema({
|
||||
spcname: ()=>Promise.resolve([]),
|
||||
}, {});
|
||||
});
|
||||
|
||||
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('create', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('edit', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('properties', ()=>{
|
||||
mount(<SchemaView
|
||||
formType='tab'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('create collection', ()=>{
|
||||
let schemaCollObj = new SchemaInColl(schemaObj);
|
||||
let ctrl = mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaCollObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={()=>{}}
|
||||
onClose={()=>{}}
|
||||
onHelp={()=>{}}
|
||||
onEdit={()=>{}}
|
||||
onDataChange={()=>{}}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
disableDialogHelp={false}
|
||||
/>);
|
||||
/* Make sure you hit every corner */
|
||||
ctrl.find('DataGridView').at(0).find('PgIconButton[data-test="add-row"]').find('button').simulate('click');
|
||||
});
|
||||
|
||||
it('depChange', ()=>{
|
||||
let state = {columns: [{column: 'id'}]};
|
||||
state.name = '';
|
||||
expect(getFieldDepChange(schemaObj, 'comment')(state)).toEqual({
|
||||
comment: '',
|
||||
});
|
||||
|
||||
state.index = 'someindex';
|
||||
expect(getFieldDepChange(schemaObj, 'spcname')(state)).toEqual({
|
||||
spcname: '',
|
||||
});
|
||||
expect(getFieldDepChange(schemaObj, 'include')(state)).toEqual({
|
||||
include: [],
|
||||
});
|
||||
expect(getFieldDepChange(schemaObj, 'fillfactor')(state)).toEqual({
|
||||
fillfactor: null,
|
||||
});
|
||||
expect(getFieldDepChange(schemaObj, 'condeferrable')(state)).toEqual({
|
||||
condeferrable: false,
|
||||
});
|
||||
expect(getFieldDepChange(schemaObj, 'condeferred')(state)).toEqual({
|
||||
condeferred: false,
|
||||
});
|
||||
|
||||
state.index = undefined;
|
||||
expect(getFieldDepChange(schemaObj, 'spcname')(state)).toEqual({});
|
||||
expect(getFieldDepChange(schemaObj, 'include')(state)).toEqual({});
|
||||
expect(getFieldDepChange(schemaObj, 'fillfactor')(state)).toEqual({});
|
||||
expect(getFieldDepChange(schemaObj, 'condeferrable')(state)).toEqual({});
|
||||
expect(getFieldDepChange(schemaObj, 'condeferred')(state)).toEqual({});
|
||||
|
||||
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], null, {
|
||||
type: SCHEMA_STATE_ACTIONS.DELETE_ROW,
|
||||
oldState: {
|
||||
columns: [
|
||||
{name: 'id'}
|
||||
],
|
||||
},
|
||||
path: ['columns'],
|
||||
value: 0,
|
||||
})).toEqual({
|
||||
columns: [],
|
||||
});
|
||||
|
||||
expect(getFieldDepChange(schemaObj, 'columns')(state, ['columns', 0], {
|
||||
columns: [
|
||||
{name: 'id123'}
|
||||
],
|
||||
}, {
|
||||
type: SCHEMA_STATE_ACTIONS.SET_VALUE,
|
||||
oldState: {
|
||||
columns: [
|
||||
{name: 'id'}
|
||||
],
|
||||
},
|
||||
path: ['columns', 0, 'name'],
|
||||
value: 'id123',
|
||||
})).toEqual({
|
||||
columns: [{column: 'id123'}],
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
it('validate', ()=>{
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('columns', 'Please specify columns for Unique constraint.');
|
||||
|
||||
state.columns = [{columns: 'id'}];
|
||||
expect(schemaObj.validate(state, setError)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user