Fixed Jasmine test cases.

This commit is contained in:
Aditya Toshniwal 2022-03-24 12:05:59 +05:30 committed by Akshay Joshi
parent 2f37f0ca51
commit 7f2e87b27d
5 changed files with 19 additions and 13 deletions

View File

@ -93,7 +93,7 @@ function isValueEqual(val1, val2) {
return (_.isEqual(val1, val2) return (_.isEqual(val1, val2)
|| ((val1 === null || _.isUndefined(val1)) && val2 === '') || ((val1 === null || _.isUndefined(val1)) && val2 === '')
|| ((val1 === null || _.isUndefined(val1)) && typeof(val2) === 'boolean' && !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 */ /* The comparator and setter */
const attrChanged = (id, change, force=false)=>{ 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; return;
} else { } else {
change = change || _.get(sessVal, id); change = change || _.get(sessVal, id);

View File

@ -28,16 +28,13 @@ export default function SelectThemes({onChange, ...props}) {
props.options.forEach((opt)=> { props.options.forEach((opt)=> {
if(opt.value == e) { if(opt.value == e) {
setPreviewSrc(opt.preview_src); setPreviewSrc(opt.preview_src);
} }
}); });
onChange(e); onChange(e);
}; };
return ( return (
<Grid <Grid container direction="column">
container
direction="column"
justifyContent="center">
<Grid item lg={12} md={12} sm={12} xs={12}> <Grid item lg={12} md={12} sm={12} xs={12}>
<InputSelect ref={props.inputRef} onChange={themeChange} {...props} /> <InputSelect ref={props.inputRef} onChange={themeChange} {...props} />
</Grid> </Grid>
@ -55,4 +52,4 @@ SelectThemes.propTypes = {
fields: PropTypes.array, fields: PropTypes.array,
options: PropTypes.array, options: PropTypes.array,
inputRef: CustomPropTypes.ref inputRef: CustomPropTypes.ref
}; };

View File

@ -196,7 +196,7 @@ describe('FormComponents', ()=>{
it('init', ()=>{ it('init', ()=>{
expect(ctrl.find(InputLabel).text()).toBe('First'); expect(ctrl.find(InputLabel).text()).toBe('First');
expect(ctrl.find(CodeMirror).prop('value')).toEqual('thevalue'); 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'); expect(ctrl.find(FormHelperText).text()).toBe('some help message');
}); });
}); });

View File

@ -15,6 +15,7 @@ export class FakeNode {
serializeData() {return this.getData();} serializeData() {return this.getData();}
getPortName(attnum) {return `port-${attnum}`;} getPortName(attnum) {return `port-${attnum}`;}
getPort() {return null;} getPort() {return null;}
getPorts() {return null;}
addPort(obj) {return obj;} addPort(obj) {return obj;}
getColumnAt(pos) {return _.find(this.getColumns()||[], (c)=>c.attnum==pos);} getColumnAt(pos) {return _.find(this.getColumns()||[], (c)=>c.attnum==pos);}
remove() {/*This is intentional (SonarQube)*/} remove() {/*This is intentional (SonarQube)*/}
@ -45,3 +46,8 @@ export class FakeLink {
setTargetPort() {/*This is intentional (SonarQube)*/} setTargetPort() {/*This is intentional (SonarQube)*/}
remove() {/*This is intentional (SonarQube)*/} remove() {/*This is intentional (SonarQube)*/}
} }
export class FakePort {
constructor() {}
getLinks() {return null;}
}

View File

@ -10,7 +10,7 @@ import * as erdModule from 'pgadmin.tools.erd/erd_module';
import erdPref from './erd_preferences'; import erdPref from './erd_preferences';
import BodyWidget from 'pgadmin.tools.erd/erd_tool/ui_components/BodyWidget'; import BodyWidget from 'pgadmin.tools.erd/erd_tool/ui_components/BodyWidget';
import * as ERDSqlTool from 'tools/datagrid/static/js/show_query_tool'; 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'; import Notify from '../../../../pgadmin/static/js/helpers/Notifier';
@ -310,22 +310,25 @@ describe('ERD BodyWidget', ()=>{
it('onDeleteNode', (done)=>{ it('onDeleteNode', (done)=>{
let node = new FakeNode({name: 'table1', schema: 'erd1'}); let node = new FakeNode({name: 'table1', schema: 'erd1'});
spyOn(node, 'remove');
let link = new FakeLink({local_table_uid: 'tid1'}); 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 = { let nodesDict = {
'tid1': node 'tid1': node
}; };
spyOn(bodyInstance.diagram, 'getModel').and.returnValue({ spyOn(bodyInstance.diagram, 'getModel').and.returnValue({
'getNodesDict': ()=>nodesDict, 'getNodesDict': ()=>nodesDict,
}); });
spyOn(bodyInstance.diagram, 'removeOneToManyLink');
spyOn(bodyInstance.diagram, 'getSelectedNodes').and.returnValue([node]); spyOn(bodyInstance.diagram, 'getSelectedNodes').and.returnValue([node]);
spyOn(bodyInstance.diagram, 'getSelectedLinks').and.returnValue([link]); spyOn(bodyInstance.diagram, 'getSelectedLinks').and.returnValue([link]);
bodyInstance.onDeleteNode(); bodyInstance.onDeleteNode();
setTimeout(()=>{ setTimeout(()=>{
expect(node.remove).toHaveBeenCalled(); expect(node.remove).toHaveBeenCalled();
expect(link.remove).toHaveBeenCalled(); expect(bodyInstance.diagram.removeOneToManyLink).toHaveBeenCalledWith(link);
done(); done();
}); });
}); });