Skip to content

Commit

Permalink
remove shouldOpenAdminRoom param and add a test case
Browse files Browse the repository at this point in the history
  • Loading branch information
mkzie2 committed Feb 4, 2025
1 parent ac7016d commit 7e793ce
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/libs/navigateAfterOnboarding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ const navigateAfterOnboarding = (
onboardingPolicyID?: string,
activeWorkspaceID?: string,
onboardingAdminsChatReportID?: string,
shouldOpenAdminRoom?: boolean,
) => {
Navigation.dismissModal();

// When hasCompletedGuidedSetupFlow is true, OnboardingModalNavigator in AuthScreen is removed from the navigation stack.
// On small screens, this removal redirects navigation to HOME. Dismissing the modal doesn't work properly,
// so we need to specifically navigate to the last accessed report.
if (!isSmallScreenWidth) {
if (shouldOpenAdminRoom && onboardingAdminsChatReportID) {
if (onboardingAdminsChatReportID) {
Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(onboardingAdminsChatReportID));
}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ function BaseOnboardingAccounting({shouldUseNativeStyles}: BaseOnboardingAccount
setOnboardingAdminsChatReportID();
setOnboardingPolicyID();
});
navigateAfterOnboarding(isSmallScreenWidth, canUseDefaultRooms, onboardingPolicyID, activeWorkspaceID, onboardingAdminsChatReportID, true);
navigateAfterOnboarding(isSmallScreenWidth, canUseDefaultRooms, onboardingPolicyID, activeWorkspaceID, onboardingAdminsChatReportID);
}}
pressOnEnter
/>
Expand Down
22 changes: 16 additions & 6 deletions tests/unit/navigateAfterOnboardingTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,15 @@ describe('navigateAfterOnboarding', () => {
jest.clearAllMocks();
});

it('should navigate to the admin room report if shouldOpenAdminRoom and has onboardingAdminsChatReportID', () => {
it('should navigate to the admin room report if onboardingAdminsChatReportID is provided', () => {
const navigate = jest.spyOn(Navigation, 'navigate');

navigateAfterOnboarding(false, true, undefined, undefined, ONBOARDING_ADMINS_CHAT_REPORT_ID, true);
navigateAfterOnboarding(false, true, undefined, undefined, ONBOARDING_ADMINS_CHAT_REPORT_ID);
expect(navigate).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(ONBOARDING_ADMINS_CHAT_REPORT_ID));
});

it('should not navigate if shouldOpenAdminRoom is false', () => {
navigateAfterOnboarding(false, true, undefined, undefined, ONBOARDING_ADMINS_CHAT_REPORT_ID, false);
it('should not navigate if onboardingAdminsChatReportID is not provided', () => {
navigateAfterOnboarding(false, true, undefined, undefined);
expect(Navigation.navigate).not.toHaveBeenCalled();
});

Expand All @@ -67,7 +67,7 @@ describe('navigateAfterOnboarding', () => {
mockFindLastAccessedReport.mockReturnValue(lastAccessedReport);
mockShouldOpenOnAdminRoom.mockReturnValue(false);

navigateAfterOnboarding(true, true, ONBOARDING_POLICY_ID, ACTIVE_WORKSPACE_ID, undefined, false);
navigateAfterOnboarding(true, true, ONBOARDING_POLICY_ID, ACTIVE_WORKSPACE_ID, ONBOARDING_ADMINS_CHAT_REPORT_ID);
expect(navigate).not.toHaveBeenCalled();
});

Expand All @@ -76,7 +76,17 @@ describe('navigateAfterOnboarding', () => {
mockFindLastAccessedReport.mockReturnValue(lastAccessedReport);
mockShouldOpenOnAdminRoom.mockReturnValue(false);

navigateAfterOnboarding(true, true, ONBOARDING_POLICY_ID, ACTIVE_WORKSPACE_ID, undefined, false);
navigateAfterOnboarding(true, true, ONBOARDING_POLICY_ID, ACTIVE_WORKSPACE_ID, ONBOARDING_ADMINS_CHAT_REPORT_ID);
expect(Navigation.navigate).not.toHaveBeenCalled();
});

it('should navigate to last accessed report if shouldOpenOnAdminRoom is true on small screens', () => {
const navigate = jest.spyOn(Navigation, 'navigate');
const lastAccessedReport = {reportID: REPORT_ID};
mockFindLastAccessedReport.mockReturnValue(lastAccessedReport);
mockShouldOpenOnAdminRoom.mockReturnValue(true);

navigateAfterOnboarding(true, true, ONBOARDING_POLICY_ID, ACTIVE_WORKSPACE_ID, ONBOARDING_ADMINS_CHAT_REPORT_ID);
expect(navigate).toHaveBeenCalledWith(ROUTES.REPORT_WITH_ID.getRoute(REPORT_ID));
});
});

0 comments on commit 7e793ce

Please sign in to comment.