2021-08-10 01:07:51 -05:00
|
|
|
/////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2023-01-02 00:23:55 -06:00
|
|
|
// Copyright (C) 2013 - 2023, The pgAdmin Development Team
|
2021-08-10 01:07:51 -05:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2021-08-10 01:07:51 -05:00
|
|
|
import BaseUISchema from 'sources/SchemaView/base_schema.ui';
|
|
|
|
import TriggerFunctionSchema from '../../../pgadmin/browser/server_groups/servers/databases/schemas/functions/static/js/trigger_function.ui';
|
2022-01-28 05:50:34 -06:00
|
|
|
import {genericBeforeEach, getCreateView, getEditView, getPropertiesView} from '../genericFunctions';
|
2021-08-10 01:07:51 -05:00
|
|
|
|
|
|
|
class MockSchema extends BaseUISchema {
|
|
|
|
get baseFields() {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
describe('TriggerFunctionSchema', ()=>{
|
2023-10-23 07:13:17 -05:00
|
|
|
|
2021-08-10 01:07:51 -05:00
|
|
|
let schemaObj = new TriggerFunctionSchema(
|
|
|
|
()=>new MockSchema(),
|
|
|
|
()=>new MockSchema(),
|
|
|
|
{
|
|
|
|
role: [],
|
|
|
|
schema: [],
|
|
|
|
language: [],
|
|
|
|
nodeInfo: {}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
funcowner: 'postgres',
|
|
|
|
pronamespace: 'public'
|
|
|
|
}
|
|
|
|
);
|
|
|
|
let getInitData = ()=>Promise.resolve({});
|
|
|
|
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
|
|
|
|
|
2021-08-10 01:07:51 -05:00
|
|
|
|
|
|
|
beforeEach(()=>{
|
2022-01-28 05:50:34 -06:00
|
|
|
genericBeforeEach();
|
2021-08-10 01:07:51 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('create', async ()=>{
|
|
|
|
await getCreateView(schemaObj);
|
2021-08-10 01:07:51 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('edit', async ()=>{
|
|
|
|
await getEditView(schemaObj, getInitData);
|
2021-08-10 01:07:51 -05:00
|
|
|
});
|
|
|
|
|
2023-10-23 07:13:17 -05:00
|
|
|
it('properties', async ()=>{
|
|
|
|
await getPropertiesView(schemaObj, getInitData);
|
2021-08-10 01:07:51 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('validate', ()=>{
|
|
|
|
let state = {};
|
2023-10-23 07:13:17 -05:00
|
|
|
let setError = jest.fn();
|
2021-08-10 01:07:51 -05:00
|
|
|
|
|
|
|
state.prosrc = null;
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('prosrc', 'Code cannot be empty.');
|
|
|
|
|
|
|
|
state.prosrc = 'SELECT 1';
|
|
|
|
schemaObj.validate(state, setError);
|
|
|
|
expect(setError).toHaveBeenCalledWith('prosrc', null);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|