From 7f2e87b27d16c54d1b256fd5efa01b3c6c7cc11c Mon Sep 17 00:00:00 2001 From: Aditya Toshniwal Date: Thu, 24 Mar 2022 12:05:59 +0530 Subject: [PATCH] Fixed Jasmine test cases. --- web/pgadmin/static/js/SchemaView/index.jsx | 4 ++-- web/pgadmin/static/js/components/SelectThemes.jsx | 9 +++------ .../javascript/components/FormComponents.spec.js | 2 +- web/regression/javascript/erd/fake_item.js | 6 ++++++ .../javascript/erd/ui_components/body_widget_spec.js | 11 +++++++---- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/web/pgadmin/static/js/SchemaView/index.jsx b/web/pgadmin/static/js/SchemaView/index.jsx index 2c180d708..852e1498d 100644 --- a/web/pgadmin/static/js/SchemaView/index.jsx +++ b/web/pgadmin/static/js/SchemaView/index.jsx @@ -93,7 +93,7 @@ function isValueEqual(val1, val2) { return (_.isEqual(val1, val2) || ((val1 === null || _.isUndefined(val1)) && val2 === '') || ((val1 === null || _.isUndefined(val1)) && typeof(val2) === 'boolean' && !val2) - || (attrDefined ? _.isEqual(val1.toString(), val2.toString()) : false + || (attrDefined ? (!_.isObject(val1) && _.isEqual(val1.toString(), val2.toString())) : false )); } @@ -108,7 +108,7 @@ function getChangedData(topSchema, viewHelperProps, sessData, stringify=false, i /* The comparator and setter */ const attrChanged = (id, change, force=false)=>{ - if(isValueEqual(_.get(origVal, id), _.get(sessVal, id)) && !force && (_.isObject(_.get(origVal, id)) && _.isEqual(_.get(origVal, id), _.get(sessData, id)))) { + if(isValueEqual(_.get(origVal, id), _.get(sessVal, id)) && !force) { return; } else { change = change || _.get(sessVal, id); diff --git a/web/pgadmin/static/js/components/SelectThemes.jsx b/web/pgadmin/static/js/components/SelectThemes.jsx index 07e157674..5d360159f 100644 --- a/web/pgadmin/static/js/components/SelectThemes.jsx +++ b/web/pgadmin/static/js/components/SelectThemes.jsx @@ -28,16 +28,13 @@ export default function SelectThemes({onChange, ...props}) { props.options.forEach((opt)=> { if(opt.value == e) { setPreviewSrc(opt.preview_src); - } + } }); onChange(e); }; return ( - + @@ -55,4 +52,4 @@ SelectThemes.propTypes = { fields: PropTypes.array, options: PropTypes.array, inputRef: CustomPropTypes.ref -}; \ No newline at end of file +}; diff --git a/web/regression/javascript/components/FormComponents.spec.js b/web/regression/javascript/components/FormComponents.spec.js index dc180d42e..d53dd41aa 100644 --- a/web/regression/javascript/components/FormComponents.spec.js +++ b/web/regression/javascript/components/FormComponents.spec.js @@ -196,7 +196,7 @@ describe('FormComponents', ()=>{ it('init', ()=>{ expect(ctrl.find(InputLabel).text()).toBe('First'); expect(ctrl.find(CodeMirror).prop('value')).toEqual('thevalue'); - expect(ctrl.find(CodeMirror).prop('op1')).toEqual('test'); + expect(ctrl.find(CodeMirror).prop('options')).toEqual(jasmine.objectContaining({'op1': 'test'})); expect(ctrl.find(FormHelperText).text()).toBe('some help message'); }); }); diff --git a/web/regression/javascript/erd/fake_item.js b/web/regression/javascript/erd/fake_item.js index 2ae3b6070..472c626fa 100644 --- a/web/regression/javascript/erd/fake_item.js +++ b/web/regression/javascript/erd/fake_item.js @@ -15,6 +15,7 @@ export class FakeNode { serializeData() {return this.getData();} getPortName(attnum) {return `port-${attnum}`;} getPort() {return null;} + getPorts() {return null;} addPort(obj) {return obj;} getColumnAt(pos) {return _.find(this.getColumns()||[], (c)=>c.attnum==pos);} remove() {/*This is intentional (SonarQube)*/} @@ -45,3 +46,8 @@ export class FakeLink { setTargetPort() {/*This is intentional (SonarQube)*/} remove() {/*This is intentional (SonarQube)*/} } + +export class FakePort { + constructor() {} + getLinks() {return null;} +} diff --git a/web/regression/javascript/erd/ui_components/body_widget_spec.js b/web/regression/javascript/erd/ui_components/body_widget_spec.js index 0738e7f82..3fb2cf0bd 100644 --- a/web/regression/javascript/erd/ui_components/body_widget_spec.js +++ b/web/regression/javascript/erd/ui_components/body_widget_spec.js @@ -10,7 +10,7 @@ import * as erdModule from 'pgadmin.tools.erd/erd_module'; import erdPref from './erd_preferences'; import BodyWidget from 'pgadmin.tools.erd/erd_tool/ui_components/BodyWidget'; import * as ERDSqlTool from 'tools/datagrid/static/js/show_query_tool'; -import { FakeLink, FakeNode } from '../fake_item'; +import { FakeLink, FakeNode, FakePort } from '../fake_item'; import Notify from '../../../../pgadmin/static/js/helpers/Notifier'; @@ -310,22 +310,25 @@ describe('ERD BodyWidget', ()=>{ it('onDeleteNode', (done)=>{ let node = new FakeNode({name: 'table1', schema: 'erd1'}); - spyOn(node, 'remove'); let link = new FakeLink({local_table_uid: 'tid1'}); - spyOn(link, 'remove'); + 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(link.remove).toHaveBeenCalled(); + expect(bodyInstance.diagram.removeOneToManyLink).toHaveBeenCalledWith(link); done(); }); });