[FIX] mail: resolve issue with discuss app not considered opened
`isOpen` is only written during mounted but it might happen that the discuss record is not yet created when the component is mounted. task-2632702 closes odoo/odoo#75655 Signed-off-by: Alexandre Kühn (aku) <aku@odoo.com>
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import { registerMessagingComponent } from '@mail/utils/messaging_component';
|
||||
import { link, unlink } from '@mail/model/model_field_command';
|
||||
import { useUpdate } from '@mail/component_hooks/use_update/use_update';
|
||||
|
||||
const { Component } = owl;
|
||||
const { useRef } = owl.hooks;
|
||||
@@ -24,28 +25,19 @@ export class Discuss extends Component {
|
||||
// bind since passed as props
|
||||
this._onMobileAddItemHeaderInputSelect = this._onMobileAddItemHeaderInputSelect.bind(this);
|
||||
this._onMobileAddItemHeaderInputSource = this._onMobileAddItemHeaderInputSource.bind(this);
|
||||
useUpdate({ func: () => this._update() });
|
||||
}
|
||||
|
||||
mounted() {
|
||||
_update() {
|
||||
if (!this.discuss) {
|
||||
return;
|
||||
}
|
||||
this.discuss.update({ isOpen: true });
|
||||
if (this.discuss.thread) {
|
||||
this.trigger('o-push-state-action-manager');
|
||||
} else if (this.discuss.messaging.isInitialized) {
|
||||
} else if (!this._activeThreadCache && this.discuss.messaging.isInitialized) {
|
||||
this.discuss.openInitThread();
|
||||
}
|
||||
this._updateLocalStoreProps();
|
||||
}
|
||||
|
||||
patched() {
|
||||
if (!this.discuss) {
|
||||
return;
|
||||
}
|
||||
if (this.discuss.thread) {
|
||||
this.trigger('o-push-state-action-manager');
|
||||
}
|
||||
if (
|
||||
this.discuss.thread &&
|
||||
this.discuss.thread === this.messaging.inbox &&
|
||||
|
||||
@@ -23,14 +23,16 @@ QUnit.module('discuss_tests.js', {
|
||||
beforeEach(this);
|
||||
|
||||
this.start = async params => {
|
||||
const { afterEvent, env, widget } = await start(Object.assign({}, params, {
|
||||
const res = await start(Object.assign({}, params, {
|
||||
autoOpenDiscuss: true,
|
||||
data: this.data,
|
||||
hasDiscuss: true,
|
||||
}));
|
||||
const { afterEvent, env, widget } = res;
|
||||
this.afterEvent = afterEvent;
|
||||
this.env = env;
|
||||
this.widget = widget;
|
||||
return res;
|
||||
};
|
||||
},
|
||||
afterEach() {
|
||||
@@ -50,6 +52,34 @@ QUnit.test('messaging not created', async function (assert) {
|
||||
messagingBeforeCreationDeferred.resolve();
|
||||
});
|
||||
|
||||
QUnit.test('discuss should be marked as opened if the component is already rendered and messaging becomes created afterwards', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
const messagingBeforeCreationDeferred = makeTestPromise();
|
||||
await this.start({
|
||||
messagingBeforeCreationDeferred,
|
||||
waitUntilMessagingCondition: 'none',
|
||||
});
|
||||
|
||||
await afterNextRender(() => messagingBeforeCreationDeferred.resolve());
|
||||
assert.ok(
|
||||
this.messaging.discuss.isOpen,
|
||||
"discuss should be marked as opened if the component is already rendered and messaging becomes created afterwards"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('discuss should be marked as closed when the component is unmounted', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
const { widget } = await this.start();
|
||||
|
||||
await afterNextRender(() => widget.destroy());
|
||||
assert.notOk(
|
||||
this.messaging.discuss.isOpen,
|
||||
"discuss should be marked as closed when the component is unmounted"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('messaging not initialized', async function (assert) {
|
||||
assert.expect(1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user