Skip to content

Commit

Permalink
test(update): update sidebar methods and tests to look for specific name
Browse files Browse the repository at this point in the history
  • Loading branch information
luisecm committed Mar 25, 2024
1 parent 3d1a52a commit d28842b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 36 deletions.
56 changes: 38 additions & 18 deletions tests/screenobjects/chats/ChatsSidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,13 @@ class ChatsSidebar extends UplinkMainScreen {

// Validations or assertions

async validateLastMessageDisplayed(message: string) {
const sidebarStatusValue = await this.sidebarChatsUserStatusValue;
await sidebarStatusValue.waitUntil(
async validateLastMessageDisplayed(message: string, username: string) {
const sidebarUserLocator =
await this.getExistingElementByAriaLabel(username);
const sidebarStatusValue = await sidebarUserLocator
?.$(SELECTORS.SIDEBAR_CHATS_USER_STATUS)
.$(SELECTORS.SIDEBAR_CHATS_USER_STATUS_VALUE);
await sidebarStatusValue?.waitUntil(
async () => {
return (await sidebarStatusValue.getText()) === message;
},
Expand All @@ -296,20 +300,28 @@ class ChatsSidebar extends UplinkMainScreen {
);
}

async validateLastMessageTimeAgo() {
const timeAgo = await this.sidebarChatsUserBadgeTimeAgoValue;
async validateLastMessageTimeAgo(username: string) {
const sidebarUserLocator =
await this.getExistingElementByAriaLabel(username);
const timeAgo = await sidebarUserLocator
?.$(SELECTORS.SIDEBAR_CHATS_USER_BADGE_TIME_AGO)
.$(SELECTORS.SIDEBAR_CHATS_USER_BADGE_TIME_AGO_VALUE);
await expect(timeAgo).toHaveTextContaining(
/(?:\d{1,2}\s+(?:second|minute)s?\s+ago|now)$/,
);
}

async validateNoUnreadMessages() {
await this.sidebarChatsUserBadge.waitForExist({
reverse: true,
timeout: 15000,
timeoutMsg:
"Expected badge number of unread messages is still displayed after 15 seconds",
});
async validateNoUnreadMessages(username: string) {
const sidebarUserLocator =
await this.getExistingElementByAriaLabel(username);
await sidebarUserLocator
?.$(SELECTORS.SIDEBAR_CHATS_USER_BADGE)
.waitForExist({
reverse: true,
timeout: 15000,
timeoutMsg:
"Expected badge number of unread messages is still displayed after 15 seconds",
});
}

async validateNoSidebarChatsAreDisplayed() {
Expand Down Expand Up @@ -348,14 +360,22 @@ class ChatsSidebar extends UplinkMainScreen {
);
}

async validateNumberOfUnreadMessages(badgeNumber: string) {
const unreadMessages = await this.sidebarChatsUserBadgeNumberValue;
await expect(unreadMessages).toHaveTextContaining(badgeNumber);
async validateNumberOfUnreadMessages(badgeNumber: string, username: string) {
const sidebarUserLocator =
await this.getExistingElementByAriaLabel(username);
const badgeNumberDisplayed = await sidebarUserLocator
?.$(SELECTORS.SIDEBAR_CHATS_USER_BADGE_NUMBER)
.$(SELECTORS.SIDEBAR_CHATS_USER_BADGE_NUMBER_VALUE);
await expect(badgeNumberDisplayed).toHaveTextContaining(badgeNumber);
}

async validateUsernameDisplayed(username: string) {
const usernameDisplayed = await this.sidebarChatsUserNameValue;
await expect(usernameDisplayed).toHaveTextContaining(username);
async validateUsernameIsDisplayed(username: string) {
const sidebarUserLocator =
await this.getExistingElementByAriaLabel(username);
const usernameDisplayed = await sidebarUserLocator
?.$(SELECTORS.SIDEBAR_CHATS_USER_NAME)
.$(SELECTORS.SIDEBAR_CHATS_USER_NAME_VALUE);
await expect(usernameDisplayed).toHaveText(username);
}

async validateSidebarChatsIsShown() {
Expand Down
12 changes: 6 additions & 6 deletions tests/specs/reusable-accounts/08-sidebar-chats.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default async function sidebarChatsTests() {
await MessageLocal.waitForMessageSentToExist("__hello__");

// Validate last message on Sidebar is not formatted with markdown
await ChatsSidebar.validateLastMessageDisplayed("__hello__");
await ChatsSidebar.validateLastMessageDisplayed("__hello__", "ChatUserA");
});

it("Chat User A - Wait until Chat User B accepts friend request and sends a message", async () => {
Expand All @@ -68,25 +68,25 @@ export default async function sidebarChatsTests() {

it("Chat User A - Sidebar - Any active chats user has created should appear in Sidebar", async () => {
// Validate Sidebar shows Username
await ChatsSidebar.validateUsernameDisplayed("ChatUserB");
await ChatsSidebar.validateUsernameIsDisplayed("ChatUserB");

// Validate number of unread messages is displayed on sidebar
await ChatsSidebar.validateNumberOfUnreadMessages("1");
await ChatsSidebar.validateNumberOfUnreadMessages("1", "ChatUserB");

// Validate time ago displayed on sidebar
await ChatsSidebar.validateLastMessageTimeAgo();
await ChatsSidebar.validateLastMessageTimeAgo("ChatUserB");
});

it("Sidebar - Message preview on Sidebar should not display the message with markdown", async () => {
// Validate last message contents on Sidebar displays hello __hello__ without applying the markdown
await ChatsSidebar.validateLastMessageDisplayed("__hello__");
await ChatsSidebar.validateLastMessageDisplayed("__hello__", "ChatUserB");
});

it("Chat User A - Sidebar - Context Menu - Clear Unreads", async () => {
// Open context menu and right click on Clear Unreads
await ChatsSidebar.openContextMenuOnSidebar("ChatUserB");
await ContextMenuSidebar.selectChatsClearUnreads();
await ChatsSidebar.validateNoUnreadMessages();
await ChatsSidebar.validateNoUnreadMessages("ChatUserB");
});

it("Chat User A - Sidebar - Context Menu - Hide chat", async () => {
Expand Down
19 changes: 7 additions & 12 deletions tests/specs/reusable-accounts/11-group-chats-sidebar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ export default async function groupChatSidebarTests() {

it("Group Chats Testing - Go to another chat conversation", async () => {
// Go to another chat conversation
await Topbar.goToFriends();
await FriendsScreen.validateFriendsScreenIsShown();
await FriendsScreen.validateChatWithFriendButtonIsShown();
await FriendsScreen.hoverOnChatWithFriendButton("ChatUserB");
await FriendsScreen.clickOnChatWithFriend();
await Topbar.validateTopbarExists();
await ChatsSidebar.goToSidebarChat("ChatUserB");
await Topbar.validateTopbarUserName("ChatUserB");
});

it("Group Chat - Send message to the group with User B", async () => {
Expand All @@ -70,24 +66,23 @@ export default async function groupChatSidebarTests() {
await activateFirstApplication();

// Validate Sidebar shows Group Name
await ChatsSidebar.goToSidebarGroupChat("renamed");
await ChatsSidebar.validateUsernameDisplayed("renamed");
await ChatsSidebar.validateUsernameIsDisplayed("renamed");

// Validate last message content from group is displayed on sidebar
await ChatsSidebar.validateLastMessageDisplayed("HelloGroup");
await ChatsSidebar.validateLastMessageDisplayed("HelloGroup", "renamed");

// Validate number of unread messages from the group is displayed on sidebar
await ChatsSidebar.validateNumberOfUnreadMessages("1");
await ChatsSidebar.validateNumberOfUnreadMessages("1", "renamed");

// Validate time ago is displayed on sidebar for group chat
await ChatsSidebar.validateLastMessageTimeAgo();
await ChatsSidebar.validateLastMessageTimeAgo("renamed");
});

it("Group Chat - Sidebar - Context Menu - Clear Unreads", async () => {
// Open context menu on group chat and select Clear Unreads
await ChatsSidebar.openContextMenuOnGroupChat("renamed");
await ContextMenuSidebar.selectChatsClearUnreads();
await ChatsSidebar.validateNoUnreadMessages();
await ChatsSidebar.validateNoUnreadMessages("renamed");
});

it("Group Chat - Sidebar - Context Menu - Hide chat", async () => {
Expand Down

0 comments on commit d28842b

Please sign in to comment.