Skip to content

Commit

Permalink
test: add channel and thread unread
Browse files Browse the repository at this point in the history
  • Loading branch information
juliajforesti committed Nov 29, 2024
1 parent 286e44e commit b95935d
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 44 deletions.
103 changes: 65 additions & 38 deletions apps/meteor/tests/e2e/feature-preview.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ test.describe.serial('feature preview', () => {
let poHomeChannel: HomeChannel;
let poAccountProfile: AccountProfile;
let targetChannel: string;
let targetTeam: string;
let sidepanelTeam: string;
const targetChannelNameInTeam = `channel-from-team-${faker.number.int()}`;

test.beforeAll(async ({ api }) => {
await setSettingValueById(api, 'Accounts_AllowFeaturePreview', true);
targetChannel = await createTargetChannel(api);
targetChannel = await createTargetChannel(api, { members: ['user1'] });
});

test.afterAll(async ({ api }) => {
Expand Down Expand Up @@ -165,6 +165,8 @@ test.describe.serial('feature preview', () => {

test.describe('Sidepanel', () => {
test.beforeEach(async ({ api }) => {
sidepanelTeam = await createTargetTeam(api, { sidepanel: { items: ['channels', 'discussions'] } });

await setUserPreferences(api, {
sidebarViewMode: 'Medium',
featuresPreview: [
Expand All @@ -178,10 +180,11 @@ test.describe.serial('feature preview', () => {
},
],
});
targetTeam = await createTargetTeam(api);
});

test.afterEach(async ({ api }) => {
await deleteTeam(api, sidepanelTeam);

await setUserPreferences(api, {
sidebarViewMode: 'Medium',
featuresPreview: [
Expand All @@ -195,7 +198,6 @@ test.describe.serial('feature preview', () => {
},
],
});
await deleteTeam(api, targetTeam);
});
test('should be able to toggle "Sidepanel" feature', async ({ page }) => {
await page.goto('/account/feature-preview');
Expand All @@ -212,29 +214,21 @@ test.describe.serial('feature preview', () => {
await expect(sidepanelCheckbox).not.toBeChecked();
});

test('should display sidepanel on a team', async ({ page }) => {
await page.goto('/home');

await poHomeChannel.sidebar.openChat(targetTeam);
test('should display sidepanel on a team and hide it on edit', async ({ page }) => {
await page.goto(`/group/${sidepanelTeam}`);
await poHomeChannel.content.waitForChannel();
await expect(poHomeChannel.sidepanel.sidepanelList).toBeVisible();

await poHomeChannel.tabs.btnRoomInfo.click();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.room.toggleSidepanelWithChannels();
await poHomeChannel.tabs.room.toggleSidepanelItems();

await expect(poHomeChannel.sidepanel.sidepanelList).toBeVisible();
await expect(poHomeChannel.sidepanel.sidepanelList).not.toBeVisible();
});

test('should display new channel from team on the sidepanel', async ({ page, api }) => {
await page.goto('/home');

await poHomeChannel.sidebar.openChat(targetTeam);

await poHomeChannel.tabs.btnRoomInfo.click();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.room.toggleSidepanelWithChannels();

await expect(poHomeChannel.toastSuccess).toBeVisible();
await poHomeChannel.dismissToast();
await page.goto(`/group/${sidepanelTeam}`);
await poHomeChannel.content.waitForChannel();

await poHomeChannel.tabs.btnChannels.click();
await poHomeChannel.tabs.channels.btnCreateNew.click();
Expand All @@ -253,16 +247,9 @@ test.describe.serial('feature preview', () => {
const message = 'hello world';

await poHomeChannel.sidebar.setDisplayMode('Extended');
await poHomeChannel.sidebar.openChat(targetTeam);

await poHomeChannel.tabs.btnRoomInfo.click();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.room.toggleSidepanelWithChannels();
await expect(poHomeChannel.toastSuccess).toBeVisible();
await poHomeChannel.dismissToast();

await poHomeChannel.sidebar.openChat(sidepanelTeam);
await poHomeChannel.content.sendMessage(message);
await expect(poHomeChannel.sidepanel.getExtendedItem(targetTeam, message)).toBeVisible();
await expect(poHomeChannel.sidepanel.getExtendedItem(sidepanelTeam, message)).toBeVisible();
});

// remove .fail after fix
Expand All @@ -272,19 +259,59 @@ test.describe.serial('feature preview', () => {
const parsedWrong = 'hello > world';

await poHomeChannel.sidebar.setDisplayMode('Extended');
await poHomeChannel.sidebar.openChat(sidepanelTeam);
await poHomeChannel.content.sendMessage(message);

await poHomeChannel.sidebar.openChat(targetTeam);
await expect(poHomeChannel.sidepanel.getExtendedItem(sidepanelTeam, message)).toBeVisible();
await expect(poHomeChannel.sidepanel.getExtendedItem(sidepanelTeam, message)).not.toHaveText(parsedWrong);
});

await poHomeChannel.tabs.btnRoomInfo.click();
await poHomeChannel.tabs.room.btnEdit.click();
await poHomeChannel.tabs.room.toggleSidepanelWithChannels();
await expect(poHomeChannel.toastSuccess).toBeVisible();
await poHomeChannel.dismissToast();
test('should show channel in sidepanel after adding existing one', async ({ page }) => {
await page.goto(`/group/${sidepanelTeam}`);

await poHomeChannel.content.sendMessage(message);
await poHomeChannel.tabs.btnChannels.click();
await poHomeChannel.tabs.channels.btnAddExisting.click();
await poHomeChannel.tabs.channels.inputChannels.fill(targetChannel);
await page.getByRole('listbox').getByRole('option', { name: targetChannel }).click();
await poHomeChannel.tabs.channels.btnAdd.click();
await poHomeChannel.content.waitForChannel();

await expect(poHomeChannel.sidepanel.getItemByName(targetChannel)).toBeVisible();
});

await expect(poHomeChannel.sidepanel.getExtendedItem(targetTeam, message)).toBeVisible();
await expect(poHomeChannel.sidepanel.getExtendedItem(targetTeam, message)).not.toHaveText(parsedWrong);
test('should sort by last message even if unread message is inside thread', async ({ page, browser }) => {
const user1Page = await browser.newPage({ storageState: Users.user1.state });
const user1Channel = new HomeChannel(user1Page);

await page.goto(`/group/${sidepanelTeam}`);

await poHomeChannel.tabs.btnChannels.click();
await poHomeChannel.tabs.channels.btnAddExisting.click();
await poHomeChannel.tabs.channels.inputChannels.fill(targetChannel);
await page.getByRole('listbox').getByRole('option', { name: targetChannel }).click();
await poHomeChannel.tabs.channels.btnAdd.click();

const sidepanelTeamItem = poHomeChannel.sidepanel.getItemByName(sidepanelTeam);
const targetChannelItem = poHomeChannel.sidepanel.getItemByName(targetChannel);

await targetChannelItem.click();
expect(page.url()).toContain(`/channel/${targetChannel}`);
await poHomeChannel.content.sendMessage('hello channel');
await sidepanelTeamItem.focus();
await sidepanelTeamItem.click();
expect(page.url()).toContain(`/group/${sidepanelTeam}`);
await poHomeChannel.content.sendMessage('hello team');

await user1Page.goto(`/channel/${targetChannel}`);
await user1Channel.content.waitForChannel();
await user1Channel.content.openReplyInThread();
await user1Channel.content.toggleAlsoSendThreadToChannel(false);
await user1Channel.content.sendMessageInThread('hello thread');

const item = poHomeChannel.sidepanel.getItemByName(targetChannel);
await expect(item.locator('..')).toHaveAttribute('data-item-index', '0');

await user1Page.close();
});
});
});
20 changes: 18 additions & 2 deletions apps/meteor/tests/e2e/page-objects/fragments/home-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,10 @@ export class HomeContent {
}

async toggleAlsoSendThreadToChannel(isChecked: boolean): Promise<void> {
await this.page.getByRole('dialog').locator('[name="alsoSendThreadToChannel"]').setChecked(isChecked);
await this.page
.getByRole('dialog')
.locator('label', { has: this.page.getByRole('checkbox', { name: 'Also send to channel' }) })
.setChecked(isChecked);
}

get lastSystemMessageBody(): Locator {
Expand Down Expand Up @@ -398,7 +401,20 @@ export class HomeContent {
async waitForChannel(): Promise<void> {
await this.page.locator('role=main').waitFor();
await this.page.locator('role=main >> role=heading[level=1]').waitFor();
const messageList = this.page.getByRole('main').getByRole('list', { name: 'Message list', exact: true });
await messageList.waitFor();

await expect(this.page.locator('role=main >> role=list')).not.toHaveAttribute('aria-busy', 'true');
await expect(messageList).not.toHaveAttribute('aria-busy', 'true');
}

async openReplyInThread(): Promise<void> {
await this.page.locator('[data-qa-type="message"]').last().hover();
await this.page.locator('[data-qa-type="message"]').last().locator('role=button[name="Reply in thread"]').waitFor();
await this.page.locator('[data-qa-type="message"]').last().locator('role=button[name="Reply in thread"]').click();
}

async sendMessageInThread(text: string): Promise<void> {
await this.page.getByRole('dialog').getByRole('textbox', { name: 'Message' }).fill(text);
await this.page.getByRole('dialog').getByRole('button', { name: 'Send', exact: true }).click();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,10 @@ export class HomeFlextabRoom {
return this.page.getByRole('dialog').locator('label', { has: this.page.getByRole('checkbox', { name: 'Discussions' }) });
}

async toggleSidepanelWithChannels() {
async toggleSidepanelItems() {
await this.advancedSettingsAccordion.click();
await this.checkboxChannels.click();
await this.checkboxDiscussions.click();
await this.btnSave.click();
}
}
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/page-objects/fragments/sidepanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class Sidepanel {
}

getItemByName(name: string): Locator {
return this.sidepanelList.getByRole('link', { name, exact: true });
return this.sidepanelList.getByRole('link').filter({ hasText: name });
}

getExtendedItem(name: string, subtitle?: string): Locator {
Expand Down
8 changes: 6 additions & 2 deletions apps/meteor/tests/e2e/utils/create-target-channel.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { faker } from '@faker-js/faker';
import type { IRoom } from '@rocket.chat/core-typings';
import type { ChannelsCreateProps, GroupsCreateProps } from '@rocket.chat/rest-typings';

import type { BaseTest } from './test';
Expand All @@ -25,9 +26,12 @@ export async function createTargetPrivateChannel(api: BaseTest['api'], options?:
return name;
}

export async function createTargetTeam(api: BaseTest['api']): Promise<string> {
export async function createTargetTeam(
api: BaseTest['api'],
options?: { sidepanel?: IRoom['sidepanel'] } & Omit<GroupsCreateProps, 'name'>,
): Promise<string> {
const name = faker.string.uuid();
await api.post('/teams.create', { name, type: 1, members: ['user2', 'user1'] });
await api.post('/teams.create', { name, type: 1, members: ['user2', 'user1'], ...options });

return name;
}
Expand Down

0 comments on commit b95935d

Please sign in to comment.