From 3b42e13489d4aa23a8cf82630bf3d8f4ddd9820e Mon Sep 17 00:00:00 2001 From: Anant Bhasin Date: Fri, 11 Jun 2021 02:20:11 +0530 Subject: [PATCH] [ANDROID] AccessibilityLabels and helper fns --- app/containers/ActionSheet/ActionSheet.js | 1 + app/containers/ActionSheet/Item.js | 1 + app/views/NewMessageView.js | 1 + e2e/helpers/app.js | 14 +++++++++++++- e2e/tests/room/05-threads.spec.js | 17 ++++++++--------- e2e/tests/room/07-markasunread.spec.js | 4 ++-- 6 files changed, 26 insertions(+), 12 deletions(-) diff --git a/app/containers/ActionSheet/ActionSheet.js b/app/containers/ActionSheet/ActionSheet.js index af98a75ce..49ae1db3d 100644 --- a/app/containers/ActionSheet/ActionSheet.js +++ b/app/containers/ActionSheet/ActionSheet.js @@ -135,6 +135,7 @@ const ActionSheet = React.memo(forwardRef(({ children, theme }, ref) => { onPress={hide} style={[styles.button, { backgroundColor: themes[theme].auxiliaryBackground }]} theme={theme} + accessibilityLabel={I18n.t('Cancel')} > {I18n.t('Cancel')} diff --git a/app/containers/ActionSheet/Item.js b/app/containers/ActionSheet/Item.js index 2cacd0855..663682da4 100644 --- a/app/containers/ActionSheet/Item.js +++ b/app/containers/ActionSheet/Item.js @@ -19,6 +19,7 @@ export const Item = React.memo(({ item, hide, theme }) => { style={[styles.item, { backgroundColor: themes[theme].focusedBackground }]} theme={theme} testID={item.testID} + accessibilityLabel={item.title} > diff --git a/app/views/NewMessageView.js b/app/views/NewMessageView.js index 8d5f62ceb..9e312c48b 100644 --- a/app/views/NewMessageView.js +++ b/app/views/NewMessageView.js @@ -153,6 +153,7 @@ class NewMessageView extends React.Component { style={{ backgroundColor: themes[theme].backgroundColor }} testID={testID} theme={theme} + accessibilityLabel={title} > diff --git a/e2e/helpers/app.js b/e2e/helpers/app.js index 7c13d5c27..b0de2116c 100644 --- a/e2e/helpers/app.js +++ b/e2e/helpers/app.js @@ -92,6 +92,17 @@ async function dismissReviewNag(){ await element(by.text('NO').and(by.type(alertButtonType))).tap(); // Tap `no` on ask for review alert } +async function mockMessageWithNag(message, isThread = false) { + let input = isThread ? 'messagebox-input-thread' : 'messagebox-input'; + await element(by.id(input)).tap(); + await element(by.id(input)).typeText(`${ data.random }${ message }`); + await element(by.id('messagebox-send-message')).tap(); + await dismissReviewNag(); + await waitFor(element(by.text(`${ data.random }${ message }`))).toExist().withTimeout(60000); + await expect(element(by.text(`${ data.random }${ message }`))).toExist(); + await element(by.text(`${ data.random }${ message }`)).atIndex(0).tap(); +}; + async function tapBack() { await element(by.id('header-back')).atIndex(0).tap(); } @@ -153,5 +164,6 @@ module.exports = { searchRoom, tryTapping, checkServer, - closeKeyboard + closeKeyboard, + mockMessageWithNag }; \ No newline at end of file diff --git a/e2e/tests/room/05-threads.spec.js b/e2e/tests/room/05-threads.spec.js index 40652df7d..6fe5fccad 100644 --- a/e2e/tests/room/05-threads.spec.js +++ b/e2e/tests/room/05-threads.spec.js @@ -2,7 +2,7 @@ const { device, expect, element, by, waitFor } = require('detox'); const data = require('../../data'); -const { navigateToLogin, login, mockMessage, tapBack, sleep, searchRoom, starMessage, pinMessage, dismissReviewNag, tryTapping } = require('../../helpers/app'); +const { navigateToLogin, login, mockMessage, tapBack, sleep, searchRoom, starMessage, pinMessage, dismissReviewNag, tryTapping, mockMessageWithNag } = require('../../helpers/app'); async function navigateToRoom(roomName) { await device.launchApp({ permissions: { notifications: 'YES' }, delete: true }); @@ -68,11 +68,11 @@ describe('Threads', () => { const thread = `${ data.random }thread`; it('should create thread', async() => { await mockMessage('thread'); - await element(by.label(thread)).atIndex(0).longPress(); + await element(by.text(thread)).atIndex(0).longPress(); await expect(element(by.id('action-sheet'))).toExist(); await expect(element(by.id('action-sheet-handle'))).toBeVisible(); await element(by.id('action-sheet-handle')).swipe('up', 'fast', 0.5); - await element(by.label('Reply in Thread')).tap(); + await element(by.text('Reply in Thread')).tap(); await element(by.id('messagebox-input')).typeText('replied'); await element(by.id('messagebox-send-message')).tap(); await waitFor(element(by.id(`message-thread-button-${ thread }`))).toExist().withTimeout(5000); @@ -105,9 +105,9 @@ describe('Threads', () => { await mockMessage(messageText, true); await tapBack(); await waitFor(element(by.id('room-header').and(by.label(`${ mainRoom }`)))).toBeVisible().withTimeout(2000); - await waitFor(element(by.id('room-header').and(by.label(`${ data.random }thread`)))).toBeNotVisible().withTimeout(2000); + await waitFor(element(by.id('room-header').and(by.text(`${ data.random }thread`)))).toBeNotVisible().withTimeout(2000); await sleep(500) //TODO: Find a better way to wait for the animation to finish and the messagebox-input to be available and usable :( - await waitFor(element(by.label(`${ data.random }${ messageText }`)).atIndex(0)).toNotExist().withTimeout(2000); + await waitFor(element(by.text(`${ data.random }${ messageText }`)).atIndex(0)).toNotExist().withTimeout(2000); }); it('should mark send to channel and show on main channel', async() => { @@ -118,22 +118,21 @@ describe('Threads', () => { await element(by.id('messagebox-send-message')).tap(); await tapBack(); await waitFor(element(by.id('room-header').and(by.label(`${ mainRoom }`)))).toBeVisible().withTimeout(2000); - await waitFor(element(by.id('room-header').and(by.label(`${ data.random }thread`)))).toBeNotVisible().withTimeout(2000); + await waitFor(element(by.id('room-header').and(by.text(`${ data.random }thread`)))).toBeNotVisible().withTimeout(2000); await sleep(500) //TODO: Find a better way to wait for the animation to finish and the messagebox-input to be available and usable :( await waitFor(element(by.label(messageText)).atIndex(0)).toExist().withTimeout(2000); }); it('should navigate to thread from thread name', async() => { const messageText = 'navthreadname'; - await mockMessage('dummymessagebetweenthethread'); - await dismissReviewNag() //TODO: Create a proper test for this elsewhere. + await mockMessageWithNag('dummymessagebetweenthethread'); await element(by.id(`message-thread-button-${ thread }`)).tap(); await element(by.id('messagebox-input-thread')).typeText(messageText); await element(by.id('messagebox-send-to-channel')).tap(); await element(by.id('messagebox-send-message')).tap(); await tapBack(); await waitFor(element(by.id('room-header').and(by.label(`${ mainRoom }`)))).toBeVisible().withTimeout(2000); - await waitFor(element(by.id('room-header').and(by.label(`${ data.random }thread`)))).toBeNotVisible().withTimeout(2000); + await waitFor(element(by.id('room-header').and(by.text(`${ data.random }thread`)))).toBeNotVisible().withTimeout(2000); await waitFor(element(by.id(`message-thread-replied-on-${ thread }`))).toBeVisible().withTimeout(2000); await element(by.id(`message-thread-replied-on-${ thread }`)).tap(); await waitFor(element(by.id(`room-view-title-${ thread }`))).toExist().withTimeout(5000); diff --git a/e2e/tests/room/07-markasunread.spec.js b/e2e/tests/room/07-markasunread.spec.js index dcbc50367..549c5bce5 100644 --- a/e2e/tests/room/07-markasunread.spec.js +++ b/e2e/tests/room/07-markasunread.spec.js @@ -28,8 +28,8 @@ describe('Mark as unread', () => { const message = `${ data.random }message`; const channelName = `@${ data.users.regular.username }`; await sendMessage(data.users.alternate, channelName, message); - await waitFor(element(by.label(message)).atIndex(0)).toExist().withTimeout(30000); - await element(by.label(message)).atIndex(0).longPress(); + await waitFor(element(by.text(message)).atIndex(0)).toExist().withTimeout(30000); + await element(by.text(message)).atIndex(0).longPress(); await expect(element(by.id('action-sheet'))).toExist(); await expect(element(by.id('action-sheet-handle'))).toBeVisible(); await element(by.id('action-sheet-handle')).swipe('up', 'fast', 0.5);