Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"perf-test": "NODE_OPTIONS=--experimental-vm-modules npx reassure",
"typecheck": "NODE_OPTIONS=--max_old_space_size=8192 tsc",
"typecheck-tsgo": "tsgo --project tsconfig.tsgo.json",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=335 --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --concurrency=auto",
"lint": "NODE_OPTIONS=--max_old_space_size=8192 eslint . --max-warnings=334 --cache --cache-location=node_modules/.cache/eslint --cache-strategy content --concurrency=auto",
"lint-changed": "NODE_OPTIONS=--max_old_space_size=8192 ./scripts/lintChanged.sh",
"check-lazy-loading": "ts-node scripts/checkLazyLoading.ts",
"lint-watch": "npx eslint-watch --watch --changed",
Expand Down
2 changes: 1 addition & 1 deletion src/components/PromotedActionsBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ const PromotedActions = {
return;
}
if (accountID) {
navigateToAndOpenReportWithAccountIDs([accountID], currentUserAccountID);
navigateToAndOpenReportWithAccountIDs([accountID], currentUserAccountID, introSelected);
}
},
}),
Expand Down
10 changes: 2 additions & 8 deletions src/libs/actions/Report/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@
// map of reportID to all reportActions for that report
const allReportActions: OnyxCollection<ReportActions> = {};

Onyx.connect({

Check warning on line 368 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT_ACTIONS,
callback: (actions, key) => {
if (!key || !actions) {
Expand All @@ -377,7 +377,7 @@
});

let allReports: OnyxCollection<Report>;
Onyx.connect({

Check warning on line 380 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.COLLECTION.REPORT,
waitForCollectionCallback: true,
callback: (value) => {
Expand All @@ -386,7 +386,7 @@
});

let allPersonalDetails: OnyxEntry<PersonalDetailsList> = {};
Onyx.connect({

Check warning on line 389 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
callback: (value) => {
allPersonalDetails = value ?? {};
Expand All @@ -404,7 +404,7 @@
});

let onboarding: OnyxEntry<Onboarding>;
Onyx.connect({

Check warning on line 407 in src/libs/actions/Report/index.ts

View workflow job for this annotation

GitHub Actions / Changed files ESLint check

Onyx.connect() is deprecated. Use useOnyx() hook instead and pass the data as parameters to a pure function
key: ONYXKEYS.NVP_ONBOARDING,
callback: (val) => {
if (Array.isArray(val)) {
Expand All @@ -414,12 +414,6 @@
},
});

let deprecatedIntroSelected: OnyxEntry<IntroSelected> = {};
Onyx.connect({
key: ONYXKEYS.NVP_INTRO_SELECTED,
callback: (val) => (deprecatedIntroSelected = val),
});

let environment: EnvironmentType;
getEnvironment().then((env) => {
environment = env;
Expand Down Expand Up @@ -1996,7 +1990,7 @@
*
* @param participantAccountIDs of user logins to start a chat report with.
*/
function navigateToAndOpenReportWithAccountIDs(participantAccountIDs: number[], currentUserAccountID: number) {
function navigateToAndOpenReportWithAccountIDs(participantAccountIDs: number[], currentUserAccountID: number, introSelected: OnyxEntry<IntroSelected>) {
let newChat: OptimisticChatReport | undefined;
const chat = getChatByParticipants([...participantAccountIDs, currentUserAccountID]);
if (!chat) {
Expand All @@ -2006,7 +2000,7 @@
// We want to pass newChat here because if anything is passed in that param (even an existing chat), we will try to create a chat on the server
openReport({
reportID: newChat?.reportID,
introSelected: deprecatedIntroSelected,
introSelected,
newReportObject: newChat,
parentReportActionID: '0',
participantAccountIDList: participantAccountIDs,
Expand Down
93 changes: 93 additions & 0 deletions tests/unit/PromotedActionsBarTest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import {PromotedActions} from '@components/PromotedActionsBar';
import {navigateToAndOpenReport, navigateToAndOpenReportWithAccountIDs} from '@userActions/Report';
import CONST from '@src/CONST';

jest.mock('@userActions/Report', () => ({
navigateToAndOpenReport: jest.fn(),
navigateToAndOpenReportWithAccountIDs: jest.fn(),
joinRoom: jest.fn(),
}));

jest.mock('@userActions/Session', () => ({
callFunctionIfActionIsAllowed: (fn: () => void) => fn,
}));

jest.mock('@libs/Navigation/Navigation', () => ({
navigate: jest.fn(),
dismissModal: jest.fn(),
}));

const mockNavigateToAndOpenReport = jest.mocked(navigateToAndOpenReport);
const mockNavigateToAndOpenReportWithAccountIDs = jest.mocked(navigateToAndOpenReportWithAccountIDs);

describe('PromotedActions.message', () => {
beforeEach(() => {
jest.clearAllMocks();
});

it('should pass introSelected to navigateToAndOpenReport when login is provided', () => {
const introSelected = {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM};
const action = PromotedActions.message({
login: 'test@example.com',
currentUserAccountID: 1,
introSelected,
});

action.onSelected();

expect(mockNavigateToAndOpenReport).toHaveBeenCalledWith(['test@example.com'], 1, introSelected, false);
});

it('should pass introSelected to navigateToAndOpenReportWithAccountIDs when accountID is provided', () => {
const introSelected = {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM};
const action = PromotedActions.message({
accountID: 42,
currentUserAccountID: 1,
introSelected,
});

action.onSelected();

expect(mockNavigateToAndOpenReportWithAccountIDs).toHaveBeenCalledWith([42], 1, introSelected);
});

it('should pass undefined introSelected when not provided', () => {
const action = PromotedActions.message({
accountID: 42,
currentUserAccountID: 1,
introSelected: undefined,
});

action.onSelected();

expect(mockNavigateToAndOpenReportWithAccountIDs).toHaveBeenCalledWith([42], 1, undefined);
});

it('should navigate to report directly when reportID is provided', () => {
const action = PromotedActions.message({
reportID: 'report123',
currentUserAccountID: 1,
introSelected: undefined,
});

action.onSelected();

expect(mockNavigateToAndOpenReport).not.toHaveBeenCalled();
expect(mockNavigateToAndOpenReportWithAccountIDs).not.toHaveBeenCalled();
});

it('should prefer login over accountID when both are provided', () => {
const introSelected = {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM};
const action = PromotedActions.message({
accountID: 42,
login: 'test@example.com',
currentUserAccountID: 1,
introSelected,
});

action.onSelected();

expect(mockNavigateToAndOpenReport).toHaveBeenCalledWith(['test@example.com'], 1, introSelected, false);
expect(mockNavigateToAndOpenReportWithAccountIDs).not.toHaveBeenCalled();
});
});
Loading