mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Extract the generate_url(..) function from node.js, and collection.js
This commit is contained in:
committed by
Ashesh Vashi
parent
e9b80dae9c
commit
d527769bf8
95
web/regression/javascript/browser/generate_url_spec.js
Normal file
95
web/regression/javascript/browser/generate_url_spec.js
Normal file
@@ -0,0 +1,95 @@
|
||||
import {generate_url} from 'sources/browser/generate_url';
|
||||
|
||||
describe('generate_url', () => {
|
||||
describe('in collection', () => {
|
||||
let baseUrl, treeInfo, actionType, nodeType, pickFunction;
|
||||
beforeEach(() => {
|
||||
baseUrl = 'http://base/and-extension/';
|
||||
treeInfo = {
|
||||
treeNode1: {
|
||||
_id: 'an_id',
|
||||
priority: 1000,
|
||||
},
|
||||
};
|
||||
actionType = 'actionType';
|
||||
nodeType = 'nodeType';
|
||||
pickFunction = () => {
|
||||
return true;
|
||||
};
|
||||
});
|
||||
it('returns a correctly formatted URL', () => {
|
||||
let formattedUrl = generate_url(baseUrl, treeInfo, actionType, nodeType, pickFunction);
|
||||
|
||||
expect(formattedUrl).toEqual('http://base/and-extension/nodeType/actionType/an_id/');
|
||||
});
|
||||
|
||||
describe('given there are multiple treeInfoItems', () => {
|
||||
beforeEach(() => {
|
||||
treeInfo['treeNode2'] = {
|
||||
_id: 'another_id',
|
||||
priority: 500,
|
||||
};
|
||||
treeInfo['treeNode3'] = {
|
||||
_id: 'a_third_id',
|
||||
priority: 100,
|
||||
};
|
||||
|
||||
pickFunction = (value, key) => {
|
||||
return key != 'treeNode2';
|
||||
};
|
||||
});
|
||||
|
||||
it('chooses the correct treeInfo', () => {
|
||||
let formattedUrl = generate_url(baseUrl, treeInfo, actionType, nodeType, pickFunction);
|
||||
|
||||
expect(formattedUrl).toEqual('http://base/and-extension/nodeType/actionType/a_third_id/an_id/');
|
||||
});
|
||||
});
|
||||
});
|
||||
describe('in node', () => {
|
||||
let baseUrl, treeInfo, actionType, nodeType, pickFunction, itemDataID;
|
||||
beforeEach(() => {
|
||||
baseUrl = 'http://base/and-extension/';
|
||||
treeInfo = {
|
||||
treeNode1: {
|
||||
_id: 'an_id',
|
||||
priority: 1000,
|
||||
},
|
||||
};
|
||||
actionType = 'actionType';
|
||||
nodeType = 'nodeType';
|
||||
pickFunction = () => {
|
||||
return true;
|
||||
};
|
||||
itemDataID = 'item1';
|
||||
});
|
||||
it('returns a correctly formatted URL', () => {
|
||||
let formattedUrl = generate_url(baseUrl, treeInfo, actionType, nodeType, pickFunction, itemDataID);
|
||||
|
||||
expect(formattedUrl).toEqual('http://base/and-extension/nodeType/actionType/an_id/item1');
|
||||
});
|
||||
|
||||
describe('given there are multiple treeInfoItems', () => {
|
||||
beforeEach(() => {
|
||||
treeInfo['treeNode2'] = {
|
||||
_id: 'another_id',
|
||||
priority: 500,
|
||||
};
|
||||
treeInfo['treeNode3'] = {
|
||||
_id: 'a_third_id',
|
||||
priority: 100,
|
||||
};
|
||||
|
||||
pickFunction = (value) => {
|
||||
return value.priority > 100;
|
||||
};
|
||||
});
|
||||
|
||||
it('chooses the correct treeInfo', () => {
|
||||
let formattedUrl = generate_url(baseUrl, treeInfo, actionType, nodeType, pickFunction, itemDataID);
|
||||
|
||||
expect(formattedUrl).toEqual('http://base/and-extension/nodeType/actionType/another_id/an_id/item1');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user