Skip to content

Commit

Permalink
test: fix mark unread locators
Browse files Browse the repository at this point in the history
  • Loading branch information
juliajforesti committed Nov 12, 2024
1 parent 835c5b3 commit f8403f6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 31 deletions.
22 changes: 10 additions & 12 deletions apps/meteor/tests/e2e/mark-unread.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ test.describe.serial('mark-unread', () => {
test('should not mark empty room as unread', async () => {
await poHomeChannel.sidenav.selectMarkAsUnread(targetChannel);

await expect(poHomeChannel.sidenav.getRoomBadge(targetChannel)).not.toBeVisible();
await expect(poHomeChannel.sidenav.getSidebarItemBadge(targetChannel)).not.toBeVisible();
});

test('should mark a populated room as unread', async () => {
await poHomeChannel.sidenav.openChat(targetChannel);
await poHomeChannel.content.sendMessage('this is a message for reply');
await poHomeChannel.sidenav.selectMarkAsUnread(targetChannel);

await expect(poHomeChannel.sidenav.getRoomBadge(targetChannel)).toBeVisible();
await expect(poHomeChannel.sidenav.getSidebarItemBadge(targetChannel)).toBeVisible();
});

test('should mark a populated room as unread - search', async () => {
Expand All @@ -43,29 +43,27 @@ test.describe.serial('mark-unread', () => {
await poHomeChannel.sidenav.selectMarkAsUnread(targetChannel);
await poHomeChannel.sidenav.searchRoom(targetChannel);

await expect(poHomeChannel.sidenav.getSearchChannelBadge(targetChannel)).toBeVisible();
await expect(poHomeChannel.sidenav.getSearchItemBadge(targetChannel)).toBeVisible();
});
});

test.describe('Mark Unread - Message Action', () => {
let poHomeChannelUser2: HomeChannel;

test('should mark a populated room as unread', async ({ browser }) => {
test('should mark a populated room as unread - message', async ({ browser }) => {
const { page: user2Page } = await createAuxContext(browser, Users.user2);
poHomeChannelUser2 = new HomeChannel(user2Page);

await poHomeChannelUser2.sidenav.openChat(targetChannel);
await poHomeChannelUser2.content.sendMessage('this is a message for reply');
await user2Page.close();

await poHomeChannel.sidenav.openChat(targetChannel);

// wait for the sidebar item to be read
await poHomeChannel.sidenav.getSidebarItemByName(targetChannel, true).waitFor();
await poHomeChannel.content.openLastMessageMenu();
await poHomeChannel.markUnread.click();

await expect(poHomeChannel.sidenav.getRoomBadge(targetChannel)).toBeVisible();
await expect(async () => {
await poHomeChannel.sidenav.openChat(targetChannel);
await poHomeChannel.content.openLastMessageMenu();
await poHomeChannel.markUnread.click();
await expect(poHomeChannel.sidenav.getSidebarItemBadge(targetChannel)).toBeVisible();
}).toPass();
});
});
});
33 changes: 15 additions & 18 deletions apps/meteor/tests/e2e/page-objects/fragments/home-sidenav.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,20 @@ export class HomeSidenav {
return this.page.locator('role=menuitemcheckbox[name="Profile"]');
}

// TODO: refactor getSidebarItemByName to not use data-qa
getSidebarItemByName(name: string, isRead?: boolean): Locator {
return this.page.locator(
['[data-qa="sidebar-item"]', `[aria-label="${name}"]`, isRead && '[data-unread="false"]'].filter(Boolean).join(''),
);
getSidebarItemByName(name: string): Locator {
return this.page.getByRole('link', { name, exact: true });
}

getSearchItemByName(name: string): Locator {
return this.page.getByRole('search').getByRole('listbox').getByRole('link', { name, exact: true });
}

getSidebarItemBadge(name: string): Locator {
return this.getSidebarItemByName(`1 unread message from ${name}`).getByRole('status');
}

getSearchItemBadge(name: string): Locator {
return this.getSearchItemByName(`1 unread message from ${name}`).getByRole('status');
}

async selectMarkAsUnread(name: string) {
Expand Down Expand Up @@ -108,10 +117,6 @@ export class HomeSidenav {
await this.page.locator('role=navigation >> role=button[name=Search]').click();
}

getSearchRoomByName(name: string): Locator {
return this.page.locator(`role=search >> role=listbox >> role=link >> text="${name}"`);
}

async searchRoom(name: string): Promise<void> {
await this.openSearch();
await this.page.locator('role=search >> role=searchbox').fill(name);
Expand All @@ -129,7 +134,7 @@ export class HomeSidenav {

async openChat(name: string): Promise<void> {
await this.searchRoom(name);
await this.getSearchRoomByName(name).click();
await this.getSearchItemByName(name).click();
await this.waitForChannel();
}

Expand Down Expand Up @@ -180,12 +185,4 @@ export class HomeSidenav {
await this.checkboxEncryption.click();
await this.btnCreate.click();
}

getRoomBadge(roomName: string): Locator {
return this.getSidebarItemByName(roomName).getByRole('status', { exact: true });
}

getSearchChannelBadge(name: string): Locator {
return this.page.locator(`[data-qa="sidebar-item"][aria-label="${name}"]`).first().getByRole('status', { exact: true });
}
}
2 changes: 1 addition & 1 deletion apps/meteor/tests/e2e/team-management.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ test.describe.serial('teams-management', () => {

await poHomeTeam.tabs.room.confirmDeleteTeam();
await poHomeTeam.sidenav.searchRoom(targetTeamNonPrivate);
await expect(poHomeTeam.sidenav.getSearchRoomByName(targetTeamNonPrivate)).not.toBeVisible();
await expect(poHomeTeam.sidenav.getSearchItemByName(targetTeamNonPrivate)).not.toBeVisible();
});

test('should user1 leave from targetTeam', async ({ browser }) => {
Expand Down

0 comments on commit f8403f6

Please sign in to comment.