Files
odoo_source/addons/calendar/static/tests/systray_activity_menu_tests.js
T
Sébastien Theys c2918c139b [IMP] web, *: improve mock server and replace most mail mockRPC
Improve mock server:

- add support for mocked `fetch`
- add support for `active_test`
- add support for x2m `in` in domains
- add support for default values computed from a function
- implement a more natural "next id" compute
- allow initial data without ids
- ensure write and x2m commands integrity
- improve bad data/bad commands error messages
- always warn for failing RPC, not only in debug mode
- fix all existing tests that had inconsistency data

Other changes done in mail (or dependents) that are not just related to tests:

- remove `direct_partner` from formatter result
  ->`correspondent` can be computed from other keys, especially `members`

- fix `livechat_visitor` convertData
  -> only process if there is value

- add `current_partner` and `current_user_id` as `init_messaging` result
  -> easier to mock than session

- remove usage of `need_moderation`
  -> that was just a search indirection to `moderation_status`

- adapt `partner_id` -> `res_partner_id` key in `_notification_format`
  -> to be consistent with field name

- add name in result of `mail_partner_format`
  -> sometimes display_name is not the same

- remove usage of `is_moderator`
  -> that was just an indirection to `moderation_channel_ids`

Enterprise counterpart: https://github.com/odoo/enterprise/pull/11523
task-2287171

closes odoo/odoo#55854

X-original-commit: 7ba3fecb3377a720d1eb70e7515a0c45da73836d
Related: odoo/enterprise#12391
Signed-off-by: Sébastien Theys (seb) <seb@odoo.com>
2020-08-13 16:26:35 +00:00

83 lines
2.9 KiB
JavaScript

odoo.define('calendar.systray.ActivityMenuTests', function (require) {
"use strict";
const { afterEach, beforeEach, start } = require('mail/static/src/utils/test_utils.js');
var ActivityMenu = require('mail.systray.ActivityMenu');
var testUtils = require('web.test_utils');
QUnit.module('calendar', {}, function () {
QUnit.module('ActivityMenu', {
beforeEach() {
beforeEach(this);
Object.assign(this.data, {
'calendar.event': {
fields: { // those are all fake, this is the mock of a formatter
meetings: { type: 'binary' },
model: { type: 'char' },
name: { type: 'char', required: true },
type: { type: 'char' },
},
records: [{
name: "Today's meeting (3)",
model: "calendar.event",
type: 'meeting',
meetings: [{
id: 1,
res_model: "calendar.event",
name: "meeting1",
start: "2018-04-20 06:30:00",
allday: false,
}, {
id: 2,
res_model: "calendar.event",
name: "meeting2",
start: "2018-04-20 09:30:00",
allday: false,
}]
}],
},
});
},
afterEach() {
afterEach(this);
},
});
QUnit.test('activity menu widget:today meetings', async function (assert) {
assert.expect(6);
var self = this;
const { widget } = await start({
data: this.data,
mockRPC: function (route, args) {
if (args.method === 'systray_get_activities') {
return Promise.resolve(self.data['calendar.event']['records']);
}
return this._super(route, args);
},
});
const activityMenu = new ActivityMenu(widget);
await activityMenu.appendTo($('#qunit-fixture'));
assert.hasClass(activityMenu.$el, 'o_mail_systray_item', 'should be the instance of widget');
await testUtils.dom.click(activityMenu.$('.dropdown-toggle'));
testUtils.mock.intercept(activityMenu, 'do_action', function (event) {
assert.strictEqual(event.data.action, "calendar.action_calendar_event", 'should open meeting calendar view in day mode');
});
await testUtils.dom.click(activityMenu.$('.o_mail_preview'));
assert.ok(activityMenu.$('.o_meeting_filter'), "should be a meeting");
assert.containsN(activityMenu, '.o_meeting_filter', 2, 'there should be 2 meetings');
assert.hasClass(activityMenu.$('.o_meeting_filter').eq(0), 'o_meeting_bold', 'this meeting is yet to start');
assert.doesNotHaveClass(activityMenu.$('.o_meeting_filter').eq(1), 'o_meeting_bold', 'this meeting has been started');
widget.destroy();
});
});
});