From d79e684c761b4665f64e3eca410940dfffee76bf Mon Sep 17 00:00:00 2001 From: git-avc Date: Wed, 10 Dec 2025 09:10:24 +0100 Subject: [PATCH] test: add child row form test --- cypress/fixtures/child_table_with_tabs.js | 48 ++++++ .../fixtures/doctype_with_child_table_tabs.js | 43 ++++++ cypress/integration/grid_row_form_tabs.js | 142 ++++++++++++++++++ 3 files changed, 233 insertions(+) create mode 100644 cypress/fixtures/child_table_with_tabs.js create mode 100644 cypress/fixtures/doctype_with_child_table_tabs.js create mode 100644 cypress/integration/grid_row_form_tabs.js diff --git a/cypress/fixtures/child_table_with_tabs.js b/cypress/fixtures/child_table_with_tabs.js new file mode 100644 index 0000000000..b1b9a909b5 --- /dev/null +++ b/cypress/fixtures/child_table_with_tabs.js @@ -0,0 +1,48 @@ +export default { + name: "Child Table With Tabs", + actions: [], + custom: 1, + autoname: "hash", + doctype: "DocType", + editable_grid: 1, + engine: "InnoDB", + fields: [ + { + fieldname: "item_name", + fieldtype: "Data", + in_list_view: 1, + label: "Item Name", + reqd: 1, + }, + { + fieldname: "quantity", + fieldtype: "Int", + in_list_view: 1, + label: "Quantity", + }, + { + fieldname: "tab_details", + fieldtype: "Tab Break", + label: "More Details", + }, + { + fieldname: "description", + fieldtype: "Small Text", + label: "Description", + }, + { + fieldname: "notes", + fieldtype: "Data", + label: "Notes", + }, + ], + istable: 1, + links: [], + modified_by: "Administrator", + module: "Custom", + owner: "Administrator", + permissions: [], + sort_field: "creation", + sort_order: "ASC", + track_changes: 1, +}; diff --git a/cypress/fixtures/doctype_with_child_table_tabs.js b/cypress/fixtures/doctype_with_child_table_tabs.js new file mode 100644 index 0000000000..bd0a2dd171 --- /dev/null +++ b/cypress/fixtures/doctype_with_child_table_tabs.js @@ -0,0 +1,43 @@ +export default { + name: "Doctype With Child Table Tabs", + actions: [], + custom: 1, + autoname: "format: Test-Child-Tabs-{####}", + doctype: "DocType", + editable_grid: 1, + engine: "InnoDB", + fields: [ + { + fieldname: "title", + fieldtype: "Data", + label: "Title", + reqd: 1, + }, + { + fieldname: "items", + fieldtype: "Table", + label: "Items", + options: "Child Table With Tabs", + reqd: 1, + }, + ], + links: [], + modified_by: "Administrator", + module: "Custom", + owner: "Administrator", + permissions: [ + { + create: 1, + delete: 1, + email: 1, + print: 1, + read: 1, + role: "System Manager", + share: 1, + write: 1, + }, + ], + sort_field: "creation", + sort_order: "ASC", + track_changes: 1, +}; diff --git a/cypress/integration/grid_row_form_tabs.js b/cypress/integration/grid_row_form_tabs.js new file mode 100644 index 0000000000..282863bd36 --- /dev/null +++ b/cypress/integration/grid_row_form_tabs.js @@ -0,0 +1,142 @@ +import child_table_with_tabs from "../fixtures/child_table_with_tabs"; +import doctype_with_child_table_tabs from "../fixtures/doctype_with_child_table_tabs"; + +const parent_doctype_name = doctype_with_child_table_tabs.name; +const child_doctype_name = child_table_with_tabs.name; + +context("Grid Row Form Tabs", () => { + before(() => { + cy.login(); + cy.visit("/desk/website"); + // Create child table doctype first, then parent + return cy.insert_doc("DocType", child_table_with_tabs, true).then(() => { + return cy.insert_doc("DocType", doctype_with_child_table_tabs, true); + }); + }); + + beforeEach(() => { + cy.login(); + cy.visit("/desk/website"); + }); + + it("should display tabs in grid row form", () => { + cy.new_form(parent_doctype_name); + cy.fill_field("title", "Test Document"); + + // Add a row to the child table + cy.get('.frappe-control[data-fieldname="items"]').as("table"); + cy.get("@table").findByRole("button", { name: "Add Row" }).click(); + + // Open the grid row form + cy.get("@table").find('[data-idx="1"]').as("row1"); + cy.get("@row1").find(".btn-open-row").click(); + + // Verify grid row form is open + cy.get(".grid-row-open").as("table-form"); + + // Verify tabs are visible in the grid row form + cy.get("@table-form").find(".form-tabs-list").should("be.visible"); + cy.get("@table-form").find(".form-tabs .nav-item").should("have.length", 2); + + // Verify first tab (General) is active by default + cy.get("@table-form").find(".form-tabs .nav-link").first().should("have.class", "active"); + }); + + it("should switch tabs in grid row form", () => { + cy.new_form(parent_doctype_name); + cy.fill_field("title", "Test Tab Switch"); + + // Add a row to the child table + cy.get('.frappe-control[data-fieldname="items"]').as("table"); + cy.get("@table").findByRole("button", { name: "Add Row" }).click(); + + // Open the grid row form + cy.get("@table").find('[data-idx="1"]').as("row1"); + cy.get("@row1").find(".btn-open-row").click(); + cy.get(".grid-row-open").as("table-form"); + + // Verify initial tab content - fields from General tab should be visible + cy.get("@table-form") + .find('.frappe-control[data-fieldname="item_name"]') + .should("be.visible"); + cy.get("@table-form") + .find('.frappe-control[data-fieldname="quantity"]') + .should("be.visible"); + + // Click on the "Details" tab + cy.get("@table-form").findByRole("tab", { name: "Details" }).click(); + + // Verify second tab is now active + cy.get("@table-form").find(".form-tabs .nav-link").last().should("have.class", "active"); + + // Verify first tab is no longer active + cy.get("@table-form") + .find(".form-tabs .nav-link") + .first() + .should("not.have.class", "active"); + + // Fields from Details tab should be visible + cy.get("@table-form") + .find('.frappe-control[data-fieldname="description"]') + .should("be.visible"); + cy.get("@table-form").find('.frappe-control[data-fieldname="notes"]').should("be.visible"); + }); + + it("should preserve tab state when switching between rows", () => { + cy.new_form(parent_doctype_name); + cy.fill_field("title", "Test Tab Persistence"); + + // Add two rows to the child table + cy.get('.frappe-control[data-fieldname="items"]').as("table"); + cy.get("@table").findByRole("button", { name: "Add Row" }).click(); + cy.get("@table").findByRole("button", { name: "Add Row" }).click(); + + // Open first row and switch to Details tab + cy.get("@table").find('[data-idx="1"]').as("row1"); + cy.get("@row1").find(".btn-open-row").click(); + cy.get(".grid-row-open").as("table-form"); + cy.get("@table-form").findByRole("tab", { name: "Details" }).click(); + + // Collapse first row + cy.get("@table-form").find(".grid-collapse-row").click(); + + // Open second row - should show first tab by default (not persist from row 1) + cy.get("@table").find('[data-idx="2"]').as("row2"); + cy.get("@row2").find(".btn-open-row").click(); + cy.get(".grid-row-open").as("table-form2"); + + // First tab should be active in new row + cy.get("@table-form2").find(".form-tabs .nav-link").first().should("have.class", "active"); + }); + + it("should allow data entry in fields across different tabs", () => { + cy.new_form(parent_doctype_name); + cy.fill_field("title", "Test Data Entry"); + + // Add a row to the child table + cy.get('.frappe-control[data-fieldname="items"]').as("table"); + cy.get("@table").findByRole("button", { name: "Add Row" }).click(); + + // Open the grid row form + cy.get("@table").find('[data-idx="1"]').as("row1"); + cy.get("@row1").find(".btn-open-row").click(); + cy.get(".grid-row-open").as("table-form"); + + // Fill fields in first tab + cy.fill_table_field("items", "1", "item_name", "Test Item"); + cy.fill_table_field("items", "1", "quantity", "10"); + + // Switch to Details tab + cy.get("@table-form").findByRole("tab", { name: "Details" }).click(); + + // Fill fields in second tab + cy.fill_table_field("items", "1", "description", "This is a test description"); + cy.fill_table_field("items", "1", "notes", "Some notes here"); + + // Switch back to first tab and verify data is preserved + cy.get("@table-form").findByRole("tab", { name: "General" }).click(); + cy.get("@table-form") + .find('.frappe-control[data-fieldname="item_name"] input') + .should("have.value", "Test Item"); + }); +});