2021-08-23 03:10:14 -05:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2024-01-01 02:43:48 -06:00
|
|
|
// Copyright (C) 2013 - 2024, The pgAdmin Development Team
|
2021-08-23 03:10:14 -05:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2021-08-23 03:10:14 -05:00
|
|
|
import ColumnSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/tables/columns/static/js/column.ui';
|
|
|
|
import BaseUISchema from '../../../pgadmin/static/js/SchemaView/base_schema.ui';
|
|
|
|
import _ from 'lodash';
|
2023-10-23 07:13:17 -05:00
|
|
|
import {addNewDatagridRow, genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
2024-08-18 23:23:00 -05:00
|
|
|
import { initializeSchemaWithData } from './utils';
|
2021-08-23 03:10:14 -05:00
|
|
|
|
|
|
|
class MockSchema extends BaseUISchema {
|
|
|
|
get baseFields() {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class ColumnInColl extends BaseUISchema {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
|
|
|
get baseFields() {
|
|
|
|
return [{
|
|
|
|
id: 'columns', label: '', type: 'collection',
|
|
|
|
schema: new ColumnSchema(
|
|
|
|
()=>new MockSchema(),
|
|
|
|
{},
|
|
|
|
()=>Promise.resolve([]),
|
|
|
|
()=>Promise.resolve([]),
|
|
|
|
),
|
|
|
|
editable: false,
|
|
|
|
canAdd: true, canEdit: false, canDelete: true, hasRole: true,
|
|
|
|
columns : ['name' , 'cltype', 'attlen', 'attprecision', 'attnotnull', 'is_primary_key'],
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getFieldDepChange(schema, id) {
|
|
|
|
return _.find(schema.fields, (f)=>f.id==id)?.depChange;
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('ColumnSchema', ()=>{
|
Improved the extendability of the SchemaView and DataGridView. (#7876)
Restructured these modules for ease of maintenance and apply the single
responsibility principle (wherever applicable).
* SchemaView
- Split the code based on the functionality and responsibility.
- Introduced a new View 'InlineView' instead of using the
'nextInline' configuration of the fields to have a better, and
manageable view.
- Using the separate class 'SchemaState' for managing the data and
states of the SchemaView (separated from the 'useSchemaState'
custom hook).
- Introduced three new custom hooks 'useFieldValue',
'useFieldOptions', 'useFieldError' for the individual control to
use for each Schema Field.
- Don't pass value as the parameter props, and let the
'useFieldValue' and other custom hooks to decide, whether to
rerender the control itself or the whole dialog/view. (single
responsibility principle)
- Introduced a new data store with a subscription facility.
- Moving the field metadata (option) evaluation to a separate place
for better management, and each option can be defined for a
particular kind of field (for example - collection, row, cell,
general, etc).
- Allow to provide custom control for all kind of Schema field.
* DataGridView
- Same as SchemaView, split the DataGridView call into smaller,
manageable chunks. (For example - grid, row, mappedCell, etc).
- Use context based approach for providing the row and table data
instead of passing them as parameters to every component
separately.
- Have a facility to extend this feature separately in future.
(for example - selectable cell, column grouping, etc.)
- Separated the features like deletable, editable, reorder,
expandable etc. cells using the above feature support.
- Added ability to provide the CustomHeader, and CustomRow through the
Schema field, which will extend the ability to customize better.
- Removed the 'DataGridViewWithHeaderForm' as it has been achieved
through providing 'CustomHeader', and also introduced
'DataGridFormHeader' (a custom header) to achieve the same feature
as 'DataGridViewWithHeaderForm'.
2024-09-09 03:57:31 -05:00
|
|
|
const createSchemaObj = () => new ColumnSchema(
|
2021-08-23 03:10:14 -05:00
|
|
|
()=>new MockSchema(),
|
|
|
|
{},
|
|
|
|
()=>Promise.resolve([]),
|
|
|
|
()=>Promise.resolve([]),
|
|
|
|
);
|
Improved the extendability of the SchemaView and DataGridView. (#7876)
Restructured these modules for ease of maintenance and apply the single
responsibility principle (wherever applicable).
* SchemaView
- Split the code based on the functionality and responsibility.
- Introduced a new View 'InlineView' instead of using the
'nextInline' configuration of the fields to have a better, and
manageable view.
- Using the separate class 'SchemaState' for managing the data and
states of the SchemaView (separated from the 'useSchemaState'
custom hook).
- Introduced three new custom hooks 'useFieldValue',
'useFieldOptions', 'useFieldError' for the individual control to
use for each Schema Field.
- Don't pass value as the parameter props, and let the
'useFieldValue' and other custom hooks to decide, whether to
rerender the control itself or the whole dialog/view. (single
responsibility principle)
- Introduced a new data store with a subscription facility.
- Moving the field metadata (option) evaluation to a separate place
for better management, and each option can be defined for a
particular kind of field (for example - collection, row, cell,
general, etc).
- Allow to provide custom control for all kind of Schema field.
* DataGridView
- Same as SchemaView, split the DataGridView call into smaller,
manageable chunks. (For example - grid, row, mappedCell, etc).
- Use context based approach for providing the row and table data
instead of passing them as parameters to every component
separately.
- Have a facility to extend this feature separately in future.
(for example - selectable cell, column grouping, etc.)
- Separated the features like deletable, editable, reorder,
expandable etc. cells using the above feature support.
- Added ability to provide the CustomHeader, and CustomRow through the
Schema field, which will extend the ability to customize better.
- Removed the 'DataGridViewWithHeaderForm' as it has been achieved
through providing 'CustomHeader', and also introduced
'DataGridFormHeader' (a custom header) to achieve the same feature
as 'DataGridViewWithHeaderForm'.
2024-09-09 03:57:31 -05:00
|
|
|
let schemaObj = createSchemaObj();
|
2021-08-23 03:10:14 -05:00
|
|
|
let datatypes = [
|
|
|
|
{value: 'numeric', length: true, precision: true, min_val: 1, max_val: 140391},
|
|
|
|
{value: 'character varying', length: true, precision: false, min_val: 1, max_val: 140391},
|
|
|
|
];
|
|
|
|
let getInitData = ()=>Promise.resolve({});
|
|
|
|
|
|
|
|
beforeEach(()=>{
|
2022-01-28 05:50:34 -06:00
|
|
|
genericBeforeEach();
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('create', async ()=>{
|
Improved the extendability of the SchemaView and DataGridView. (#7876)
Restructured these modules for ease of maintenance and apply the single
responsibility principle (wherever applicable).
* SchemaView
- Split the code based on the functionality and responsibility.
- Introduced a new View 'InlineView' instead of using the
'nextInline' configuration of the fields to have a better, and
manageable view.
- Using the separate class 'SchemaState' for managing the data and
states of the SchemaView (separated from the 'useSchemaState'
custom hook).
- Introduced three new custom hooks 'useFieldValue',
'useFieldOptions', 'useFieldError' for the individual control to
use for each Schema Field.
- Don't pass value as the parameter props, and let the
'useFieldValue' and other custom hooks to decide, whether to
rerender the control itself or the whole dialog/view. (single
responsibility principle)
- Introduced a new data store with a subscription facility.
- Moving the field metadata (option) evaluation to a separate place
for better management, and each option can be defined for a
particular kind of field (for example - collection, row, cell,
general, etc).
- Allow to provide custom control for all kind of Schema field.
* DataGridView
- Same as SchemaView, split the DataGridView call into smaller,
manageable chunks. (For example - grid, row, mappedCell, etc).
- Use context based approach for providing the row and table data
instead of passing them as parameters to every component
separately.
- Have a facility to extend this feature separately in future.
(for example - selectable cell, column grouping, etc.)
- Separated the features like deletable, editable, reorder,
expandable etc. cells using the above feature support.
- Added ability to provide the CustomHeader, and CustomRow through the
Schema field, which will extend the ability to customize better.
- Removed the 'DataGridViewWithHeaderForm' as it has been achieved
through providing 'CustomHeader', and also introduced
'DataGridFormHeader' (a custom header) to achieve the same feature
as 'DataGridViewWithHeaderForm'.
2024-09-09 03:57:31 -05:00
|
|
|
await getCreateView(createSchemaObj());
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('edit', async ()=>{
|
Improved the extendability of the SchemaView and DataGridView. (#7876)
Restructured these modules for ease of maintenance and apply the single
responsibility principle (wherever applicable).
* SchemaView
- Split the code based on the functionality and responsibility.
- Introduced a new View 'InlineView' instead of using the
'nextInline' configuration of the fields to have a better, and
manageable view.
- Using the separate class 'SchemaState' for managing the data and
states of the SchemaView (separated from the 'useSchemaState'
custom hook).
- Introduced three new custom hooks 'useFieldValue',
'useFieldOptions', 'useFieldError' for the individual control to
use for each Schema Field.
- Don't pass value as the parameter props, and let the
'useFieldValue' and other custom hooks to decide, whether to
rerender the control itself or the whole dialog/view. (single
responsibility principle)
- Introduced a new data store with a subscription facility.
- Moving the field metadata (option) evaluation to a separate place
for better management, and each option can be defined for a
particular kind of field (for example - collection, row, cell,
general, etc).
- Allow to provide custom control for all kind of Schema field.
* DataGridView
- Same as SchemaView, split the DataGridView call into smaller,
manageable chunks. (For example - grid, row, mappedCell, etc).
- Use context based approach for providing the row and table data
instead of passing them as parameters to every component
separately.
- Have a facility to extend this feature separately in future.
(for example - selectable cell, column grouping, etc.)
- Separated the features like deletable, editable, reorder,
expandable etc. cells using the above feature support.
- Added ability to provide the CustomHeader, and CustomRow through the
Schema field, which will extend the ability to customize better.
- Removed the 'DataGridViewWithHeaderForm' as it has been achieved
through providing 'CustomHeader', and also introduced
'DataGridFormHeader' (a custom header) to achieve the same feature
as 'DataGridViewWithHeaderForm'.
2024-09-09 03:57:31 -05:00
|
|
|
await getEditView(createSchemaObj(), getInitData);
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('properties', async ()=>{
|
Improved the extendability of the SchemaView and DataGridView. (#7876)
Restructured these modules for ease of maintenance and apply the single
responsibility principle (wherever applicable).
* SchemaView
- Split the code based on the functionality and responsibility.
- Introduced a new View 'InlineView' instead of using the
'nextInline' configuration of the fields to have a better, and
manageable view.
- Using the separate class 'SchemaState' for managing the data and
states of the SchemaView (separated from the 'useSchemaState'
custom hook).
- Introduced three new custom hooks 'useFieldValue',
'useFieldOptions', 'useFieldError' for the individual control to
use for each Schema Field.
- Don't pass value as the parameter props, and let the
'useFieldValue' and other custom hooks to decide, whether to
rerender the control itself or the whole dialog/view. (single
responsibility principle)
- Introduced a new data store with a subscription facility.
- Moving the field metadata (option) evaluation to a separate place
for better management, and each option can be defined for a
particular kind of field (for example - collection, row, cell,
general, etc).
- Allow to provide custom control for all kind of Schema field.
* DataGridView
- Same as SchemaView, split the DataGridView call into smaller,
manageable chunks. (For example - grid, row, mappedCell, etc).
- Use context based approach for providing the row and table data
instead of passing them as parameters to every component
separately.
- Have a facility to extend this feature separately in future.
(for example - selectable cell, column grouping, etc.)
- Separated the features like deletable, editable, reorder,
expandable etc. cells using the above feature support.
- Added ability to provide the CustomHeader, and CustomRow through the
Schema field, which will extend the ability to customize better.
- Removed the 'DataGridViewWithHeaderForm' as it has been achieved
through providing 'CustomHeader', and also introduced
'DataGridFormHeader' (a custom header) to achieve the same feature
as 'DataGridViewWithHeaderForm'.
2024-09-09 03:57:31 -05:00
|
|
|
await getPropertiesView(createSchemaObj(), getInitData);
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('create collection', async ()=>{
|
2021-08-23 03:10:14 -05:00
|
|
|
let schemaCollObj = new ColumnInColl();
|
2023-10-23 07:13:17 -05:00
|
|
|
const {ctrl, user} = await getCreateView(schemaCollObj);
|
2021-08-23 03:10:14 -05:00
|
|
|
/* Make sure you hit every corner */
|
2023-10-23 07:13:17 -05:00
|
|
|
|
|
|
|
await addNewDatagridRow(user, ctrl);
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('isTypeIdentity', ()=>{
|
|
|
|
let state = {colconstype: 'i'};
|
|
|
|
expect(schemaObj.isTypeIdentity(state)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('isTypeGenerated', ()=>{
|
|
|
|
let state = {colconstype: 'g'};
|
|
|
|
expect(schemaObj.isTypeGenerated(state)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('inSchemaWithModelCheck', ()=>{
|
|
|
|
let state = {attnum: 1};
|
|
|
|
schemaObj.nodeInfo.schema = {};
|
|
|
|
expect(schemaObj.inSchemaWithModelCheck(state)).toBe(true);
|
|
|
|
state.attnum = null;
|
|
|
|
expect(schemaObj.inSchemaWithModelCheck(state)).toBe(false);
|
|
|
|
schemaObj.nodeInfo = {};
|
|
|
|
expect(schemaObj.inSchemaWithModelCheck(state)).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('attlenRange', ()=>{
|
|
|
|
schemaObj.datatypes = datatypes;
|
|
|
|
let state = {cltype: 'character varying'};
|
|
|
|
expect(schemaObj.attlenRange(state)).toEqual({min: 1, max: 140391});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('attprecisionRange', ()=>{
|
|
|
|
schemaObj.datatypes = datatypes;
|
|
|
|
let state = {cltype: 'numeric'};
|
2023-10-11 06:01:02 -05:00
|
|
|
expect(schemaObj.attprecisionRange(state)).toEqual({min: -140391, max: 140391});
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('inSchemaWithColumnCheck', ()=>{
|
|
|
|
let state = {};
|
|
|
|
schemaObj.nodeInfo = {schema: {}};
|
|
|
|
expect(schemaObj.inSchemaWithColumnCheck(state)).toBe(false);
|
|
|
|
|
|
|
|
state.attnum = -1;
|
|
|
|
expect(schemaObj.inSchemaWithColumnCheck(state)).toBe(true);
|
|
|
|
|
|
|
|
state.inheritedfrom = 140391;
|
|
|
|
expect(schemaObj.inSchemaWithColumnCheck(state)).toBe(true);
|
|
|
|
|
|
|
|
schemaObj.nodeInfo.view = {};
|
|
|
|
expect(schemaObj.inSchemaWithColumnCheck(state)).toBe(true);
|
|
|
|
|
|
|
|
schemaObj.nodeInfo = {};
|
2021-10-11 07:12:14 -05:00
|
|
|
expect(schemaObj.inSchemaWithColumnCheck(state)).toBe(false);
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('editableCheckForTable', ()=>{
|
|
|
|
let state = {};
|
|
|
|
schemaObj.nodeInfo = {};
|
2021-10-11 07:12:14 -05:00
|
|
|
expect(schemaObj.editableCheckForTable(state)).toBe(true);
|
2021-08-23 03:10:14 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('depChange', ()=>{
|
|
|
|
schemaObj.datatypes = datatypes;
|
|
|
|
let state = {cltype: 'numeric'};
|
|
|
|
getFieldDepChange(schemaObj, 'collspcname')(state);
|
|
|
|
|
|
|
|
expect(getFieldDepChange(schemaObj, 'attlen')(state)).toEqual({
|
|
|
|
cltype: 'numeric',
|
|
|
|
min_val_attlen: 1,
|
|
|
|
max_val_attlen: 140391,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(getFieldDepChange(schemaObj, 'attprecision')(state)).toEqual({
|
|
|
|
cltype: 'numeric',
|
2023-10-11 06:01:02 -05:00
|
|
|
min_val_attprecision: -140391,
|
2021-08-23 03:10:14 -05:00
|
|
|
max_val_attprecision: 140391,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('validate', ()=>{
|
|
|
|
let state = {};
|
2023-10-23 07:13:17 -05:00
|
|
|
let setError = jest.fn();
|
2021-08-23 03:10:14 -05:00
|
|
|
|
|
|
|
state.cltype = 'bigint';
|
|
|
|
state.min_val_attlen = 5;
|
|
|
|
state.max_val_attlen = 10;
|
|
|
|
state.attlen = 3;
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('attlen', 'Length/Precision should not be less than: 5');
|
|
|
|
state.attlen = 11;
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('attlen', 'Length/Precision should not be greater than: 10');
|
|
|
|
|
|
|
|
state.attlen = 6;
|
|
|
|
state.min_val_attprecision = 5;
|
|
|
|
state.max_val_attprecision = 10;
|
|
|
|
state.attprecision = 3;
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('attprecision', 'Scale should not be less than: 5');
|
|
|
|
state.attprecision = 11;
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('attprecision', 'Scale should not be greater than: 10');
|
|
|
|
|
|
|
|
state.attprecision = 6;
|
|
|
|
state.colconstype = 'g';
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('genexpr', 'Expression value cannot be empty.');
|
|
|
|
|
|
|
|
state.attnum = 1;
|
|
|
|
state.attidentity = 'a';
|
|
|
|
state.colconstype = 'i';
|
2024-08-18 23:23:00 -05:00
|
|
|
initializeSchemaWithData(schemaObj, {attidentity:'a'});
|
2021-08-23 03:10:14 -05:00
|
|
|
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('seqincrement', 'Increment value cannot be empty.');
|
|
|
|
|
|
|
|
state.seqincrement = 1;
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('seqmin', 'Minimum value cannot be empty.');
|
|
|
|
|
|
|
|
state.seqmin = 1;
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('seqmax', 'Maximum value cannot be empty.');
|
|
|
|
|
|
|
|
state.seqmax = 1;
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('seqcache', 'Cache value cannot be empty.');
|
|
|
|
|
|
|
|
state.attnum = null;
|
|
|
|
state.seqmin = null;
|
|
|
|
state.seqmax = null;
|
2024-08-18 23:23:00 -05:00
|
|
|
initializeSchemaWithData(schemaObj, {attidentity: undefined});
|
2021-08-23 03:10:14 -05:00
|
|
|
expect(schemaObj.validate(state, setError)).toBe(false);
|
|
|
|
|
|
|
|
state.seqmin = 3;
|
|
|
|
state.seqmax = 2;
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('seqmin', 'Minimum value must be less than maximum value.');
|
|
|
|
|
|
|
|
state.seqmin = 3;
|
|
|
|
state.seqmax = 5;
|
|
|
|
state.seqstart = 2;
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('seqstart', 'Start value cannot be less than minimum value.');
|
|
|
|
|
|
|
|
state.seqstart = 6;
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('seqstart', 'Start value cannot be greater than maximum value.');
|
|
|
|
|
|
|
|
|
|
|
|
state.seqstart = 4;
|
|
|
|
expect(schemaObj.validate(state, setError)).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|