summaryrefslogtreecommitdiff
path: root/addons/mail/static/src/components/thread_view/thread_view_tests.js
diff options
context:
space:
mode:
authorDidier (did) <did@odoo.com>2020-10-29 08:23:32 +0000
committerDidier (did) <did@odoo.com>2020-11-02 12:43:48 +0000
commit46be4866adacafdd147c799d1cc91e27a88a99d0 (patch)
treefdfeda7b9b66b3f0b8138816cbaa73576187cebf /addons/mail/static/src/components/thread_view/thread_view_tests.js
parentdc15021752ec83d4f36127b1bf75bece1074757d (diff)
[IMP] mail: add test for channel mention and channel link
task-2366680 PR https://github.com/odoo/odoo/pull/60593
Diffstat (limited to 'addons/mail/static/src/components/thread_view/thread_view_tests.js')
-rw-r--r--addons/mail/static/src/components/thread_view/thread_view_tests.js191
1 files changed, 188 insertions, 3 deletions
diff --git a/addons/mail/static/src/components/thread_view/thread_view_tests.js b/addons/mail/static/src/components/thread_view/thread_view_tests.js
index 89ae34a0f8e..dcdfee9d8fd 100644
--- a/addons/mail/static/src/components/thread_view/thread_view_tests.js
+++ b/addons/mail/static/src/components/thread_view/thread_view_tests.js
@@ -1150,7 +1150,7 @@ QUnit.test('Post a message containing an email address followed by a mention on
await this.start();
const thread = this.env.models['mail.thread'].findFromIdentifyingData({
id: 11,
- model: 'mail.channel'
+ model: 'mail.channel',
});
const threadViewer = this.env.models['mail.thread_viewer'].create({
hasThreadView: true,
@@ -1168,9 +1168,9 @@ QUnit.test('Post a message containing an email address followed by a mention on
.dispatchEvent(new window.KeyboardEvent('keyup'));
})
});
- await afterNextRender(() => {
+ await afterNextRender(() =>
document.querySelector('.o_ComposerSuggestion').click()
- });
+ );
await afterNextRender(() => {
document.querySelector('.o_Composer_buttonSend').click();
});
@@ -1181,6 +1181,191 @@ QUnit.test('Post a message containing an email address followed by a mention on
);
});
+QUnit.test('mention a channel with space in the name', async function (assert) {
+ assert.expect(2);
+
+ this.data['mail.channel'].records.push({
+ id: 7,
+ name: "General good boy",
+ });
+ await this.start();
+ const thread = this.env.models['mail.thread'].findFromIdentifyingData({
+ id: 7,
+ model: 'mail.channel',
+ });
+ const threadViewer = this.env.models['mail.thread_viewer'].create({
+ hasThreadView: true,
+ thread: [['link', thread]],
+ });
+ await this.createThreadViewComponent(threadViewer.threadView, { hasComposer: true });
+
+ await afterNextRender(() => {
+ document.querySelector(`.o_ComposerTextInput_textarea`).focus();
+ document.execCommand('insertText', false, "#");
+ document.querySelector(`.o_ComposerTextInput_textarea`)
+ .dispatchEvent(new window.KeyboardEvent('keydown'));
+ document.querySelector(`.o_ComposerTextInput_textarea`)
+ .dispatchEvent(new window.KeyboardEvent('keyup'));
+ });
+ await afterNextRender(() =>
+ document.querySelector('.o_ComposerSuggestion').click()
+ );
+ await afterNextRender(() => {
+ document.querySelector('.o_Composer_buttonSend').click();
+ });
+ assert.containsOnce(
+ document.querySelector('.o_Message_content'),
+ '.o_channel_redirect',
+ "message must contain a link the the mentionned channel"
+ );
+ assert.strictEqual(
+ document.querySelector('.o_channel_redirect').textContent,
+ '#General good boy',
+ "link to the channel must containt # + the channel name"
+ );
+});
+
+QUnit.test('mention a channel with "&" in the name', async function (assert) {
+ assert.expect(2);
+
+ this.data['mail.channel'].records.push({
+ id: 7,
+ name: "General & good",
+ });
+ await this.start();
+ const thread = this.env.models['mail.thread'].findFromIdentifyingData({
+ id: 7,
+ model: 'mail.channel',
+ });
+ const threadViewer = this.env.models['mail.thread_viewer'].create({
+ hasThreadView: true,
+ thread: [['link', thread]],
+ });
+ await this.createThreadViewComponent(threadViewer.threadView, { hasComposer: true });
+
+ await afterNextRender(() => {
+ document.querySelector(`.o_ComposerTextInput_textarea`).focus();
+ document.execCommand('insertText', false, "#");
+ document.querySelector(`.o_ComposerTextInput_textarea`)
+ .dispatchEvent(new window.KeyboardEvent('keydown'));
+ document.querySelector(`.o_ComposerTextInput_textarea`)
+ .dispatchEvent(new window.KeyboardEvent('keyup'));
+ });
+ await afterNextRender(() =>
+ document.querySelector('.o_ComposerSuggestion').click()
+ );
+ await afterNextRender(() => {
+ document.querySelector('.o_Composer_buttonSend').click();
+ });
+ assert.containsOnce(
+ document.querySelector('.o_Message_content'),
+ '.o_channel_redirect',
+ "message should contain a link the the mentionned channel"
+ );
+ assert.strictEqual(
+ document.querySelector('.o_channel_redirect').textContent,
+ '#General & good',
+ "link to the channel must containt # + the channel name"
+ );
+});
+
+QUnit.test('start to mention a channel and add a new line after the #', async function (assert) {
+ assert.expect(2);
+
+ this.data['mail.channel'].records.push({
+ id: 7,
+ name: "General good",
+ });
+ await this.start();
+ const thread = this.env.models['mail.thread'].findFromIdentifyingData({
+ id: 7,
+ model: 'mail.channel',
+ });
+ const threadViewer = this.env.models['mail.thread_viewer'].create({
+ hasThreadView: true,
+ thread: [['link', thread]],
+ });
+ await this.createThreadViewComponent(threadViewer.threadView, { hasComposer: true });
+
+ await afterNextRender(() => {
+ document.querySelector(`.o_ComposerTextInput_textarea`).focus();
+ document.execCommand('insertText', false, "#\n #");
+ document.querySelector(`.o_ComposerTextInput_textarea`)
+ .dispatchEvent(new window.KeyboardEvent('keydown'));
+ document.querySelector(`.o_ComposerTextInput_textarea`)
+ .dispatchEvent(new window.KeyboardEvent('keyup'));
+ });
+ await afterNextRender(() => {
+ document.querySelector('.o_ComposerSuggestion').click();
+ });
+ await afterNextRender(() => {
+ document.querySelector('.o_Composer_buttonSend').click();
+ });
+ assert.containsOnce(
+ document.querySelector('.o_Message_content'),
+ '.o_channel_redirect',
+ "message should contain a link the the mentionned channel"
+ );
+ assert.strictEqual(
+ document.querySelector('.o_channel_redirect').textContent,
+ '#General good',
+ "link to the channel must containt # + the channel name"
+ );
+});
+
+QUnit.test('mention a channel and add a new line and text after the mention', async function (assert) {
+ assert.expect(2);
+
+ this.data['mail.channel'].records.push({
+ id: 7,
+ name: "General good",
+ });
+ await this.start();
+ const thread = this.env.models['mail.thread'].findFromIdentifyingData({
+ id: 7,
+ model: 'mail.channel',
+ });
+ const threadViewer = this.env.models['mail.thread_viewer'].create({
+ hasThreadView: true,
+ thread: [['link', thread]],
+ });
+ await this.createThreadViewComponent(threadViewer.threadView, { hasComposer: true });
+
+ await afterNextRender(() => {
+ document.querySelector(`.o_ComposerTextInput_textarea`).focus();
+ document.execCommand('insertText', false, "#");
+ document.querySelector(`.o_ComposerTextInput_textarea`)
+ .dispatchEvent(new window.KeyboardEvent('keydown'));
+ document.querySelector(`.o_ComposerTextInput_textarea`)
+ .dispatchEvent(new window.KeyboardEvent('keyup'));
+ });
+ await afterNextRender(() => {
+ document.querySelector('.o_ComposerSuggestion').click();
+ });
+ await afterNextRender(() => {
+ const text = document.querySelector(`.o_ComposerTextInput_textarea`).value;
+ document.querySelector(`.o_ComposerTextInput_textarea`).value = text.slice(0, -1);
+ document.execCommand('insertText', false, "\ntest");
+ document.querySelector(`.o_ComposerTextInput_textarea`)
+ .dispatchEvent(new window.KeyboardEvent('keydown'));
+ document.querySelector(`.o_ComposerTextInput_textarea`)
+ .dispatchEvent(new window.KeyboardEvent('keyup'));
+ });
+ await afterNextRender(() => {
+ document.querySelector('.o_Composer_buttonSend').click();
+ });
+ assert.containsOnce(
+ document.querySelector('.o_Message_content'),
+ '.o_channel_redirect',
+ "message should contain a link the the mentionned channel"
+ );
+ assert.strictEqual(
+ document.querySelector('.o_channel_redirect').textContent,
+ '#General good',
+ "link to the channel must containt # + the channel name"
+ );
+});
+
QUnit.test('show empty placeholder when thread contains no message', async function (assert) {
assert.expect(2);