diff --git a/addons/mass_mailing/static/tests/mass_mailing_favorite_filter.test.js b/addons/mass_mailing/static/tests/mass_mailing_favorite_filter.test.js new file mode 100644 index 0000000000000..a1e2fc6bd1529 --- /dev/null +++ b/addons/mass_mailing/static/tests/mass_mailing_favorite_filter.test.js @@ -0,0 +1,162 @@ +import { mailModels } from "@mail/../tests/mail_test_helpers"; +import { expect, test } from "@odoo/hoot"; +import { click, edit, press, queryOne, waitFor } from "@odoo/hoot-dom"; +import { animationFrame } from "@odoo/hoot-mock"; +import { clickSave, defineModels, fields, models, mountView, onRpc } from "@web/../tests/web_test_helpers"; + + +class Mailing extends models.Model { + _name = "mailing.mailing"; + + name = fields.Char({ string: "Display name" }); + subject = fields.Char({ string: "subject" }); + mailing_model_id = fields.Many2one({ string: "Recipients", relation: "ir.model" }); + mailing_model_name = fields.Char({ string: "Recipients Model Nam" }); + mailing_filter_id = fields.Many2one({ string: "Filters", relation: "mailing.filter" }); + mailing_domain = fields.Char({ string: "Domain" }); + mailing_filter_domain = fields.Char({ + string: "Domain", + related: "mailing_filter_id.mailing_domain", + }); + + mailing_filter_count = fields.Integer({ string: "filter Count" }); + + _onChanges = { + mailing_filter_id: () => {}, + }; + _records = [ + { + id: 1, + name: "Belgian Event promotion", + subject: "Early bird discount for Belgian Events! Register Now!", + mailing_model_id: 1, + mailing_model_name: "event", + mailing_domain: '[["country","=","be"]]', + mailing_filter_id: 1, + mailing_filter_count: 1, + mailing_filter_domain: '[["country","=","be"]]', + }, + { + id: 2, + name: "New Users Promotion", + subject: "Early bird discount for new users! Register Now!", + mailing_model_id: 1, + mailing_filter_count: 1, + mailing_model_name: "event", + mailing_domain: '[["new_user","=",True]]', + mailing_filter_domain: '[["new_user","=",True]]', + }, + ]; +} + +class IrModel extends models.Model { + _name = "ir.model"; + + name = fields.Char({ string: "Display name" }); + model = fields.Char({ string: "Model" }); + + _records = [ + { + id: 1, + name: "Event", + model: "event", + }, + { + id: 2, + name: "Partner", + model: "partner", + }, + ]; +} + +class MailFilter extends models.Model { + _name = "mailing.filter"; + + name = fields.Char({ string: "Name" }); + mailing_domain = fields.Char({ string: "Mailing Domain" }); + mailing_model_id = fields.Many2one({ string: "Recipients Model", relation: "ir.model" }); + + _records = [ + { + id: 1, + name: "Belgian Events", + mailing_domain: '[["country","=","be"]]', + mailing_model_id: 1, + }, + ]; +} + +defineModels({ ...mailModels, Mailing, IrModel, MailFilter }); + +test.debug("create favorite filter", async () => { + onRpc("mailing.filter", "create", ({ args }) => { + expect.step("create"); + + expect(args[0][0]).toEqual({ + name: "event promo - new users", + mailing_model_id: 1, + mailing_domain: '[["new_user","=",True]]', + }); + }); + await mountView({ + type: "form", + resModel: "mailing.mailing", + resId: 2, + arch: `
+ + + + + + + + + `, + }); + + queryOne(".o_field_mailing_filter input").autocomplete = "widget"; + expect(".o_mass_mailing_remove_filter").not.toBeVisible({ + message: "should hide the option to remove filter if no filter is set", + }); + expect(".o_mass_mailing_save_filter_container").toBeVisible({ + message: "should have option to save filter if no filter is set", + }); + click(".o_field_mailing_filter input"); + await animationFrame(); + expect(".o_field_mailing_filter .dropdown li.ui-menu-item").toHaveCount(2, { + message: "there should be only one existing filter and a search more btn", + }); + + // create a new filter + click(".o_mass_mailing_add_filter"); + await waitFor(".o_mass_mailing_filter_name"); + click(".o_mass_mailing_filter_name"); + edit("event promo - new users"); + press("Enter"); + await animationFrame(); + expect.verifySteps(["create"]); + + // check if filter is set correctly + expect(".o_field_mailing_filter input").toHaveValue("event promo - new users", { + message: "saved filter should be set automatically", + }); + + await animationFrame(); + expect(".o_mass_mailing_remove_filter").toBeVisible({ + message: "should have option to remove filter if filter is already set", + }); + expect(".o_mass_mailing_save_filter_container").not.toBeVisible({ + message: "should not have option to save filter if filter is already set", + }); + + click(".o_field_mailing_filter input"); + await animationFrame(); + expect(".o_field_mailing_filter .dropdown li.ui-menu-item").toHaveCount(3, { + message: "there should be two existing filters and a search more btn", + }); + + await clickSave(); + expect.verifySteps([]); +}); diff --git a/addons/mass_mailing/static/tests/mass_mailing_favourite_filter_tests.js b/addons/mass_mailing/static/tests/mass_mailing_favourite_filter_tests.js index 4c7a5ba82242b..2c319ca895cf5 100644 --- a/addons/mass_mailing/static/tests/mass_mailing_favourite_filter_tests.js +++ b/addons/mass_mailing/static/tests/mass_mailing_favourite_filter_tests.js @@ -9,6 +9,7 @@ let fixture; let serverData; QUnit.module('mass_mailing_favourite_filter', {}, function () { + QUnit.module('favorite filter widget', (hooks) => { hooks.beforeEach(() => { fixture = testUtils.getFixture(); @@ -110,7 +111,7 @@ QUnit.module('favorite filter widget', (hooks) => { setupViewRegistries(); }); - QUnit.test('create favorite filter', async (assert) => { + QUnit.debug('create favorite filter', async (assert) => { assert.expect(8); await makeView({ @@ -132,6 +133,7 @@ QUnit.module('favorite filter widget', (hooks) => { `, mockRPC: function (_, { args, model, method }) { if (method === 'create' && model === 'mailing.filter') { + debugger assert.deepEqual(args[0], [{mailing_domain: '[["new_user","=",True]]', mailing_model_id: 1, name: 'event promo - new users'}], "should pass correct data in create"); @@ -169,7 +171,9 @@ QUnit.module('favorite filter widget', (hooks) => { await testUtils.click(fixture.querySelector('.o_field_mailing_filter input')); assert.containsN($dropdown, 'li.ui-menu-item', 3, "there should be two existing filters and a search more btn"); + debugger await testUtils.clickSave(fixture); + debugger }); QUnit.test('unlink favorite filter', async (assert) => {