import { expect, test } from '@playwright/test'; import { beforeAllClean } from './setup/beforeEach'; import { sleepFor } from '../../session/utils/Promise'; import { newUser } from './setup/new_user'; import { sendNewMessage } from './utilities/send_message'; import { clickOnMatchingText, clickOnTestIdWithText, typeIntoInput, waitForMatchingText, waitForTestIdWithText, } from './utilities/utils'; import { openApp } from './setup/open'; test.beforeEach(beforeAllClean); // test.afterEach(() => forceCloseAllWindows(windows)); // Send message in one to one conversation with new contact test('Create contact', async () => { const [windowA, windowB] = await openApp(2); const [userA, userB] = await Promise.all([newUser(windowA, 'Alice'), newUser(windowB, 'Bob')]); const testMessage = `${userA.userName} to ${userB.userName}`; const testReply = `${userB.userName} to ${userA.userName}`; // User A sends message to User B await sendNewMessage(windowA, userB.sessionid, `${testMessage} Time: '${Date.now()}'`); // User B sends message to User B to USER A await sendNewMessage(windowB, userA.sessionid, `${testReply} Time: '${Date.now()}'`); // Navigate to contacts tab in User B's window await clickOnTestIdWithText(windowA, 'new-conversation-button'); await windowA.waitForTimeout(2000); await waitForTestIdWithText(windowB, 'module-conversation__user__profile-name', userA.userName); // Navigate to contacts tab in User A's window await clickOnTestIdWithText(windowA, 'new-conversation-button'); }); test('Block user in conversation options', async () => { // Open app and create user const [windowA, windowB] = await openApp(2); const [userA, userB] = await Promise.all([newUser(windowA, 'Alice'), newUser(windowB, 'Bob')]); const testMessage = `${userA.userName} to ${userB.userName}`; const testReply = `${userB.userName} to ${userA.userName}`; // Create contact and send new message await sendNewMessage(windowA, userB.sessionid, `${testMessage} Time: '${Date.now()}'`); await sendNewMessage(windowB, userA.sessionid, `${testReply} Time: '${Date.now()}'`); // Check to see if User B is a contact await clickOnTestIdWithText(windowA, 'new-conversation-button'); await waitForTestIdWithText(windowA, 'module-conversation__user__profile-name', userB.userName); //Click on three dots menu await clickOnTestIdWithText(windowA, 'message-section'); await clickOnTestIdWithText(windowA, 'three-dots-conversation-options'); // Select block await clickOnMatchingText(windowA, 'Block'); // Verify toast notification 'blocked' await waitForTestIdWithText(windowA, 'session-toast', 'Blocked'); // Verify the user was moved to the blocked contact list // Click on settings tab await clickOnTestIdWithText(windowA, 'settings-section'); // click on settings section 'conversation' await clickOnTestIdWithText(windowA, 'conversations-settings-menu-item'); // Navigate to blocked users tab' await clickOnTestIdWithText(windowA, 'reveal-blocked-user-settings'); // select the contact to unblock by clicking on it by name await clickOnMatchingText(windowA, userB.userName); // Unblock user by clicking on unblock await clickOnTestIdWithText(windowA, 'unblock-button-settings-screen'); // Verify toast notification says unblocked await waitForTestIdWithText(windowA, 'session-toast', 'Unblocked'); await waitForMatchingText(windowA, 'No blocked contacts'); }); test('Change username', async () => { // Open App const [window] = await openApp(1); // Create user const newUsername = 'Tiny bubble'; await newUser(window, 'Alice'); // Open Profile await clickOnTestIdWithText(window, 'leftpane-primary-avatar'); // Click on current username to open edit field await clickOnTestIdWithText(window, 'edit-profile-icon'); // Type in new username await typeIntoInput(window, 'profile-name-input', newUsername); // await window.fill('.profile-name-input', 'new username'); // Press enter to confirm username input await window.keyboard.press('Enter'); // Wait for Copy button to appear to verify username change await window.isVisible("'Copy'"); // verify name change expect(await window.innerText('[data-testid=your-profile-name]')).toBe(newUsername); // Exit profile module await window.click('.session-icon-button.small'); }); test('Change avatar', async () => { const [window] = await openApp(1); await newUser(window, 'Alice'); // Open profile await clickOnTestIdWithText(window, 'leftpane-primary-avatar'); // Click on current profile picture await waitForTestIdWithText(window, 'copy-button-profile-update', 'Copy'); await clickOnTestIdWithText(window, 'image-upload-section'); await clickOnTestIdWithText(window, 'save-button-profile-update'); await waitForTestIdWithText(window, 'loading-spinner'); await waitForTestIdWithText(window, 'copy-button-profile-update', 'Copy'); await clickOnTestIdWithText(window, 'modal-close-button'); await sleepFor(500); const leftpaneAvatarContainer = await waitForTestIdWithText(window, 'leftpane-primary-avatar'); await sleepFor(500); const screenshot = await leftpaneAvatarContainer.screenshot({ type: 'jpeg', // path: 'avatar-updated-blue', }); expect(screenshot).toMatchSnapshot({ name: 'avatar-updated-blue.jpeg' }); });