diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/calendar/static/tests | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/calendar/static/tests')
| -rw-r--r-- | addons/calendar/static/tests/calendar_tests.js | 80 | ||||
| -rw-r--r-- | addons/calendar/static/tests/systray_activity_menu_tests.js | 82 |
2 files changed, 162 insertions, 0 deletions
diff --git a/addons/calendar/static/tests/calendar_tests.js b/addons/calendar/static/tests/calendar_tests.js new file mode 100644 index 00000000..3eea3dff --- /dev/null +++ b/addons/calendar/static/tests/calendar_tests.js @@ -0,0 +1,80 @@ +odoo.define('calendar.tests', function (require) { +"use strict"; + +var FormView = require('web.FormView'); +var testUtils = require("web.test_utils"); + +var createView = testUtils.createView; + +QUnit.module('calendar', { + beforeEach: function () { + this.data = { + event: { + fields: { + partner_ids: {string: "Partners", type: "many2many", relation: "partner"}, + }, + records: [{ + id: 14, + partner_ids: [1, 2], + }], + }, + partner: { + fields: { + name: {string: "Name", type: "char"}, + }, + records: [{ + id: 1, + name: "Jesus", + }, { + id: 2, + name: "Mahomet", + }], + }, + }; + }, +}, function () { + QUnit.test("many2manyattendee widget: basic rendering", async function (assert) { + assert.expect(9); + + var form = await createView({ + View: FormView, + model: 'event', + data: this.data, + res_id: 14, + arch: + '<form>' + + '<field name="partner_ids" widget="many2manyattendee"/>' + + '</form>', + mockRPC: function (route, args) { + if (args.method === 'get_attendee_detail') { + assert.strictEqual(args.model, 'res.partner', + "the method should only be called on res.partner"); + assert.deepEqual(args.args[0], [1, 2], + "the partner ids should be passed as argument"); + assert.strictEqual(args.args[1], 14, + "the event id should be passed as argument"); + return Promise.resolve([ + [1, "Jesus", "accepted", 0], + [2, "Mahomet", "needsAction", 0], + ]); + } + return this._super.apply(this, arguments); + }, + }); + + assert.hasClass(form.$('.o_field_widget[name="partner_ids"]'), 'o_field_many2manytags'); + assert.containsN(form, '.o_field_widget[name="partner_ids"] .badge', 2, + "there should be 2 tags"); + assert.strictEqual(form.$('.o_field_widget[name="partner_ids"] .badge:first').text().trim(), "Jesus", + "the tag should be correctly named"); + assert.hasClass(form.$('.o_field_widget[name="partner_ids"] .badge:first .o_calendar_invitation'),'accepted', + "Jesus should attend the meeting"); + assert.strictEqual(form.$('.o_field_widget[name="partner_ids"] .badge[data-id="2"]').text().trim(), "Mahomet", + "the tag should be correctly named"); + assert.hasClass(form.$('.o_field_widget[name="partner_ids"] .badge[data-id="2"] .o_calendar_invitation'),'needsAction', + "Mohamet should still confirm his attendance to the meeting"); + + form.destroy(); + }); +}); +}); diff --git a/addons/calendar/static/tests/systray_activity_menu_tests.js b/addons/calendar/static/tests/systray_activity_menu_tests.js new file mode 100644 index 00000000..aaf2bd74 --- /dev/null +++ b/addons/calendar/static/tests/systray_activity_menu_tests.js @@ -0,0 +1,82 @@ +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(); +}); +}); + +}); |
