Skip to content

Commit

Permalink
chore: add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: dominictb <[email protected]>
  • Loading branch information
dominictb committed Jun 10, 2024
1 parent cc42221 commit fbad958
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/pages/home/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -704,6 +704,7 @@ function ReportScreen({
<View
style={[styles.flex1, styles.justifyContentEnd, styles.overflowHidden]}
onLayout={onListLayout}
testID={'reportActionsViewWrapper'}

Check failure on line 707 in src/pages/home/ReportScreen.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Curly braces are unnecessary here
>
{shouldShowReportActionList && (
<ReportActionsView
Expand Down
57 changes: 55 additions & 2 deletions tests/ui/UnreadIndicatorsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,15 @@ const USER_C_EMAIL = '[email protected]';
let reportAction3CreatedDate: string;
let reportAction9CreatedDate: string;

// store render result, used to trigger onLayout event
let renderResult: ReturnType<typeof render> | null = null;

/**
* Sets up a test with a logged in user that has one unread chat from another user. Returns the <App/> test instance.
*/
function signInAndGetAppWithUnreadChat(): Promise<void> {
// Render the App and sign in as a test user.
render(<App />);
renderResult = render(<App />);
return waitForBatchedUpdatesWithAct()
.then(async () => {
await waitForBatchedUpdatesWithAct();
Expand Down Expand Up @@ -462,7 +465,57 @@ describe('Unread Indicators', () => {
expect(screen.getAllByText('C User')[0]).toBeOnTheScreen();
expect(displayNameTexts[1]?.props?.style?.fontWeight).toBe(FontUtils.fontWeight.bold);
expect(screen.getByText('B User')).toBeOnTheScreen();
}));
})
);
it('Delete a chat message and verify the unread indicator is moved', async () => {
const getUnreadIndicator = () => {
const newMessageLineIndicatorHintText = Localize.translateLocal('accessibilityHints.newMessageLineIndicator');
return screen.queryAllByLabelText(newMessageLineIndicatorHintText);
}

return signInAndGetAppWithUnreadChat()
.then(() => navigateToSidebarOption(0))
.then(async () => await act(() => transitionEndCB?.()))

Check failure on line 478 in tests/ui/UnreadIndicatorsTest.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Returning an awaited promise is not allowed in this context
.then(async () => {
const reportActionsViewWrapper = await renderResult?.findByTestId('reportActionsViewWrapper');

Check failure on line 480 in tests/ui/UnreadIndicatorsTest.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

promise returned from `findByTestId` query must be handled

Check failure on line 480 in tests/ui/UnreadIndicatorsTest.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Avoid destructuring queries from `render` result, use `screen.findByTestId` instead
if(reportActionsViewWrapper) {
act(() => {

Check failure on line 482 in tests/ui/UnreadIndicatorsTest.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Avoid wrapping Testing Library util calls in `act`
fireEvent(reportActionsViewWrapper, 'onLayout', { nativeEvent: { layout: { x: 0, y: 0, width: 100, height: 100 } } });
})
}
return waitForBatchedUpdates();
})
.then(() => {
// Verify the new line indicator is present, and it's before the action with ID 4
const unreadIndicator = getUnreadIndicator();
expect(unreadIndicator).toHaveLength(1);
const reportActionID = unreadIndicator[0]?.props?.['data-action-id'];
expect(reportActionID).toBe('4');

// simulate delete comment event from Pusher
PusherHelper.emitOnyxUpdate([
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`,
value: {
'4': {
message: []
}
}
},
]);
return waitForBatchedUpdates();
})
.then(() => {

Check failure on line 509 in tests/ui/UnreadIndicatorsTest.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`
// Verify the new line indicator is now before the action with ID 5
return waitFor(() => {
const unreadIndicator = getUnreadIndicator();
expect(unreadIndicator).toHaveLength(1);
const reportActionID = unreadIndicator[0]?.props?.['data-action-id'];
expect(reportActionID).toBe('5');

Check failure on line 515 in tests/ui/UnreadIndicatorsTest.tsx

View workflow job for this annotation

GitHub Actions / Run ESLint

Avoid using multiple assertions within `waitFor` callback
})
})
})

xit('Manually marking a chat message as unread shows the new line indicator and updates the LHN', () =>
signInAndGetAppWithUnreadChat()
Expand Down

0 comments on commit fbad958

Please sign in to comment.