[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
This commit is contained in:
Mathieu Duckerts-Antoine
2022-10-04 20:58:04 +02:00
parent b072e1bd5b
commit 7db644da96
2 changed files with 46 additions and 4 deletions
@@ -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);
@@ -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`
<DomainSelector
resModel="'partner'"
value="value"
readonly="false"
update="(newValue) => this.onUpdate(newValue)"
/>
`;
// 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");
});
});