mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2024-11-22 00:37:36 -06:00
dea5335ce5
1) Do not use the Array index in keys. 2) Import from the same module should be merged. 3) Mutable variables should not be exported. 4) Variables should not be initialized to undefined. 5) startswith or endswith method should be used. 6) Unwrap this unnecessarily grouped subpattern. Additionally, addressed many other SonarQube rules.
101 lines
3.0 KiB
JavaScript
101 lines
3.0 KiB
JavaScript
/////////////////////////////////////////////////////////////
|
|
//
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
//
|
|
// Copyright (C) 2013 - 2024, The pgAdmin Development Team
|
|
// This software is released under the PostgreSQL Licence
|
|
//
|
|
//////////////////////////////////////////////////////////////
|
|
|
|
import React from 'react';
|
|
import pgAdmin from 'sources/pgadmin';
|
|
import SchemaView from '../../pgadmin/static/js/SchemaView';
|
|
import pgWindow from 'sources/window';
|
|
import fakePgAdmin from './fake_pgadmin';
|
|
import Theme from '../../pgadmin/static/js/Theme';
|
|
import { PgAdminContext } from '../../pgadmin/static/js/BrowserComponent';
|
|
import { act, render } from '@testing-library/react';
|
|
import userEvent from '@testing-library/user-event';
|
|
|
|
export function withBrowser(WrappedComp) {
|
|
// eslint-disable-next-line react/display-name
|
|
return (props)=>{
|
|
return <Theme>
|
|
<PgAdminContext.Provider value={fakePgAdmin}>
|
|
<WrappedComp {...props}/>
|
|
</PgAdminContext.Provider>
|
|
</Theme>;
|
|
};
|
|
}
|
|
|
|
const SchemaViewWithBrowser = withBrowser(SchemaView);
|
|
|
|
export const getEditView = async (schemaObj, getInitData)=> {
|
|
await act(async ()=>{
|
|
return render(<SchemaViewWithBrowser
|
|
formType='dialog'
|
|
schema={schemaObj}
|
|
getInitData={getInitData}
|
|
viewHelperProps={{
|
|
mode: 'edit',
|
|
}}
|
|
onSave={()=>{/*This is intentional (SonarQube)*/}}
|
|
onClose={()=>{/*This is intentional (SonarQube)*/}}
|
|
onHelp={()=>{/*This is intentional (SonarQube)*/}}
|
|
onEdit={()=>{/*This is intentional (SonarQube)*/}}
|
|
onDataChange={()=>{/*This is intentional (SonarQube)*/}}
|
|
confirmOnCloseReset={false}
|
|
hasSQL={false}
|
|
disableSqlHelp={false}
|
|
disableDialogHelp={false}
|
|
/>);
|
|
});
|
|
};
|
|
|
|
export const getCreateView = async (schemaObj)=> {
|
|
let ctrl;
|
|
const user = userEvent.setup();
|
|
await act(async ()=>{
|
|
ctrl = render(<SchemaViewWithBrowser
|
|
formType='dialog'
|
|
schema={schemaObj}
|
|
viewHelperProps={{
|
|
mode: 'create',
|
|
}}
|
|
onSave={()=>{/*This is intentional (SonarQube)*/}}
|
|
onClose={()=>{/*This is intentional (SonarQube)*/}}
|
|
onHelp={()=>{/*This is intentional (SonarQube)*/}}
|
|
onEdit={()=>{/*This is intentional (SonarQube)*/}}
|
|
onDataChange={()=>{/*This is intentional (SonarQube)*/}}
|
|
confirmOnCloseReset={false}
|
|
hasSQL={false}
|
|
disableSqlHelp={false}
|
|
disableDialogHelp={false}
|
|
/>);
|
|
});
|
|
return {ctrl, user};
|
|
};
|
|
|
|
export const getPropertiesView = async (schemaObj, getInitData)=> {
|
|
await act(async ()=>{
|
|
return render(<SchemaViewWithBrowser
|
|
formType='tab'
|
|
schema={schemaObj}
|
|
getInitData={getInitData}
|
|
viewHelperProps={{
|
|
mode: 'properties',
|
|
}}
|
|
onHelp={()=>{/*This is intentional (SonarQube)*/}}
|
|
onEdit={()=>{/*This is intentional (SonarQube)*/}}
|
|
/>);
|
|
});
|
|
};
|
|
|
|
export const addNewDatagridRow = async (user, ctrl)=>{
|
|
await user.click(ctrl.container.querySelector('[data-test="add-row"] button'));
|
|
};
|
|
|
|
export const genericBeforeEach = ()=> {
|
|
pgWindow.pgAdmin = pgAdmin;
|
|
};
|