From 9da6d80b79024008c0d004bdf5bc24a3bc456fef Mon Sep 17 00:00:00 2001 From: Vit Horacek Date: Fri, 13 Feb 2026 12:13:40 +0100 Subject: [PATCH] Fix empty Time Sensitive section on Home page The Time Sensitive section could render as an empty block (title only, no widgets) when the visibility guard and the actual render conditions were out of sync. Root cause: timeSensitiveCardsSelector included fraud cards that had the fraud flag set (e.g. card.fraud === 'domain') but lacked the possibleFraud data or a valid fraudAlertReportID needed by the ReviewCardFraud widget to actually render. The hasAnyTimeSensitiveContent guard said "show the section" while every child returned null. Changes: - Tighten timeSensitiveCardsSelector to require possibleFraud.fraudAlertReportID - Align hasAnyTimeSensitiveContent guard with all render conditions - Add 6 unit tests covering the exact edge cases that caused the bug Co-authored-by: Cursor --- src/pages/home/TimeSensitiveSection/index.tsx | 11 +- src/selectors/Card.ts | 6 +- tests/unit/selectors/CardTest.ts | 110 ++++++++++++++++++ 3 files changed, 124 insertions(+), 3 deletions(-) diff --git a/src/pages/home/TimeSensitiveSection/index.tsx b/src/pages/home/TimeSensitiveSection/index.tsx index 96614b902ca7..2b3402340f30 100644 --- a/src/pages/home/TimeSensitiveSection/index.tsx +++ b/src/pages/home/TimeSensitiveSection/index.tsx @@ -109,8 +109,17 @@ function TimeSensitiveSection() { const hasBrokenCompanyCards = brokenCompanyCardConnections.length > 0; const hasBrokenAccountingConnections = brokenAccountingConnections.length > 0; + // This guard must exactly match the conditions used to render each widget below. + // If a widget has additional conditions in the render (e.g. && !!discountInfo), those + // must be reflected here to avoid showing an empty "Time sensitive" section. const hasAnyTimeSensitiveContent = - shouldShowReviewCardFraud || shouldShow50off || shouldShow25off || hasBrokenCompanyCards || hasBrokenAccountingConnections || shouldShowAddShippingAddress || shouldShowActivateCard; + shouldShowReviewCardFraud || + shouldShow50off || + (shouldShow25off && !!discountInfo) || + hasBrokenCompanyCards || + hasBrokenAccountingConnections || + shouldShowAddShippingAddress || + shouldShowActivateCard; if (!hasAnyTimeSensitiveContent) { return null; diff --git a/src/selectors/Card.ts b/src/selectors/Card.ts index 021db9b018e7..46a834f5b926 100644 --- a/src/selectors/Card.ts +++ b/src/selectors/Card.ts @@ -103,8 +103,10 @@ const timeSensitiveCardsSelector = (cards: OnyxEntry): TimeSensitiveCa continue; } - // Check for fraud on any Expensify card (physical or virtual) - if (isCardWithPotentialFraud(card)) { + // Check for fraud on any Expensify card (physical or virtual). + // Only include cards that have complete possibleFraud data with a valid fraudAlertReportID, + // since without these the ReviewCardFraud widget cannot render anything meaningful. + if (isCardWithPotentialFraud(card) && card.nameValuePairs?.possibleFraud?.fraudAlertReportID) { result.cardsWithFraud.push(card); } diff --git a/tests/unit/selectors/CardTest.ts b/tests/unit/selectors/CardTest.ts index b69aca649979..50f7ef067b38 100644 --- a/tests/unit/selectors/CardTest.ts +++ b/tests/unit/selectors/CardTest.ts @@ -500,6 +500,116 @@ describe('timeSensitiveCardsSelector', () => { expect(result.cardsWithFraud.at(0)?.cardID).toBe(1); expect(result.cardsWithFraud.at(0)?.nameValuePairs?.possibleFraud?.triggerAmount).toBe(5663); }); + + it('excludes fraud cards that have fraud flag but no possibleFraud data (prevents empty Time Sensitive section)', () => { + // This is the exact scenario that caused the empty "Time sensitive" block: + // card.fraud is set (e.g., 'domain') but possibleFraud is missing from nameValuePairs + const cardWithDomainFraudNoPossibleFraud = createRandomExpensifyCard(1, { + state: CONST.EXPENSIFY_CARD.STATE.OPEN, + fraud: CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN, + }); + const cardWithIndividualFraudNoPossibleFraud = createRandomExpensifyCard(2, { + state: CONST.EXPENSIFY_CARD.STATE.OPEN, + fraud: CONST.EXPENSIFY_CARD.FRAUD_TYPES.INDIVIDUAL, + }); + + const cardList: CardList = { + '1': cardWithDomainFraudNoPossibleFraud, + '2': cardWithIndividualFraudNoPossibleFraud, + }; + + const result = timeSensitiveCardsSelector(cardList); + + // Both cards should be excluded because they lack possibleFraud data needed for rendering + expect(result.cardsWithFraud).toHaveLength(0); + }); + + it('excludes fraud cards that have possibleFraud but no fraudAlertReportID', () => { + const cardWithFraudNoReportID = createRandomExpensifyCard(1, { + state: CONST.EXPENSIFY_CARD.STATE.OPEN, + fraud: CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN, + possibleFraud: {triggerAmount: 5000, triggerMerchant: 'Test Merchant', currency: 'USD'}, + }); + + const cardList: CardList = { + '1': cardWithFraudNoReportID, + }; + + const result = timeSensitiveCardsSelector(cardList); + + // Card should be excluded because fraudAlertReportID is missing + expect(result.cardsWithFraud).toHaveLength(0); + }); + + it('excludes fraud cards that have possibleFraud with fraudAlertReportID of 0', () => { + const cardWithFraudZeroReportID = createRandomExpensifyCard(1, { + state: CONST.EXPENSIFY_CARD.STATE.OPEN, + fraud: CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN, + possibleFraud: {triggerAmount: 5000, triggerMerchant: 'Test Merchant', currency: 'USD', fraudAlertReportID: 0}, + }); + + const cardList: CardList = { + '1': cardWithFraudZeroReportID, + }; + + const result = timeSensitiveCardsSelector(cardList); + + // Card should be excluded because fraudAlertReportID is 0 (falsy) + expect(result.cardsWithFraud).toHaveLength(0); + }); + + it('only includes fraud cards with complete data for rendering when mixed with incomplete ones', () => { + // Card with complete fraud data (should be included) + const completeCard = createRandomExpensifyCard(1, { + state: CONST.EXPENSIFY_CARD.STATE.OPEN, + fraud: CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN, + possibleFraud: {triggerAmount: 5000, triggerMerchant: 'Store A', currency: 'USD', fraudAlertReportID: 123}, + }); + + // Card with fraud flag but no possibleFraud (should be excluded) + const incompleteFraudFlag = createRandomExpensifyCard(2, { + state: CONST.EXPENSIFY_CARD.STATE.OPEN, + fraud: CONST.EXPENSIFY_CARD.FRAUD_TYPES.INDIVIDUAL, + }); + + // Card with possibleFraud but missing fraudAlertReportID (should be excluded) + const incompletePossibleFraud = createRandomExpensifyCard(3, { + state: CONST.EXPENSIFY_CARD.STATE.OPEN, + fraud: CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN, + possibleFraud: {triggerAmount: 3000, triggerMerchant: 'Store B', currency: 'USD'}, + }); + + const cardList: CardList = { + '1': completeCard, + '2': incompleteFraudFlag, + '3': incompletePossibleFraud, + }; + + const result = timeSensitiveCardsSelector(cardList); + + // Only the card with complete data should be included + expect(result.cardsWithFraud).toHaveLength(1); + expect(result.cardsWithFraud.at(0)?.cardID).toBe(1); + }); + + it('returns completely empty result when only fraud cards exist but none have sufficient data to render', () => { + // This is the scenario that would cause an empty "Time sensitive" section + const cardWithFraudFlagOnly = createRandomExpensifyCard(1, { + state: CONST.EXPENSIFY_CARD.STATE.OPEN, + fraud: CONST.EXPENSIFY_CARD.FRAUD_TYPES.DOMAIN, + }); + + const cardList: CardList = { + '1': cardWithFraudFlagOnly, + }; + + const result = timeSensitiveCardsSelector(cardList); + + // All arrays should be empty, ensuring hasAnyTimeSensitiveContent would be false + expect(result.cardsWithFraud).toHaveLength(0); + expect(result.cardsNeedingShippingAddress).toHaveLength(0); + expect(result.cardsNeedingActivation).toHaveLength(0); + }); }); describe('areAllExpensifyCardsShipped', () => {