mirror of
https://github.com/bringout/oca-ocb-core.git
synced 2026-04-19 20:32:03 +02:00
Initial commit: Core packages
This commit is contained in:
commit
12c29a983b
9512 changed files with 8379910 additions and 0 deletions
|
|
@ -0,0 +1,89 @@
|
|||
/** @odoo-module */
|
||||
|
||||
import { click, getFixture } from "@web/../tests/helpers/utils";
|
||||
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
|
||||
|
||||
QUnit.module("DescriptionPageField", (hooks) => {
|
||||
let serverData;
|
||||
let target;
|
||||
|
||||
hooks.beforeEach(() => {
|
||||
target = getFixture();
|
||||
|
||||
serverData = {
|
||||
models: {
|
||||
partner: {
|
||||
fields: { lines: { type: "one2many", relation: "lines_sections" } },
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
lines: [1, 2],
|
||||
},
|
||||
],
|
||||
},
|
||||
lines_sections: {
|
||||
fields: {
|
||||
is_page: { type: "boolean" },
|
||||
title: { type: "char", string: "Title" },
|
||||
random_questions_count: { type: "number", string: "Question Count" },
|
||||
},
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
is_page: true,
|
||||
title: "firstSectionTitle",
|
||||
random_questions_count: 4,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
is_page: false,
|
||||
title: "recordTitle",
|
||||
random_questions_count: 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
views: {
|
||||
"lines_sections,false,form": `
|
||||
<form>
|
||||
<field name="title" />
|
||||
</form>
|
||||
`,
|
||||
},
|
||||
};
|
||||
|
||||
setupViewRegistries();
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"button is visible in the edited record and allows to open that record",
|
||||
async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="is_page" invisible="1" />
|
||||
<field name="title" widget="survey_description_page"/>
|
||||
<field name="random_questions_count" />
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
});
|
||||
assert.containsN(target, "td.o_survey_description_page_cell", 2);
|
||||
assert.containsNone(target, "button.o_icon_button");
|
||||
|
||||
await click(target.querySelector(".o_data_cell"));
|
||||
assert.containsOnce(target.querySelector(".o_data_row"), "button.o_icon_button");
|
||||
assert.containsNone(target, ".modal .o_form_view");
|
||||
|
||||
await click(target, "button.o_icon_button");
|
||||
assert.containsOnce(target, ".modal .o_form_view");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
@ -0,0 +1,207 @@
|
|||
/** @odoo-module */
|
||||
|
||||
import { click, getFixture } from "@web/../tests/helpers/utils";
|
||||
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
|
||||
|
||||
QUnit.module("QuestionPageListRenderer", (hooks) => {
|
||||
let serverData;
|
||||
let target;
|
||||
|
||||
hooks.beforeEach(() => {
|
||||
target = getFixture();
|
||||
|
||||
serverData = {
|
||||
models: {
|
||||
partner: {
|
||||
fields: { lines: { type: "one2many", relation: "lines_sections" } },
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
lines: [1, 2],
|
||||
},
|
||||
],
|
||||
},
|
||||
lines_sections: {
|
||||
fields: {
|
||||
sequence: { type: "number" },
|
||||
is_page: { type: "boolean" },
|
||||
title: { type: "char", string: "Title" },
|
||||
question_type: { type: "string" },
|
||||
random_questions_count: { type: "number", string: "Question Count" },
|
||||
},
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
sequence: 1,
|
||||
is_page: true,
|
||||
question_type: false,
|
||||
title: "firstSectionTitle",
|
||||
random_questions_count: 4,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
sequence: 2,
|
||||
is_page: false,
|
||||
question_type: 'simple_choice',
|
||||
title: "recordTitle",
|
||||
random_questions_count: 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
views: {
|
||||
"lines_sections,false,form": `
|
||||
<form>
|
||||
<field name="title" />
|
||||
</form>
|
||||
`,
|
||||
},
|
||||
};
|
||||
|
||||
setupViewRegistries();
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"normal list view",
|
||||
async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="title" widget="survey_description_page"/>
|
||||
<field name="question_type" />
|
||||
<field name="is_page" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
});
|
||||
assert.containsN(target, "td.o_survey_description_page_cell", 2); // Check if we have the two rows in the list
|
||||
|
||||
assert.containsOnce(target, "tr.o_is_section"); // Check if we have only one section row
|
||||
const section = target.querySelector("tr.o_is_section > td.o_survey_description_page_cell");
|
||||
assert.strictEqual(section.colSpan, 2, 'The section should have a colspan of 1');
|
||||
|
||||
await click(section);
|
||||
assert.containsOnce(section, 'div.input-group');
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test(
|
||||
"list view with random count",
|
||||
async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="title" widget="survey_description_page"/>
|
||||
<field name="question_type" />
|
||||
<field name="is_page" invisible="1"/>
|
||||
<field name="random_questions_count"/>
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
});
|
||||
assert.containsN(target, "td.o_survey_description_page_cell", 2); // Check if we have the two rows in the list
|
||||
|
||||
assert.containsOnce(target, "tr.o_is_section"); // Check if we have only one section row
|
||||
const section = target.querySelector("tr.o_is_section > td.o_survey_description_page_cell");
|
||||
assert.strictEqual(section.colSpan, 2, 'The section should have a colspan of 2');
|
||||
|
||||
// We can edit the section title
|
||||
await click(section);
|
||||
assert.containsOnce(section, 'div.input-group');
|
||||
|
||||
//We can edit the number of random questions selected
|
||||
const numberQuestions = target.querySelector("tr.o_is_section > [name='random_questions_count']");
|
||||
await click(numberQuestions);
|
||||
assert.containsOnce(numberQuestions, 'div');
|
||||
}
|
||||
);
|
||||
|
||||
QUnit.test(
|
||||
"list view with random but with question_type at the left of the title",
|
||||
async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="question_type" />
|
||||
<field name="title" widget="survey_description_page"/>
|
||||
<field name="is_page" invisible="1"/>
|
||||
<field name="random_questions_count"/>
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
});
|
||||
assert.containsN(target, "td.o_survey_description_page_cell", 2); // Check if we have the two rows in the list
|
||||
|
||||
assert.containsOnce(target, "tr.o_is_section"); // Check if we have only one section row
|
||||
const section = target.querySelector("tr.o_is_section > td.o_survey_description_page_cell");
|
||||
assert.strictEqual(section.colSpan, 1, 'The section should have a colspan of 1');
|
||||
|
||||
await click(section);
|
||||
assert.containsOnce(section, 'div.input-group');
|
||||
|
||||
const numberQuestions = target.querySelector("tr.o_is_section > [name='random_questions_count']");
|
||||
await click(numberQuestions);
|
||||
assert.containsOnce(numberQuestions, 'div');
|
||||
}
|
||||
);
|
||||
QUnit.test(
|
||||
"list view with random and question_type at the beginning of row",
|
||||
async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="sequence" widget="handle"/>
|
||||
<field name="random_questions_count"/>
|
||||
<field name="question_type" />
|
||||
<field name="title" widget="survey_description_page"/>
|
||||
<field name="is_page" invisible="1"/>
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
});
|
||||
assert.containsN(target, "td.o_survey_description_page_cell", 2); // Check if we have the two rows in the list
|
||||
|
||||
assert.containsOnce(target, "tr.o_is_section"); // Check if we have only one section row
|
||||
const section = target.querySelector("tr.o_is_section > td.o_survey_description_page_cell");
|
||||
assert.strictEqual(section.colSpan, 1, 'The section should have a colspan of 1');
|
||||
|
||||
await click(section);
|
||||
assert.containsOnce(section, 'div.input-group');
|
||||
|
||||
const numberQuestions = target.querySelector("tr.o_is_section > [name='random_questions_count']");
|
||||
await click(numberQuestions);
|
||||
assert.containsOnce(numberQuestions, 'div');
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
@ -0,0 +1,247 @@
|
|||
/** @odoo-module */
|
||||
|
||||
import { click, editInput, getFixture, nextTick, triggerHotkey } from "@web/../tests/helpers/utils";
|
||||
import { makeView, setupViewRegistries } from "@web/../tests/views/helpers";
|
||||
|
||||
QUnit.module("QuestionPageOneToManyField", (hooks) => {
|
||||
let serverData;
|
||||
let target;
|
||||
|
||||
hooks.beforeEach(() => {
|
||||
target = getFixture();
|
||||
|
||||
serverData = {
|
||||
models: {
|
||||
partner: {
|
||||
fields: { lines: { type: "one2many", relation: "lines_sections" } },
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
lines: [1, 2],
|
||||
},
|
||||
],
|
||||
},
|
||||
lines_sections: {
|
||||
fields: {
|
||||
is_page: { type: "boolean" },
|
||||
title: { type: "char", string: "Title" },
|
||||
random_questions_count: { type: "number", string: "Question Count" },
|
||||
},
|
||||
records: [
|
||||
{
|
||||
id: 1,
|
||||
is_page: true,
|
||||
title: "firstSectionTitle",
|
||||
random_questions_count: 4,
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
is_page: false,
|
||||
title: "recordTitle",
|
||||
random_questions_count: 5,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
views: {
|
||||
"lines_sections,false,form": `
|
||||
<form>
|
||||
<field name="title" />
|
||||
</form>
|
||||
`,
|
||||
},
|
||||
};
|
||||
|
||||
setupViewRegistries();
|
||||
});
|
||||
|
||||
QUnit.test("basic rendering", async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="is_page" invisible="1" />
|
||||
<field name="title" />
|
||||
<field name="random_questions_count" />
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
});
|
||||
assert.containsOnce(target, ".o_field_x2many .o_list_renderer table.o_section_list_view");
|
||||
assert.containsN(target, ".o_data_row", 2);
|
||||
const rows = target.querySelectorAll(".o_data_row");
|
||||
assert.hasClass(rows[0], "o_is_section");
|
||||
assert.hasClass(rows[0], "fw-bold");
|
||||
assert.strictEqual(rows[0].textContent, "firstSectionTitle4");
|
||||
assert.strictEqual(rows[1].textContent, "recordTitle5");
|
||||
assert.strictEqual(rows[0].querySelector("td[name=title]").getAttribute("colspan"), "1");
|
||||
assert.strictEqual(rows[1].querySelector("td[name=title]").getAttribute("colspan"), null);
|
||||
});
|
||||
|
||||
QUnit.test("click on section behaves as usual in readonly mode", async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="is_page" invisible="1" />
|
||||
<field name="title" />
|
||||
<field name="random_questions_count" />
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
mode: "readonly",
|
||||
});
|
||||
|
||||
await click(target.querySelector(".o_data_cell"));
|
||||
assert.containsNone(target, ".o_selected_row");
|
||||
assert.containsOnce(target, ".modal .o_form_view");
|
||||
});
|
||||
|
||||
QUnit.test("click on section edit the section in place", async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="is_page" invisible="1" />
|
||||
<field name="title" />
|
||||
<field name="random_questions_count" />
|
||||
</tree>
|
||||
</field>
|
||||
</form>`,
|
||||
});
|
||||
await click(target.querySelector(".o_data_cell"));
|
||||
assert.hasClass(target.querySelector(".o_is_section"), "o_selected_row");
|
||||
assert.containsNone(target, ".modal .o_form_view");
|
||||
});
|
||||
|
||||
QUnit.test("click on real line opens a dialog", async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="is_page" invisible="1" />
|
||||
<field name="title" />
|
||||
<field name="random_questions_count" />
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
});
|
||||
await click(target.querySelector(".o_data_row:nth-child(2) .o_data_cell"));
|
||||
assert.containsNone(target, ".o_selected_row");
|
||||
assert.containsOnce(target, ".modal .o_form_view");
|
||||
});
|
||||
|
||||
QUnit.test("can create section inline", async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="is_page" invisible="1" />
|
||||
<field name="title" />
|
||||
<field name="random_questions_count" />
|
||||
<control>
|
||||
<create string="add line" />
|
||||
<create string="add section" context="{'default_is_page': true}" />
|
||||
</control>
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
});
|
||||
|
||||
assert.containsNone(target, ".o_selected_row");
|
||||
|
||||
await click(target.querySelectorAll(".o_field_x2many_list_row_add a")[1]);
|
||||
assert.containsOnce(target, ".o_selected_row.o_is_section");
|
||||
assert.containsNone(target, ".modal .o_form_view");
|
||||
});
|
||||
|
||||
QUnit.test("creates real record in form dialog", async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="is_page" invisible="1" />
|
||||
<field name="title" />
|
||||
<field name="random_questions_count" />
|
||||
<control>
|
||||
<create string="add line" />
|
||||
<create string="add section" context="{'default_is_page': true}" />
|
||||
</control>
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
});
|
||||
|
||||
await click(target.querySelector(".o_field_x2many_list_row_add a"));
|
||||
assert.containsNone(target, ".o_selected_row");
|
||||
assert.containsOnce(target, ".modal .o_form_view");
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"press enter with focus in a edited section pass the section in readonly mode",
|
||||
async (assert) => {
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "partner",
|
||||
resId: 1,
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="lines" widget="question_page_one2many">
|
||||
<tree>
|
||||
<field name="is_page" invisible="1" />
|
||||
<field name="title" />
|
||||
<field name="random_questions_count" />
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
`,
|
||||
});
|
||||
await click(target.querySelector(".o_data_row .o_data_cell"));
|
||||
assert.containsOnce(target, ".o_selected_row.o_is_section");
|
||||
|
||||
await editInput(target, "[name='title'] input", "a");
|
||||
|
||||
triggerHotkey("Enter");
|
||||
await nextTick();
|
||||
|
||||
assert.containsNone(target, ".o_selected_row.o_is_section");
|
||||
assert.strictEqual(target.querySelector(".o_is_section [name=title]").innerText, "a");
|
||||
}
|
||||
);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue