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

Show Manager McTest as recipient for eligible users #56364

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
19 changes: 19 additions & 0 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {
Beta,
DismissedProductTraining,
Login,
OnyxInputOrEntry,
PersonalDetails,
Expand All @@ -38,6 +39,7 @@ import ModifiedExpenseMessage from './ModifiedExpenseMessage';
import Navigation from './Navigation/Navigation';
import Parser from './Parser';
import Performance from './Performance';
import Permissions from './Permissions';
import {getDisplayNameOrDefault} from './PersonalDetailsUtils';
import {addSMSDomainIfPhoneNumber, parsePhoneNumber} from './PhoneNumber';
import {canSendInvoiceFromWorkspace, getSubmitToAccountID} from './PolicyUtils';
Expand Down Expand Up @@ -211,6 +213,7 @@ type GetOptionsConfig = {
includeSelectedOptions?: boolean;
recentAttendees?: Attendee[];
excludeHiddenReports?: boolean;
canShowManagerMcTest?: boolean;
} & GetValidReportsConfig;

type GetUserToInviteConfig = {
Expand Down Expand Up @@ -406,6 +409,12 @@ Onyx.connect({
callback: (value) => (activePolicyID = value),
});

let nvpDismissedProductTraining: OnyxEntry<DismissedProductTraining>;
Onyx.connect({
key: ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING,
callback: (value) => (nvpDismissedProductTraining = value),
});

/**
* @param defaultValues {login: accountID} In workspace invite page, when new user is added we pass available data to opt in
* @returns Returns avatar data for a list of user accountIDs
Expand Down Expand Up @@ -1437,6 +1446,13 @@ function getValidReports(reports: OptionList['reports'], config: GetValidReports
};
}

/**
* Whether user submitted already an expense or scanned receipt
*/
function getIsUserSubmittedExpenseOrScannedReceipt(): boolean {
return !!nvpDismissedProductTraining?.[CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.SCAN_TEST_TOOLTIP];
}

/**
* Options are reports and personal details. This function filters out the options that are not valid to be displayed.
*/
Expand All @@ -1451,13 +1467,16 @@ function getValidOptions(
shouldSeparateSelfDMChat = false,
shouldSeparateWorkspaceChat = false,
excludeHiddenReports = false,
canShowManagerMcTest = false,
...config
}: GetOptionsConfig = {},
): Options {
// Gather shared configs:
const loginsToExclude: Record<string, boolean> = {
[CONST.EMAIL.NOTIFICATIONS]: true,
...excludeLogins,
// Exclude Manager McTest if user submitted expense or scanned receipt and when selection is made from Create or Submit flow
[CONST.EMAIL.MANAGER_MCTEST]: !(Permissions.canUseManagerMcTest(config.betas) && !getIsUserSubmittedExpenseOrScannedReceipt() && canShowManagerMcTest),
grgia marked this conversation as resolved.
Show resolved Hide resolved
};
// If we're including selected options from the search results, we only want to exclude them if the search input is empty
// This is because on certain pages, we show the selected options at the top when the search input is empty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ function MoneyRequestParticipantsSelector({participants = CONST.EMPTY_ARRAY, onF
shouldSeparateSelfDMChat: iouType !== CONST.IOU.TYPE.INVOICE,
shouldSeparateWorkspaceChat: true,
includeSelfDM: !isMovingTransactionFromTrackExpense(action) && iouType !== CONST.IOU.TYPE.INVOICE,
canShowManagerMcTest: true,
},
);

Expand Down
38 changes: 38 additions & 0 deletions tests/unit/OptionsListUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,15 @@ describe('OptionsListUtils', () => {
},
};

const PERSONAL_DETAILS_WITH_MANAGER_MCTEST: PersonalDetailsList = {
...PERSONAL_DETAILS,
'1003': {
accountID: 1003,
displayName: 'Manager McTest',
login: CONST.EMAIL.MANAGER_MCTEST,
reportID: '',
},
};
const policyID = 'ABC123';

const POLICY: Policy = {
Expand Down Expand Up @@ -487,6 +496,7 @@ describe('OptionsListUtils', () => {
},
[`${ONYXKEYS.COLLECTION.POLICY}${policyID}` as const]: POLICY,
[ONYXKEYS.NVP_ACTIVE_POLICY_ID]: activePolicyID,
[ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING]: {},
},
});
Onyx.registerLogger(() => {});
Expand All @@ -498,6 +508,7 @@ describe('OptionsListUtils', () => {
let OPTIONS_WITH_CHRONOS: OptionsListUtils.OptionList;
let OPTIONS_WITH_RECEIPTS: OptionsListUtils.OptionList;
let OPTIONS_WITH_WORKSPACE_ROOM: OptionsListUtils.OptionList;
let OPTIONS_WITH_MANAGER_MCTEST: OptionsListUtils.OptionList;

beforeEach(() => {
Onyx.set(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}10`, reportNameValuePairs);
Expand All @@ -506,6 +517,7 @@ describe('OptionsListUtils', () => {
OPTIONS_WITH_CHRONOS = OptionsListUtils.createOptionList(PERSONAL_DETAILS_WITH_CHRONOS, REPORTS_WITH_CHRONOS);
OPTIONS_WITH_RECEIPTS = OptionsListUtils.createOptionList(PERSONAL_DETAILS_WITH_RECEIPTS, REPORTS_WITH_RECEIPTS);
OPTIONS_WITH_WORKSPACE_ROOM = OptionsListUtils.createOptionList(PERSONAL_DETAILS, REPORTS_WITH_WORKSPACE_ROOMS);
OPTIONS_WITH_MANAGER_MCTEST = OptionsListUtils.createOptionList(PERSONAL_DETAILS_WITH_MANAGER_MCTEST);
});

it('getSearchOptions()', () => {
Expand Down Expand Up @@ -621,6 +633,32 @@ describe('OptionsListUtils', () => {
// Filtering of personalDetails that have reports is done in filterOptions
expect(results.personalDetails.length).toBe(Object.values(OPTIONS_WITH_RECEIPTS.personalDetails).length - 2);
expect(results.personalDetails).not.toEqual(expect.arrayContaining([expect.objectContaining({login: '[email protected]'})]));

// Test for check if Manager McTest is correctly included or excluded from the results
let options = OptionsListUtils.getValidOptions(
{reports: OPTIONS_WITH_MANAGER_MCTEST.reports, personalDetails: OPTIONS_WITH_MANAGER_MCTEST.personalDetails},
{includeP2P: true, canShowManagerMcTest: true, betas: [CONST.BETAS.NEWDOT_MANAGER_MCTEST]},
);
expect(options.personalDetails).toEqual(expect.arrayContaining([expect.objectContaining({login: CONST.EMAIL.MANAGER_MCTEST})]));

// Manager McTest shouldn't be included to recipients when its not an IOU action
options = OptionsListUtils.getValidOptions(
{reports: OPTIONS_WITH_MANAGER_MCTEST.reports, personalDetails: OPTIONS_WITH_MANAGER_MCTEST.personalDetails},
{includeP2P: true, betas: [CONST.BETAS.NEWDOT_MANAGER_MCTEST]},
);

expect(options.personalDetails).not.toEqual(expect.arrayContaining([expect.objectContaining({login: CONST.EMAIL.MANAGER_MCTEST})]));

return waitForBatchedUpdates()
.then(() => Onyx.set(ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING, {[CONST.PRODUCT_TRAINING_TOOLTIP_NAMES.SCAN_TEST_TOOLTIP]: new Date() as unknown as string}))
.then(() => {
// Manager McTest shouldn't be included to recipients when the user has already submitted an expense
const optionsWhenUserAlreadySubmittedExpense = OptionsListUtils.getValidOptions(
{reports: OPTIONS_WITH_MANAGER_MCTEST.reports, personalDetails: OPTIONS_WITH_MANAGER_MCTEST.personalDetails},
{includeP2P: true, canShowManagerMcTest: true, betas: [CONST.BETAS.NEWDOT_MANAGER_MCTEST]},
);
expect(optionsWhenUserAlreadySubmittedExpense.personalDetails).not.toEqual(expect.arrayContaining([expect.objectContaining({login: CONST.EMAIL.MANAGER_MCTEST})]));
});
});

it('getValidOptions() for group Chat', () => {
Expand Down