[IMP] {test_}mail: improve activity view pager test
The activity view pager test is improved to use the actual get_activity_data mock rather than checking that it is called with the right parameters. Thanks to that, we also check that the activities are displayed. To ensure that the pager influence only the records displayed and not the related activities, we set up test records with 2 activities each and check that there are 2 times more activities displayed than the number of records. Task-3508744 Part-of: odoo/odoo#135651
This commit is contained in:
@@ -24,7 +24,9 @@ patch(MockServer.prototype, {
|
||||
if (args.model === "mail.activity" && args.method === "get_activity_data") {
|
||||
const res_model = args.args[0] || args.kwargs.res_model;
|
||||
const domain = args.args[1] || args.kwargs.domain;
|
||||
return this._mockMailActivityGetActivityData(res_model, domain);
|
||||
const limit = args[2] || args.kwargs.limit || 0;
|
||||
const offset = args[3] || args.kwargs.offset || 0;
|
||||
return this._mockMailActivityGetActivityData(res_model, domain, limit, offset);
|
||||
}
|
||||
return super._performRPC(route, args);
|
||||
},
|
||||
@@ -112,11 +114,14 @@ patch(MockServer.prototype, {
|
||||
* @private
|
||||
* @param {string} res_model
|
||||
* @param {string} domain
|
||||
* @param {number} limit
|
||||
* @param {number} offset
|
||||
* @returns {Object}
|
||||
*/
|
||||
_mockMailActivityGetActivityData(res_model, domain) {
|
||||
_mockMailActivityGetActivityData(res_model, domain, limit = 0, offset = 0) {
|
||||
const self = this;
|
||||
const records = this.getRecords(res_model, domain);
|
||||
const allRecords = this.getRecords(res_model, domain);
|
||||
const records = limit ? allRecords.slice(offset, offset + limit) : allRecords;
|
||||
|
||||
const activityTypes = this.getRecords("mail.activity.type", []);
|
||||
const activityIds = records.map((x) => x.activity_ids).flat();
|
||||
|
||||
@@ -225,62 +225,62 @@ QUnit.module("test_mail", {}, function () {
|
||||
|
||||
for (let i = 0; i < 101; i++) {
|
||||
activityToCreate.push({
|
||||
display_name: "An activity " + i,
|
||||
display_name: "An activity " + (i * 2),
|
||||
date_deadline: serializeDate(DateTime.now().plus({ days: 3 })),
|
||||
can_write: true,
|
||||
state: "planned",
|
||||
activity_type_id: mailActivityTypeIds[0],
|
||||
});
|
||||
activityToCreate.push({
|
||||
display_name: "An activity " + (i * 2 + 1),
|
||||
date_deadline: serializeDate(DateTime.now().plus({ days: 2 })),
|
||||
can_write: true,
|
||||
state: "planned",
|
||||
activity_type_id: mailActivityTypeIds[1],
|
||||
});
|
||||
}
|
||||
const createdActivity = pyEnv["mail.activity"].create(activityToCreate);
|
||||
for (let i = 0; i < 101; i++) {
|
||||
// The default limit of the RelationalModel is 80, test if it is overwrited to display up to 100 records
|
||||
recordsToCreate.push({ name: i + "", activity_ids: [createdActivity[i]] });
|
||||
recordsToCreate.push({ name: "pagerTestRecord" + i, activity_ids: [createdActivity[i * 2], createdActivity[i * 2 + 1]] });
|
||||
}
|
||||
pyEnv["mail.test.activity"].create(recordsToCreate);
|
||||
|
||||
const { openView } = await start({
|
||||
serverData,
|
||||
mockRPC: function (route, args) {
|
||||
if (args.method === "get_activity_data") {
|
||||
assert.step(
|
||||
`get activities records starting with a ${args.kwargs.offset} offset`
|
||||
);
|
||||
assert.strictEqual(
|
||||
args.kwargs.limit,
|
||||
100,
|
||||
"a limit of 100 records is used when fetching activity data"
|
||||
);
|
||||
}
|
||||
},
|
||||
});
|
||||
await openView({
|
||||
res_model: "mail.test.activity",
|
||||
views: [[false, "activity"]],
|
||||
domain: [['name', 'like', 'pagerTestRecord']],
|
||||
});
|
||||
|
||||
assert.verifySteps(
|
||||
["get activities records starting with a 0 offset"],
|
||||
"'get_activity_data' has been called correctly"
|
||||
);
|
||||
assert.containsN(
|
||||
document.body,
|
||||
".o_activity_record",
|
||||
100,
|
||||
"Only 100 records should have been displayed"
|
||||
);
|
||||
|
||||
await click(document.querySelector(".o_pager_next"));
|
||||
assert.verifySteps(
|
||||
["get activities records starting with a 100 offset"],
|
||||
"'get_activity_data' has been called correctly"
|
||||
assert.containsN(
|
||||
document.body,
|
||||
".o_activity_summary_cell.planned",
|
||||
200,
|
||||
"200 activities should have been displayed (2 per records)"
|
||||
);
|
||||
await click(document.querySelector(".o_pager_next"));
|
||||
assert.containsN(
|
||||
document.body,
|
||||
".o_activity_record",
|
||||
3,
|
||||
"Only 3 records are now displayed"
|
||||
1,
|
||||
"Only 1 record is now displayed"
|
||||
);
|
||||
assert.containsN(
|
||||
document.body,
|
||||
".o_activity_summary_cell.planned",
|
||||
2,
|
||||
"Only the 2 activities of the last record are now displayed"
|
||||
);
|
||||
await click(document.querySelector(".o_pager_previous"));
|
||||
assert.containsN(document.body, ".o_activity_record", 100);
|
||||
assert.containsN(document.body, ".o_activity_summary_cell.planned", 200);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user