mirror of
https://github.com/hanzoai/frappe.git
synced 2026-11-21 09:15:22 +00:00
On-grid columns with a `depends_on` expression were only re-evaluated on a full grid refresh. When a sibling field was set programmatically (for example by an `_add` handler) after the row had rendered, `grid.set_value` only repainted the changed cell, so the dependent column kept its stale `hidden_due_to_dependency` state until the next refresh. This made fields like Stock Reconciliation's `batch_no` (which depends on `use_serial_batch_fields`) unclickable on the newest row, because `use_serial_batch_fields` is flipped to 1 asynchronously after the row renders. Adding another row triggered a refresh and fixed the previous row, so it was always the last row that stayed broken. Re-run the row's dependency evaluation in `set_value` so dependent columns update as soon as the controlling field changes.
189 lines
6.5 KiB
JavaScript
189 lines
6.5 KiB
JavaScript
context("Depends On", () => {
|
|
before(() => {
|
|
cy.login();
|
|
cy.visit("/desk/website");
|
|
return cy
|
|
.window()
|
|
.its("frappe")
|
|
.then((frappe) => {
|
|
return frappe.xcall("frappe.tests.ui_test_helpers.create_child_doctype", {
|
|
name: "Child Test Depends On",
|
|
fields: [
|
|
{
|
|
label: "Child Test Field",
|
|
fieldname: "child_test_field",
|
|
fieldtype: "Data",
|
|
in_list_view: 1,
|
|
},
|
|
{
|
|
label: "Child Dependant Field",
|
|
fieldname: "child_dependant_field",
|
|
fieldtype: "Data",
|
|
in_list_view: 1,
|
|
},
|
|
{
|
|
label: "Child Display Dependant Field",
|
|
fieldname: "child_display_dependant_field",
|
|
fieldtype: "Data",
|
|
in_list_view: 1,
|
|
depends_on: "eval:doc.child_test_field == 'show'",
|
|
},
|
|
],
|
|
});
|
|
})
|
|
.then((frappe) => {
|
|
return frappe.xcall("frappe.tests.ui_test_helpers.create_doctype", {
|
|
name: "Test Depends On",
|
|
fields: [
|
|
{
|
|
label: "Test Field",
|
|
fieldname: "test_field",
|
|
fieldtype: "Data",
|
|
},
|
|
{
|
|
label: "Dependant Field",
|
|
fieldname: "dependant_field",
|
|
fieldtype: "Data",
|
|
mandatory_depends_on: "eval:doc.test_field=='Some Value'",
|
|
read_only_depends_on: "eval:doc.test_field=='Some Other Value'",
|
|
},
|
|
{
|
|
label: "Display Dependant Field",
|
|
fieldname: "display_dependant_field",
|
|
fieldtype: "Data",
|
|
depends_on: "eval:doc.test_field=='Value'",
|
|
},
|
|
{
|
|
label: "Child Test Depends On Field",
|
|
fieldname: "child_test_depends_on_field",
|
|
fieldtype: "Table",
|
|
read_only_depends_on: "eval:doc.test_field=='Some Other Value'",
|
|
options: "Child Test Depends On",
|
|
},
|
|
{
|
|
label: "Dependent Tab",
|
|
fieldname: "dependent_tab",
|
|
fieldtype: "Tab Break",
|
|
depends_on: "eval:doc.test_field=='Show Tab'",
|
|
},
|
|
{
|
|
fieldname: "tab_section",
|
|
fieldtype: "Section Break",
|
|
},
|
|
{
|
|
label: "Field in Tab",
|
|
fieldname: "field_in_tab",
|
|
fieldtype: "Data",
|
|
},
|
|
],
|
|
});
|
|
});
|
|
});
|
|
it("should show the tab on other setting field value", () => {
|
|
cy.new_form("Test Depends On");
|
|
cy.fill_field("test_field", "Show Tab");
|
|
cy.get("body").click();
|
|
cy.findByRole("tab", { name: "Dependent Tab" }).should("be.visible");
|
|
});
|
|
it("should set the field as mandatory depending on other fields value", () => {
|
|
cy.new_form("Test Depends On");
|
|
cy.fill_field("test_field", "Some Value");
|
|
cy.findByRole("button", { name: "Save" }).click();
|
|
cy.get(".msgprint-dialog .modal-title").contains("Missing Fields").should("be.visible");
|
|
cy.hide_dialog();
|
|
cy.fill_field("test_field", "Random value");
|
|
cy.findByRole("button", { name: "Save" }).click();
|
|
cy.get(".msgprint-dialog .modal-title")
|
|
.contains("Missing Fields")
|
|
.should("not.be.visible");
|
|
});
|
|
it("should set the field as read only depending on other fields value", () => {
|
|
cy.new_form("Test Depends On");
|
|
cy.fill_field("dependant_field", "Some Value");
|
|
cy.fill_field("test_field", "Some Other Value");
|
|
cy.get("body").click();
|
|
cy.get('.control-input [data-fieldname="dependant_field"]').should("be.disabled");
|
|
cy.fill_field("test_field", "Random Value");
|
|
cy.get("body").click();
|
|
cy.get('.control-input [data-fieldname="dependant_field"]').should("not.be.disabled");
|
|
});
|
|
it("should set the table and its fields as read only depending on other fields value", () => {
|
|
cy.new_form("Test Depends On");
|
|
cy.fill_field("dependant_field", "Some Value");
|
|
//cy.fill_field('test_field', 'Some Other Value');
|
|
cy.get('.frappe-control[data-fieldname="child_test_depends_on_field"]').as("table");
|
|
cy.get("@table").findByRole("button", { name: "Add row" }).click();
|
|
cy.get("@table").find('[data-idx="1"]').as("row1");
|
|
cy.get("@row1").find(".btn-open-row").click();
|
|
cy.get("@row1").find(".form-in-grid").as("row1-form_in_grid");
|
|
//cy.get('@row1-form_in_grid').find('')
|
|
cy.fill_table_field("child_test_depends_on_field", "1", "child_test_field", "Some Value");
|
|
cy.fill_table_field(
|
|
"child_test_depends_on_field",
|
|
"1",
|
|
"child_dependant_field",
|
|
"Some Other Value"
|
|
);
|
|
|
|
cy.get("@row1-form_in_grid").find(".grid-collapse-row").click();
|
|
|
|
// set the table to read-only
|
|
cy.fill_field("test_field", "Some Other Value");
|
|
|
|
// grid row form fields should be read-only
|
|
cy.get("@row1").find(".btn-open-row").click();
|
|
|
|
cy.get("@row1-form_in_grid")
|
|
.find('.control-input [data-fieldname="child_test_field"]')
|
|
.should("be.disabled");
|
|
cy.get("@row1-form_in_grid")
|
|
.find('.control-input [data-fieldname="child_dependant_field"]')
|
|
.should("be.disabled");
|
|
});
|
|
it("should re-evaluate an on-grid column's depends_on when a sibling field is set programmatically", () => {
|
|
// Reproduces the newest-row issue: a row's controlling field is set after the
|
|
// grid has already rendered (as `_add` handlers do), so the dependent column
|
|
// must be re-evaluated on the model change, not only on the next full refresh.
|
|
cy.new_form("Test Depends On");
|
|
cy.get('.frappe-control[data-fieldname="child_test_depends_on_field"]').as("table");
|
|
cy.get("@table").findByRole("button", { name: "Add row" }).click();
|
|
|
|
let dependant_df = (win) => {
|
|
let cdn =
|
|
win.cur_frm.fields_dict.child_test_depends_on_field.grid.grid_rows[0].doc.name;
|
|
return win.frappe.meta.get_docfield(
|
|
"Child Test Depends On",
|
|
"child_display_dependant_field",
|
|
cdn
|
|
);
|
|
};
|
|
|
|
// depends_on is not satisfied yet, so the column is hidden
|
|
cy.window().should((win) => {
|
|
expect(dependant_df(win).hidden_due_to_dependency).to.be.ok;
|
|
});
|
|
|
|
// set the controlling field programmatically (the path an `_add` handler takes)
|
|
cy.window().then((win) => {
|
|
let { doctype: cdt, name: cdn } =
|
|
win.cur_frm.fields_dict.child_test_depends_on_field.grid.grid_rows[0].doc;
|
|
win.frappe.model.set_value(cdt, cdn, "child_test_field", "show");
|
|
});
|
|
|
|
// the dependent column must become editable without another full grid refresh
|
|
cy.window().should((win) => {
|
|
expect(dependant_df(win).hidden_due_to_dependency).to.not.be.ok;
|
|
});
|
|
});
|
|
it("should display the field depending on other fields value", () => {
|
|
cy.new_form("Test Depends On");
|
|
cy.get('.control-input [data-fieldname="display_dependant_field"]').should(
|
|
"not.be.visible"
|
|
);
|
|
cy.get('.control-input [data-fieldname="test_field"]').clear();
|
|
cy.fill_field("test_field", "Value");
|
|
cy.get("body").click();
|
|
cy.get('.control-input [data-fieldname="display_dependant_field"]').should("be.visible");
|
|
});
|
|
});
|