diff --git a/.changeset/rude-avocados-notice.md b/.changeset/rude-avocados-notice.md new file mode 100644 index 0000000000000..8b8b8715657c6 --- /dev/null +++ b/.changeset/rude-avocados-notice.md @@ -0,0 +1,5 @@ +--- +'@rocket.chat/meteor': patch +--- + +Fixed discussion names displaying as IDs in sidebar search results diff --git a/apps/meteor/server/lib/spotlight.js b/apps/meteor/server/lib/spotlight.js index 62218bd5928fc..dc182ee9d3a6f 100644 --- a/apps/meteor/server/lib/spotlight.js +++ b/apps/meteor/server/lib/spotlight.js @@ -34,6 +34,7 @@ export class Spotlight { joinCodeRequired: 1, lastMessage: 1, federated: true, + prid: 1, }, sort: { name: 1, diff --git a/apps/meteor/tests/e2e/page-objects/fragments/home-sidenav.ts b/apps/meteor/tests/e2e/page-objects/fragments/home-sidenav.ts index 0a4444c073c63..12a38f3b61851 100644 --- a/apps/meteor/tests/e2e/page-objects/fragments/home-sidenav.ts +++ b/apps/meteor/tests/e2e/page-objects/fragments/home-sidenav.ts @@ -33,6 +33,10 @@ export class HomeSidenav { return this.page.locator('role=button[name="Create"]'); } + get inputSearch(): Locator { + return this.page.locator('[placeholder="Search (Ctrl+K)"]').first(); + } + getSidebarItemByName(name: string): Locator { return this.page.locator(`[data-qa="sidebar-item"][aria-label="${name}"]`); } @@ -59,6 +63,10 @@ export class HomeSidenav { await this.page.locator(`role=menuitem[name="${text}"]`).click(); } + async openSearch(): Promise { + await this.page.locator('role=button[name="Search"]').click(); + } + async logout(): Promise { await this.page.locator('[data-qa="sidebar-avatar-button"]').click(); await this.page.locator('//*[contains(@class, "rcx-option__content") and contains(text(), "Logout")]').click(); diff --git a/apps/meteor/tests/e2e/search-discussion.spec.ts b/apps/meteor/tests/e2e/search-discussion.spec.ts new file mode 100644 index 0000000000000..e14813bc2dc3c --- /dev/null +++ b/apps/meteor/tests/e2e/search-discussion.spec.ts @@ -0,0 +1,47 @@ +import { Page } from '@playwright/test'; + +import { Users } from './fixtures/userStates'; +import { HomeChannel } from './page-objects'; +import { createTargetDiscussion } from './utils'; +import { getSettingValueById } from './utils/getSettingValueById'; +import { setSettingValueById } from './utils/setSettingValueById'; +import { test, expect } from './utils/test'; + +test.use({ storageState: Users.user1.state }); + +test.describe.serial('search-discussion', () => { + let settingDefaultValue: unknown; + let poHomeChannel: HomeChannel; + let discussionName: string; + + test.beforeAll(async ({ api }) => { + settingDefaultValue = await getSettingValueById(api, 'UI_Allow_room_names_with_special_chars'); + }); + + test.beforeEach(async ({ page, api }) => { + discussionName = await createTargetDiscussion(api); + poHomeChannel = new HomeChannel(page); + await page.goto('/home'); + }); + + test.afterAll(async ({ api }) => { + await setSettingValueById(api, 'UI_Allow_room_names_with_special_chars', settingDefaultValue); + }); + + const testDiscussionSearch = async (page: Page) => { + await poHomeChannel.sidenav.openSearch(); + await poHomeChannel.sidenav.inputSearch.type(discussionName); + const targetSearchItem = page.locator('role=listbox').getByText(discussionName).first(); + await expect(targetSearchItem).toBeVisible(); + } + + test('expect search discussion to show fname when UI_Allow_room_names_with_special_chars=true', async ({ page, api }) => { + await setSettingValueById(api, 'UI_Allow_room_names_with_special_chars', true); + await testDiscussionSearch(page); + }); + + test('expect search discussion to show fname when UI_Allow_room_names_with_special_chars=false', async ({ page, api }) => { + await setSettingValueById(api, 'UI_Allow_room_names_with_special_chars', false); + await testDiscussionSearch(page); + }); +}); diff --git a/apps/meteor/tests/e2e/utils/create-target-channel.ts b/apps/meteor/tests/e2e/utils/create-target-channel.ts index 856972eeffb8e..ce145f4233bd8 100644 --- a/apps/meteor/tests/e2e/utils/create-target-channel.ts +++ b/apps/meteor/tests/e2e/utils/create-target-channel.ts @@ -33,3 +33,14 @@ export async function createDirectMessage(api: BaseTest['api']): Promise { usernames: 'user1,user2', }); } + +export async function createTargetDiscussion(api: BaseTest['api']): Promise { + const channelName = faker.string.uuid(); + const discussionName = faker.string.uuid(); + + const response = await api.post('/channels.create', { name: channelName }); + const { channel } = await response.json(); + await api.post('/rooms.createDiscussion', { t_name: discussionName, prid: channel._id}); + + return discussionName; +} diff --git a/apps/meteor/tests/e2e/utils/getSettingValueById.ts b/apps/meteor/tests/e2e/utils/getSettingValueById.ts new file mode 100644 index 0000000000000..a4737024a5e68 --- /dev/null +++ b/apps/meteor/tests/e2e/utils/getSettingValueById.ts @@ -0,0 +1,7 @@ +import type { BaseTest } from './test'; + +export const getSettingValueById = async (api: BaseTest['api'], settingId: string): Promise => { + const response = await api.get(`/settings/${settingId}`); + const { value } = await response.json(); + return value; +};