2021-08-31 06:39:21 -05:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2023-01-02 00:23:55 -06:00
|
|
|
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
2021-08-31 06:39:21 -05:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2021-08-31 06:39:21 -05:00
|
|
|
import _ from 'lodash';
|
|
|
|
import * as nodeAjax from '../../../pgadmin/browser/static/js/node_ajax';
|
|
|
|
import { getNodePartitionTableSchema } from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/partitions/static/js/partition.ui';
|
2022-01-28 05:50:34 -06:00
|
|
|
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
2021-08-31 06:39:21 -05:00
|
|
|
|
|
|
|
describe('PartitionTableSchema', ()=>{
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2021-08-31 06:39:21 -05:00
|
|
|
let schemaObj;
|
|
|
|
let getInitData = ()=>Promise.resolve({});
|
|
|
|
|
|
|
|
beforeAll(()=>{
|
2023-10-23 07:13:17 -05:00
|
|
|
jest.spyOn(nodeAjax, 'getNodeAjaxOptions').mockReturnValue(Promise.resolve([]));
|
|
|
|
jest.spyOn(nodeAjax, 'getNodeListByName').mockReturnValue(Promise.resolve([]));
|
2021-08-31 06:39:21 -05:00
|
|
|
schemaObj = getNodePartitionTableSchema({
|
|
|
|
server: {
|
|
|
|
_id: 1,
|
|
|
|
},
|
|
|
|
schema: {
|
|
|
|
_label: 'public',
|
|
|
|
}
|
|
|
|
}, {}, {
|
|
|
|
Nodes: {table: {}},
|
|
|
|
serverInfo: {
|
|
|
|
1: {
|
|
|
|
user: {
|
|
|
|
name: 'Postgres',
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2021-08-31 06:39:21 -05:00
|
|
|
|
|
|
|
beforeEach(()=>{
|
2022-01-28 05:50:34 -06:00
|
|
|
genericBeforeEach();
|
2021-08-31 06:39:21 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('create', async ()=>{
|
|
|
|
await getCreateView(schemaObj);
|
2021-08-31 06:39:21 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('edit', async ()=>{
|
|
|
|
await getEditView(schemaObj, getInitData);
|
2021-08-31 06:39:21 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('properties', async ()=>{
|
|
|
|
await getPropertiesView(schemaObj, getInitData);
|
2021-08-31 06:39:21 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('depChange', ()=>{
|
|
|
|
let state = {typname: 'newtype'};
|
|
|
|
let partKeyField = _.find(schemaObj.fields, (f)=>f.id=='partition_keys');
|
|
|
|
expect(partKeyField.depChange(state, null, null, {
|
|
|
|
oldState: {
|
|
|
|
typname: 'oldtype',
|
|
|
|
}
|
|
|
|
})).toEqual({
|
|
|
|
partition_keys: []
|
|
|
|
});
|
|
|
|
|
|
|
|
state = {
|
|
|
|
partition_type: 'list',
|
|
|
|
columns: [{name: 'id'}],
|
|
|
|
partition_keys: [],
|
|
|
|
};
|
|
|
|
expect(partKeyField.canAddRow(state)).toBe(true);
|
|
|
|
|
|
|
|
state = {is_partitioned: true};
|
|
|
|
expect(partKeyField.canAdd(state)).toBe(true);
|
|
|
|
|
|
|
|
expect(_.find(schemaObj.fields, (f)=>f.id=='partitions').depChange(state, ['is_partitioned']))
|
|
|
|
.toEqual({
|
|
|
|
partitions: []
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('validate', ()=>{
|
|
|
|
let state = {is_partitioned: true};
|
2023-10-23 07:13:17 -05:00
|
|
|
let setError = jest.fn();
|
2021-08-31 06:39:21 -05:00
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|