|
| 1 | +import type { IMessage } from '@rocket.chat/core-typings'; |
| 2 | +import { Random } from '@rocket.chat/random'; |
| 3 | + |
| 4 | +import { Users } from './fixtures/userStates'; |
| 5 | +import { HomeChannel } from './page-objects'; |
| 6 | +import { setSettingValueById } from './utils'; |
| 7 | +import type { BaseTest } from './utils/test'; |
| 8 | +import { expect, test } from './utils/test'; |
| 9 | + |
| 10 | +test.use({ storageState: Users.admin.state }); |
| 11 | + |
| 12 | +test.describe.serial('Global Search', () => { |
| 13 | + let targetChannel: { name: string; _id: string }; |
| 14 | + let targetGroup: { name: string; _id: string }; |
| 15 | + let threadMessage: IMessage; |
| 16 | + let poHomeChannel: HomeChannel; |
| 17 | + |
| 18 | + const fillMessages = async (api: BaseTest['api']) => { |
| 19 | + const { message: parentMessage } = await ( |
| 20 | + await api.post('/chat.postMessage', { roomId: targetChannel._id, text: 'This is main message in channel' }) |
| 21 | + ).json(); |
| 22 | + |
| 23 | + const { message: childMessage } = await ( |
| 24 | + await api.post('/chat.postMessage', { roomId: targetChannel._id, text: `This is thread message in channel`, tmid: parentMessage._id }) |
| 25 | + ).json(); |
| 26 | + threadMessage = childMessage; |
| 27 | + }; |
| 28 | + |
| 29 | + test.beforeAll(async ({ api }) => { |
| 30 | + await Promise.all([ |
| 31 | + api |
| 32 | + .post('/channels.create', { name: Random.id() }) |
| 33 | + .then((res) => res.json()) |
| 34 | + .then((data) => { |
| 35 | + targetChannel = data.channel; |
| 36 | + }), |
| 37 | + api |
| 38 | + .post('/groups.create', { |
| 39 | + name: Random.id(), |
| 40 | + extraData: { encrypted: false }, |
| 41 | + }) |
| 42 | + .then((res) => res.json()) |
| 43 | + .then((data) => { |
| 44 | + targetGroup = data.group; |
| 45 | + }), |
| 46 | + setSettingValueById(api, 'Search.defaultProvider.GlobalSearchEnabled', true), |
| 47 | + ]); |
| 48 | + await fillMessages(api); |
| 49 | + }); |
| 50 | + |
| 51 | + test.afterAll(({ api }) => |
| 52 | + Promise.all([ |
| 53 | + api.post('/channels.delete', { roomId: targetChannel._id }), |
| 54 | + api.post('/groups.delete', { roomId: targetGroup._id }), |
| 55 | + setSettingValueById(api, 'Search.defaultProvider.GlobalSearchEnabled', false), |
| 56 | + ]), |
| 57 | + ); |
| 58 | + |
| 59 | + test.beforeEach(async ({ page }) => { |
| 60 | + poHomeChannel = new HomeChannel(page); |
| 61 | + await page.goto('/home'); |
| 62 | + }); |
| 63 | + |
| 64 | + test('should open the correct message when jumping from global search in group to channel thread', async ({ page }) => { |
| 65 | + await poHomeChannel.sidenav.openChat(targetGroup.name); |
| 66 | + await poHomeChannel.roomToolbar.btnSearchMessages.click(); |
| 67 | + |
| 68 | + await poHomeChannel.tabs.searchMessages.search(threadMessage.msg.slice(10), { global: true }); // fill partial text to match search |
| 69 | + |
| 70 | + const message = await poHomeChannel.tabs.searchMessages.getResultItem(threadMessage.msg); |
| 71 | + await message.hover(); |
| 72 | + const jumpToMessageButton = message.getByRole('button', { name: 'Jump to message' }); |
| 73 | + await jumpToMessageButton.click(); |
| 74 | + |
| 75 | + await expect(page.locator('header').getByRole('button').filter({ hasText: targetChannel.name })).toBeVisible(); // match channel name in room header |
| 76 | + await expect(page.getByText(threadMessage.msg)).toBeVisible(); |
| 77 | + }); |
| 78 | +}); |
0 commit comments