mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-22 08:46:39 -06:00
83 lines
2.7 KiB
JavaScript
83 lines
2.7 KiB
JavaScript
/////////////////////////////////////////////////////////////
|
|
//
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
//
|
|
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
|
// This software is released under the PostgreSQL Licence
|
|
//
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
|
import pgAdmin from 'sources/pgadmin';
|
|
import ServerSchema from '../../../pgadmin/browser/server_groups/servers/static/js/server.ui';
|
|
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
|
|
|
describe('ServerSchema', ()=>{
|
|
|
|
let schemaObj = new ServerSchema([{
|
|
label: 'Servers', value: 1,
|
|
}], 0, {
|
|
user_id: 'jasmine',
|
|
});
|
|
let getInitData = ()=>Promise.resolve({});
|
|
|
|
beforeEach(()=>{
|
|
genericBeforeEach();
|
|
pgAdmin.Browser.utils.support_ssh_tunnel = true;
|
|
});
|
|
|
|
it('create', async ()=>{
|
|
await getCreateView(schemaObj);
|
|
});
|
|
|
|
it('edit', async ()=>{
|
|
await getEditView(schemaObj, getInitData);
|
|
});
|
|
|
|
it('properties', async ()=>{
|
|
await getPropertiesView(schemaObj, getInitData);
|
|
});
|
|
|
|
it('validate', ()=>{
|
|
let state = {};
|
|
let setError = jest.fn();
|
|
|
|
schemaObj.validate(state, setError);
|
|
expect(setError).toHaveBeenCalledWith('host', 'Either Host name or Service must be specified.');
|
|
|
|
state.host = '127.0.0.1';
|
|
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';
|
|
schemaObj.validate(state, setError);
|
|
expect(setError).toHaveBeenCalledWith('tunnel_keep_alive', 'Keep alive must be specified. Specify 0 for no keep alive.');
|
|
|
|
state.tunnel_keep_alive = 0;
|
|
expect(schemaObj.validate(state, setError)).toBe(false);
|
|
});
|
|
});
|