| 1 |
import { waitUntilSubscribe } from "@bus/../tests/bus_test_helpers"; |
| 2 |
import { |
| 3 |
contains, |
| 4 |
defineMailModels, |
| 5 |
openDiscuss, |
| 6 |
start, |
| 7 |
startServer, |
| 8 |
} from "@mail/../tests/mail_test_helpers"; |
| 9 |
import { describe, expect, test } from "@odoo/hoot"; |
| 10 |
import { EventBus } from "@odoo/owl"; |
| 11 |
import { Command, mockService, patchWithCleanup, withUser } from "@web/../tests/web_test_helpers"; |
| 12 |
import { browser } from "@web/core/browser/browser"; |
| 13 |
|
| 14 |
import { rpc } from "@web/core/network/rpc"; |
| 15 |
|
| 16 |
describe.current.tags("desktop"); |
| 17 |
defineMailModels(); |
| 18 |
|
| 19 |
test("open channel in discuss from push notification", async () => { |
| 20 |
patchWithCleanup(window.navigator, { |
| 21 |
serviceWorker: Object.assign(new EventBus(), { |
| 22 |
register: () => Promise.resolve(), |
| 23 |
ready: Promise.resolve(), |
| 24 |
}), |
| 25 |
}); |
| 26 |
const pyEnv = await startServer(); |
| 27 |
const channelId = pyEnv["discuss.channel"].create({ name: "General" }); |
| 28 |
await start(); |
| 29 |
await openDiscuss("mail.box_inbox"); |
| 30 |
await contains(".o-mail-DiscussContent-threadName[title='Inbox']"); |
| 31 |
browser.navigator.serviceWorker.dispatchEvent( |
| 32 |
new MessageEvent("message", { |
| 33 |
data: { action: "OPEN_CHANNEL", data: { id: channelId } }, |
| 34 |
}) |
| 35 |
); |
| 36 |
await contains(".o-mail-DiscussContent-threadName[title='General']"); |
| 37 |
}); |
| 38 |
|
| 39 |
test("notify message to user as non member", async () => { |
| 40 |
patchWithCleanup(window, { |
| 41 |
Notification: class Notification { |
| 42 |
static get permission() { |
| 43 |
return "granted"; |
| 44 |
} |
| 45 |
constructor() { |
| 46 |
expect.step("push notification"); |
| 47 |
} |
| 48 |
addEventListener() {} |
| 49 |
}, |
| 50 |
}); |
| 51 |
mockService("multi_tab", { isOnMainTab: () => true }); |
| 52 |
const pyEnv = await startServer(); |
| 53 |
const johnUser = pyEnv["res.users"].create({ name: "John" }); |
| 54 |
const johnPartner = pyEnv["res.partner"].create({ name: "John", user_ids: [johnUser] }); |
| 55 |
const channelId = pyEnv["discuss.channel"].create({ |
| 56 |
channel_type: "chat", |
| 57 |
channel_member_ids: [Command.create({ partner_id: johnPartner })], |
| 58 |
}); |
| 59 |
await start(); |
| 60 |
await Promise.all([openDiscuss(channelId), waitUntilSubscribe(`discuss.channel_${channelId}`)]); |
| 61 |
await withUser(johnUser, () => |
| 62 |
rpc("/mail/message/post", { |
| 63 |
post_data: { body: "Hello!", message_type: "comment" }, |
| 64 |
thread_id: channelId, |
| 65 |
thread_model: "discuss.channel", |
| 66 |
}) |
| 67 |
); |
| 68 |
await contains(".o-mail-Message", { text: "Hello!" }); |
| 69 |
expect.verifySteps(["push notification"]); |
| 70 |
}); |