From 1402f7d9cd826c252848900ee0cb52bddda0f369 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Fri, 16 Oct 2026 00:46:52 +0100 Subject: [PATCH] Fix the Jest addNewDatagridRow helper so schema UI specs actually add a row. #10602 (#10624) --- .../javascript/genericFunctions.jsx | 22 ++++++++++++++++++- .../schema_ui_files/foreign_key.ui.spec.js | 5 ++++- .../partition.utils.ui.spec.js | 5 ++++- .../schema_ui_files/primary_key.ui.spec.js | 5 ++++- .../unique_constraint.ui.spec.js | 5 ++++- 5 files changed, 37 insertions(+), 5 deletions(-) diff --git a/web/regression/javascript/genericFunctions.jsx b/web/regression/javascript/genericFunctions.jsx index 4c97e9cac..b3b2240c5 100644 --- a/web/regression/javascript/genericFunctions.jsx +++ b/web/regression/javascript/genericFunctions.jsx @@ -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 = ()=> { diff --git a/web/regression/javascript/schema_ui_files/foreign_key.ui.spec.js b/web/regression/javascript/schema_ui_files/foreign_key.ui.spec.js index 75b04c88f..05e27b5dd 100644 --- a/web/regression/javascript/schema_ui_files/foreign_key.ui.spec.js +++ b/web/regression/javascript/schema_ui_files/foreign_key.ui.spec.js @@ -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(); }); diff --git a/web/regression/javascript/schema_ui_files/partition.utils.ui.spec.js b/web/regression/javascript/schema_ui_files/partition.utils.ui.spec.js index 4401cca05..4bcef2484 100644 --- a/web/regression/javascript/schema_ui_files/partition.utils.ui.spec.js +++ b/web/regression/javascript/schema_ui_files/partition.utils.ui.spec.js @@ -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 */ diff --git a/web/regression/javascript/schema_ui_files/primary_key.ui.spec.js b/web/regression/javascript/schema_ui_files/primary_key.ui.spec.js index aaa2081c2..be8ebde82 100644 --- a/web/regression/javascript/schema_ui_files/primary_key.ui.spec.js +++ b/web/regression/javascript/schema_ui_files/primary_key.ui.spec.js @@ -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([]), }, {}); diff --git a/web/regression/javascript/schema_ui_files/unique_constraint.ui.spec.js b/web/regression/javascript/schema_ui_files/unique_constraint.ui.spec.js index 6bb414efc..fe2671fb9 100644 --- a/web/regression/javascript/schema_ui_files/unique_constraint.ui.spec.js +++ b/web/regression/javascript/schema_ui_files/unique_constraint.ui.spec.js @@ -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([]), }, {});