pgadmin4/web/regression/javascript/schema_ui_files/view.ui.spec.js

81 lines
1.9 KiB
JavaScript
Raw Normal View History

2021-07-26 00:49:19 -05:00
/////////////////////////////////////////////////////////////
//
// pgAdmin 4 - PostgreSQL Tools
//
2023-01-02 00:23:55 -06:00
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
2021-07-26 00:49:19 -05:00
// This software is released under the PostgreSQL Licence
//
//////////////////////////////////////////////////////////////
2021-07-26 00:49:19 -05:00
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
import ViewSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/views/static/js/view.ui';
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
2021-07-26 00:49:19 -05:00
class MockSchema extends BaseUISchema {
get baseFields() {
return [];
}
}
describe('ViewSchema', ()=>{
2021-07-26 00:49:19 -05:00
let schemaObj = new ViewSchema(
()=>new MockSchema(),
{server: {server_type: 'pg'}},
{
role: ()=>[],
schema: ()=>[],
},
{
owner: 'postgres',
schema: 'public'
}
);
let getInitData = ()=>Promise.resolve({});
2021-07-26 00:49:19 -05:00
beforeEach(()=>{
genericBeforeEach();
2021-07-26 00:49:19 -05:00
});
it('create', async ()=>{
await getCreateView(schemaObj);
2021-07-26 00:49:19 -05:00
});
it('edit', async ()=>{
await getEditView(schemaObj, getInitData);
2021-07-26 00:49:19 -05:00
});
it('properties', async ()=>{
await getPropertiesView(schemaObj, getInitData);
2021-07-26 00:49:19 -05:00
});
it('validate', ()=>{
let state = {};
let setError = jest.fn();
2021-07-26 00:49:19 -05:00
state.definition = null;
schemaObj.validate(state, setError);
expect(setError).toHaveBeenCalledWith('definition', 'Please enter view code.');
state.definition = 'SELECT 1;';
schemaObj.validate(state, setError);
expect(setError).toHaveBeenCalledWith('definition', null);
state.definition = 'SELECT 1';
schemaObj.validate(state, setError);
expect(setError).toHaveBeenCalledWith('definition', null);
state.service = 'Test';
state.definition = 'SELECT 1';
schemaObj.validate(state, setError);
expect(setError).toHaveBeenCalledWith('definition', null);
});
});