diff --git a/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_canned_response_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_canned_response_tests.js index 35f0ed38df5..827899b0042 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_canned_response_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_canned_response_tests.js @@ -11,22 +11,20 @@ QUnit.test('canned response suggestion displayed', async function (assert) { const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create(); - const { createComposerSuggestionComponent, messaging } = await start(); - const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: mailChannelId1, - model: 'mail.channel', - }); - const cannedResponse = messaging.models['CannedResponse'].create({ - id: 7, + pyEnv['mail.shortcode'].create({ source: 'hello', substitution: "Hello, how are you?", }); - await createComposerSuggestionComponent(thread.composer, { - isActive: true, - modelName: 'CannedResponse', - recordLocalId: cannedResponse.localId, + const { insertText, openDiscuss } = await start({ + discuss: { + params: { + default_active_id: mailChannelId1, + }, + }, + hasDiscuss: true, }); - + await openDiscuss(); + await insertText('.o_ComposerTextInput_textarea', ":hello"); assert.containsOnce( document.body, `.o_ComposerSuggestion`, @@ -35,31 +33,24 @@ QUnit.test('canned response suggestion displayed', async function (assert) { }); QUnit.test('canned response suggestion correct data', async function (assert) { - assert.expect(5); + assert.expect(4); const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create(); - const { createComposerSuggestionComponent, messaging } = await start(); - const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: mailChannelId1, - model: 'mail.channel', - }); - const cannedResponse = messaging.models['CannedResponse'].create({ - id: 7, + pyEnv['mail.shortcode'].create({ source: 'hello', substitution: "Hello, how are you?", }); - await createComposerSuggestionComponent(thread.composer, { - isActive: true, - modelName: 'CannedResponse', - recordLocalId: cannedResponse.localId, + const { insertText, openDiscuss } = await start({ + discuss: { + params: { + default_active_id: mailChannelId1, + }, + }, + hasDiscuss: true, }); - - assert.containsOnce( - document.body, - '.o_ComposerSuggestion', - "Canned response suggestion should be present" - ); + await openDiscuss(); + await insertText('.o_ComposerTextInput_textarea', ":hello"); assert.containsOnce( document.body, '.o_ComposerSuggestion_part1', @@ -83,31 +74,24 @@ QUnit.test('canned response suggestion correct data', async function (assert) { }); QUnit.test('canned response suggestion active', async function (assert) { - assert.expect(2); + assert.expect(1); const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create(); - const { createComposerSuggestionComponent, messaging } = await start(); - const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: mailChannelId1, - model: 'mail.channel', - }); - const cannedResponse = messaging.models['CannedResponse'].create({ - id: 7, + pyEnv['mail.shortcode'].create({ source: 'hello', substitution: "Hello, how are you?", }); - await createComposerSuggestionComponent(thread.composer, { - isActive: true, - modelName: 'CannedResponse', - recordLocalId: cannedResponse.localId, + const { insertText, openDiscuss } = await start({ + discuss: { + params: { + default_active_id: mailChannelId1, + }, + }, + hasDiscuss: true, }); - - assert.containsOnce( - document.body, - '.o_ComposerSuggestion', - "Canned response suggestion should be displayed" - ); + await openDiscuss(); + await insertText('.o_ComposerTextInput_textarea', ":hello"); assert.hasClass( document.querySelector('.o_ComposerSuggestion'), 'active', diff --git a/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_channel_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_channel_tests.js index a3701002bac..4caba51ed8b 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_channel_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_channel_tests.js @@ -10,18 +10,17 @@ QUnit.test('channel mention suggestion displayed', async function (assert) { assert.expect(1); const pyEnv = await startServer(); - const mailChannelId1 = pyEnv['mail.channel'].create(); - const { createComposerSuggestionComponent, messaging } = await start(); - const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: mailChannelId1, - model: 'mail.channel', + const mailChannelId1 = pyEnv['mail.channel'].create({ name: 'my-channel' }); + const { insertText, openDiscuss } = await start({ + discuss: { + params: { + default_active_id: mailChannelId1, + }, + }, + hasDiscuss: true, }); - await createComposerSuggestionComponent(thread.composer, { - isActive: true, - modelName: 'Thread', - recordLocalId: thread.localId, - }); - + await openDiscuss(); + await insertText('.o_ComposerTextInput_textarea', "#my-channel"); assert.containsOnce( document.body, `.o_ComposerSuggestion`, @@ -30,26 +29,20 @@ QUnit.test('channel mention suggestion displayed', async function (assert) { }); QUnit.test('channel mention suggestion correct data', async function (assert) { - assert.expect(3); + assert.expect(2); const pyEnv = await startServer(); const mailChannelId1 = pyEnv['mail.channel'].create({ name: "General" }); - const { createComposerSuggestionComponent, messaging } = await start(); - const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: mailChannelId1, - model: 'mail.channel', + const { insertText, openDiscuss } = await start({ + discuss: { + params: { + default_active_id: mailChannelId1, + }, + }, + hasDiscuss: true, }); - await createComposerSuggestionComponent(thread.composer, { - isActive: true, - modelName: 'Thread', - recordLocalId: thread.localId, - }); - - assert.containsOnce( - document.body, - '.o_ComposerSuggestion', - "Channel mention suggestion should be present" - ); + await openDiscuss(); + await insertText('.o_ComposerTextInput_textarea', "#General"); assert.containsOnce( document.body, '.o_ComposerSuggestion_part1', @@ -63,26 +56,20 @@ QUnit.test('channel mention suggestion correct data', async function (assert) { }); QUnit.test('channel mention suggestion active', async function (assert) { - assert.expect(2); + assert.expect(1); const pyEnv = await startServer(); - const mailChannelId1 = pyEnv['mail.channel'].create(); - const { createComposerSuggestionComponent, messaging } = await start(); - const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: mailChannelId1, - model: 'mail.channel', + const mailChannelId1 = pyEnv['mail.channel'].create({ name: 'my-channel' }); + const { insertText, openDiscuss } = await start({ + discuss: { + params: { + default_active_id: mailChannelId1, + }, + }, + hasDiscuss: true, }); - await createComposerSuggestionComponent(thread.composer, { - isActive: true, - modelName: 'Thread', - recordLocalId: thread.localId, - }); - - assert.containsOnce( - document.body, - '.o_ComposerSuggestion', - "Channel mention suggestion should be displayed" - ); + await openDiscuss(); + await insertText('.o_ComposerTextInput_textarea', "#my-channel"); assert.hasClass( document.querySelector('.o_ComposerSuggestion'), 'active', diff --git a/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_command_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_command_tests.js index 0c540122677..623bca79db1 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_command_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_command_tests.js @@ -10,56 +10,39 @@ QUnit.test('command suggestion displayed', async function (assert) { assert.expect(1); const pyEnv = await startServer(); - const mailChannelId1 = pyEnv['mail.channel'].create(); - const { createComposerSuggestionComponent, messaging } = await start(); - const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: mailChannelId1, - model: 'mail.channel', + const mailChannelId1 = pyEnv['mail.channel'].create({ name: 'my-channel' }); + const { insertText, openDiscuss } = await start({ + discuss: { + params: { + default_active_id: mailChannelId1, + }, + }, + hasDiscuss: true, }); - const command = messaging.models['ChannelCommand'].create({ - methodName: '', - name: 'whois', - help: "Displays who it is", - }); - await createComposerSuggestionComponent(thread.composer, { - isActive: true, - modelName: 'ChannelCommand', - recordLocalId: command.localId, - }); - + await openDiscuss(); + await insertText('.o_ComposerTextInput_textarea', "/who"); assert.containsOnce( document.body, - `.o_ComposerSuggestion`, - "Command suggestion should be present" + '.o_ComposerSuggestion', + "Command suggestion should be present", ); }); QUnit.test('command suggestion correct data', async function (assert) { - assert.expect(5); + assert.expect(4); const pyEnv = await startServer(); - const mailChannelId1 = pyEnv['mail.channel'].create(); - const { createComposerSuggestionComponent, messaging } = await start(); - const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: mailChannelId1, - model: 'mail.channel', + const mailChannelId1 = pyEnv['mail.channel'].create({ name: 'my-channel' }); + const { insertText, openDiscuss } = await start({ + discuss: { + params: { + default_active_id: mailChannelId1, + }, + }, + hasDiscuss: true, }); - const command = messaging.models['ChannelCommand'].create({ - methodName: '', - name: 'whois', - help: "Displays who it is", - }); - await createComposerSuggestionComponent(thread.composer, { - isActive: true, - modelName: 'ChannelCommand', - recordLocalId: command.localId, - }); - - assert.containsOnce( - document.body, - '.o_ComposerSuggestion', - "Command suggestion should be present" - ); + await openDiscuss(); + await insertText('.o_ComposerTextInput_textarea', "/who"); assert.containsOnce( document.body, '.o_ComposerSuggestion_part1', @@ -67,51 +50,40 @@ QUnit.test('command suggestion correct data', async function (assert) { ); assert.strictEqual( document.querySelector(`.o_ComposerSuggestion_part1`).textContent, - "whois", + "who", "Command name should be displayed" ); assert.containsOnce( - document.body, + document.querySelector('.o_ComposerSuggestion'), '.o_ComposerSuggestion_part2', "Command help should be present" ); assert.strictEqual( document.querySelector(`.o_ComposerSuggestion_part2`).textContent, - "Displays who it is", + "List users in the current channel", "Command help should be displayed" ); }); QUnit.test('command suggestion active', async function (assert) { - assert.expect(2); + assert.expect(1); const pyEnv = await startServer(); - const mailChannelId1 = pyEnv['mail.channel'].create(); - const { createComposerSuggestionComponent, messaging } = await start(); - const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: mailChannelId1, - model: 'mail.channel', + const mailChannelId1 = pyEnv['mail.channel'].create({ name: 'my-channel' }); + const { insertText, openDiscuss } = await start({ + discuss: { + params: { + default_active_id: mailChannelId1, + }, + }, + hasDiscuss: true, }); - const command = messaging.models['ChannelCommand'].create({ - methodName: '', - name: 'whois', - help: "Displays who it is", - }); - await createComposerSuggestionComponent(thread.composer, { - isActive: true, - modelName: 'ChannelCommand', - recordLocalId: command.localId, - }); - - assert.containsOnce( - document.body, - '.o_ComposerSuggestion', - "Command suggestion should be displayed" - ); + await openDiscuss(); + await insertText('.o_ComposerTextInput_textarea', "/who"); assert.hasClass( document.querySelector('.o_ComposerSuggestion'), 'active', - "should be active initially" + "1st suggestion should be active initially" ); }); diff --git a/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_partner_tests.js b/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_partner_tests.js index 85f53a01425..7f317c1890b 100644 --- a/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_partner_tests.js +++ b/addons/mail/static/tests/qunit_suite_tests/components/composer_suggestion_partner_tests.js @@ -10,23 +10,22 @@ QUnit.test('partner mention suggestion displayed', async function (assert) { assert.expect(1); const pyEnv = await startServer(); - const mailChannelId1 = pyEnv['mail.channel'].create(); - const { createComposerSuggestionComponent, messaging } = await start(); - const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: mailChannelId1, - model: 'mail.channel', - }); - const partner = messaging.models['Partner'].create({ - id: 7, + const mailChannelId1 = pyEnv['mail.channel'].create({}); + pyEnv['res.partner'].create({ + email: "demo_user@odoo.com", im_status: 'online', - name: "Demo User", + name: 'Demo User', }); - await createComposerSuggestionComponent(thread.composer, { - isActive: true, - modelName: 'Partner', - recordLocalId: partner.localId, + const { insertText, openDiscuss } = await start({ + discuss: { + params: { + default_active_id: mailChannelId1, + }, + }, + hasDiscuss: true, }); - + await openDiscuss(); + await insertText('.o_ComposerTextInput_textarea', "@demo"); assert.containsOnce( document.body, `.o_ComposerSuggestion`, @@ -35,35 +34,28 @@ QUnit.test('partner mention suggestion displayed', async function (assert) { }); QUnit.test('partner mention suggestion correct data', async function (assert) { - assert.expect(6); + assert.expect(5); const pyEnv = await startServer(); - const mailChannelId1 = pyEnv['mail.channel'].create(); - const { createComposerSuggestionComponent, messaging } = await start(); - const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: mailChannelId1, - model: 'mail.channel', - }); - const partner = messaging.models['Partner'].create({ + const mailChannelId1 = pyEnv['mail.channel'].create({}); + pyEnv['res.partner'].create({ email: "demo_user@odoo.com", - id: 7, im_status: 'online', - name: "Demo User", + name: 'Demo User', }); - await createComposerSuggestionComponent(thread.composer, { - isActive: true, - modelName: 'Partner', - recordLocalId: partner.localId, + const { insertText, openDiscuss } = await start({ + discuss: { + params: { + default_active_id: mailChannelId1, + }, + }, + hasDiscuss: true, }); - + await openDiscuss(); + await insertText('.o_ComposerTextInput_textarea', "@demo"); assert.containsOnce( - document.body, - '.o_ComposerSuggestion', - "Partner mention suggestion should be present" - ); - assert.strictEqual( - document.querySelectorAll(`.o_PartnerImStatusIcon`).length, - 1, + document.querySelector('.o_ComposerSuggestion'), + '.o_PartnerImStatusIcon', "Partner's im_status should be displayed" ); assert.containsOnce( @@ -72,7 +64,7 @@ QUnit.test('partner mention suggestion correct data', async function (assert) { "Partner's name should be present" ); assert.strictEqual( - document.querySelector(`.o_ComposerSuggestion_part1`).textContent, + document.querySelector('.o_ComposerSuggestion_part1').textContent, "Demo User", "Partner's name should be displayed" ); @@ -82,38 +74,32 @@ QUnit.test('partner mention suggestion correct data', async function (assert) { "Partner's email should be present" ); assert.strictEqual( - document.querySelector(`.o_ComposerSuggestion_part2`).textContent, + document.querySelector('.o_ComposerSuggestion_part2').textContent, "(demo_user@odoo.com)", "Partner's email should be displayed" ); }); QUnit.test('partner mention suggestion active', async function (assert) { - assert.expect(2); + assert.expect(1); const pyEnv = await startServer(); - const mailChannelId1 = pyEnv['mail.channel'].create(); - const { createComposerSuggestionComponent, messaging } = await start(); - const thread = messaging.models['Thread'].findFromIdentifyingData({ - id: mailChannelId1, - model: 'mail.channel', - }); - const partner = messaging.models['Partner'].create({ - id: 7, + const mailChannelId1 = pyEnv['mail.channel'].create({}); + pyEnv['res.partner'].create({ + email: "demo_user@odoo.com", im_status: 'online', - name: "Demo User", + name: 'Demo User', }); - await createComposerSuggestionComponent(thread.composer, { - isActive: true, - modelName: 'Partner', - recordLocalId: partner.localId, + const { insertText, openDiscuss } = await start({ + discuss: { + params: { + default_active_id: mailChannelId1, + }, + }, + hasDiscuss: true, }); - - assert.containsOnce( - document.body, - '.o_ComposerSuggestion', - "Partner mention suggestion should be displayed" - ); + await openDiscuss(); + await insertText('.o_ComposerTextInput_textarea', "@demo"); assert.hasClass( document.querySelector('.o_ComposerSuggestion'), 'active',