From e962f2bb77d1d794c357d1cdacc0dd2c4912b850 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexandre=20K=C3=BChn?= Date: Mon, 27 Aug 2018 10:52:53 +0200 Subject: [PATCH] [FIX] mail: add new note without date from activity menu Before this commit, it was not possible to add a note from the activity menu when no datetime has been selected from the datepicker. This is due to the server-side code that requires a deadline date to be set, otherwise no note is created. Even though the placeholder of the datetime tells 'Today', no datetime was provided to the server, thus the problem mentionned above. This commit fixes the issue by ensuring that a deadline date is always provided to the server from the `/note/new` route. In particular, if no datetime has been selected, it still displays 'Today' and sets the current datetime before the RPC. Task-ID 1875668 --- .../static/src/js/systray_activity_menu.js | 4 + .../tests/systray_activity_menu_tests.js | 81 ++++++++++++++++--- 2 files changed, 75 insertions(+), 10 deletions(-) diff --git a/addons/note/static/src/js/systray_activity_menu.js b/addons/note/static/src/js/systray_activity_menu.js index f65dfce244f..e2e484ca10f 100644 --- a/addons/note/static/src/js/systray_activity_menu.js +++ b/addons/note/static/src/js/systray_activity_menu.js @@ -36,6 +36,8 @@ ActivityMenu.include({ }, /** * Save the note to database using datepicker date and field as note + * By default, when no datetime is set, it uses the current datetime. + * * @private */ _saveNote: function () { @@ -47,6 +49,8 @@ ActivityMenu.include({ var noteDateTime = this.noteDateTimeWidget.getValue(); if (noteDateTime) { params = _.extend(params, {'date_deadline': noteDateTime}); + } else { + params = _.extend(params, {'date_deadline': moment()}); } this.$('.o_note_show').removeClass('d-none'); this.$('.o_note').addClass('d-none'); diff --git a/addons/note/static/tests/systray_activity_menu_tests.js b/addons/note/static/tests/systray_activity_menu_tests.js index 5260cd3a685..81b2c5ac198 100644 --- a/addons/note/static/tests/systray_activity_menu_tests.js +++ b/addons/note/static/tests/systray_activity_menu_tests.js @@ -13,51 +13,112 @@ QUnit.module("ActivityMenu", { this.services = mailTestUtils.getMailServices(); 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: [], + } }; } }); QUnit.test('note activity menu widget: create note from activity menu', function (assert) { - assert.expect(8); + assert.expect(15); var self = this; var activityMenu = new ActivityMenu(); testUtils.addMockEnvironment(activityMenu, { services: this.services, mockRPC: function (route, args) { if (args.method === 'systray_get_activities') { - return $.when(self.data['mail.activity.menu']['records']); + return $.when(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 $.when(); } return this._super(route, args); }, }); activityMenu.appendTo($('#qunit-fixture')); - assert.ok(activityMenu.$el.hasClass('o_mail_systray_item'), 'should be the instance of widget'); + assert.ok(activityMenu.$el.hasClass('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 activityMenu.$('.dropdown-toggle').click(); - assert.strictEqual(activityMenu.$('.o_note_show').hasClass('d-none'), false, 'ActivityMenu should have Add new note CTA'); + assert.strictEqual(activityMenu.$('.o_no_activity').length, 1, + "should not have any activity preview"); + assert.strictEqual(activityMenu.$('.o_note_show').hasClass('d-none'), false, + 'ActivityMenu should have Add new note CTA'); activityMenu.$('.o_note_show').click(); - assert.strictEqual(activityMenu.$('.o_note_show').hasClass('d-none'), true, 'ActivityMenu should hide CTA when entering a new note'); - assert.strictEqual(activityMenu.$('.o_note').hasClass('d-none'), false, 'ActivityMenu should display input for new note'); + assert.strictEqual(activityMenu.$('.o_note_show').hasClass('d-none'), true, + 'ActivityMenu should hide CTA when entering a new note'); + assert.strictEqual(activityMenu.$('.o_note').hasClass('d-none'), false, + 'ActivityMenu should display input for new note'); // creating quick note without date activityMenu.$("input.o_note_input").val("New Note"); activityMenu.$(".o_note_save").click(); - assert.strictEqual(activityMenu.$('.o_note_show').hasClass('d-none'), false, 'ActivityMenu add note button should be displayed'); - assert.strictEqual(activityMenu.$('.o_note').hasClass('d-none'), true, 'ActivityMenu add note input should be hidden'); + assert.strictEqual(activityMenu.$('.o_notification_counter').text(), '1', + "should increment activity notification counter after creating a note"); + assert.strictEqual(activityMenu.$('.o_mail_preview[data-res_model="note.note"]').length, 1, + "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.strictEqual(activityMenu.$('.o_note_show').hasClass('d-none'), false, + 'ActivityMenu add note button should be displayed'); + assert.strictEqual(activityMenu.$('.o_note').hasClass('d-none'), true, + 'ActivityMenu add note input should be hidden'); // creating quick note with date activityMenu.$('.o_note_show').click(); activityMenu.$('input.o_note_input').val("New Note"); activityMenu.$('.o_note_set_datetime').click(); activityMenu.$(".o_note_save").click(); - assert.strictEqual(activityMenu.$('.o_note_show').hasClass('d-none'), false, 'ActivityMenu add note button should be displayed'); - assert.strictEqual(activityMenu.$('.o_note').hasClass('d-none'), true, 'ActivityMenu add note input should be hidden'); + 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.strictEqual(activityMenu.$('.o_note_show').hasClass('d-none'), false, + 'ActivityMenu add note button should be displayed'); + assert.strictEqual(activityMenu.$('.o_note').hasClass('d-none'), true, + 'ActivityMenu add note input should be hidden'); activityMenu.destroy(); }); });