diff --git a/src/components/Icon/index.js b/src/components/Icon/index.js index c65030afc407..269f642d8ed5 100644 --- a/src/components/Icon/index.js +++ b/src/components/Icon/index.js @@ -52,7 +52,7 @@ class Icon extends PureComponent { if (this.props.inline) { return ( @@ -68,7 +68,7 @@ class Icon extends PureComponent { return ( { hovered && !props.isFocused ? props.hoverStyle : null, ]} > - + { { {optionItem.isChatRoom && ( )} @@ -188,7 +188,7 @@ const OptionRowLHN = (props) => { {optionItem.alternateText} diff --git a/src/components/OptionRow.js b/src/components/OptionRow.js index 29c2e3c5d0ce..8c08765b5690 100644 --- a/src/components/OptionRow.js +++ b/src/components/OptionRow.js @@ -232,7 +232,7 @@ class OptionRow extends Component { } ( - + {props.translate('common.new')} diff --git a/src/languages/en.js b/src/languages/en.js index 765be98ed4dc..6bed9dd108fb 100755 --- a/src/languages/en.js +++ b/src/languages/en.js @@ -276,6 +276,8 @@ export default { fabNewChat: 'New chat (Floating action)', chatPinned: 'Chat pinned', draftedMessage: 'Drafted message', + listOfChatMessages: 'List of chat messages', + listOfChats: 'List of chats', }, iou: { amount: 'Amount', @@ -608,6 +610,7 @@ export default { invalidFormatEmailLogin: 'The email entered is invalid. Please fix the format and try again.', }, cannotGetAccountDetails: 'Couldn\'t retrieve account details, please try to sign in again.', + loginForm: 'Login form', }, personalDetails: { error: { @@ -1203,4 +1206,15 @@ export default { }, allStates: COMMON_CONST.STATES, allCountries: CONST.ALL_COUNTRIES, + accessibilityHints: { + navigateToChatsList: 'Navigate back to chats list', + chatWelcomeMessage: 'Chat welcome message', + navigatesToChat: 'Navigates to a chat', + newMessageLineIndicator: 'New message line indicator', + chatMessage: 'Chat message', + lastChatMessagePreview: 'Last chat message preview', + workspaceName: 'Workspace name', + chatUserDisplayNames: 'Chat user display names', + scrollToNewestMessages: 'Scroll to newest messages', + }, }; diff --git a/src/languages/es.js b/src/languages/es.js index f7012c3d6654..f8173c43aee7 100644 --- a/src/languages/es.js +++ b/src/languages/es.js @@ -275,6 +275,8 @@ export default { fabNewChat: 'Nuevo chat', chatPinned: 'Chat fijado', draftedMessage: 'Mensaje borrador', + listOfChatMessages: 'Lista de mensajes del chat', + listOfChats: 'lista de chats', }, iou: { amount: 'Importe', @@ -607,6 +609,7 @@ export default { invalidFormatEmailLogin: 'El email introducido no es válido. Corrígelo e inténtalo de nuevo.', }, cannotGetAccountDetails: 'No se pudieron cargar los detalles de tu cuenta, por favor intenta iniciar sesión de nuevo.', + loginForm: 'Formulario de inicio de sesión', }, personalDetails: { error: { @@ -1669,4 +1672,15 @@ export default { ZM: 'Zambia', ZW: 'Zimbabue', }, + accessibilityHints: { + navigateToChatsList: 'Vuelve a la lista de chats', + chatWelcomeMessage: 'Mensaje de bienvenida al chat', + navigatesToChat: 'Navega a un chat', + newMessageLineIndicator: 'Indicador de nueva línea de mensaje', + chatMessage: 'mensaje de chat', + lastChatMessagePreview: 'Vista previa del último mensaje del chat', + workspaceName: 'Nombre del espacio de trabajo', + chatUserDisplayNames: 'Nombres de los usuarios del chat', + scrollToNewestMessages: 'Desplázate a los mensajes más recientes', + }, }; diff --git a/src/pages/home/HeaderView.js b/src/pages/home/HeaderView.js index 0c5066e652c5..6594ec21590f 100644 --- a/src/pages/home/HeaderView.js +++ b/src/pages/home/HeaderView.js @@ -93,7 +93,7 @@ const HeaderView = (props) => { diff --git a/src/pages/home/report/FloatingMessageCounter/index.js b/src/pages/home/report/FloatingMessageCounter/index.js index 2297f8fc5368..5754993fbda5 100644 --- a/src/pages/home/report/FloatingMessageCounter/index.js +++ b/src/pages/home/report/FloatingMessageCounter/index.js @@ -63,7 +63,7 @@ class FloatingMessageCounter extends PureComponent { render() { return ( diff --git a/src/pages/home/report/ReportActionItem.js b/src/pages/home/report/ReportActionItem.js index d06e75de566f..a23b96b08b42 100644 --- a/src/pages/home/report/ReportActionItem.js +++ b/src/pages/home/report/ReportActionItem.js @@ -38,6 +38,7 @@ import focusTextInputAfterAnimation from '../../../libs/focusTextInputAfterAnima import ChronosOOOListActions from '../../../components/ReportActionItem/ChronosOOOListActions'; import ReportActionItemReactions from '../../../components/Reactions/ReportActionItemReactions'; import * as Report from '../../../libs/actions/Report'; +import withLocalize from '../../../components/withLocalize'; const propTypes = { /** Report for this action */ @@ -240,7 +241,7 @@ class ReportActionItem extends Component { > {hovered => ( - + {this.props.shouldDisplayNewMarker && ( )} @@ -305,6 +306,7 @@ ReportActionItem.defaultProps = defaultProps; export default compose( withWindowDimensions, + withLocalize, withNetwork(), withBlockedFromConcierge({propName: 'blockedFromConcierge'}), withReportActionsDrafts({ diff --git a/src/pages/home/report/ReportActionItemCreated.js b/src/pages/home/report/ReportActionItemCreated.js index 89cda085bdfd..f942b9e05139 100644 --- a/src/pages/home/report/ReportActionItemCreated.js +++ b/src/pages/home/report/ReportActionItemCreated.js @@ -16,6 +16,7 @@ import EmptyStateBackgroundImage from '../../../../assets/images/empty-state_bac import * as StyleUtils from '../../../styles/StyleUtils'; import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; import compose from '../../../libs/compose'; +import withLocalize from '../../../components/withLocalize'; const propTypes = { /** The id of the report */ @@ -57,7 +58,7 @@ const ReportActionItemCreated = (props) => { style={StyleUtils.getReportWelcomeBackgroundImageStyle(props.isSmallScreenWidth)} /> `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, diff --git a/src/pages/home/report/ReportActionsList.js b/src/pages/home/report/ReportActionsList.js index 38d19864ea5a..2e02a794ed03 100644 --- a/src/pages/home/report/ReportActionsList.js +++ b/src/pages/home/report/ReportActionsList.js @@ -20,6 +20,7 @@ import CONST from '../../../CONST'; import * as StyleUtils from '../../../styles/StyleUtils'; import reportPropTypes from '../../reportPropTypes'; import networkPropTypes from '../../../components/networkPropTypes'; +import withLocalize from '../../../components/withLocalize'; const propTypes = { /** Position of the "New" line marker */ @@ -150,7 +151,7 @@ class ReportActionsList extends React.Component { return ( - + this.input = el} label={this.props.translate('loginForm.phoneOrEmail')} diff --git a/tests/ui/UnreadIndicatorsTest.js b/tests/ui/UnreadIndicatorsTest.js index 5f65d8b20b50..ad2d622a4315 100644 --- a/tests/ui/UnreadIndicatorsTest.js +++ b/tests/ui/UnreadIndicatorsTest.js @@ -24,6 +24,7 @@ import * as User from '../../src/libs/actions/User'; import * as Pusher from '../../src/libs/Pusher/pusher'; import PusherConnectionManager from '../../src/libs/PusherConnectionManager'; import CONFIG from '../../src/CONFIG'; +import * as Localize from '../../src/libs/Localize'; // We need a large timeout here as we are lazy loading React Navigation screens and this test is running against the entire mounted App jest.setTimeout(30000); @@ -51,7 +52,8 @@ beforeAll(() => { }); function scrollUpToRevealNewMessagesBadge() { - fireEvent.scroll(screen.queryByLabelText('List of chat messages'), { + const hintText = Localize.translateLocal('sidebarScreen.listOfChatMessages'); + fireEvent.scroll(screen.queryByLabelText(hintText), { nativeEvent: { contentOffset: { y: 250, @@ -74,7 +76,8 @@ function scrollUpToRevealNewMessagesBadge() { * @return {Boolean} */ function isNewMessagesBadgeVisible() { - const badge = screen.queryByAccessibilityHint('Scroll to newest messages'); + const hintText = Localize.translateLocal('accessibilityHints.scrollToNewestMessages'); + const badge = screen.queryByAccessibilityHint(hintText); return Math.round(badge.props.style.transform[0].translateY) === 10; } @@ -82,7 +85,8 @@ function isNewMessagesBadgeVisible() { * @return {Promise} */ function navigateToSidebar() { - const reportHeaderBackButton = screen.queryByAccessibilityHint('Navigate back to chats list'); + const hintText = Localize.translateLocal('accessibilityHints.navigateToChatsList'); + const reportHeaderBackButton = screen.queryByAccessibilityHint(hintText); fireEvent(reportHeaderBackButton, 'press'); return waitForPromisesToResolve(); } @@ -92,7 +96,8 @@ function navigateToSidebar() { * @return {Promise} */ function navigateToSidebarOption(index) { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); fireEvent(optionRows[index], 'press'); return waitForPromisesToResolve(); } @@ -101,7 +106,8 @@ function navigateToSidebarOption(index) { * @return {Boolean} */ function isDrawerOpen() { - const sidebarLinks = screen.queryAllByLabelText('List of chats'); + const hintText = Localize.translateLocal('sidebarScreen.listOfChats'); + const sidebarLinks = screen.queryAllByLabelText(hintText); return !lodashGet(sidebarLinks, [0, 'props', 'accessibilityElementsHidden']); } @@ -126,7 +132,8 @@ function signInAndGetAppWithUnreadChat() { render(); return waitForPromisesToResolveWithAct() .then(() => { - const loginForm = screen.queryAllByLabelText('Login form'); + const hintText = Localize.translateLocal('loginForm.loginForm'); + const loginForm = screen.queryAllByLabelText(hintText); expect(loginForm).toHaveLength(1); return TestHelper.signInWithTestUser(USER_A_ACCOUNT_ID, USER_A_EMAIL, undefined, undefined, 'A'); @@ -201,16 +208,19 @@ describe('Unread Indicators', () => { expect(LocalNotification.showCommentNotification.mock.calls).toHaveLength(0); // Verify the sidebar links are rendered - const sidebarLinks = screen.queryAllByLabelText('List of chats'); + const sidebarLinksHintText = Localize.translateLocal('sidebarScreen.listOfChats'); + const sidebarLinks = screen.queryAllByLabelText(sidebarLinksHintText); expect(sidebarLinks).toHaveLength(1); expect(isDrawerOpen()).toBe(true); // Verify there is only one option in the sidebar - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const optionRowsHintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(optionRowsHintText); expect(optionRows).toHaveLength(1); // And that the text is bold - const displayNameText = screen.queryByLabelText('Chat user display names'); + const displayNameHintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNameText = screen.queryByLabelText(displayNameHintText); expect(lodashGet(displayNameText, ['props', 'style', 0, 'fontWeight'])).toBe(fontWeightBold); return navigateToSidebarOption(0); @@ -220,14 +230,17 @@ describe('Unread Indicators', () => { expect(isDrawerOpen()).toBe(false); // That the report actions are visible along with the created action - const createdAction = screen.queryByLabelText('Chat welcome message'); + const welcomeMessageHintText = Localize.translateLocal('accessibilityHints.chatWelcomeMessage'); + const createdAction = screen.queryByLabelText(welcomeMessageHintText); expect(createdAction).toBeTruthy(); - const reportComments = screen.queryAllByLabelText('Chat message'); + const reportCommentsHintText = Localize.translateLocal('accessibilityHints.chatMessage'); + const reportComments = screen.queryAllByLabelText(reportCommentsHintText); expect(reportComments).toHaveLength(9); // Since the last read timestamp is the timestamp of action 3 we should have an unread indicator above the next "unread" action which will // have actionID of 4 - const unreadIndicator = screen.queryAllByLabelText('New message line indicator'); + const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); + const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(1); const reportActionID = lodashGet(unreadIndicator, [0, 'props', 'data-action-id']); expect(reportActionID).toBe('4'); @@ -252,7 +265,8 @@ describe('Unread Indicators', () => { expect(isDrawerOpen()).toBe(true); // Verify that the option row in the LHN is no longer bold (since OpenReport marked it as read) - const updatedDisplayNameText = screen.queryByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const updatedDisplayNameText = screen.queryByLabelText(hintText); expect(lodashGet(updatedDisplayNameText, ['props', 'style', 0, 'fontWeight'])).toBe(undefined); // Tap on the chat again @@ -260,7 +274,8 @@ describe('Unread Indicators', () => { }) .then(() => { // Verify the unread indicator is not present - const unreadIndicator = screen.queryAllByLabelText('New message line indicator'); + const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); + const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(0); expect(isDrawerOpen()).toBe(false); @@ -334,11 +349,13 @@ describe('Unread Indicators', () => { }) .then(() => { // // Verify the new report option appears in the LHN - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const optionRowsHintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(optionRowsHintText); expect(optionRows).toHaveLength(2); // Verify the text for both chats are bold indicating that nothing has not yet been read - const displayNameTexts = screen.queryAllByLabelText('Chat user display names'); + const displayNameHintTexts = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNameTexts = screen.queryAllByLabelText(displayNameHintTexts); expect(displayNameTexts).toHaveLength(2); const firstReportOption = displayNameTexts[0]; expect(lodashGet(firstReportOption, ['props', 'style', 0, 'fontWeight'])).toBe(fontWeightBold); @@ -353,7 +370,8 @@ describe('Unread Indicators', () => { }) .then(() => { // Verify that report we navigated to appears in a "read" state while the original unread report still shows as unread - const displayNameTexts = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNameTexts = screen.queryAllByLabelText(hintText); expect(displayNameTexts).toHaveLength(2); expect(lodashGet(displayNameTexts[0], ['props', 'style', 0, 'fontWeight'])).toBe(undefined); expect(lodashGet(displayNameTexts[0], ['props', 'children'])).toBe('C User'); @@ -373,7 +391,8 @@ describe('Unread Indicators', () => { }) .then(() => { // Verify the indicator appears above the last action - const unreadIndicator = screen.queryAllByLabelText('New message line indicator'); + const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); + const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(1); const reportActionID = lodashGet(unreadIndicator, [0, 'props', 'data-action-id']); expect(reportActionID).toBe('3'); @@ -387,7 +406,8 @@ describe('Unread Indicators', () => { .then(navigateToSidebar) .then(() => { // Verify the report is marked as unread in the sidebar - const displayNameTexts = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNameTexts = screen.queryAllByLabelText(hintText); expect(displayNameTexts).toHaveLength(1); expect(lodashGet(displayNameTexts[0], ['props', 'style', 0, 'fontWeight'])).toBe(fontWeightBold); expect(lodashGet(displayNameTexts[0], ['props', 'children'])).toBe('B User'); @@ -398,7 +418,8 @@ describe('Unread Indicators', () => { .then(() => navigateToSidebar()) .then(() => { // Verify the report is now marked as read - const displayNameTexts = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNameTexts = screen.queryAllByLabelText(hintText); expect(displayNameTexts).toHaveLength(1); expect(lodashGet(displayNameTexts[0], ['props', 'style', 0, 'fontWeight'])).toBe(undefined); expect(lodashGet(displayNameTexts[0], ['props', 'children'])).toBe('B User'); @@ -407,7 +428,8 @@ describe('Unread Indicators', () => { return navigateToSidebarOption(0); }) .then(() => { - const unreadIndicator = screen.queryAllByLabelText('New message line indicator'); + const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); + const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(0); // Scroll up and verify the "New messages" badge is hidden @@ -420,7 +442,8 @@ describe('Unread Indicators', () => { // Verify we are on the LHN and that the chat shows as unread in the LHN expect(isDrawerOpen()).toBe(true); - const displayNameTexts = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNameTexts = screen.queryAllByLabelText(hintText); expect(displayNameTexts).toHaveLength(1); expect(lodashGet(displayNameTexts[0], ['props', 'children'])).toBe('B User'); expect(lodashGet(displayNameTexts[0], ['props', 'style', 0, 'fontWeight'])).toBe(fontWeightBold); @@ -429,7 +452,8 @@ describe('Unread Indicators', () => { return navigateToSidebarOption(0); }) .then(() => { - const unreadIndicator = screen.queryAllByLabelText('New message line indicator'); + const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); + const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(1); // Leave a comment as the current user and verify the indicator is removed @@ -437,7 +461,8 @@ describe('Unread Indicators', () => { return waitForPromisesToResolve(); }) .then(() => { - const unreadIndicator = screen.queryAllByLabelText('New message line indicator'); + const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); + const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(0); })); @@ -446,7 +471,8 @@ describe('Unread Indicators', () => { // Verify we are on the LHN and that the chat shows as unread in the LHN expect(isDrawerOpen()).toBe(true); - const displayNameTexts = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNameTexts = screen.queryAllByLabelText(hintText); expect(displayNameTexts).toHaveLength(1); expect(lodashGet(displayNameTexts[0], ['props', 'children'])).toBe('B User'); expect(lodashGet(displayNameTexts[0], ['props', 'style', 0, 'fontWeight'])).toBe(fontWeightBold); @@ -455,7 +481,8 @@ describe('Unread Indicators', () => { return navigateToSidebarOption(0); }) .then(() => { - const unreadIndicator = screen.queryAllByLabelText('New message line indicator'); + const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); + const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(1); // Then back to the LHN - then back to the chat again and verify the new line indicator has cleared @@ -463,7 +490,8 @@ describe('Unread Indicators', () => { }) .then(() => navigateToSidebarOption(0)) .then(() => { - const unreadIndicator = screen.queryAllByLabelText('New message line indicator'); + const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); + const unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(0); // Mark a previous comment as unread and verify the unread action indicator returns @@ -471,7 +499,8 @@ describe('Unread Indicators', () => { return waitForPromisesToResolve(); }) .then(() => { - let unreadIndicator = screen.queryAllByLabelText('New message line indicator'); + const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator'); + let unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(1); // Trigger the app going inactive and active again @@ -479,7 +508,7 @@ describe('Unread Indicators', () => { AppState.emitCurrentTestState('active'); // Verify the new line is still present - unreadIndicator = screen.queryAllByLabelText('New message line indicator'); + unreadIndicator = screen.queryAllByLabelText(newMessageLineIndicatorHintText); expect(unreadIndicator).toHaveLength(1); })); @@ -512,7 +541,8 @@ describe('Unread Indicators', () => { }) .then(() => { // Verify the chat preview text matches the last comment from the current user - const alternateText = screen.queryAllByLabelText('Last chat message preview'); + const hintText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview'); + const alternateText = screen.queryAllByLabelText(hintText); expect(alternateText).toHaveLength(1); expect(alternateText[0].props.children).toBe('Current User Comment 1'); @@ -520,7 +550,8 @@ describe('Unread Indicators', () => { return waitForPromisesToResolve(); }) .then(() => { - const alternateText = screen.queryAllByLabelText('Last chat message preview'); + const hintText = Localize.translateLocal('accessibilityHints.lastChatMessagePreview'); + const alternateText = screen.queryAllByLabelText(hintText); expect(alternateText).toHaveLength(1); expect(alternateText[0].props.children).toBe('Comment 9'); }); diff --git a/tests/unit/SidebarFilterTest.js b/tests/unit/SidebarFilterTest.js index 47ead27d8789..a393199f2d4e 100644 --- a/tests/unit/SidebarFilterTest.js +++ b/tests/unit/SidebarFilterTest.js @@ -5,6 +5,7 @@ import * as LHNTestUtils from '../utils/LHNTestUtils'; import waitForPromisesToResolve from '../utils/waitForPromisesToResolve'; import CONST from '../../src/CONST'; import DateUtils from '../../src/libs/DateUtils'; +import * as Localize from '../../src/libs/Localize'; // Be sure to include the mocked permissions library or else the beta tests won't work jest.mock('../../src/libs/Permissions'); @@ -53,7 +54,8 @@ describe('Sidebar', () => { // Then no reports are rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(0); }); }); @@ -79,7 +81,8 @@ describe('Sidebar', () => { // Then no reports are rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(0); }) @@ -90,7 +93,8 @@ describe('Sidebar', () => { // Then there is one report rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(1); }); }); @@ -116,7 +120,8 @@ describe('Sidebar', () => { // Then no reports are rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(0); }) @@ -127,7 +132,8 @@ describe('Sidebar', () => { // Then there is one report rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(1); }); }); @@ -163,7 +169,8 @@ describe('Sidebar', () => { // Then no reports are rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(0); }) @@ -174,7 +181,8 @@ describe('Sidebar', () => { // Then all three reports are showing in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(3); }); }); @@ -206,7 +214,8 @@ describe('Sidebar', () => { // Then the report is rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(1); }) @@ -215,7 +224,8 @@ describe('Sidebar', () => { // Then the report is not rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(0); }); }); @@ -295,13 +305,16 @@ describe('Sidebar', () => { .then(() => { if (booleansWhichRemovesActiveReport.indexOf(JSON.stringify(boolArr)) > -1) { // Only one report visible - expect(screen.queryAllByAccessibilityHint('Navigates to a chat')).toHaveLength(1); - expect(screen.queryAllByLabelText('Chat user display names')).toHaveLength(1); - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const displayNamesHintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(displayNamesHintText); + const navigatesToChatHintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + expect(screen.queryAllByAccessibilityHint(navigatesToChatHintText)).toHaveLength(1); + expect(displayNames).toHaveLength(1); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Three, Four'); } else { // Both reports visible - expect(screen.queryAllByAccessibilityHint('Navigates to a chat')).toHaveLength(2); + const navigatesToChatHintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + expect(screen.queryAllByAccessibilityHint(navigatesToChatHintText)).toHaveLength(2); } }); }); @@ -331,7 +344,8 @@ describe('Sidebar', () => { // Then the reports 1 and 2 are shown and 3 is not .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(2); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('One, Two'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Three, Four'); @@ -345,7 +359,8 @@ describe('Sidebar', () => { // Then all three chats are showing .then(() => { - expect(screen.queryAllByAccessibilityHint('Navigates to a chat')).toHaveLength(3); + const navigatesToChatHintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + expect(screen.queryAllByAccessibilityHint(navigatesToChatHintText)).toHaveLength(3); }) // When report 1 becomes read (it's the active report) @@ -353,7 +368,8 @@ describe('Sidebar', () => { // Then all three chats are still showing .then(() => { - expect(screen.queryAllByAccessibilityHint('Navigates to a chat')).toHaveLength(3); + const navigatesToChatHintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + expect(screen.queryAllByAccessibilityHint(navigatesToChatHintText)).toHaveLength(3); }) // When report 2 becomes the active report @@ -364,7 +380,8 @@ describe('Sidebar', () => { // Then report 1 should now disappear .then(() => { - expect(screen.queryAllByAccessibilityHint('Navigates to a chat')).toHaveLength(2); + const navigatesToChatHintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + expect(screen.queryAllByAccessibilityHint(navigatesToChatHintText)).toHaveLength(2); expect(screen.queryAllByText(/One, Two/)).toHaveLength(0); }); }); @@ -393,7 +410,8 @@ describe('Sidebar', () => { // Then both reports are visible .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(2); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Three, Four'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two'); @@ -441,7 +459,8 @@ describe('Sidebar', () => { // Then neither reports are visible .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(0); }) @@ -461,7 +480,8 @@ describe('Sidebar', () => { // Then they are all visible .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); }); }); @@ -497,7 +517,8 @@ describe('Sidebar', () => { // Then neither reports are visible .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(0); }) @@ -514,7 +535,8 @@ describe('Sidebar', () => { // Then both rooms are visible .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(2); }); }); @@ -595,13 +617,16 @@ describe('Sidebar', () => { .then(() => { if (booleansWhichRemovesActiveReport.indexOf(JSON.stringify(boolArr)) > -1) { // Only one report visible - expect(screen.queryAllByAccessibilityHint('Navigates to a chat')).toHaveLength(1); - expect(screen.queryAllByLabelText('Chat user display names')).toHaveLength(1); - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const displayNamesHintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(displayNamesHintText); + const navigatesToChatHintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + expect(screen.queryAllByAccessibilityHint(navigatesToChatHintText)).toHaveLength(1); + expect(displayNames).toHaveLength(1); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Three, Four'); } else { // Both reports visible - expect(screen.queryAllByAccessibilityHint('Navigates to a chat')).toHaveLength(2); + const navigatesToChatHintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + expect(screen.queryAllByAccessibilityHint(navigatesToChatHintText)).toHaveLength(2); } }); }); @@ -640,7 +665,8 @@ describe('Sidebar', () => { // Then the report is rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(1); }) @@ -651,7 +677,8 @@ describe('Sidebar', () => { // Then the report is rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(1); }); }); @@ -687,7 +714,8 @@ describe('Sidebar', () => { // Then the report is not rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(0); }) @@ -699,7 +727,8 @@ describe('Sidebar', () => { // Then the report is rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(1); }); }); @@ -734,7 +763,8 @@ describe('Sidebar', () => { // Then the report is not rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(0); }) @@ -743,7 +773,8 @@ describe('Sidebar', () => { // Then the report is rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(1); }); }); @@ -777,7 +808,8 @@ describe('Sidebar', () => { // Then the report is not rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(0); }) @@ -789,7 +821,8 @@ describe('Sidebar', () => { // Then the report is rendered in the LHN .then(() => { - const optionRows = screen.queryAllByAccessibilityHint('Navigates to a chat'); + const hintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + const optionRows = screen.queryAllByAccessibilityHint(hintText); expect(optionRows).toHaveLength(1); }); }); diff --git a/tests/unit/SidebarOrderTest.js b/tests/unit/SidebarOrderTest.js index 6072bccca3de..0706ccf2ab97 100644 --- a/tests/unit/SidebarOrderTest.js +++ b/tests/unit/SidebarOrderTest.js @@ -5,6 +5,7 @@ import waitForPromisesToResolve from '../utils/waitForPromisesToResolve'; import * as LHNTestUtils from '../utils/LHNTestUtils'; import CONST from '../../src/CONST'; import DateUtils from '../../src/libs/DateUtils'; +import * as Localize from '../../src/libs/Localize'; // Be sure to include the mocked Permissions and Expensicons libraries or else the beta tests won't work jest.mock('../../src/libs/Permissions'); @@ -62,7 +63,8 @@ describe('Sidebar', () => { // Then the component should be rendered with an empty list since it will get past the early return .then(() => { expect(screen.toJSON()).not.toBe(null); - expect(screen.queryAllByAccessibilityHint('Navigates to a chat')).toHaveLength(0); + const navigatesToChatHintText = Localize.translateLocal('accessibilityHints.navigatesToChat'); + expect(screen.queryAllByAccessibilityHint(navigatesToChatHintText)).toHaveLength(0); }); }); @@ -113,7 +115,8 @@ describe('Sidebar', () => { // Then the component should be rendered with the mostly recently updated report first .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Three, Four'); @@ -147,10 +150,11 @@ describe('Sidebar', () => { // Then there should be a pencil icon and report one should be the first one because putting a draft on the active report should change its location // in the ordered list .then(() => { - const pencilIcon = screen.getAllByAccessibilityHint('Pencil Icon'); + const pencilIcon = screen.queryAllByTestId('Pencil Icon'); expect(pencilIcon).toHaveLength(1); - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('One, Two'); // this has `hasDraft` flag enabled so it will be on top expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Five, Six'); @@ -185,7 +189,8 @@ describe('Sidebar', () => { // Then the order of the reports should be 1 > 3 > 2 // ^--- (1 goes to the front and pushes other two down) .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('One, Two'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Five, Six'); @@ -228,7 +233,8 @@ describe('Sidebar', () => { // Then the order of the reports should be 2 > 3 > 1 // ^--- (2 goes to the front and pushes 3 down) .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Three, Four'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Five, Six'); @@ -257,7 +263,7 @@ describe('Sidebar', () => { // Then there should be a pencil icon showing .then(() => { - expect(screen.getAllByAccessibilityHint('Pencil Icon')).toHaveLength(1); + expect(screen.queryAllByTestId('Pencil Icon')).toHaveLength(1); }) // When the draft is removed @@ -265,7 +271,7 @@ describe('Sidebar', () => { // Then the pencil icon goes away .then(() => { - expect(screen.queryAllByAccessibilityHint('Pencil Icon')).toHaveLength(0); + expect(screen.queryAllByTestId('Pencil Icon')).toHaveLength(0); }); }); @@ -290,7 +296,7 @@ describe('Sidebar', () => { // Then there should be a pencil icon showing .then(() => { - expect(screen.getAllByAccessibilityHint('Pin Icon')).toHaveLength(1); + expect(screen.queryAllByTestId('Pin Icon')).toHaveLength(1); }) // When the draft is removed @@ -298,7 +304,7 @@ describe('Sidebar', () => { // Then the pencil icon goes away .then(() => { - expect(screen.queryAllByAccessibilityHint('Pin Icon')).toHaveLength(0); + expect(screen.queryAllByTestId('Pin Icon')).toHaveLength(0); }); }); @@ -352,10 +358,11 @@ describe('Sidebar', () => { // there is a pencil icon // there is a pinned icon .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); - expect(screen.getAllByAccessibilityHint('Pin Icon')).toHaveLength(1); - expect(screen.getAllByAccessibilityHint('Pencil Icon')).toHaveLength(1); + expect(screen.queryAllByTestId('Pin Icon')).toHaveLength(1); + expect(screen.queryAllByTestId('Pencil Icon')).toHaveLength(1); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('One, Two'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [2, 'props', 'children'])).toBe('Three, Four'); @@ -395,7 +402,8 @@ describe('Sidebar', () => { // Then the reports are in alphabetical order .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two'); @@ -407,7 +415,8 @@ describe('Sidebar', () => { // Then they are still in alphabetical order .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two'); @@ -449,7 +458,8 @@ describe('Sidebar', () => { // Then the reports are in alphabetical order .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two'); @@ -461,7 +471,8 @@ describe('Sidebar', () => { // Then they are still in alphabetical order .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two'); @@ -502,7 +513,8 @@ describe('Sidebar', () => { // Then the first report is in last position .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Three, Four'); @@ -534,7 +546,8 @@ describe('Sidebar', () => { // Then the reports are in alphabetical order .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two'); @@ -546,7 +559,8 @@ describe('Sidebar', () => { // Then they are still in alphabetical order .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(4); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two'); @@ -587,7 +601,8 @@ describe('Sidebar', () => { // Then the first report is in last position .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('Three, Four'); @@ -666,7 +681,8 @@ describe('Sidebar', () => { // Then the reports are ordered alphabetically since their amounts are the same .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two'); @@ -704,7 +720,8 @@ describe('Sidebar', () => { // Then the reports are ordered alphabetically since their lastVisibleActionCreated are the same .then(() => { - const displayNames = screen.queryAllByLabelText('Chat user display names'); + const hintText = Localize.translateLocal('accessibilityHints.chatUserDisplayNames'); + const displayNames = screen.queryAllByLabelText(hintText); expect(displayNames).toHaveLength(3); expect(lodashGet(displayNames, [0, 'props', 'children'])).toBe('Five, Six'); expect(lodashGet(displayNames, [1, 'props', 'children'])).toBe('One, Two');