1
0
mirror of synced 2026-10-23 07:08:55 +03:00

Fix the Jest addNewDatagridRow helper so schema UI specs actually add a row. #10602 (#10624)

This commit is contained in:
Dave Page
2026-10-16 00:46:52 +01:00
parent 6594977cc3
commit 1402f7d9cd
5 changed files with 37 additions and 5 deletions

View File

@@ -7,6 +7,7 @@
//
//////////////////////////////////////////////////////////////
/* global expect */
import pgAdmin from 'sources/pgadmin';
import SchemaView from '../../pgadmin/static/js/SchemaView';
import pgWindow from 'sources/window';
@@ -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 = ()=> {

View File

@@ -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();
});

View File

@@ -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 */

View File

@@ -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([]),
}, {});

View File

@@ -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([]),
}, {});