2018-06-05 05:36:19 -05:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2022-01-04 02:24:25 -06:00
|
|
|
// Copyright (C) 2013 - 2022, The pgAdmin Development Team
|
2018-06-05 05:36:19 -05:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
import {
|
|
|
|
isTreeItemOfChildOfSchema, childCreateMenuEnabled,
|
|
|
|
} from 'pgadmin.schema.dir/schema_child_tree_node';
|
2021-09-27 06:14:26 -05:00
|
|
|
import pgAdmin from 'sources/pgadmin';
|
2018-06-05 05:36:19 -05:00
|
|
|
import {TreeFake} from '../../tree/tree_fake';
|
|
|
|
|
2021-09-27 06:14:26 -05:00
|
|
|
|
2018-06-05 05:36:19 -05:00
|
|
|
describe('#childCreateMenuEnabled', () => {
|
2021-09-27 06:14:26 -05:00
|
|
|
let data,
|
|
|
|
tree,
|
|
|
|
pgBrowser = pgAdmin.Browser;
|
2018-06-05 05:36:19 -05:00
|
|
|
|
|
|
|
describe(' - when data is not null', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
data = {};
|
|
|
|
});
|
|
|
|
describe(' and check is false', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
data = {check: false};
|
|
|
|
});
|
|
|
|
it(', then it returns true', () => {
|
|
|
|
expect(childCreateMenuEnabled({}, {}, data)).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(' and check', () => {
|
|
|
|
describe(' is true', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
data = {check: true};
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(', on schema node', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
let hierarchy = {
|
|
|
|
id: 'root',
|
|
|
|
children: [{
|
|
|
|
id: 'level2',
|
|
|
|
data: {_type: 'schema'},
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
|
2021-09-27 06:14:26 -05:00
|
|
|
tree = TreeFake.build(hierarchy, pgBrowser);
|
|
|
|
pgBrowser.tree = tree;
|
2018-06-05 05:36:19 -05:00
|
|
|
});
|
|
|
|
it(' it is true', () => {
|
|
|
|
expect(childCreateMenuEnabled(
|
|
|
|
{}, [{id: 'level2'}], data
|
|
|
|
)).toBe(true);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(', on child collection node under schema node ', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
let hierarchy = {
|
|
|
|
id: 'root',
|
|
|
|
children: [{
|
|
|
|
id: 'level2',
|
|
|
|
data: {_type: 'schema'},
|
|
|
|
children: [{
|
|
|
|
id: 'coll-table',
|
|
|
|
data: {_type: 'coll-table'},
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
|
2021-09-27 06:14:26 -05:00
|
|
|
tree = TreeFake.build(hierarchy, pgBrowser);
|
|
|
|
pgBrowser.tree = tree;
|
2018-06-05 05:36:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it(' it is true', () => {
|
|
|
|
expect(childCreateMenuEnabled(
|
|
|
|
{}, [{id: 'coll-table'}], data
|
|
|
|
)).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(', on one of the child node under schema node ', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
let hierarchy = {
|
|
|
|
id: 'root',
|
|
|
|
children: [{
|
|
|
|
id: 'level2',
|
|
|
|
data: {_type: 'schema'},
|
|
|
|
children: [{
|
|
|
|
id: 'coll-table',
|
|
|
|
data: {_type: 'coll-table'},
|
|
|
|
children: [{
|
|
|
|
id: 'table/1',
|
|
|
|
data: {_type: 'table'},
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
|
2021-09-27 06:14:26 -05:00
|
|
|
tree = TreeFake.build(hierarchy, pgBrowser);
|
|
|
|
pgBrowser.tree = tree;
|
2018-06-05 05:36:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it(' it is true', () => {
|
|
|
|
expect(childCreateMenuEnabled(
|
|
|
|
{}, [{id: 'table/1'}], data
|
|
|
|
)).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(', on catalog node', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
let hierarchy = {
|
|
|
|
id: 'root',
|
|
|
|
children: [{
|
|
|
|
id: 'level2',
|
|
|
|
data: {_type: 'catalog'},
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
|
2021-09-27 06:14:26 -05:00
|
|
|
tree = TreeFake.build(hierarchy, pgBrowser);
|
|
|
|
pgBrowser.tree = tree;
|
2018-06-05 05:36:19 -05:00
|
|
|
});
|
|
|
|
it(' it is false', () => {
|
|
|
|
expect(
|
|
|
|
childCreateMenuEnabled({}, [{id: 'level2'}], data)
|
|
|
|
).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(', on child collection node under catalog node ', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
let hierarchy = {
|
|
|
|
id: 'root',
|
|
|
|
children: [{
|
|
|
|
id: 'level2',
|
|
|
|
data: {_type: 'catalog'},
|
|
|
|
children: [{
|
|
|
|
id: 'coll-table',
|
|
|
|
data: {_type: 'coll-table'},
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
|
2021-09-27 06:14:26 -05:00
|
|
|
tree = TreeFake.build(hierarchy, pgBrowser);
|
|
|
|
pgBrowser.tree = tree;
|
2018-06-05 05:36:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it(' it is false', () => {
|
|
|
|
expect(childCreateMenuEnabled(
|
|
|
|
{}, [{id: 'coll-table'}], data
|
|
|
|
)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe(', on one of the child node under catalog node ', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
let hierarchy = {
|
|
|
|
id: 'root',
|
|
|
|
children: [{
|
|
|
|
id: 'level2',
|
|
|
|
data: {_type: 'catalog'},
|
|
|
|
children: [{
|
|
|
|
id: 'coll-table',
|
|
|
|
data: {_type: 'coll-table'},
|
|
|
|
children: [{
|
|
|
|
id: 'table/1',
|
|
|
|
data: {_type: 'table'},
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
|
2021-09-27 06:14:26 -05:00
|
|
|
tree = TreeFake.build(hierarchy, pgBrowser);
|
|
|
|
pgBrowser.tree = tree;
|
2018-06-05 05:36:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it(' it is false', () => {
|
|
|
|
expect(childCreateMenuEnabled(
|
|
|
|
{}, [{id: 'table/1'}], data
|
|
|
|
)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('#childDropMenuEnabled', () => {
|
2021-09-27 06:14:26 -05:00
|
|
|
let tree,
|
|
|
|
pgBrowser = pgAdmin.Browser;
|
|
|
|
|
2018-06-05 05:36:19 -05:00
|
|
|
|
|
|
|
describe(' - the child node under schema node ', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
let hierarchy = {
|
|
|
|
id: 'root',
|
|
|
|
children: [{
|
|
|
|
id: 'level2',
|
|
|
|
data: {_type: 'schema'},
|
|
|
|
children: [{
|
|
|
|
id: 'coll-table',
|
|
|
|
data: {_type: 'coll-table'},
|
|
|
|
children: [{
|
|
|
|
id: 'table/1',
|
|
|
|
data: {_type: 'table'},
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
|
2021-09-27 06:14:26 -05:00
|
|
|
tree = TreeFake.build(hierarchy, pgBrowser);
|
|
|
|
pgBrowser.tree = tree;
|
2018-06-05 05:36:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it(' it is true', () => {
|
|
|
|
expect(isTreeItemOfChildOfSchema(
|
|
|
|
{}, [{id: 'table/1'}]
|
|
|
|
)).toBe(true);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('- the child node under the catalog node ', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
let hierarchy = {
|
|
|
|
id: 'root',
|
|
|
|
children: [{
|
|
|
|
id: 'level2',
|
|
|
|
data: {_type: 'catalog'},
|
|
|
|
children: [{
|
|
|
|
id: 'coll-table',
|
|
|
|
data: {_type: 'coll-table'},
|
|
|
|
children: [{
|
|
|
|
id: 'table/1',
|
|
|
|
data: {_type: 'table'},
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
}],
|
|
|
|
};
|
|
|
|
|
2021-09-27 06:14:26 -05:00
|
|
|
tree = TreeFake.build(hierarchy, pgBrowser);
|
|
|
|
pgBrowser.tree = tree;
|
2018-06-05 05:36:19 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it(' it is false', () => {
|
|
|
|
expect(isTreeItemOfChildOfSchema(
|
|
|
|
{}, [{id: 'table/1'}]
|
|
|
|
)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|