`,
resId: 2,
});
expect(`.o_field_widget[name="display_name"]`).not.toHaveClass("text-danger");
expect(`.o_field_widget[name="foo"]`).toHaveClass("text-danger");
});
test(`form with o2m having a many2many fields using the many2many_tags widget along the color_field option`, async () => {
// In this scenario, the x2many form view isn't inline, so when we click on the record,
// it does an independant getView, which doesn't return all fields of the model. In the
// x2many list view, there's a field with a many2many_tags widget with the color option,
// and the color field (color) in our case, isn't in the form view.
// This test ensures that we can open the form view in this situation.
Partner._records[0].type_ids = [12, 14];
Partner._views = {
form: `
`,
resId: 17,
});
expect(`.o_field_widget[name=type_ids] .o_field_tags`).toHaveCount(1);
await contains(`.o_data_row .o_data_cell`).click();
expect(`.modal .o_form_view .o_field_widget[name=type_ids]`).toHaveCount(1);
});
test(`form with o2m having a field with fieldDependencies`, async () => {
// In this scenario, the x2many form view isn't inline, so when we click on the record,
// it does an independant getView, which doesn't return all fields of the model. In the
// x2many list view, there's a field with fieldDependencies, and the dependency field
// (int_field) in our case, isn't in the form view. This test ensures that we can open
// the form view in this situation.
class MyField extends CharField {}
fieldsRegistry.add("my_widget", {
component: MyField,
fieldDependencies: [{ name: "int_field", type: "integer" }],
});
Partner._records[1].child_ids = [1];
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect(`.o_field_widget[name=foo]`).toHaveClass(["o_field_char", "col-lg-6"]);
expect(`.o_form_label[for=foo_0]`).toHaveClass(["plop", "plop2", "col-lg-6"]);
});
test(`group containing both a field and a group`, async () => {
// The purpose of this test is to check that classnames defined in a
// field widget and those added by the form renderer are correctly
// combined. For instance, the renderer adds className 'o_group_col_x'
// on outer group's children (an outer group being a group that contains
// at least a group).
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect(`.o_group .o_field_widget[name=foo]`).toHaveCount(1);
expect(`.o_group .o_inner_group .o_field_widget[name=int_field]`).toHaveCount(1);
expect(`.o_field_widget[name=foo]`).toHaveClass(["o_field_char", "col-lg-6"]);
});
test(`field ids are unique (same field name in 2 form views)`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect(".o_field_widget input#foo_0").toHaveCount(1);
await contains(".o_field_x2many_list_row_add a").click();
expect(".modal .o_form_view").toHaveCount(1);
expect(".o_field_widget input#foo_0").toHaveCount(1);
expect(".modal .o_field_widget input#foo_0").toHaveCount(1);
expect(".modal .o_field_widget input#bar_0").toHaveCount(1);
});
test(`Form and subview with _view_ref contexts`, async () => {
Product._fields.type_ids = fields.One2many({ relation: "partner.type" });
Product._records = [{ id: 1, name: "Tromblon", type_ids: [12, 14] }];
Partner._records[0].product_id = 1;
// This is an old test, written before "get_views" (formerly "load_views") automatically
// inlines x2many subviews. As the purpose of this test is to assert that the js fetches
// the correct sub view when it is not inline (which can still happen in nested form views),
// we bypass the inline mecanism of "get_views" by setting widget="one2many" on the field.
Partner._views = {
form: `
`,
resId: 1,
});
expect.verifySteps(["get_views (partner)"]);
await contains(`.o_field_widget[name='type_ids'] .o_field_cell`).click();
expect.verifySteps(["get_views (partner.type)"]);
});
test(`invisible fields are properly hidden`, async () => {
await mountView({
resModel: "partner",
type: "form",
// the arch contains an x2many field without inline view: as it is always invisible,
// the view should not be fetched. we don't specify any view in this test, so if it
// ever tries to fetch it, it will crash, indicating that this is wrong.
arch: `
`,
resId: 1,
});
expect(`.o_form_statusbar button:contains(coucou)`).toHaveCount(0);
expect(`.o_notebook li a:contains(visible)`).toHaveCount(1);
expect(`.o_notebook li a:contains(invisible)`).toHaveCount(0);
expect(`div.o_inner_group:contains(visgroup)`).toHaveCount(1);
expect(`div.o_inner_group:contains(invgroup)`).toHaveCount(0);
});
test(`invisible attrs on fields are re-evaluated on field change`, async () => {
// we set the value bar to simulate a falsy boolean value.
Partner._records[0].bar = false;
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect(`.o_field_widget[name=int_field]`).toHaveCount(1);
expect(`.o_field_widget[name=type_ids]`).toHaveCount(0);
expect(`.o_field_widget[name=foo]`).toHaveCount(0);
expect(`.o_field_widget[name=bar]`).toHaveCount(0);
await contains(`.o_field_widget[name=int_field] input`).edit("44");
expect(`.o_field_widget[name=int_field]`).toHaveCount(1);
expect(`.o_field_widget[name=type_ids]`).toHaveCount(0);
expect(`.o_field_widget[name=foo]`).toHaveCount(1);
expect(`.o_field_widget[name=bar]`).toHaveCount(0);
});
test(`invisible attrs char fields`, async () => {
// For a char/text field, the server can return false or "" (empty string),
// depending if the field isn't set in db (NULL) or set to the empty string.
// This makes no difference in the UI, but it matters when evaluating modifiers.
Partner._records[0].name = false;
Partner._records[0].foo = "";
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect(`.o_notebook .nav .nav-item:eq(0) .nav-link`).not.toHaveClass("active");
expect(`.o_notebook .nav .nav-item:eq(1) .nav-link`).toHaveClass("active");
});
test(`invisible attrs on group are re-evaluated on field change`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect(`div.o_group`).toHaveCount(1);
await contains(`.o_field_boolean input`).click();
expect(`div.o_group`).toHaveCount(0);
});
test(`invisible attrs with zero value in expression and unset value in data`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
this should be invisible
`,
});
expect(`div.hello`).toHaveCount(0);
});
test(`reset local state when switching to another view`, async () => {
Partner._views = {
form: `
`,
list: ``,
};
defineActions([
{
id: 1,
name: "Partner",
res_model: "partner",
views: [
[false, "list"],
[false, "form"],
],
},
]);
await mountWithCleanup(WebClient);
await getService("action").doAction(1);
await contains(`.o_control_panel_main_buttons button.o_list_button_add`).click();
expect(`.o_form_view`).toHaveCount(1);
// sanity check: notebook active page is first page
expect(`.o_notebook .nav-link:eq(0)`).toHaveClass("active");
// click on second page tab
await contains(`.o_notebook .nav-link:eq(1)`).click();
expect(`.o_notebook .nav-link:eq(1)`).toHaveClass("active");
await contains(`.o_control_panel .o_form_button_cancel`).click();
expect(`.o_form_view`).toHaveCount(0);
await contains(`.o_control_panel_main_buttons button.o_list_button_add`).click();
expect(`.o_form_view`).toHaveCount(1);
// check notebook active page is first page again
expect(`.o_notebook .nav-link:eq(0)`).toHaveClass("active");
});
test.tags("desktop");
test(`trying to leave an invalid form view should not change the navbar`, async () => {
defineMenus([
{ id: 1, name: "App0", actionID: 1 },
{ id: 2, name: "App1", actionID: 2 },
]);
defineActions([
{
id: 1,
name: "Partner",
res_model: "partner",
views: [[false, "form"]],
},
{
id: 2,
name: "Product",
res_model: "product",
views: [[false, "list"]],
},
]);
Partner._views = {
form: `
`,
resId: 2,
});
expect(`label.o_form_label`).toHaveCount(1);
expect(`label.o_form_label`).toHaveText("label2");
expect(`.o_cell`).toHaveCount(2);
});
test(`label is not rendered when invisible and not at top-level in a group`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
expect(`label.o_form_label`).toHaveCount(0);
});
test(`input ids for multiple occurrences of fields in form view`, async () => {
// A same field can occur several times in the view, but its id must be
// unique by occurrence, otherwise there is a warning in the console (in
// edit mode) as we get several inputs with the same "id" attribute, and
// several labels the same "for" attribute.
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
const fieldIdAttrs = queryAllAttributes(`.o_field_widget input`, "id");
const labelForAttrs = queryAllAttributes(`.o_form_label`, "for");
expect(new Set(fieldIdAttrs)).toHaveLength(4);
expect(fieldIdAttrs).toEqual(labelForAttrs);
});
test(`input ids for multiple occurrences of fields in sub form view (inline)`, async () => {
// A same field can occur several times in the view, but its id must be
// unique by occurrence, otherwise there is a warning in the console (in
// edit mode) as we get several inputs with the same "id" attribute, and
// several labels the same "for" attribute.
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
await contains(`.o_field_x2many_list_row_add a`).click();
const fieldIdAttrs = queryAllAttributes(`.modal .o_form_view .o_field_widget input`, "id");
const labelForAttrs = queryAllAttributes(`.modal .o_form_view .o_form_label`, "for");
expect(new Set(fieldIdAttrs)).toHaveLength(4);
expect(fieldIdAttrs).toEqual(labelForAttrs);
});
test.tags("desktop");
test(`input ids for multiple occurrences of fields in sub form view (not inline)`, async () => {
// A same field can occur several times in the view, but its id must be
// unique by occurrence, otherwise there is a warning in the console (in
// edit mode) as we get several inputs with the same "id" attribute, and
// several labels the same "for" attribute.
Partner._views = {
list: ``,
form: `
`,
});
expect(`.o_field_widget[name=foo]`).toHaveCount(0);
await contains(`.o_field_widget[name=bar] input`).click();
expect(`.o_field_widget[name=foo]`).toHaveCount(1);
// foo is required, and as it isn't invisible (at least for one occurrence), it shouldn't
// allow to save as it is not set
await contains(`.o_form_button_save`).click();
expect(".o_field_widget[name=foo]").toHaveClass("o_field_invalid");
expect.verifySteps(["get_views", "onchange"]);
});
test(`required field computed by another field in a form view`, async () => {
Partner._fields.foo = fields.Char({
onChange(record) {
if (record.foo) {
record.name = "plop";
}
},
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
await contains(`.o_form_button_save`).click();
expect(`.o_form_editable`).toHaveCount(1);
expect(`.o_field_invalid`).toHaveCount(1);
await contains(`[name='foo'] input`).edit("hello");
expect(`.o_form_editable`).toHaveCount(1);
expect(`.o_field_invalid`).toHaveCount(0);
});
test(`required field computed by another field in a x2m`, async () => {
Partner._fields.foo = fields.Char({
default: false,
onChange(record) {
if (record.foo) {
record.name = "plop";
}
},
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
expect(`.o_form_label_empty`).toHaveCount(0);
expect(`.o_field_empty`).toHaveCount(0);
});
test(`label tag added for fields have o_form_empty class in readonly mode if field is empty`, async () => {
Partner._fields.foo = fields.Char({
onChange(record) {
if (record.foo === "hello") {
record.int_field = false;
}
},
});
Partner._fields.int_field = fields.Integer({ readonly: true });
Partner._records[1].foo = false; // 1 is record with id=2
Partner._records[1].parent_id = false; // 1 is record with id=2
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
expect(".o_field_empty").toHaveCount(1);
expect(".o_form_label_empty").toHaveCount(1);
await contains(`div[name=foo] input`).edit("test");
expect(`.o_field_empty`).toHaveCount(0);
expect(`.o_form_label_empty`).toHaveCount(0);
await contains(`div[name=foo] input`).edit("hello");
expect(`.o_field_empty`).toHaveCount(1);
expect(`.o_form_label_empty`).toHaveCount(1);
});
test(`required attrs on fields are re-evaluated on field change`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect(`div.o_horizontal_separator`).toHaveCount(0);
});
test(`form views in dialogs do not have a control panel`, async () => {
Partner._views = {
form: `
`,
resId: 2,
});
expect.verifySteps(["web_read1", "willStart"]);
await contains(`.o_form_statusbar button.child_ids`).click();
expect.verifySteps(["web_read2", "willUpdateProps"]);
await contains(`.o_form_statusbar button.child_ids`).click();
expect.verifySteps(["web_read3", "willUpdateProps"]);
});
test.tags("desktop");
test(`buttons in form view, new record`, async () => {
// this test simulates a situation similar to the settings forms.
let resId = null;
mockService("action", {
doActionButton(params) {
expect.step("execute_action");
expect(params.resId).toBe(resId);
params.onClose();
},
});
onRpc("web_save", ({ parent }) => {
const result = parent();
resId = result[0].id;
return result;
});
onRpc(({ method }) => expect.step(method));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
expect.verifySteps(["get_views", "onchange"]);
await contains(`.o_form_statusbar button.child_ids`).click();
expect.verifySteps(["web_save", "execute_action", "web_read"]);
});
test(`buttons in form view, new record, with field id in view`, async () => {
// buttons in form view are one of the rare example of situation when we
// save a record without reloading it immediately, because we only care
// about its id for the next step. But at some point, if the field id
// is in the view, it was registered in the changes, and caused invalid
// values in the record (data.id was set to null)
let resId = null;
mockService("action", {
doActionButton(params) {
expect.step("execute_action");
expect(params.resId).toBe(resId);
params.onClose();
},
});
onRpc("web_save", ({ parent }) => {
const result = parent();
resId = result[0].id;
return result;
});
onRpc(({ method }) => expect.step(method));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 17,
});
// trigger an onchange that update a readonly field by modifying user name
await contains(`.o_field_widget[name=name] input`).edit("Test");
// add a o2m row
await contains(`.o_field_x2many_list_row_add a`).click();
expect.verifySteps([]);
// trigger an onchange by modifying float_field
// confirm with blur s.t. it doesn't create a new line which would call another onchange and
// pollute our assertions
checkOnchange = true;
await contains(`.o_field_one2many .o_field_widget[name=float_field] input`).edit("12.4", {
confirm: "blur",
});
expect.verifySteps(["onchange"]);
});
test(`evaluate in python field options`, async () => {
class MyField extends Component {
static props = ["*"];
static template = xml`
`,
resId: 1,
actionMenus: {},
});
expect(`.o_cp_action_menus`).toHaveCount(1);
await toggleActionMenu();
expect(queryAllTexts`.o-dropdown--menu .dropdown-item`).toEqual([
"Custom Default Available",
"Duplicate",
"Custom Available",
"Delete",
]);
await toggleMenuItem("Custom Available");
expect.verifySteps(["Custom Available"]);
await toggleActionMenu();
await toggleMenuItem("Custom Default Available");
expect.verifySteps(["Custom Default Available"]);
});
test(`archive a record with intermediary action`, async () => {
// add active field on partner model to have archive option
Partner._fields.active = fields.Boolean();
Partner._fields.archived = fields.Char({ default: "false" });
Partner._views = {
form: /* xml */ `
`,
};
Product._views = {
form: /* xml */ `
`,
};
let readPartner = 0;
onRpc("do_archive", () => false);
onRpc("action_archive", () => ({
type: "ir.actions.act_window",
res_model: "product",
target: "new",
views: [[false, "form"]],
}));
onRpc("partner", "web_read", () => {
if (readPartner === 1) {
return [{ id: 1, archived: "true" }];
}
readPartner++;
});
onRpc(({ model, method, route }) =>
expect.step(`${method || route}${method ? ": " + model : ""}`)
);
await mountWithCleanup(WebClient);
await getService("action").doAction({
res_model: "partner",
res_id: 1,
type: "ir.actions.act_window",
views: [[false, "form"]],
});
expect(`[name='archived'] input`).toHaveValue("false");
expect.verifySteps(["get_views: partner", "web_read: partner"]);
await toggleActionMenu();
expect(`.o-dropdown--menu .o-dropdown-item:contains(Archive)`).toHaveCount(1);
await toggleMenuItem("Archive");
expect(`.modal`).toHaveCount(1);
expect.verifySteps([]);
await contains(`.modal-footer .btn-primary`).click();
expect.verifySteps(["action_archive: partner", "get_views: product", "onchange: product"]);
await contains(`.modal footer .myButton`).click();
expect.verifySteps(["web_save: product", "do_archive: product", "web_read: partner"]);
expect(`.modal`).toHaveCount(0);
expect(`[name='archived'] input`).toHaveValue("true");
});
test(`archive action with active field not in view`, async () => {
// add active field on partner model, but do not put it in the view
Partner._fields.active = fields.Boolean();
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
actionMenus: {},
});
expect(`.o_cp_action_menus`).toHaveCount(1);
await toggleActionMenu();
expect(`.o_cp_action_menus span:contains(Archive)`).toHaveCount(0);
expect(`.o_cp_action_menus span:contains(Unarchive)`).toHaveCount(0);
});
test(`archive action not shown with readonly active field`, async () => {
// add active field on partner model in readonly mode to do not have Archive option
Partner._fields.active = fields.Boolean({ readonly: true });
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect(`.o_field_widget[name=foo] input`).toHaveValue("yop");
await contains(`.o_field_widget[name=foo] input`).edit("new value");
expect(`.o_field_widget[name=foo] input`).toHaveValue("new value");
await contains(`.o_form_button_cancel`).click();
expect(`.o_field_widget input`).toHaveValue("yop");
expect.verifySteps([]);
});
test(`discard changes on a dirty form view (for date field)`, async () => {
// this test checks that the relational model properly handles date object
// when they are discarded and saved. This may be an issue because
// dates are saved as luxon instances, and were at one point stringified,
// then parsed into string, which is wrong.
Partner._fields.date = fields.Date({ default: "2017-01-25" });
await mountView({
type: "form",
resModel: "partner",
arch: `
`,
});
// also focus the buttons before clicking on them to precisely reproduce what
// really happens (mostly because the datepicker lib need that focus
// event to properly focusout the input, otherwise it crashes later on
// when the 'blur' event is triggered by the re-rendering)
await contains(`.o_form_button_cancel`).click();
await contains(`.o_form_button_save`).click();
expect(`.o_field_widget button`).toHaveValue("01/25/2017");
});
test.tags("desktop");
test(`discard changes on relational data on new record`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
await contains(`.o_field_x2many_list_row_add a`).click();
await contains(`.o_input_dropdown input`).click();
await contains(`.dropdown-item:contains(xphone)`).click();
expect(`.o_field_widget[name="product_id"] input`).toHaveValue("xphone");
await contains(`.o_form_button_cancel`).click();
expect(`.o_data_row`).toHaveCount(0);
});
test("discard changes on relational data on existing record", async () => {
Partner._records[0].product_ids = [37];
Partner._records[0].bar = false;
Partner._onChanges = {
bar(record) {
// when bar changes, push another record in product_ids.
record.product_ids = [[4, 41]];
},
};
await mountView({
type: "form",
resModel: "partner",
resId: 1,
arch: `
`,
});
expect(queryAllTexts`.o_data_cell`).toEqual(["xphone"]);
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(0);
// Click on bar
await contains(`.o_field_widget[name=bar] input`).click();
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(1);
expect(queryAllTexts`.o_data_cell`).toEqual(["xphone", "xpad"]);
// click on discard
await contains(`.o_form_button_cancel`).click();
expect(queryAllTexts`.o_data_cell`).toEqual(["xphone"]);
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(0);
});
test("discard changes on relational data on new record (1)", async () => {
// When bar is changed, it pushes a record in product_ids
// After discarding, product_ids should be empty
Partner._onChanges = {
bar(record) {
if (record.bar) {
// when bar changes, push another record in product_ids.
record.product_ids = [[4, 41]];
}
},
};
await mountView({
type: "form",
resModel: "partner",
arch: `
`,
});
expect(queryAllTexts`.o_data_cell`).toEqual([]);
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(0);
// Click on bar
await contains(`.o_field_widget[name=bar] input`).click();
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(1);
expect(queryAllTexts`.o_data_cell`).toEqual(["xpad"]);
// click on discard
await contains(`.o_form_button_cancel`).click();
expect(queryAllTexts`.o_data_cell`).toEqual([]);
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(0);
});
test("discard changes on relational data on new record (2)", async () => {
// An initial onChange push a record in product_ids
// When bar is changed, it pushes a second record in product_ids
// After discarding, product_ids should contain the inital record pushed by the inital onChange
Partner._onChanges = {
product_ids(record) {
record.product_ids = [[4, 41]];
},
bar(record) {
if (record.bar) {
// when bar changes, push another record in product_ids.
record.product_ids = [[4, 37]];
}
},
};
await mountView({
type: "form",
resModel: "partner",
arch: `
`,
});
expect(queryAllTexts`.o_data_cell`).toEqual(["xpad"]);
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(0);
// Click on bar
await contains(`.o_field_widget[name=bar] input`).click();
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(1);
expect(queryAllTexts`.o_data_cell`).toEqual(["xpad", "xphone"]);
// click on discard
await contains(`.o_form_button_cancel`).click();
expect(queryAllTexts`.o_data_cell`).toEqual(["xpad"]);
expect(`.o_field_widget[name=bar] input:checked`).toHaveCount(0);
});
test(`discard changes on a new (non dirty, except for defaults) form view`, async () => {
Partner._fields.foo = fields.Char({ default: "ABC" });
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect(`.o_statusbar_status .dropdown-toggle:visible`).toHaveCount(1);
await contains(`.o_field_widget[name=name] input`).edit("xpad");
expect(`.o_statusbar_status .dropdown-toggle:visible`).toHaveCount(1);
await contains(`.o_form_button_cancel`).click();
expect(`.o_statusbar_status .dropdown-toggle:visible`).toHaveCount(1);
expect(`.o_statusbar_status .dropdown-toggle:visible`).toHaveText("xphone");
});
test(`switching to another record from a dirty one`, async () => {
onRpc("web_save", () => expect.step("web_save"));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resIds: [1, 2],
resId: 1,
});
expect(`.o_field_widget[name=foo] input`).toHaveValue("yop");
await contains(`.o_field_widget[name=foo] input`).edit("new value");
expect(`.o_field_widget[name=foo] input`).toHaveValue("new value");
await contains(`.o_pager_next`).click();
expect(`.o_field_widget[name=foo] input`).toHaveValue("blip");
expect.verifySteps(["web_save"]);
await contains(`.o_pager_previous`).click();
expect(`.o_field_widget[name=foo] input`).toHaveValue("new value");
expect.verifySteps([]);
});
test.tags("desktop");
test(`switching to another record from a dirty one on desktop`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resIds: [1, 2],
resId: 1,
});
expect(getPagerValue()).toEqual([1]);
expect(getPagerLimit()).toBe(2);
await contains(`.o_field_widget[name=foo] input`).edit("new value");
await contains(`.o_pager_next`).click();
expect(getPagerValue()).toEqual([2]);
await contains(`.o_pager_previous`).click();
expect(getPagerValue()).toEqual([1]);
});
test.tags("desktop");
test("Save record, no changes but dirty (add and remove tag)", async () => {
onRpc("web_save", () => expect.step("ERROR: web_save should not be called"));
onRpc("web_read", () => expect.step("web_read"));
await mountView({
type: "form",
resModel: "partner",
arch: `
`,
resId: 1,
});
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(0);
// add a tag
await contains(`.o_input_dropdown input`).click();
await contains(`.dropdown-item:contains(gold)`).click();
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(1);
// remove tag
await contains(`.o_field_widget[name=type_ids] .o_tag .o_delete`).click();
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(0);
expect.verifySteps(["web_read", "web_read"]);
// click on save
await contains(`.o_form_button_save`).click();
// The `web_save` RPC should not be called as there are no changes.
// The record must be marked as not dirty.
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1);
expect.verifySteps([]); // avoid doint an extra web_read
});
test.tags("desktop");
test("switching to another record from a dirty record but wo changes (add and remove tag)", async () => {
onRpc("web_save", () => expect.step("ERROR: web_save should not be called"));
onRpc("web_read", () => expect.step("web_read"));
await mountView({
type: "form",
resModel: "partner",
arch: `
`,
resIds: [1, 2],
resId: 1,
});
expect(getPagerValue()).toEqual([1]);
expect(getPagerLimit()).toBe(2);
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(0);
expect(`.o_breadcrumb`).toHaveText("first record");
// add a tag
await contains(`.o_input_dropdown input`).click();
await contains(`.dropdown-item:contains(gold)`).click();
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(1);
// remove tag
await contains(`.o_field_widget[name=type_ids] .o_tag .o_delete`).click();
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(0);
expect.verifySteps(["web_read", "web_read"]);
// click on the pager to switch to the next record
// The `web_save` RPC should not be called as there are no changes.
// The next record should be load correctly.
await contains(`.o_pager_next`).click();
expect(`.modal`).toHaveCount(0);
expect(getPagerValue()).toEqual([2]);
expect(`.o_breadcrumb`).toHaveText("second record");
expect.verifySteps(["web_read"]);
});
test(`do not reload after save when using pager`, async () => {
onRpc(({ method }) => expect.step(method));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resIds: [1, 2],
resId: 1,
});
expect.verifySteps(["get_views", "web_read"]);
expect(`.o_input`).toHaveValue("yop");
await contains(`.o_field_widget[name=foo] input`).edit("new value");
await contains(`.o_pager_next`).click();
expect(`.o_input`).toHaveValue("blip");
expect.verifySteps(["web_save"]);
});
test.tags("desktop");
test(`do not reload after save when using pager on desktop`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resIds: [1, 2],
resId: 1,
});
expect(getPagerValue()).toEqual([1]);
expect(getPagerLimit()).toBe(2);
await contains(`.o_field_widget[name=foo] input`).edit("new value");
await contains(`.o_pager_next`).click();
expect(getPagerValue()).toEqual([2]);
});
test(`switching to another record from an invalid one`, async () => {
onRpc("web_save", () => expect.step("web_save"));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resIds: [1, 2],
resId: 1,
});
expect(`.o_breadcrumb`).toHaveText("first record");
expect(`.o_field_widget[name=foo]`).toHaveClass("o_required_modifier");
await contains(`.o_field_widget[name=foo] input`).edit("");
await contains(`.o_pager_next`).click();
expect(`.o_breadcrumb`).toHaveText("first record");
expect(`.o_form_status_indicator .text-danger`).toHaveAttribute(
"data-tooltip",
"Unable to save. Correct the issue or discard all changes"
);
expect(`.o_field_widget[name=foo]`).toHaveClass("o_field_invalid");
expect(`.o_notification_manager .o_notification`).toHaveCount(1);
expect.verifySteps([]);
});
test.tags("desktop");
test(`switching to another record from an invalid one on desktop`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resIds: [1, 2],
resId: 1,
});
expect(getPagerValue()).toEqual([1]);
expect(getPagerLimit()).toBe(2);
await contains(`.o_field_widget[name=foo] input`).edit("");
await contains(`.o_pager_next`).click();
expect(getPagerValue()).toEqual([1]);
expect(getPagerLimit()).toBe(2);
});
test(`keynav: switching to another record from an invalid one`, async () => {
onRpc("web_save", () => expect.step("web_save"));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resIds: [1, 2],
resId: 1,
});
expect(`.o_breadcrumb`).toHaveText("first record");
expect(`.o_field_widget[name=foo]`).toHaveClass("o_required_modifier");
await contains(`.o_field_widget[name=foo] input`).edit("");
await press(["alt", "n"]);
await tick();
await animationFrame();
expect(`.o_breadcrumb`).toHaveText("first record");
expect(`.o_form_status_indicator .text-danger`).toHaveAttribute(
"data-tooltip",
"Unable to save. Correct the issue or discard all changes"
);
expect(`.o_field_widget[name=foo]`).toHaveClass("o_field_invalid");
expect(`.o_notification_manager .o_notification`).toHaveCount(1);
expect.verifySteps([]);
});
test.tags("desktop");
test(`keynav: switching to another record from an invalid one on desktop`, async () => {
onRpc("web_save", () => expect.step("web_save"));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resIds: [1, 2],
resId: 1,
});
expect(`.o_pager_counter`).toHaveText("1 / 2");
await contains(`.o_field_widget[name=foo] input`).edit("");
await press(["alt", "n"]);
await tick();
await animationFrame();
expect(`.o_pager_counter`).toHaveText("1 / 2");
});
test(`switching to another record from an invalid one (2)`, async () => {
// in this scenario, the record is already invalid in db, so we should be allowed to
// leave it
Partner._records[0].foo = false;
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resIds: [1, 2],
resId: 1,
});
expect(`.o_breadcrumb`).toHaveText("first record");
expect(`.o_field_widget[name=foo]`).toHaveClass("o_required_modifier");
await contains(`.o_pager_next`).click();
expect(`.o_breadcrumb`).toHaveText("second record");
await contains(`.o_pager_previous`).click();
expect(`.o_breadcrumb`).toHaveText("first record");
expect(`.o_field_widget[name=foo]`).toHaveClass("o_required_modifier");
});
test("open a new record from an invalid one", async () => {
// in this scenario, the record is already invalid in db, so we should be allowed to
// leave it
Partner._records[0].foo = false;
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resIds: [1],
resId: 1,
});
expect(`.o_breadcrumb`).toHaveText("first record");
expect(`.o_field_widget[name=foo]`).toHaveClass("o_required_modifier");
await contains(".o_control_panel_main_buttons .o_form_button_create").click();
expect(`.o_breadcrumb`).toHaveText("New");
});
test.tags("desktop");
test(`switching to another record from an invalid one (2) on desktop`, async () => {
// in this scenario, the record is already invalid in db, so we should be allowed to
// leave it
Partner._records[0].foo = false;
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resIds: [1, 2],
resId: 1,
});
expect(`.o_pager_counter`).toHaveText("1 / 2");
await contains(`.o_pager_next`).click();
expect(`.o_pager_counter`).toHaveText("2 / 2");
await contains(`.o_pager_previous`).click();
expect(`.o_pager_counter`).toHaveText("1 / 2");
});
test(`keynav: switching to another record from a dirty one`, async () => {
onRpc("web_save", () => expect.step("web_save"));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resIds: [1, 2],
resId: 1,
});
expect(`.o_field_widget[name=foo] input`).toHaveValue("yop");
await contains(`.o_field_widget[name=foo] input`).edit("new value", { confirm: false });
await press(["alt", "n"]);
await tick();
await animationFrame();
expect.verifySteps(["web_save"]);
expect(`.o_field_widget[name=foo] input`).toHaveValue("blip");
await press(["alt", "p"]);
await tick();
await animationFrame();
expect.verifySteps([]);
expect(`.o_field_widget[name=foo] input`).toHaveValue("new value");
});
test.tags("desktop");
test(`keynav: switching to another record from a dirty one on desktop`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
expect(queryAllTexts`.o_data_cell`).toEqual(["aaa", "No records"]);
await contains(`.o_field_widget[name=foo] input`).edit("tralala");
expect(queryAllTexts`.o_data_cell`).toEqual(["gold", "No records"]);
});
test(`delete a line in a one2many while editing another line`, async () => {
Partner._records[0].child_ids = [1, 2];
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
expect.verifySteps(["get_views", "web_read"]);
expect(`.o_field_many2many .o_data_row`).toHaveCount(0);
await contains(`.o_field_widget[name=foo] input`).edit("let us trigger an onchange");
expect.verifySteps(["onchange"]);
expect(`.o_data_row`).toHaveCount(2);
expect(`.o_data_row .o_data_cell:eq(0)`).toHaveText("gold");
expect(`.o_data_row .o_data_cell:eq(1)`).toHaveText("silver");
await contains(`.o_form_button_save`).click();
expect.verifySteps(["web_save"]);
});
test(`form with domain widget: opening a many2many form and save should not crash`, async () => {
// We just test that there is no crash in this situation
Partner._records[0].type_ids = [12];
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
expect.verifySteps(["get_views", "web_read"]);
// edit int_field, and check that an onchange has been applied
await contains(`.o_field_widget[name="int_field"] input`).edit("123");
expect(`.o_field_widget[name="foo"] input`).toHaveValue("123");
// enter an invalid value in a float, and check that no onchange has
// been applied
await contains(`.o_field_widget[name="int_field"] input`).edit("123a");
expect(`.o_field_widget[name="foo"] input`).toHaveValue("123");
expect.verifySteps(["onchange"]);
// save, and check that the int_field input is marked as invalid
await contains(`.o_form_button_save`).click();
expect(`.o_field_widget[name="int_field"]`).toHaveClass("o_field_invalid");
expect.verifySteps([]);
});
test(`rpc complete after destroying parent`, async () => {
Partner._views = {
form: `
`,
list: ``,
};
defineActions([
{
id: 1,
name: "Partner",
res_model: "partner",
res_id: 1,
views: [[false, "form"]],
target: "new",
},
{
id: 2,
name: "Partner 2",
res_model: "partner",
views: [[false, "list"]],
},
]);
const deferred = new Deferred();
onRpc("update_module", async () => {
await deferred;
return { type: "ir.actions.act_window_close" };
});
await mountWithCleanup(WebClient);
await getService("action").doAction(1);
expect(`.o_form_view`).toHaveCount(1);
// should not crash when the call to "update_module" returns, as we should not
// try to reload the form view, which will no longer be in the DOM
await contains(`.o_form_button_update`).click();
// simulate that we executed another action before update_module returns
await getService("action").doAction(2);
expect(`.o_list_view`).toHaveCount(1);
deferred.resolve(); // call to update_module finally returns
await animationFrame();
expect(`.o_list_view`).toHaveCount(1);
});
test(`onchanges that complete after discarding`, async () => {
Partner._onChanges = {
foo(record) {
record.int_field = record.foo.length + 1000;
},
};
const deferred = new Deferred();
onRpc("onchange", async () => {
await deferred;
expect.step("onchange is done");
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
expect(`.o_field_widget[name="foo"] input`).toHaveValue("blip");
// edit a field and discard
await contains(`.o_field_widget[name=foo] input`).edit("1234");
await contains(`.o_form_button_cancel`).click();
expect(`.modal`).toHaveCount(0);
expect(`.o_field_widget[name="foo"] input`).toHaveValue("1234");
expect.verifySteps([]);
// complete the onchange
deferred.resolve();
await animationFrame();
expect(`.o_field_widget[name="foo"] input`).toHaveValue("blip");
expect.verifySteps(["onchange is done"]);
});
test(`discarding before save returns`, async () => {
const deferred = new Deferred();
onRpc("web_save", async () => {
await deferred;
});
const view = await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
const form = findComponent(view, (c) => c instanceof FormController);
expect(`.o_form_view .o_form_editable`).toHaveCount(1);
await contains(`.o_field_widget[name=foo] input`).edit("1234");
// save the value and discard directly
await contains(`.o_form_button_save`).click();
expect(`.o_form_button_cancel`).not.toBeEnabled();
// with form view extensions, it may happen that someone tries to discard
// while there is a pending save, so we simulate this here
form.discard();
await animationFrame();
expect(`.o_form_view .o_form_editable`).toHaveCount(1);
expect(`.o_field_widget[name="foo"] input`).toHaveValue("1234");
expect(`.modal`).toHaveCount(0);
// complete the write
deferred.resolve();
await animationFrame();
expect(`.modal`).toHaveCount(0);
expect(`.o_field_widget[name="foo"] input`).toHaveValue("1234");
});
test(`unchanged relational data is not sent for onchanges`, async () => {
Partner._records[1].child_ids = [4];
Partner._onChanges = {
foo(record) {
record.int_field = record.foo.length + 1000;
},
};
onRpc("onchange", ({ args }) => {
expect.step("onchange");
expect(args[1]).toEqual({ foo: "trigger an onchange" });
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
await contains(`.o_field_widget[name=foo] input`).edit("coucou");
expect.verifySteps(["onchange"]);
});
test.tags("desktop");
test(`clicking on a stat button with a context on desktop`, async () => {
mockService("action", {
doActionButton({ buttonContext }) {
// button context should have been evaluated and given to the
// action, with magic keys but without previous context
expect(buttonContext).toEqual({ test: 2 });
expect.step("doActionButton");
},
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
context: { some_context: true },
});
await contains(`button.oe_stat_button`).click();
expect.verifySteps(["doActionButton"]);
});
test.tags("mobile");
test(`clicking on a stat button with a context on mobile`, async () => {
mockService("action", {
doActionButton({ buttonContext }) {
// button context should have been evaluated and given to the
// action, with magic keys but without previous context
expect(buttonContext).toEqual({ test: 2 });
expect.step("doActionButton");
},
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
context: { some_context: true },
});
await contains(".o-form-buttonbox .o_button_more").click();
await contains(`button.oe_stat_button`).click();
expect.verifySteps(["doActionButton"]);
});
test.tags("desktop");
test(`clicking on a stat button with x2many in context on desktop`, async () => {
Partner._records[1].type_ids = [12];
mockService("action", {
doActionButton({ buttonContext }) {
expect(buttonContext).toEqual({ test: [12] });
expect.step("doActionButton");
},
});
await mountView({
type: "form",
resModel: "partner",
arch: `
`,
resId: 2,
context: { some_context: true },
});
await contains(`button.oe_stat_button`).click();
expect.verifySteps(["doActionButton"]);
});
test.tags("mobile");
test(`clicking on a stat button with x2many in context on mobile`, async () => {
Partner._records[1].type_ids = [12];
mockService("action", {
doActionButton({ buttonContext }) {
expect(buttonContext).toEqual({ test: [12] });
expect.step("doActionButton");
},
});
await mountView({
type: "form",
resModel: "partner",
arch: `
`,
resId: 2,
context: { some_context: true },
});
await contains(".o-form-buttonbox .o_button_more").click();
await contains(`button.oe_stat_button`).click();
expect.verifySteps(["doActionButton"]);
});
test.tags("desktop");
test(`clicking on a stat button with no context on desktop`, async () => {
mockService("action", {
doActionButton({ buttonContext }) {
// button context should have been evaluated and given to the
// action, with magic keys but without previous context
expect(buttonContext).toEqual({});
expect.step("doActionButton");
},
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
context: { some_context: true },
});
await contains(`button.oe_stat_button`).click();
expect.verifySteps(["doActionButton"]);
});
test.tags("mobile");
test(`clicking on a stat button with no context on mobile`, async () => {
mockService("action", {
doActionButton({ buttonContext }) {
// button context should have been evaluated and given to the
// action, with magic keys but without previous context
expect(buttonContext).toEqual({});
expect.step("doActionButton");
},
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
expect(`button .o_field_widget`).toHaveCount(1);
expect(`button .o_field_widget > *`).toHaveCount(2);
expect(`button .o_field_widget .o_stat_value`).toHaveText("9");
});
test.tags("desktop");
test(`display something else than a button in a buttonbox on desktop`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
expect(`.o-form-buttonbox > *`).toHaveCount(2);
expect(`.o-form-buttonbox > .oe_stat_button`).toHaveCount(1);
expect(`.o-form-buttonbox > label`).toHaveCount(1);
});
test.tags("mobile");
test(`display something else than a button in a buttonbox on mobile`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
await contains(".o-form-buttonbox .o_button_more").click();
expect(`.o-form-buttonbox-small > .o-dropdown-item`).toHaveCount(2);
expect(`.o-form-buttonbox-small > .o-dropdown-item > .oe_stat_button`).toHaveCount(1);
expect(`.o-form-buttonbox-small > .o-dropdown-item > label`).toHaveCount(1);
});
test.tags("desktop");
test(`invisible fields are not considered as visible in a buttonbox on desktop`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
expect(`.o-form-buttonbox > *`).toHaveCount(1);
expect(`.o-form-buttonbox`).toHaveClass("o_not_full");
});
test.tags("mobile");
test(`invisible fields are not considered as visible in a buttonbox on mobile`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
resIds: [1, 2],
context: { some_context: 354 },
});
expect.verifySteps([
"undefined", // main get_views
"undefined", // x2many get_views
"module.list_view_ref", // x2many get_views
"354", // read
]);
// reload to check that the record's context hasn't been modified
await contains(`.o_pager_next`).click();
expect.verifySteps(["354"]);
});
test(`non inline subview and create=0 in action context`, async () => {
// the create=0 should apply on the main view (form), but not on subviews
// this works because we pass the "base_model" in the context for the "get_views" call
Product._views = {
kanban: `
`,
};
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
context: { create: false },
});
expect(`.o_form_button_create`).toHaveCount(0);
expect(`.o-kanban-button-new`).toHaveCount(1);
});
test(`readonly fields with modifiers may be saved`, async () => {
// the readonly property on the field description only applies on view,
// this is not a DB constraint. It should be seen as a default value,
// that may be overridden in views, for example with modifiers. So
// basically, a field defined as readonly may be edited.
Partner._fields.foo = fields.Char({ readonly: true });
onRpc("web_save", ({ args }) => {
expect.step("web_save");
expect(args[1]).toEqual({ foo: "New foo value" });
});
await mountView({
type: "form",
resModel: "partner",
arch: `
`,
resId: 1,
});
// bar being set to true, foo shouldn't be readonly and thus its value
// could be saved, even if in its field description it is readonly
expect(`.o_field_widget[name="foo"] input`).toHaveCount(1);
await contains(`.o_field_widget[name="foo"] input`).edit("New foo value");
await contains(`.o_form_button_save`).click();
expect(`.o_field_widget[name=foo] input`).toHaveValue("New foo value");
expect.verifySteps(["web_save"]);
});
test(`readonly sub fields fields with force_save attribute`, async () => {
Partner._fields.foo = fields.Char({ readonly: true });
Partner._fields.int_field = fields.Integer({ readonly: true });
onRpc("web_save", ({ args }) => {
// foo should be saved because of the "force_save" attribute
// float_field should be saved because it isn't readonly
// int_field should not be saved as it is readonly
expect.step("web_save");
const commands = args[1].child_ids;
expect(commands).toEqual([[0, commands[0][1], { foo: "some value", float_field: 6.5 }]]);
});
onRpc("onchange", () => {
expect.step("onchange");
return {
value: {
child_ids: [[0, false, { foo: "some value", int_field: 44, float_field: 6.5 }]],
},
};
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
expect.verifySteps(["onchange"]);
await contains(`.o_form_button_save`).click();
expect.verifySteps(["web_save"]);
});
test(`readonly set by modifier do not break many2many_tags`, async () => {
Partner._onChanges = {
bar(record) {
record.type_ids = [[4, 12]];
},
};
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 5,
});
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(0);
await contains(`.o_field_widget[name=bar] input`).click();
expect(`.o_field_widget[name=type_ids] .o_tag`).toHaveCount(1);
});
test(`check if id is available in evaluation context`, async () => {
let checkOnchange = false;
onRpc("onchange", ({ kwargs }) => {
if (checkOnchange) {
expect.step("onchange");
expect(kwargs.context.current_id).toBe(false);
}
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
checkOnchange = true;
await contains(`.o_field_x2many_list_row_add a`).click();
expect.verifySteps(["onchange"]);
});
test(`modifiers are considered on multiple tags`, async () => {
Partner._views = {
form: `
`,
};
defineActions([
{
id: 1,
name: "Partner",
res_model: "partner",
res_id: 1,
views: [[false, "form"]],
target: "new",
},
]);
await mountWithCleanup(WebClient);
await getService("action").doAction(1);
expect(queryAllTexts`.modal-footer button:visible`).toEqual(["Hello", "World"]);
await contains(`.o_field_boolean input`).click();
expect(queryAllTexts`.modal-footer button:visible`).toEqual(["Foo"]);
});
test(`buttons in footer are moved to $buttons if necessary`, async () => {
Partner._views = {
form: `
`,
});
expect(`.o_field_widget[name="foo"] input`).toBeFocused();
});
test.tags("desktop");
test(`in create mode, if two fields have default focus, the first gets the focus`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
expect(`.o_field_widget[name="int_field"] input`).toBeFocused();
});
test.tags("desktop");
test(`in create mode, if two fields have default focus but the first is invisible, the second gets the focus`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
expect(`.o_field_widget[name="int_field"] input`).not.toBeFocused();
await contains(`.o_form_button_save`).click();
expect(`.o_field_widget[name="int_field"] input`).not.toBeFocused();
});
test.tags("desktop");
test(`In READ mode, focus the first primary button of the form`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 2,
});
expect(`button.firstButton`).toBeFocused();
});
// should clearly be a mobile test too
test.tags("desktop");
test(`check scroll on small height screens`, async () => {
Partner._views = {
list: ``,
form: `
`,
resIds: [1, 2],
resId: 1,
});
expect(`.o_notebook .nav-item`).toHaveCount(2);
expect(`.o_notebook .nav-link:eq(0)`).toHaveClass("active");
// click on the pager to switch to the next record
await contains(`.o_pager_next`).click();
expect(`.o_notebook .nav-item`).toHaveCount(1);
expect(`.o_notebook .nav-link`).toHaveClass("active");
// click on the pager to switch back to the previous record
await contains(`.o_pager_previous`).click();
expect(`.o_notebook .nav-item`).toHaveCount(2);
expect(`.o_notebook .nav-link:eq(1)`).toHaveClass("active");
});
test(`required fields inside notebook`, async () => {
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 4,
});
await contains(`.o_field_x2many_list_row_add a`).click();
expect(`.modal`).toHaveCount(1);
// set a value on the m2o and click save & new
await contains(`.o_field_many2one[name="partner_type_id"] input`).click();
expect.verifySteps(["web_name_search"]);
await contains(`.dropdown .dropdown-item:contains(gold)`).click();
await contains(`.modal-footer .o_form_button_save_new`).click();
// set a value on the m2o
await contains(`.o_field_many2one[name="partner_type_id"] input`).click();
expect.verifySteps(["web_name_search"]);
await contains(`.dropdown .dropdown-item:contains(silver)`).click();
await contains(`.modal-footer .o_form_button_save`).click();
});
test(`readonly fields are not sent when saving`, async () => {
// define an onchange on name to check that the value of readonly
// fields is correctly sent for onchanges
Partner._onChanges = {
name() {},
child_ids() {},
};
let checkOnchange = false;
onRpc("onchange", ({ args }) => {
if (checkOnchange) {
expect.step("onchange");
if (args[2][0] === "name") {
// onchange on field name
expect(args[1].foo).toBe("foo value");
} else {
// onchange on field p
expect(args[1].child_ids).toEqual([
[0, args[1].child_ids[0][1], { name: "readonly", foo: "foo value" }],
]);
}
}
});
onRpc("web_save", ({ args }) => {
expect.step("web_save");
expect(args[1]).toEqual({
child_ids: [[0, args[1].child_ids[0][1], { name: "readonly" }]],
});
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
expect(`.o_field_widget[name=foo]`).toHaveClass("o_readonly_modifier");
await contains(`.o_form_button_save`).click();
expect(`.o_field_widget[name=foo]`).not.toHaveClass("o_readonly_modifier");
});
test(`delete a duplicated record`, async () => {
const newRecordID = 6; // ids from 1 to 5 are already taken so the new record will have id 6
onRpc("unlink", ({ args }) => {
expect.step("unlink");
expect(args[0]).toEqual([newRecordID]);
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
await hover(`button[name='empty_method']`);
await runAllTimers();
expect(`.o-tooltip`).toHaveText(
"Button : Empty Button\nObject:partner\nButton Type:object\nMethod:empty_method"
);
await hover(`button[name='some_method']`);
await runAllTimers();
expect(`.o-tooltip`).toHaveText(
`Button : Button\n\nThis is title\n\nObject:partner\nReadonly:display_name == 'readonly'\nButton Type:object\nMethod:some_method`
);
await hover(`button[name='other_method']`);
await runAllTimers();
expect(`.o-tooltip`).toHaveText(
`Button : Button2\n\nhelp Button2\n\nObject:partner\nButton Type:object\nMethod:other_method`
);
});
test(`reload event is handled only once`, async () => {
// In this test, several form controllers are nested (all of them are
// opened in dialogs). When the users clicks on save in the last
// opened dialog, a 'reload' event is triggered up to reload the (direct)
// parent view. If this event isn't stopPropagated by the first controller
// catching it, it will crash when the other one will try to handle it,
// as this one doesn't know at all the dataPointID to reload.
Partner._views = {
form: `
`,
resId: 2,
});
expect.verifySteps(["get_views", "web_read"]);
expect(`.o_dialog`).toHaveCount(1);
await contains(`.o_external_button`, { visible: false }).click();
expect(`.o_dialog`).toHaveCount(2);
expect.verifySteps([
"get_formview_id", // id of first form view opened in a dialog
"get_views", // arch of first form view opened in a dialog
"web_read", // first dialog
]);
await contains(`.o_dialog:eq(1) .o_external_button`, { visible: false }).click();
expect(`.o_dialog`).toHaveCount(3);
expect.verifySteps([
"get_formview_id", // id of second form view opened in a dialog
"web_read", // second dialog
]);
await contains(`.o_dialog:eq(2) .o_field_widget[name=name] input`).edit("new name");
await contains(`.o_dialog:eq(2) footer .o_form_button_save`).click();
expect.verifySteps([
"web_save",
"read", // reload the name (first dialog)
]);
expect(`.o_dialog:eq(1) .o_field_widget[name="parent_id"] input`).toHaveValue("new name");
});
test(`process the context for inline subview`, async () => {
Partner._records[0].child_ids = [2];
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
await contains(`.o_field_x2many_list_row_add a`).click();
await contains(`.o_field_widget[name=name] input`).edit("abc", { confirm: false });
values = {
name: "abc",
product_id: false,
};
await contains(`button.child_ids`).click();
expect.verifySteps(["web_save"]);
expect.verifyErrors(["RPC_ERROR: Odoo Server Error"]);
await contains(`.o_form_view .o_field_one2many .o_data_row .o_data_cell:eq(1)`).click();
await contains(`.o_field_many2one[name="product_id"] input`).click();
await contains(`.dropdown .dropdown-item:contains(xphone)`).click();
expect(`.o_field_many2one input`).toHaveValue("xphone");
values = {
product_id: 37,
};
await contains(`.o_form_button_save`).click();
expect.verifySteps(["web_save"]);
});
test(`no deadlock when saving with uncommitted changes`, async () => {
// Before saving a record, all field widgets are asked to commit their changes (new values
// that they wouldn't have sent to the model yet). This test is added alongside a bug fix
// ensuring that we don't end up in a deadlock when a widget actually has some changes to
// commit at that moment. By chance, this situation isn't reached when the user clicks on
// 'Save' (which is the natural way to save a record), because by clicking outside the
// widget, the 'change' event (this is mainly for InputFields) is triggered, and the widget
// notifies the model of its new value on its own initiative, before being requested to.
// In this test, we try to reproduce the deadlock situation by forcing the field widget to
// commit changes before the save. We thus manually call 'saveRecord', instead of clicking
// on 'Save'.
onRpc(({ method }) => expect.step(method));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
expect.verifySteps(["get_views", "onchange"]);
await contains(`.o_field_widget[name=float_field] input`).edit("some float_field value");
await contains(`.o_form_button_save`).click();
expect(`.o_form_editable`).toHaveCount(1);
expect(`.o_form_view .o_form_editable input`).toHaveValue("some float_field value");
expect(`[name=float_field]`).toHaveClass("o_field_invalid");
expect(`.o_notification_bar.bg-danger`).toHaveCount(1);
expect(`.o_form_editable .o_field_invalid[name=float_field]`).toHaveCount(1);
expect.verifySteps([]);
});
test(`save record with onchange on one2many with required field`, async () => {
// in this test, we have a one2many with a required field, whose value is
// set by an onchange on another field ; we manually set the value of that
// first field, and directly click on Save (before the onchange RPC returns
// and sets the value of the required field)
Partner._fields.foo = fields.Char();
Partner._onChanges = {
name(record) {
record.foo = record.name ? "foo value" : undefined;
},
};
let onchangeDeferred = undefined;
onRpc("onchange", () => onchangeDeferred);
onRpc("web_save", ({ args }) => {
expect.step("web_save");
expect(args[1].child_ids[0][2].foo).toBe("foo value");
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
await hover(`.o_form_label[for=product_id_0] sup`);
await runAllTimers();
expect(`.o-tooltip .o-tooltip--help`).toHaveText(
"this is a tooltip\n\nValues set here are company-specific."
);
await hover(`.o_form_label[for=foo_0] sup`);
await runAllTimers();
expect(`.o-tooltip .o-tooltip--help`).toHaveText("Values set here are company-specific.");
});
test.tags("desktop");
test(`company_dependent field in form view, not in multi company group`, async () => {
Partner._fields.product_id = fields.Many2one({
relation: "product",
company_dependent: true,
help: "this is a tooltip",
});
serverState.companies = [
{ id: 1, name: "Company 1", sequence: 1, parent_id: false, child_ids: [] },
];
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
await hover(`.o_form_label sup`);
await runAllTimers();
expect(`.o-tooltip .o-tooltip--help`).toHaveText("this is a tooltip");
});
test(`no 'oh snap' error when clicking on a save button`, async () => {
expect.errors(1);
onRpc("web_save", () => {
throw makeServerError({ message: "Some business message" });
});
onRpc(({ method }) => expect.step(method));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1);
await contains(`.o_field_widget input`).edit("dirty");
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(0);
});
test(`status indicator: field dirty state`, async () => {
// this test check that the indicator don't need the onchange to be displayed
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1);
await contains(`.o_field_widget input`).edit("dirty", { confirm: false });
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(0);
});
test(`status indicator: field dirty state (date)`, async () => {
// this test check that the indicator don't need the onchange to be displayed
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(1);
await contains(".o_field_widget button").click();
await contains(`.o_field_widget input`).edit("03/26/2019", { confirm: false });
expect(`.o_form_status_indicator_buttons.invisible`).toHaveCount(0);
});
test(`status indicator: field dirty state (datetime)`, async () => {
// this test check that the indicator don't need the onchange to be displayed
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
expect(`.o_setting_left_pane > *`).toHaveCount(0);
expect(`.o_field_char input`).toHaveCount(0);
expect(`.o_form_label`).toHaveText("Personalize setting");
expect(`.text-muted`).toHaveText("this is full personalize setting");
});
test(`action button in x2many should display a notification if the record is virtual`, async () => {
mockService("notification", {
add(message, { type }) {
expect.step(`${type}:${message}`);
},
});
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
await contains(`.o_field_one2many .o_field_x2many_list_row_add a`).click();
await contains(`button.oe_stat_button[name='test_action']`).click();
expect.verifySteps([`danger:Please save your changes first`]);
});
test(`open form view action in x2many should display a notification if the record is virtual`, async () => {
mockService("action", {
async doAction({ type, res_id, res_model }) {
expect.step(`${type}:${res_model}(${res_id})`);
},
});
onRpc("web_save", () => expect.step(`web_save`));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
await contains(`.o_field_one2many .o_field_x2many_list_row_add a`).click();
await contains(`.o_list_record_open_form_view`).click();
expect.verifySteps(["web_save", "ir.actions.act_window:partner(7)"]);
});
test(`open form view action in x2many should work with several virtual record`, async () => {
mockService("action", {
async doAction({ type, res_id, res_model }) {
expect.step(`${type}:${res_model}(${res_id})`);
},
});
onRpc("web_save", () => expect.step(`web_save`));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
});
async function createVirtualRecord(x) {
await contains(`.o_field_x2many_list_row_add a`).click();
await contains(`.o_data_row [name='foo'] input`).edit(`record ${x}`);
}
await createVirtualRecord("a");
await createVirtualRecord("b");
await createVirtualRecord("c");
await createVirtualRecord("d");
await contains(".o_list_record_open_form_view:eq(4)").click();
expect.verifySteps(["web_save", "ir.actions.act_window:partner(11)"]);
});
test(`open form view action in x2many with several virtual record with limit`, async () => {
mockService("action", {
async doAction({ type, res_id, res_model }) {
expect.step(`${type}:${res_model}(${res_id})`);
},
});
onRpc("web_save", () => expect.step(`web_save`));
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
};
await mountWithCleanup(WebClient);
def.resolve({ test: 1 });
await getService("action").doAction(1);
expect(`.o_last_breadcrumb_item`).toHaveText("second record");
expect(`.my_widget`).toHaveText("MyWidget 1");
await contains(`[name='int_field'] input`).edit("42");
expect.verifySteps(["get_special_data 9", "get_special_data 42"]);
// Go to another model, to remove the model cache
await getService("action").doAction(2);
expect(`.o_last_breadcrumb_item`).toHaveText("Christine");
//Came back to the model with the special data
def = new Deferred();
await getService("action").doAction(1);
expect(`.o_last_breadcrumb_item`).toHaveText("second record");
expect(`.my_widget`).toHaveText("MyWidget 1");
def.resolve({ test: 2 });
await animationFrame();
expect(`.o_last_breadcrumb_item`).toHaveText("second record");
expect(`.my_widget`).toHaveText("MyWidget 2");
expect.verifySteps(["get_special_data 42"]);
});
test(`x2many field in form dialog view is correctly saved when using a view button`, async () => {
defineActions([
{
id: 1,
name: "Partner",
res_model: "partner",
views: [[false, "form"]],
view_mode: "form",
res_id: 6,
},
]);
Partner._views = {
form: `
`,
});
expect(".o_statusbar_buttons button:eq(0)").toHaveText("Confirm");
// open the dropdown
await contains(".o_statusbar_buttons button:has(.oi-ellipsis-v)").click();
await animationFrame();
expect(".o-dropdown--menu:visible").toHaveCount(1, { message: "dropdown should be visible" });
expect(".o-dropdown--menu button").toHaveCount(1, {
message: "should have 1 button in the dropdown",
});
});
test.tags("mobile");
test(`statusbar widgets should appear in the CogMenu dropdown`, async () => {
await mountView({
type: "form",
resModel: "partner",
resId: 2,
arch: `
`,
});
expect(".o_statusbar_buttons button:eq(0)").toHaveText("Attach document");
// Now there should an action dropdown, because there are two visible buttons
expect(".o_statusbar_buttons button:has(.oi-ellipsis-v)").toHaveCount(1, {
message: "should have 'More' dropdown",
});
await contains(".o_statusbar_buttons button:has(.oi-ellipsis-v)").click();
expect(".o-dropdown--menu button").toHaveCount(1, {
message: "should have 1 button in the dropdown",
});
// change display_name to update buttons modifiers and make one button visible
await contains(".o_field_widget[name=name] input").edit("first record");
expect(".o_statusbar_buttons button:eq(0)").toHaveText("Attach document");
expect(".o_statusbar_buttons button:has(.oi-ellipsis-v)").toHaveCount(0, {
message: "shouldn't have 'More' dropdown",
});
});
test.tags("mobile");
test(`CogMenu dropdown's open/close state shouldn't be modified after 'onchange'`, async () => {
Partner._onChanges = {
name() {},
};
const onchangeDef = new Deferred();
onRpc("partner", "onchange", ({ args }) => {
if (args[2][0] === "name") {
return onchangeDef;
}
});
await mountView({
type: "form",
resModel: "partner",
arch: `
`,
});
expect(".o_cp_action_menus button:has(.fa-cog)").toHaveCount(1, {
message: "statusbar should contain a dropdown",
});
expect(".o_cp_action_menus button:has(.fa-cog)").not.toHaveClass("show", {
message: "dropdown should be opened",
});
await contains(".o_field_widget[name=name] input").edit("before onchange");
await contains(".o_cp_action_menus button:has(.fa-cog)").click();
expect(".o_cp_action_menus button:has(.fa-cog)").toHaveClass("show", {
message: "dropdown should be opened",
});
onchangeDef.resolve({ value: { name: "after onchange" } });
await animationFrame();
expect(".o_field_widget[name=name] input").toHaveValue("after onchange");
expect(".o_cp_action_menus button:has(.fa-cog)").toHaveClass("show", {
message: "dropdown should be opened",
});
});
test(`cog menu action is executed with up to date context`, async () => {
// this test simulates a case where the context of a form view evolves, which can happen with
// js customizations (js_class, custom widgets...) and the user then executes a cog menu action.
mockService("action", {
doAction(id, { additionalContext }) {
expect.step(`doAction ${additionalContext.x}`);
},
});
class MyField extends CharField {
static template = xml``;
onClick() {
this.props.record.model.load({ context: { x: "z" } });
}
}
fieldsRegistry.add("my_widget", {
component: MyField,
});
await mountView({
resModel: "partner",
type: "form",
resId: 1,
arch: `
`,
});
expect.verifySteps([["cog displayed", "partner", 5]]);
await contains(".o_cp_action_menus button").click();
await contains("button.test-cog").click();
expect.verifySteps([["cog clicked", "partner", 5]]);
});
test.tags("mobile");
test(`preserve current scroll position on form view while closing dialog`, async () => {
Partner._views = {
kanban: ``,
};
await mountView({
type: "form",
resModel: "partner",
resId: 2,
arch: `
`,
});
let position = { top: 0, left: 0 };
patchWithCleanup(window, {
scrollTo(newPosition) {
position = newPosition;
},
get scrollX() {
return position.left;
},
get scrollY() {
return position.top;
},
});
window.scrollTo({ top: 265, left: 0 });
expect(window.scrollY).toBe(265, { message: "Should have scrolled 265 px vertically" });
expect(window.scrollX).toBe(0, { message: "Should be 0 px from left as it is" });
// click on m2o field
await contains(".o_field_many2one input").click();
// assert.strictEqual(window.scrollY, 0, "Should have scrolled to top (0) px");
expect(".modal.o_modal_full").toHaveCount(1, {
message: "there should be a many2one modal opened in full screen",
});
// click on back button
await contains(".modal .modal-header .oi-arrow-left").click();
expect(window.scrollY).toBe(265, { message: "Should have scrolled 265 px vertically" });
expect(window.scrollX).toBe(0, { message: "Should be 0 px from left as it is" });
});
test.tags("mobile");
test("attach_document widget also works inside a dropdown", async () => {
let fileInput;
patchWithCleanup(AttachDocumentWidget.prototype, {
setup() {
super.setup();
fileInput = this.fileInput;
},
});
mockService("http", {
post: (route, params) => {
expect.step("post");
expect(route).toBe("/web/binary/upload_attachment");
expect(params.model).toBe("partner");
expect(params.id).toBe(1);
return '[{ "id": 5 }, { "id": 2 }]';
},
});
await mountView({
type: "form",
resModel: "partner",
resId: 1,
arch: `
`,
});
await contains(".o_statusbar_buttons button:has(.oi-ellipsis-v)").click();
await contains(".o_attach_document").click();
await manuallyDispatchProgrammaticEvent(fileInput, "change");
await animationFrame();
expect.verifySteps(["post"]);
});
test(`do not perform button action for records with invalid datas`, async () => {
mockService("action", {
doActionButton(params) {
expect.step("Perform Action");
expect(params.name).toBe("lovely action");
},
});
mockService("notification", {
add: (message) => {
expect.step(`Pop Up: Invalid Field: ${message}`);
},
});
defineActions([
{
id: "lovely action",
name: "lovely action",
res_model: "partner",
type: "ir.actions.server",
},
]);
patchWithCleanup(FormController.prototype, {
beforeExecuteActionButton(clickParams) {
expect.step("Check/prepare record datas");
return super.beforeExecuteActionButton(clickParams);
},
});
onRpc("partner", "web_save", () => {
expect.step("web_save");
});
// The records data are invalid since foo is required
Partner._records[0].name = "Bob";
Partner._records[0].foo = "";
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
resId: 1,
});
expect.verifySteps([]);
// Try to perform the action with invalid datas
await contains(".btn[name='lovely action']").click();
// the action should not be called thanks to the `_checkValidity`
expect.verifySteps([
"Check/prepare record datas",
"Pop Up: Invalid Field: Missing required fields",
]);
// Edit the required field
await contains(`.o_input`).edit("Foo Value");
// Try to perform the action once more
await contains(".btn[name='lovely action']").click();
// the record should have been saved and the action performed.
expect.verifySteps(["Check/prepare record datas", "web_save", "Perform Action"]);
});
test(`open x2many with non inline form view, delayed get_views, form destroyed`, async () => {
Partner._records[0].product_ids = [37];
Product._views = {
form: `
`,
resId: 1,
});
// click on an x2many record to open it in dialog (get_views delayed)
def = new Deferred();
await contains(".o_data_row .o_data_cell").click();
expect(".o_dialog").toHaveCount(0);
// destroy the form view while get_views is pending
form.__owl__.destroy();
def.resolve();
await animationFrame();
// everything should have gone smoothly, nothing should have happened as the view is destroyed
expect.verifySteps(["get_views", "get_views"]);
});
test.tags("desktop");
test("executing new action, closes dialog, and avoid reload previous view", async () => {
onRpc(({ method }) => expect.step(method));
defineActions([
{
id: 1,
xml_id: "someaction",
res_id: 1,
res_model: "partner",
type: "ir.actions.act_window",
target: "new",
views: [[false, "form"]],
},
]);
Partner._views = {
form: `
`,
kanban: `
`,
};
await mountWithCleanup(WebClient);
await getService("action").doAction({
res_id: 1,
type: "ir.actions.act_window",
target: "current",
res_model: "partner",
view_mode: "form",
views: [[false, "form"]],
});
expect(`.o_form_view`).toHaveCount(1);
expect.verifySteps(["get_views", "web_read"]);
await contains(`.oe_stat_button`).click();
await animationFrame();
expect(".o_dialog .o_form_view").toHaveCount(1);
await getService("action").doAction({
type: "ir.actions.act_window",
res_model: "partner",
view_mode: "kanban",
views: [[false, "kanban"]],
});
expect(`.o_kanban_view`).toHaveCount(1);
expect.verifySteps([
"get_views",
//"web_read", We shouldn't be doing a web_read for the view that we are leaving.
"get_views",
"web_search_read",
"has_group",
]);
});
test.tags("mobile");
test(`pager is up to date`, async () => {
patchWithCleanup(transitionConfig, { disabled: true });
await mountView({
resModel: "partner",
type: "form",
arch: `
`,
};
defineActions([
{
id: 1,
name: "Partner",
res_model: "partner",
res_id: 1,
views: [[false, "form"]],
cache: true, // true is the default !
},
{
id: 2,
name: "Partner",
res_model: "partner",
res_id: 2,
views: [[false, "form"]],
},
]);
await mountWithCleanup(WebClient);
// Open and Cache the first action
await getService("action").doAction(1);
expect(`.o_field_char input`).toHaveValue("yop");
expect(`.o_last_breadcrumb_item`).toHaveText("first record");
// Change the record to the second record
await getService("action").doAction(2);
expect(`.o_field_char input`).toHaveValue("blip");
expect(`.o_last_breadcrumb_item`).toHaveText("second record");
def = new Deferred();
// Come back to the first action
getService("action").doAction(1);
await animationFrame();
// The record is shown even if the rpc is not finish (cached values)
expect(`.o_field_char input`).toHaveValue("yop");
expect(`.o_last_breadcrumb_item`).toHaveText("first record");
def.resolve([{ id: 1, foo: "new yop", display_name: "new first record" }]);
await animationFrame();
// The record is updated with the new values
expect(`.o_field_char input`).toHaveValue("new yop");
expect(`.o_last_breadcrumb_item`).toHaveText("new first record");
expect.verifySteps(["web_read", "web_read", "web_read"]);
});
test(`cached web_read: don't cache if action have cache:false`, async () => {
let def = null;
onRpc("web_read", async () => {
expect.step("web_read");
return def;
});
Partner._views = {
form: `
`,
};
defineActions([
{
id: 1,
name: "Partner",
res_model: "partner",
res_id: 1,
views: [[false, "form"]],
cache: false, // true is the default !
},
{
id: 2,
name: "Partner",
res_model: "partner",
res_id: 2,
views: [[false, "form"]],
cache: false, // true is the default !
},
]);
await mountWithCleanup(WebClient);
// Open the first action
await getService("action").doAction(1);
expect(`.o_field_char input`).toHaveValue("yop");
expect(`.o_last_breadcrumb_item`).toHaveText("first record");
// Change the record (the second record)
await getService("action").doAction(2);
expect(`.o_field_char input`).toHaveValue("blip");
expect(`.o_last_breadcrumb_item`).toHaveText("second record");
def = new Deferred();
// Come back to the first action
getService("action").doAction(1);
await animationFrame();
// The second record is still shown, waiting to the RPC to be finish
expect(`.o_field_char input`).toHaveValue("blip");
expect(`.o_last_breadcrumb_item`).toHaveText("second record");
def.resolve([{ id: 1, foo: "new yop", display_name: "new first record" }]);
await animationFrame();
// Show the new values when the rpc is finish
expect(`.o_field_char input`).toHaveValue("new yop");
expect(`.o_last_breadcrumb_item`).toHaveText("new first record");
expect.verifySteps(["web_read", "web_read", "web_read"]);
});
test(`cached web_read - don't loose changes`, async () => {
let def = null;
onRpc("web_read", async () => {
expect.step("web_read");
return def;
});
Partner._views = {
form: `
`,
};
defineActions([
{
id: 1,
name: "Partner",
res_model: "partner",
res_id: 1,
views: [[false, "form"]],
cache: true, // true is the default !
},
{
id: 2,
name: "Partner",
res_model: "partner",
res_id: 2,
views: [[false, "form"]],
},
]);
await mountWithCleanup(WebClient);
// Open and Cache the first action
await getService("action").doAction(1);
expect(`.o_field_char input`).toHaveValue("yop");
expect(`.o_last_breadcrumb_item`).toHaveText("first record");
// Open and Cache the second action
await getService("action").doAction(2);
expect(`.o_field_char input`).toHaveValue("blip");
expect(`.o_last_breadcrumb_item`).toHaveText("second record");
def = new Deferred();
// Come back to the first action
getService("action").doAction(1);
await animationFrame();
// The record is shown even if the rpc is not finish (cached values)
expect(`.o_field_char input`).toHaveValue("yop");
expect(`.o_last_breadcrumb_item`).toHaveText("first record");
// Edit the field while the rpc is pending
await contains(`.o_field_widget[name=foo] input`).edit("This is yop");
// The rpc returns differnt values.
def.resolve([{ id: 1, foo: "new yop", display_name: "new first record" }]);
await animationFrame();
// The record is updated with the new values and the edition is kept
expect(`.o_field_char input`).toHaveValue("This is yop");
expect(`.o_last_breadcrumb_item`).toHaveText("new first record");
expect.verifySteps(["web_read", "web_read", "web_read"]);
});
test(`cached onchange - don't loose changes`, async () => {
let def = null;
onRpc("onchange", async () => {
expect.step("onchange");
return def;
});
Partner._views = {
form: `
`,
};
defineActions([
{
id: 1,
name: "Partner",
res_model: "partner",
views: [[false, "form"]],
cache: true, // true is the default !
},
{
id: 2,
name: "Partner",
res_model: "partner",
res_id: 2,
views: [[false, "form"]],
},
]);
await mountWithCleanup(WebClient);
// Open and Cache the first action
await getService("action").doAction(1);
expect(`.o_field_char input`).toHaveValue("My little Foo Value");
expect(`.o_last_breadcrumb_item`).toHaveText("New");
// Open and Cache the second action
await getService("action").doAction(2);
expect(`.o_field_char input`).toHaveValue("blip");
expect(`.o_last_breadcrumb_item`).toHaveText("second record");
def = new Deferred();
// Come back to the first action
getService("action").doAction(1);
await animationFrame();
// The record is shown even if the rpc is not finish (cached values)
expect(`.o_field_char input`).toHaveValue("My little Foo Value");
expect(`.o_last_breadcrumb_item`).toHaveText("New");
// Edit the field while the rpc is pending
await contains(`.o_field_widget[name=foo] input`).edit("This is yop");
// The rpc returns differnt values.
def.resolve({
value: {
foo: "My New little Foo Value",
display_name: "",
},
});
await animationFrame();
// The record is updated with the new values and the edition is kept
expect(`.o_field_char input`).toHaveValue("This is yop");
expect(`.o_last_breadcrumb_item`).toHaveText("New");
expect.verifySteps(["onchange", "onchange"]);
});