Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion web/regression/javascript/genericFunctions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
//
//////////////////////////////////////////////////////////////

/* global expect */
import pgAdmin from 'sources/pgadmin';
import SchemaView from '../../pgadmin/static/js/SchemaView';
import pgWindow from 'sources/window';
Expand Down Expand Up @@ -90,8 +91,27 @@ export const getPropertiesView = async (schemaObj, getInitData)=> {
});
};

// Count the rows belonging to the data grid itself, ignoring rows of any
// grid nested inside an expanded row.
const countDatagridRows = (gridEle)=>{
const tableEle = gridEle.querySelector('[data-test="data-grid-view"]');
return Array.from(
tableEle?.querySelectorAll('[data-test="data-table-row"]') ?? []
).filter(
(rowEle)=>rowEle.closest('[data-test="data-grid-view"]') === tableEle
).length;
};

export const addNewDatagridRow = async (user, ctrl)=>{
await user.click(ctrl.container.querySelector('[data-test="add-row"] button'));
const addBtn = ctrl.container.querySelector('[data-test="add-row"]');
expect(addBtn).not.toBeNull();

const gridEle = addBtn.closest('.DataGridView-grid');
expect(gridEle).not.toBeNull();

const rowCount = countDatagridRows(gridEle);
await user.click(addBtn);
expect(countDatagridRows(gridEle)).toBe(rowCount + 1);
};

export const genericBeforeEach = ()=> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,13 @@ describe('ForeignKeySchema', ()=>{
beforeAll(()=>{
jest.spyOn(nodeAjax, 'getNodeAjaxOptions').mockReturnValue(Promise.resolve([]));
jest.spyOn(nodeAjax, 'getNodeListByName').mockReturnValue(Promise.resolve([]));
schemaObj = getNodeForeignKeySchema({}, {}, {Nodes: {table: {}}});
});

beforeEach(()=>{
// A fresh schema per test, as each dialog gets in the product; the
// properties view mutates its fields (helpMessage), which would otherwise
// leak into the grid cells rendered by later tests.
schemaObj = getNodeForeignKeySchema({}, {}, {Nodes: {table: {}}});
genericBeforeEach();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,11 @@ describe('PartitionsSchema', ()=>{
});

it('create collection', async ()=>{
// Let the collection become the top schema, as the table dialog is in
// the product, rather than the partition schema being its own top with
// no session data.
let schemaCollObj = new SchemaInColl(
schemaObj,[ 'is_attach', 'partition_name', 'is_default', 'values_from', 'values_to', 'values_in', 'values_modulus', 'values_remainder']
new PartitionsSchema(),[ 'is_attach', 'partition_name', 'is_default', 'values_from', 'values_to', 'values_in', 'values_modulus', 'values_remainder']
);
const {ctrl, user} = await getCreateView(schemaCollObj);
/* Make sure you hit every corner */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ describe('PrimaryKeySchema', ()=>{
let schemaObj;
let getInitData = ()=>Promise.resolve({});

beforeAll(()=>{
// A fresh schema per test, as each dialog gets in the product; the
// properties view mutates its fields (helpMessage), which would otherwise
// leak into the grid cells rendered by later tests.
beforeEach(()=>{
schemaObj = new PrimaryKeySchema({
spcname: ()=>Promise.resolve([]),
}, {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ describe('UniqueConstraintSchema', ()=>{
let schemaObj;
let getInitData = ()=>Promise.resolve({});

beforeAll(()=>{
// A fresh schema per test, as each dialog gets in the product; the
// properties view mutates its fields (helpMessage), which would otherwise
// leak into the grid cells rendered by later tests.
beforeEach(()=>{
schemaObj = new UniqueConstraintSchema({
spcname: ()=>Promise.resolve([]),
}, {});
Expand Down
Loading