Files
odoo_source/addons/note/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

131 lines
5.3 KiB
JavaScript

odoo.define('note.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('note', {}, function () {
QUnit.module("ActivityMenu", {
beforeEach() {
beforeEach(this);
Object.assign(this.data, {
'mail.activity.menu': {
fields: {
name: { type: "char" },
model: { type: "char" },
type: { type: "char" },
planned_count: { type: "integer" },
today_count: { type: "integer" },
overdue_count: { type: "integer" },
total_count: { type: "integer" }
},
records: [],
},
'note.note': {
fields: {
memo: { type: 'char' },
},
records: [],
}
});
},
afterEach() {
afterEach(this);
},
});
QUnit.test('note activity menu widget: create note from activity menu', async function (assert) {
assert.expect(15);
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['mail.activity.menu'].records);
}
if (route === '/note/new') {
if (args.date_deadline) {
var note = {
id: 1,
memo: args.note,
date_deadline: args.date_deadline
};
self.data['note.note'].records.push(note);
if (_.isEmpty(self.data['mail.activity.menu'].records)) {
self.data['mail.activity.menu'].records.push({
name: "Note",
model: "note.note",
type: "activity",
planned_count: 0,
today_count: 0,
overdue_count: 0,
total_count: 0,
});
}
self.data['mail.activity.menu'].records[0].today_count++;
self.data['mail.activity.menu'].records[0].total_count++;
}
return Promise.resolve();
}
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');
assert.strictEqual(activityMenu.$('.o_notification_counter').text(), '0',
"should not have any activity notification initially");
// toggle quick create for note
await testUtils.dom.click(activityMenu.$('.dropdown-toggle'));
assert.containsOnce(activityMenu, '.o_no_activity',
"should not have any activity preview");
assert.doesNotHaveClass(activityMenu.$('.o_note_show'), 'd-none',
'ActivityMenu should have Add new note CTA');
await testUtils.dom.click(activityMenu.$('.o_note_show'));
assert.hasClass(activityMenu.$('.o_note_show'), 'd-none',
'ActivityMenu should hide CTA when entering a new note');
assert.doesNotHaveClass(activityMenu.$('.o_note'), 'd-none',
'ActivityMenu should display input for new note');
// creating quick note without date
await testUtils.fields.editInput(activityMenu.$("input.o_note_input"), "New Note");
await testUtils.dom.click(activityMenu.$(".o_note_save"));
assert.strictEqual(activityMenu.$('.o_notification_counter').text(), '1',
"should increment activity notification counter after creating a note");
assert.containsOnce(activityMenu, '.o_mail_preview[data-res_model="note.note"]',
"should have an activity preview that is a note");
assert.strictEqual(activityMenu.$('.o_activity_filter_button[data-filter="today"]').text().trim(),
"1 Today",
"should display one note for today");
assert.doesNotHaveClass(activityMenu.$('.o_note_show'), 'd-none',
'ActivityMenu add note button should be displayed');
assert.hasClass(activityMenu.$('.o_note'), 'd-none',
'ActivityMenu add note input should be hidden');
// creating quick note with date
await testUtils.dom.click(activityMenu.$('.o_note_show'));
activityMenu.$('input.o_note_input').val("New Note");
await testUtils.dom.click(activityMenu.$(".o_note_save"));
assert.strictEqual(activityMenu.$('.o_notification_counter').text(), '2',
"should increment activity notification counter after creating a second note");
assert.strictEqual(activityMenu.$('.o_activity_filter_button[data-filter="today"]').text().trim(),
"2 Today",
"should display 2 notes for today");
assert.doesNotHaveClass(activityMenu.$('.o_note_show'), 'd-none',
'ActivityMenu add note button should be displayed');
assert.hasClass(activityMenu.$('.o_note'), 'd-none',
'ActivityMenu add note input should be hidden');
widget.destroy();
});
});
});