Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scheduled post Actions #8603

Open
wants to merge 14 commits into
base: list-scheduled-post
Choose a base branch
from

Conversation

Rajat-Dabade
Copy link
Contributor

Summary

Ticket Link

Checklist

  • Added or updated unit tests (required for all new features)
  • Has UI changes
  • Includes text changes and localization file updates
  • Have tested against the 5 core themes to ensure consistency between them.
  • Have run E2E tests by adding label E2E iOS tests for PR.

Device Information

This PR was tested on:

Screenshots

Release Note


@Rajat-Dabade Rajat-Dabade force-pushed the scheduled-post-options branch 2 times, most recently from ad1c32e to 10b0d66 Compare February 21, 2025 09:05
@Rajat-Dabade Rajat-Dabade force-pushed the list-scheduled-post branch 2 times, most recently from de2b148 to 3a6f367 Compare February 21, 2025 09:15
@Rajat-Dabade Rajat-Dabade force-pushed the scheduled-post-options branch 2 times, most recently from cd6e159 to 2bd8672 Compare February 21, 2025 09:39
@Rajat-Dabade Rajat-Dabade self-assigned this Feb 21, 2025
@Rajat-Dabade Rajat-Dabade added the 2: Dev Review Requires review by a core commiter label Feb 21, 2025
@Rajat-Dabade Rajat-Dabade marked this pull request as ready for review February 21, 2025 09:47
Copy link
Member

@harshilsharma63 harshilsharma63 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link
Contributor

@larkox larkox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments to address, but in general it looks good.

@Rajat-Dabade Rajat-Dabade force-pushed the scheduled-post-options branch from 2bd8672 to 5517875 Compare February 25, 2025 12:14
@Rajat-Dabade Rajat-Dabade requested a review from larkox February 26, 2025 07:24
Copy link
Contributor

@larkox larkox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more things to look at in the tests.

// Mock implementation to capture the sendMessageHandler
let capturedHandler: Function;
(sendMessageWithAlert as jest.Mock).mockImplementation((params) => {
capturedHandler = params.sendMessageHandler;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Personal opinion) This is one way to do it, but I think it is more elegant to inspect the mock calls instead of trying to set this variable. 0/5.

// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const toggleSaveButton = useCallback(preventDoubleTap((enabled = true) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a hook called usePreventDoubleTap, use that one instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

}
}, [intl, onClose]);

const onSavePostMessage = useCallback(async () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should have the prevent double tap has well, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup done

Copy link
Contributor

@larkox larkox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! A couple more comments, but really minor things.


it('calls dismissBottomSheet and showModal when pressed', async () => {
// Mock implementation to resolve immediately
(dismissBottomSheet as jest.Mock).mockResolvedValue(undefined);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One last jest.Mock.

cancelButton.onPress?.();

// Verify swipeable close is called
expect(baseProps.swipeable?.current?.close).toHaveBeenCalled();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to verify the delete has not been called in this scenario.

const buttons = alertMock.mock.calls[0]?.[2] ?? []; // Ensure buttons array exists
const cancelButton = buttons[0];
expect(cancelButton).toBeDefined();
const onPress = cancelButton.onPress ?? (() => {});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is weird. If the ?? (() => {}) part is just to keep typescript happy, you can use the non-null assertion operator (! the exclamation mark) to tell TS that you are sure it is never going to be undefined.

The non-null assertion operator is dangerous and should be used scarcely, but in this scenario should be fine.

// Check that the component registered with proper navigation handler
const registerCall = jest.mocked(Navigation.events().registerComponentListener).mock.calls[0][0];
expect(registerCall).toBeDefined();
expect(registerCall.navigationButtonPressed).toBeDefined();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We check it exist. Do we want to check if it does what it has to do? I would expect something similar to what you have in the last test of this file, but also for other buttons (not only the close one).

Comment on lines +124 to +127
const setButtonsMock = jest.mocked(setButtons);
const mockCalls = setButtonsMock.mock.calls;

const lastCallIndex = mockCalls.length - 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can clear the mocks (setButtonsMock.clearMocks) before performing the action that will trigger this.

If there are more than one call because of executing the action, could mean you are calling it more than needed.

import {Screens} from '@constants';
import {dismissBottomSheet, showModal} from '@screens/navigation';
import {renderWithIntlAndTheme} from '@test/intl-test-helper';
import test_helper from '@test/test_helper';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import this as TestHelper, please.

Comment on lines +119 to +122
const draftInput = wrapper.getByTestId('test_send_handler');
expect(draftInput).toBeTruthy();
const priority = wrapper.getByText('URGENT');
expect(priority).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0/5 for simplicity

Suggested change
const draftInput = wrapper.getByTestId('test_send_handler');
expect(draftInput).toBeTruthy();
const priority = wrapper.getByText('URGENT');
expect(priority).toBeTruthy();
expect( wrapper.getByTestId('test_send_handler')).toBeTruthy();
expect(wrapper.getByText('URGENT')).toBeTruthy();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2: Dev Review Requires review by a core commiter release-note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants