From 7db644da9690de13ec455de6895fef93c60b0bf5 Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Mon, 3 Oct 2022 15:31:01 +0000 Subject: [PATCH] [FIX] web: DomainSelector: operator change In a domain selector, have a selection field and the operator "is set" selected, then change the operator to be "=". A crash occurs. This happens because the category of operator change and thus the function onDidTypeChange of DomainSelectorSelectionField is called with no parameter. The same problem can happen with DomainSelectorDateTimeField. We fix that by calling component.onDidTypeChange with the right parameter in any case. X-original-commit: a01c2473d93d0d123391ba0131ad505775b3c50b Part-of: odoo/odoo#102156 --- .../domain_selector_leaf_node.js | 5 +-- .../tests/core/domain_selector_tests.js | 45 ++++++++++++++++++- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/core/domain_selector/domain_selector_leaf_node.js b/addons/web/static/src/core/domain_selector/domain_selector_leaf_node.js index 847e53a1c97..65fe7c9fd71 100644 --- a/addons/web/static/src/core/domain_selector/domain_selector_leaf_node.js +++ b/addons/web/static/src/core/domain_selector/domain_selector_leaf_node.js @@ -86,9 +86,8 @@ export class DomainSelectorLeafNode extends Component { const changes = { operator: operatorInfo.value }; Object.assign( changes, - operatorInfo.onDidChange( - this.getOperatorInfo(this.props.node.operator), - component.onDidTypeChange + operatorInfo.onDidChange(this.getOperatorInfo(this.props.node.operator), () => + component.onDidTypeChange(this.fieldInfo) ) ); this.props.node.update(changes); diff --git a/addons/web/static/tests/core/domain_selector_tests.js b/addons/web/static/tests/core/domain_selector_tests.js index 46cfcef9742..180f73b9ac6 100644 --- a/addons/web/static/tests/core/domain_selector_tests.js +++ b/addons/web/static/tests/core/domain_selector_tests.js @@ -9,7 +9,7 @@ import { registry } from "@web/core/registry"; import { uiService } from "@web/core/ui/ui_service"; import { viewService } from "@web/views/view_service"; import { makeTestEnv } from "../helpers/mock_env"; -import { click, getFixture, mount, triggerEvent } from "../helpers/utils"; +import { click, editSelect, getFixture, mount, triggerEvent } from "../helpers/utils"; import { makeFakeLocalizationService } from "../helpers/mock_services"; const { Component, xml } = owl; @@ -500,4 +500,47 @@ QUnit.module("Components", (hooks) => { assert.verifySteps(["fields_get"]); }); + + QUnit.test("selection field with operator change from 'is set' to '='", async (assert) => { + serverData.models.partner.fields.state = { + string: "State", + type: "selection", + selection: [ + ["abc", "ABC"], + ["def", "DEF"], + ["ghi", "GHI"], + ], + }; + + class Parent extends Component { + setup() { + this.value = `[['state', '!=', false]]`; + } + onUpdate(newValue) { + this.value = newValue; + this.render(); + } + } + Parent.components = { DomainSelector }; + Parent.template = xml` + + `; + + // Create the domain selector and its mock environment + await mountComponent(Parent); + + assert.strictEqual(target.querySelector(".o_field_selector_chain_part").innerText, "State"); + assert.strictEqual(target.querySelector(".o_domain_leaf_operator_select").value, "2"); // option "!=" + + await editSelect(target, ".o_domain_leaf_operator_select", 0); + + assert.strictEqual(target.querySelector(".o_field_selector_chain_part").innerText, "State"); + assert.strictEqual(target.querySelector(".o_domain_leaf_operator_select").value, "0"); // option "=" + assert.strictEqual(target.querySelector(".o_domain_leaf_value_input").value, "abc"); + }); });