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 3 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
17 changes: 17 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} from './PolicyUtils';
Expand Down Expand Up @@ -400,6 +402,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 @@ -1408,6 +1416,13 @@ function getValidReports(
return validReportOptions;
}

/**
* 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 @@ -1429,6 +1444,8 @@ function getValidOptions(
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() && config.action),
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should introduce a new prop as includeMCTest instead of using config.action to detect which place should be allowed to display Manager MCtest

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed @DylanDylann

};
// 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
30 changes: 30 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,8 @@ describe('OptionsListUtils', () => {
},
[`${ONYXKEYS.COLLECTION.POLICY}${policyID}` as const]: POLICY,
[ONYXKEYS.NVP_ACTIVE_POLICY_ID]: activePolicyID,
[ONYXKEYS.NVP_DISMISSED_PRODUCT_TRAINING]: {},
[ONYXKEYS.BETAS]: [CONST.BETAS.NEWDOT_MANAGER_MCTEST],
},
});
Onyx.registerLogger(() => {});
Expand All @@ -498,6 +509,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 +518,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 +634,23 @@ 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
const options = OptionsListUtils.getValidOptions(
{reports: OPTIONS_WITH_MANAGER_MCTEST.reports, personalDetails: OPTIONS_WITH_MANAGER_MCTEST.personalDetails},
{includeP2P: true, action: 'create'},
);
expect(options.personalDetails).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(() => {
const optionsWhenUserAlreadySubmittedExpense = OptionsListUtils.getValidOptions(
{reports: OPTIONS_WITH_MANAGER_MCTEST.reports, personalDetails: OPTIONS_WITH_MANAGER_MCTEST.personalDetails},
{includeP2P: true, action: 'create'},
);
expect(optionsWhenUserAlreadySubmittedExpense.personalDetails).not.toEqual(expect.arrayContaining([expect.objectContaining({login: CONST.EMAIL.MANAGER_MCTEST})]));
});
});

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