mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-22 08:46:39 -06:00
be69470d55
1. Unable to change shared server switch. 2. DB restriction and schema restriction have an empty option. 3. File select input control does not allow manual text input. 4. In the Parameters tab if the value is a switch control, then an empty value error should not come. 5. Values for parameters should be reset on changing parameters. 6. Added a new key - helpMessageMode which can have a value similar to mode. It will show the help message if the mode is supported. Fixes #6814
142 lines
4.1 KiB
JavaScript
142 lines
4.1 KiB
JavaScript
/////////////////////////////////////////////////////////////
|
|
//
|
|
// 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';
|
|
import ServerSchema from '../../../pgadmin/browser/server_groups/servers/static/js/server.ui';
|
|
|
|
describe('ServerSchema', ()=>{
|
|
let mount;
|
|
let schemaObj = new ServerSchema([{
|
|
label: 'Servers', value: 1,
|
|
}], 0, {
|
|
user_id: 'jasmine',
|
|
});
|
|
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 || {};
|
|
pgAdmin.Browser.utils.support_ssh_tunnel = true;
|
|
});
|
|
|
|
it('create', ()=>{
|
|
mount(<SchemaView
|
|
formType='dialog'
|
|
schema={schemaObj}
|
|
viewHelperProps={{
|
|
mode: 'create',
|
|
}}
|
|
onSave={()=>{}}
|
|
onClose={()=>{}}
|
|
onHelp={()=>{}}
|
|
onEdit={()=>{}}
|
|
onDataChange={()=>{}}
|
|
confirmOnCloseReset={false}
|
|
hasSQL={false}
|
|
disableSqlHelp={false}
|
|
disableDialogHelp={false}
|
|
/>);
|
|
});
|
|
|
|
it('edit', ()=>{
|
|
mount(<SchemaView
|
|
formType='dialog'
|
|
schema={schemaObj}
|
|
getInitData={getInitData}
|
|
viewHelperProps={{
|
|
mode: 'edit',
|
|
}}
|
|
onSave={()=>{}}
|
|
onClose={()=>{}}
|
|
onHelp={()=>{}}
|
|
onEdit={()=>{}}
|
|
onDataChange={()=>{}}
|
|
confirmOnCloseReset={false}
|
|
hasSQL={false}
|
|
disableSqlHelp={false}
|
|
disableDialogHelp={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');
|
|
|
|
schemaObj.validate(state, setError);
|
|
expect(setError).toHaveBeenCalledWith('host', 'Either Host name, Address or Service must be specified.');
|
|
|
|
state.hostaddr = 'incorrectip';
|
|
schemaObj.validate(state, setError);
|
|
expect(setError).toHaveBeenCalledWith('hostaddr', 'Host address must be valid IPv4 or IPv6 address.');
|
|
|
|
state.host = '127.0.0.1';
|
|
state.hostaddr = null;
|
|
schemaObj.validate(state, setError);
|
|
expect(setError).toHaveBeenCalledWith('username', 'Username must be specified.');
|
|
|
|
state.username = 'postgres';
|
|
schemaObj.validate(state, setError);
|
|
expect(setError).toHaveBeenCalledWith('port', 'Port must be specified.');
|
|
|
|
state.port = 5432;
|
|
state.use_ssh_tunnel = true;
|
|
schemaObj.validate(state, setError);
|
|
expect(setError).toHaveBeenCalledWith('tunnel_host', 'SSH Tunnel host must be specified.');
|
|
|
|
state.service = 'pgservice';
|
|
state.tunnel_host = 'localhost';
|
|
schemaObj.validate(state, setError);
|
|
expect(setError).toHaveBeenCalledWith('tunnel_port', 'SSH Tunnel port must be specified.');
|
|
|
|
state.tunnel_port = 8080;
|
|
schemaObj.validate(state, setError);
|
|
expect(setError).toHaveBeenCalledWith('tunnel_username', 'SSH Tunnel username must be specified.');
|
|
|
|
state.tunnel_username = 'jasmine';
|
|
state.tunnel_authentication = true;
|
|
schemaObj.validate(state, setError);
|
|
expect(setError).toHaveBeenCalledWith('tunnel_identity_file', 'SSH Tunnel identity file must be specified.');
|
|
|
|
state.tunnel_identity_file = '/file/path/xyz.pem';
|
|
expect(schemaObj.validate(state, setError)).toBeFalse();
|
|
});
|
|
});
|