@@ -23,6 +23,7 @@ import { strings } from '../../../../../../locales/i18n';
2323import MOCK_MONEY_TRANSACTIONS from '../../constants/mockActivityData' ;
2424import useMoneyAccountBalance from '../../hooks/useMoneyAccountBalance' ;
2525import { selectIsCardholder } from '../../../../../selectors/cardController' ;
26+ import { getDetectedGeolocation } from '../../../../../reducers/fiatOrders' ;
2627import { moneyFormatFiat } from '../../utils/moneyFormatFiat' ;
2728
2829const mockGoBack = jest . fn ( ) ;
@@ -85,7 +86,13 @@ jest.mock('../../../../../selectors/cardController', () => ({
8586 selectIsCardholder : jest . fn ( ) ,
8687} ) ) ;
8788
89+ jest . mock ( '../../../../../reducers/fiatOrders' , ( ) => ( {
90+ ...jest . requireActual ( '../../../../../reducers/fiatOrders' ) ,
91+ getDetectedGeolocation : jest . fn ( ) ,
92+ } ) ) ;
93+
8894const mockSelectIsCardholder = jest . mocked ( selectIsCardholder ) ;
95+ const mockGetDetectedGeolocation = jest . mocked ( getDetectedGeolocation ) ;
8996
9097const mockUseMoneyAccountTransactions = jest . mocked (
9198 useMoneyAccountTransactions ,
@@ -134,6 +141,7 @@ describe('MoneyHomeView', () => {
134141 global . alert = jest . fn ( ) ;
135142
136143 mockSelectIsCardholder . mockReturnValue ( false ) ;
144+ mockGetDetectedGeolocation . mockReturnValue ( 'US' ) ;
137145
138146 mockUseMoneyAccountBalance . mockReturnValue ( {
139147 totalFiatFormatted : '$3.00' ,
@@ -592,4 +600,82 @@ describe('MoneyHomeView', () => {
592600 } ) ;
593601 } ) ;
594602 } ) ;
603+
604+ describe ( 'Metal card geolocation gating' , ( ) => {
605+ it ( 'renders the Metal card row when geolocation is US' , ( ) => {
606+ mockGetDetectedGeolocation . mockReturnValue ( 'US' ) ;
607+
608+ const { getByTestId } = renderWithProvider ( < MoneyHomeView /> ) ;
609+
610+ expect (
611+ getByTestId ( MoneyMetaMaskCardTestIds . METAL_CARD_ROW ) ,
612+ ) . toBeOnTheScreen ( ) ;
613+ expect (
614+ getByTestId ( MoneyMetaMaskCardTestIds . VIRTUAL_CARD_ROW ) ,
615+ ) . toBeOnTheScreen ( ) ;
616+ } ) ;
617+
618+ it ( 'renders the Metal card row when geolocation is a US sub-region (e.g. US-CA)' , ( ) => {
619+ mockGetDetectedGeolocation . mockReturnValue ( 'us-ca' ) ;
620+
621+ const { getByTestId } = renderWithProvider ( < MoneyHomeView /> ) ;
622+
623+ expect (
624+ getByTestId ( MoneyMetaMaskCardTestIds . METAL_CARD_ROW ) ,
625+ ) . toBeOnTheScreen ( ) ;
626+ } ) ;
627+
628+ it ( 'hides the Metal card row when geolocation is GB' , ( ) => {
629+ mockGetDetectedGeolocation . mockReturnValue ( 'GB' ) ;
630+
631+ const { queryByTestId, getByTestId } = renderWithProvider (
632+ < MoneyHomeView /> ,
633+ ) ;
634+
635+ expect (
636+ queryByTestId ( MoneyMetaMaskCardTestIds . METAL_CARD_ROW ) ,
637+ ) . not . toBeOnTheScreen ( ) ;
638+ expect (
639+ getByTestId ( MoneyMetaMaskCardTestIds . VIRTUAL_CARD_ROW ) ,
640+ ) . toBeOnTheScreen ( ) ;
641+ } ) ;
642+
643+ it ( 'hides the Metal card row when geolocation is undefined (loading/unknown - fail closed)' , ( ) => {
644+ mockGetDetectedGeolocation . mockReturnValue ( undefined ) ;
645+
646+ const { queryByTestId, getByTestId } = renderWithProvider (
647+ < MoneyHomeView /> ,
648+ ) ;
649+
650+ expect (
651+ queryByTestId ( MoneyMetaMaskCardTestIds . METAL_CARD_ROW ) ,
652+ ) . not . toBeOnTheScreen ( ) ;
653+ expect (
654+ getByTestId ( MoneyMetaMaskCardTestIds . VIRTUAL_CARD_ROW ) ,
655+ ) . toBeOnTheScreen ( ) ;
656+ } ) ;
657+ } ) ;
658+
659+ describe ( 'Get now navigation' , ( ) => {
660+ it ( 'navigates to the card sign-up flow when the virtual card Get now button is pressed' , ( ) => {
661+ mockGetDetectedGeolocation . mockReturnValue ( 'GB' ) ;
662+
663+ const { getByText } = renderWithProvider ( < MoneyHomeView /> ) ;
664+
665+ fireEvent . press ( getByText ( strings ( 'money.metamask_card.get_now' ) ) ) ;
666+
667+ expect ( mockNavigate ) . toHaveBeenCalledWith ( Routes . CARD . ROOT ) ;
668+ } ) ;
669+
670+ it ( 'navigates to the card sign-up flow when the metal card Get now button is pressed' , ( ) => {
671+ mockGetDetectedGeolocation . mockReturnValue ( 'US' ) ;
672+
673+ const { getAllByText } = renderWithProvider ( < MoneyHomeView /> ) ;
674+ const buttons = getAllByText ( strings ( 'money.metamask_card.get_now' ) ) ;
675+
676+ fireEvent . press ( buttons [ 1 ] ) ;
677+
678+ expect ( mockNavigate ) . toHaveBeenCalledWith ( Routes . CARD . ROOT ) ;
679+ } ) ;
680+ } ) ;
595681} ) ;
0 commit comments