|
| 1 | +import { expect, TestInfo } from '@playwright/test'; |
| 2 | +import { USERNAME } from '@session-foundation/qa-seeder'; |
| 3 | + |
| 4 | +import { testCommunityLink, testCommunityName } from '../../constants/community'; |
| 5 | +import { englishStrippedStr } from '../../localizer/englishStrippedStr'; |
| 6 | +import { bothPlatformsIt } from '../../types/sessionIt'; |
| 7 | +import { CloseSettings } from './locators'; |
| 8 | +import { ConversationHeaderName, MessageBody } from './locators/conversation'; |
| 9 | +import { MessageRequestsBanner } from './locators/home'; |
| 10 | +import { PrivacyMenuItem, UserSettings } from './locators/settings'; |
| 11 | +import { newUser } from './utils/create_account'; |
| 12 | +import { joinCommunity } from './utils/join_community'; |
| 13 | +import { closeApp, openAppTwoDevices, SupportedPlatformsType } from './utils/open_app'; |
| 14 | + |
| 15 | +bothPlatformsIt({ |
| 16 | + title: 'Blinded message request', |
| 17 | + risk: 'medium', |
| 18 | + testCb: blindedMessageRequests, |
| 19 | + countOfDevicesNeeded: 2, |
| 20 | + allureDescription: |
| 21 | + 'Verifies that a message request can be sent when Community Message Requests are on.', |
| 22 | + allureLinks: { |
| 23 | + ios: 'SES-4722', |
| 24 | + }, |
| 25 | +}); |
| 26 | + |
| 27 | +// TODO: tidy this up with neat locators |
| 28 | +async function blindedMessageRequests(platform: SupportedPlatformsType, testInfo: TestInfo) { |
| 29 | + const { device1, device2 } = await openAppTwoDevices(platform, testInfo); |
| 30 | + const [alice, bob] = await Promise.all([ |
| 31 | + newUser(device1, USERNAME.ALICE, { saveUserData: false }), |
| 32 | + newUser(device2, USERNAME.BOB, { saveUserData: false }), |
| 33 | + ]); |
| 34 | + await device2.clickOnElementAll(new UserSettings(device2)); |
| 35 | + await device2.clickOnElementAll(new PrivacyMenuItem(device2)); |
| 36 | + await device2.onAndroid().clickOnElementAll({ |
| 37 | + strategy: '-android uiautomator', |
| 38 | + selector: 'new UiSelector().text("Community Message Requests")', |
| 39 | + }); |
| 40 | + await device2.onIOS().clickOnElementAll({ |
| 41 | + strategy: 'accessibility id', |
| 42 | + selector: 'Community Message Requests', |
| 43 | + }); |
| 44 | + await device2.navigateBack(); |
| 45 | + await device2.clickOnElementAll(new CloseSettings(device2)); |
| 46 | + await Promise.all( |
| 47 | + [device1, device2].map(async device => { |
| 48 | + await joinCommunity(device, testCommunityLink, testCommunityName); |
| 49 | + }) |
| 50 | + ); |
| 51 | + const message = `I accept blinded message requests + ${platform} + ${Date.now()}`; |
| 52 | + await device2.sendMessage(message); |
| 53 | + await device2.navigateBack(); |
| 54 | + // Click on profile picture (Android) or sender name (iOS) |
| 55 | + await device1 |
| 56 | + .onAndroid() |
| 57 | + .clickOnElementXPath( |
| 58 | + `//android.view.ViewGroup[@resource-id='network.loki.messenger.qa:id/mainContainer'][.//android.widget.TextView[contains(@text,'${message}')]]//androidx.compose.ui.platform.ComposeView[@resource-id='network.loki.messenger.qa:id/profilePictureView']` |
| 59 | + ); |
| 60 | + await device1 |
| 61 | + .onIOS() |
| 62 | + .clickOnElementXPath( |
| 63 | + `//XCUIElementTypeCell[.//XCUIElementTypeOther[@name='Message body' and contains(@label,'${message}')]]//XCUIElementTypeStaticText[contains(@value,'(')]` |
| 64 | + ); |
| 65 | + if (platform === 'android') { |
| 66 | + const el = await device1.waitForTextElementToBePresent({ |
| 67 | + strategy: 'id', |
| 68 | + selector: 'account-id', |
| 69 | + }); |
| 70 | + const elText = await device1.getTextFromElement(el); |
| 71 | + expect(elText).toMatch(/^15/); |
| 72 | + await device1.clickOnElementAll({ |
| 73 | + strategy: '-android uiautomator', |
| 74 | + selector: 'new UiSelector().text("Message")', |
| 75 | + }); |
| 76 | + } else { |
| 77 | + await device1.waitForTextElementToBePresent({ |
| 78 | + strategy: 'accessibility id', |
| 79 | + selector: 'Blinded ID', |
| 80 | + }); |
| 81 | + await device1.clickOnByAccessibilityID('Message'); |
| 82 | + } |
| 83 | + |
| 84 | + await device1.clickOnElementAll(new ConversationHeaderName(device1, bob.userName)); |
| 85 | + const messageRequestPendingDescription = englishStrippedStr( |
| 86 | + 'messageRequestPendingDescription' |
| 87 | + ).toString(); |
| 88 | + await device1.onIOS().waitForTextElementToBePresent({ |
| 89 | + strategy: 'accessibility id', |
| 90 | + selector: 'Control message', |
| 91 | + text: messageRequestPendingDescription, |
| 92 | + }); |
| 93 | + await device1.onAndroid().waitForTextElementToBePresent({ |
| 94 | + strategy: 'id', |
| 95 | + selector: 'network.loki.messenger.qa:id/textSendAfterApproval', |
| 96 | + text: messageRequestPendingDescription, |
| 97 | + }); |
| 98 | + await device1.sendMessage('Howdy partner'); |
| 99 | + await device2.clickOnElementAll(new MessageRequestsBanner(device2)); |
| 100 | + // Bob clicks on request conversation item |
| 101 | + await device2.clickOnByAccessibilityID('Message request'); |
| 102 | + await device2.waitForTextElementToBePresent(new ConversationHeaderName(device2, alice.userName)); |
| 103 | + const messageRequestsAcceptDescription = englishStrippedStr( |
| 104 | + 'messageRequestsAcceptDescription' |
| 105 | + ).toString(); |
| 106 | + await device2.onIOS().waitForControlMessageToBePresent(messageRequestsAcceptDescription); |
| 107 | + await device2.onAndroid().waitForTextElementToBePresent({ |
| 108 | + strategy: 'id', |
| 109 | + selector: 'network.loki.messenger.qa:id/sendAcceptsTextView', |
| 110 | + text: messageRequestsAcceptDescription, |
| 111 | + }); |
| 112 | + |
| 113 | + // Send message from Bob to Alice |
| 114 | + const acceptMessage = 'Howdy back'; |
| 115 | + await device2.sendMessage(acceptMessage); |
| 116 | + await device1.waitForTextElementToBePresent(new MessageBody(device1, acceptMessage)); |
| 117 | + await closeApp(device1, device2); |
| 118 | +} |
0 commit comments