mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Port Collation node to react. Fixes #6584.
This commit is contained in:
committed by
Akshay Joshi
parent
a06f78b2d5
commit
6fe83d1f06
141
web/regression/javascript/schema_ui_files/collation.ui.spec.js
Normal file
141
web/regression/javascript/schema_ui_files/collation.ui.spec.js
Normal file
@@ -0,0 +1,141 @@
|
||||
/////////////////////////////////////////////////////////////
|
||||
//
|
||||
// pgAdmin 4 - PostgreSQL Tools
|
||||
//
|
||||
// Copyright (C) 2013 - 2021, The pgAdmin Development Team
|
||||
// This software is released under the PostgreSQL Licence
|
||||
//
|
||||
//////////////////////////////////////////////////////////////
|
||||
|
||||
import jasmineEnzyme from 'jasmine-enzyme';
|
||||
import React from 'react';
|
||||
import '../helper/enzyme.helper';
|
||||
import { createMount } from '@material-ui/core/test-utils';
|
||||
import pgAdmin from 'sources/pgadmin';
|
||||
import { messages } from '../fake_messages';
|
||||
import SchemaView from '../../../pgadmin/static/js/SchemaView';
|
||||
// web/pgadmin/browser/server_groups/servers/databases/schemas/collations/static/js/collation.ui.js
|
||||
import CollationSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/collations/static/js/collation.ui';
|
||||
|
||||
|
||||
describe('CollationsSchema', () => {
|
||||
let mount;
|
||||
let schemaObj = new CollationSchema(
|
||||
{
|
||||
rolesList: () => [],
|
||||
schemaList: () => [],
|
||||
collationsList: () => []
|
||||
},
|
||||
{
|
||||
owner: 'postgres',
|
||||
schema: ''
|
||||
}
|
||||
);
|
||||
let getInitData = () => Promise.resolve({});
|
||||
|
||||
/* Use createMount so that material ui components gets the required context */
|
||||
/* https://material-ui.com/guides/testing/#api */
|
||||
beforeAll(() => {
|
||||
mount = createMount();
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
mount.cleanUp();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jasmineEnzyme();
|
||||
/* messages used by validators */
|
||||
pgAdmin.Browser = pgAdmin.Browser || {};
|
||||
pgAdmin.Browser.messages = pgAdmin.Browser.messages || messages;
|
||||
pgAdmin.Browser.utils = pgAdmin.Browser.utils || {};
|
||||
});
|
||||
|
||||
it('create', () => {
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={() => { }}
|
||||
onClose={() => { }}
|
||||
onHelp={() => { }}
|
||||
onEdit={() => { }}
|
||||
onDataChange={() => { }}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('edit', () => {
|
||||
mount(<SchemaView
|
||||
formType='dialog'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'create',
|
||||
}}
|
||||
onSave={() => { }}
|
||||
onClose={() => { }}
|
||||
onHelp={() => { }}
|
||||
onEdit={() => { }}
|
||||
onDataChange={() => { }}
|
||||
confirmOnCloseReset={false}
|
||||
hasSQL={false}
|
||||
disableSqlHelp={false}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('properties', () => {
|
||||
mount(<SchemaView
|
||||
formType='tab'
|
||||
schema={schemaObj}
|
||||
getInitData={getInitData}
|
||||
viewHelperProps={{
|
||||
mode: 'properties',
|
||||
}}
|
||||
onHelp={() => { }}
|
||||
onEdit={() => { }}
|
||||
/>);
|
||||
});
|
||||
|
||||
it('validate', () => {
|
||||
let state = {};
|
||||
let setError = jasmine.createSpy('setError');
|
||||
|
||||
state.name = null;
|
||||
state.locale = 'locale';
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('name', 'Name cannot be empty.');
|
||||
|
||||
state.name = 'test';
|
||||
state.copy_collation = null;
|
||||
state.lc_type = null;
|
||||
state.lc_collate = null;
|
||||
state.locale = null;
|
||||
schemaObj.validate(state, setError);
|
||||
expect(setError).toHaveBeenCalledWith('copy_collation', 'Definition incomplete. Please provide Locale OR Copy Collation OR LC_TYPE/LC_COLLATE.');
|
||||
});
|
||||
|
||||
it('disableFields',() => {
|
||||
let state = {};
|
||||
|
||||
state.name = 'test';
|
||||
state.locale = 'locale';
|
||||
expect(schemaObj.disableFields(state)).toBeTrue();
|
||||
|
||||
state.name = 'test';
|
||||
state.copy_collation = 'copy_collation';
|
||||
state.locale = null;
|
||||
expect(schemaObj.disableFields(state)).toBeTrue();
|
||||
|
||||
state.name = 'test';
|
||||
state.copy_collation = null;
|
||||
state.locale = null;
|
||||
expect(schemaObj.disableFields(state)).toBeFalse();
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user