Skip to content
Open
146 changes: 146 additions & 0 deletions src/ReturnUserExperience/ReturnUserExperience-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import React from 'react'
import { describe, it, expect } from 'vitest'
import { render, screen } from 'src/utilities/testingLibrary'
import { ReturnUserExperience } from './ReturnUserExperience'

describe('ReturnUserExperience', () => {
const mockAppName = 'Test Financial App'

const preloadedState = {
profiles: {
client: {
oauth_app_name: mockAppName,
},
},
}

describe('rendering', () => {
it('should render the component without crashing', () => {
render(<ReturnUserExperience />, { preloadedState })
expect(screen.getByText('Connect your accounts')).toBeInTheDocument()
})

it('should render the development warning alert', () => {
render(<ReturnUserExperience />, { preloadedState })
const alert = screen.getByText('This feature is currently in development.')

Check failure on line 25 in src/ReturnUserExperience/ReturnUserExperience-test.tsx

View workflow job for this annotation

GitHub Actions / Unit tests

src/ReturnUserExperience/ReturnUserExperience-test.tsx > ReturnUserExperience > rendering > should render the development warning alert

TestingLibraryElementError: Unable to find an element with the text: This feature is currently in development.. This could be because the text is broken up by multiple elements. In this case, you can provide a function for your text matcher to make your matcher more flexible. Ignored nodes: comments, script, style <body> <div> <div class="_pageContainer_134e31" > <div class="MuiStack-root _logoHeaders_134e31 css-niqf4j-MuiStack-root" > <div class="_clientLogo_134e31" > <img alt="Client logo" class="f1d5s45m undefined" height="64" src="https://content.moneydesktop.com/storage/MD_Client/oauth_logos/undefined.png" width="64" /> </div> <svg aria-hidden="true" class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1ofsbaj-MuiSvgIcon-root" focusable="false" height="20" viewBox="0 -960 960 960" width="20" > <path d="M440-440H240q-17 0-28.5-11.5T200-480q0-17 11.5-28.5T240-520h200v-200q0-17 11.5-28.5T480-760q17 0 28.5 11.5T520-720v200h200q17 0 28.5 11.5T760-480q0 17-11.5 28.5T720-440H520v200q0 17-11.5 28.5T480-200q-17 0-28.5-11.5T440-240v-200Z" /> </svg> <div class="_mxLogo_134e31" > <svg aria-hidden="true" class="mx-kmui-icon" focusable="false" height="64" viewBox="0 0 16 16" width="64" xmlns="http://www.w3.org/2000/svg" > <path clip-rule="evenodd" d="M16 0H0V16H16V0ZM13.979 5.5H12.7758C12.7703 5.5 12.7639 5.50299 12.7607 5.50897L11.3396 7.25908C11.3301 7.26805 11.3151 7.26805 11.3087 7.25908L9.8876 5.50897C9.88443 5.50299 9.87888 5.5 9.87254 5.5H8.66938C8.65353 5.5 8.64244 5.51719 8.65353 5.53139L10.6889 7.98543C10.6945 7.99141 10.6945 8.00336 10.6889 8.00859L8.65353 10.4626C8.64561 10.4738 8.65353 10.4948 8.66938 10.4948H9.87254C9.87888 10.4948 9.88443 10.4918 9.8876 10.4858L11.3087 8.73494C11.3182 8.72672 11.3333 8.72672 11.3396 8.73494L12.7607 10.4858C12.7639 10.4918 12.7703 10.4948 12.7758 10.4948H13.979C13.9948 10.4948 14.0067 10.4768 13.9948 10.4626L11.9594 8.00859C11.9531 8.00336 11.9531 7.99141 11.9594 7.98543L13.9948 5.53139C14.0067 5.52018 13.9972 5.5 13.979 5.5ZM8.97366 9.46462L8.18186 10.3853C8.166 10.4047 8.12875 10.3965 8.12558 10.3703L7.66905 7.28258C7.66588 7.25419 7.62229 7.24821 7.6104 7.27436L5.93486 10.4831C5.93168 10.4951 5.919 10.5003 5.90711 10.5003H5.24371C5.23183 10.5003 5.22231 10.4951 5.21597 10.4831L3.51982 7.25717C3.50714 7.23102 3.46355 7.23625 3.46038 7.26539L2.9983 10.4719C2.9983 10.4861 2.98245 10.4973 2.96659 10.4973H2.03133C2.01231 10.4973 1.99725 10.4802 2.00042 10.463L2.76686 5.52948C2.77003 5.51528 2.78271 5.50333 2.79856 5.50333H3.60859C3.62048 5.50333 3.6292 5.5093 3.63554 5.52051L5.55758 9.17841C5.5663 9.20158 5.60038 9.20158 5.61227 9.17841L7.51529 5.52051C7.51846 5.5093 7.53034 5.50333 7.54303 5.50333H8.34434C8.3594 5.50333 8.37208 5.51528 8.37525 5.52948L8.98238 9.44444C8.98238 9.45042 8.9792 9.45864 8.97366 9.46462Z" fill="currentColor" fill-rule="evenodd" /> </svg> </div> </div> <div class="MuiStack-root _titleContainer_134e31 css-18tmxe7-MuiStack-root" > <h2 class="MuiTypography-root MuiTypography-h2 mx-kmui-text _centerText_134e31 css-16sjf0p-MuiTypography-root" > Connect your accounts </h2> <h6 class="MuiTypography-root MuiTypography-subtitle1 mx-kmui-text _centerText_134e31 css-jtrj1p-MuiTypography-root" > Test Financial App uses MX to connect your accounts. <a class="MuiTypography-root MuiTypography-subtitle1 MuiLink-root MuiLink-underlineAlways css-15auv2-MuiTypography-root-MuiLink-root" href="https://mx.com/learn-more" > Learn more
expect(alert).toBeInTheDocument()
})

it('should render the main heading', () => {
render(<ReturnUserExperience />, { preloadedState })
const heading = screen.getByRole('heading', { level: 2 })
expect(heading).toHaveTextContent('Connect your accounts')
})

it('should render the subtitle with app name interpolation', () => {
render(<ReturnUserExperience />, { preloadedState })
const subtitle = screen.getByText(new RegExp(mockAppName))
expect(subtitle).toBeInTheDocument()
expect(subtitle).toHaveTextContent(`${mockAppName} uses MX to connect your accounts.`)
})

it('should render the learn more link', () => {
render(<ReturnUserExperience />, { preloadedState })
const link = screen.getByRole('link', { name: /learn more about mx/i })
expect(link).toBeInTheDocument()
expect(link).toHaveAttribute('href', 'https://mx.com/learn-more')
expect(link).toHaveAttribute('target', '_blank')

Check failure on line 47 in src/ReturnUserExperience/ReturnUserExperience-test.tsx

View workflow job for this annotation

GitHub Actions / Unit tests

src/ReturnUserExperience/ReturnUserExperience-test.tsx > ReturnUserExperience > rendering > should render the learn more link

Error: expect(element).toHaveAttribute("target", "_blank") // element.getAttribute("target") === "_blank" Expected the element to have attribute: target="_blank" Received: null ❯ src/ReturnUserExperience/ReturnUserExperience-test.tsx:47:20
expect(link).toHaveAttribute('rel', 'noopener noreferrer')
})

it('should render the MX sign in button', () => {
render(<ReturnUserExperience />, { preloadedState })
const button = screen.getByRole('button', { name: /connect faster by signing into mx/i })

Check failure on line 53 in src/ReturnUserExperience/ReturnUserExperience-test.tsx

View workflow job for this annotation

GitHub Actions / Unit tests

src/ReturnUserExperience/ReturnUserExperience-test.tsx > ReturnUserExperience > rendering > should render the MX sign in button

TestingLibraryElementError: Unable to find an accessible element with the role "button" and name `/connect faster by signing into mx/i` Here are the accessible roles: img: Name "Client logo": <img alt="Client logo" class="f1d5s45m undefined" height="64" src="https://content.moneydesktop.com/storage/MD_Client/oauth_logos/undefined.png" width="64" /> -------------------------------------------------- heading: Name "Connect your accounts": <h2 class="MuiTypography-root MuiTypography-h2 mx-kmui-text _centerText_134e31 css-16sjf0p-MuiTypography-root" /> Name "Test Financial App uses MX to connect your accounts. Learn more about MX.": <h6 class="MuiTypography-root MuiTypography-subtitle1 mx-kmui-text _centerText_134e31 css-jtrj1p-MuiTypography-root" /> -------------------------------------------------- link: Name "Learn more about MX.": <a class="MuiTypography-root MuiTypography-subtitle1 MuiLink-root MuiLink-underlineAlways css-15auv2-MuiTypography-root-MuiLink-root" href="https://mx.com/learn-more" /> -------------------------------------------------- paragraph: Name "": <p class="MuiTypography-root MuiTypography-body1 mx-kmui-text css-18u46mh-MuiTypography-root" /> Name "": <p class="MuiTypography-root MuiTypography-body1 mx-kmui-text css-18u46mh-MuiTypography-root" /> Name "": <p class="MuiTypography-root MuiTypography-body1 mx-kmui-text css-18u46mh-MuiTypography-root" /> -------------------------------------------------- button: Name "Continue": <button class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-colorPrimary MuiButton-fullWidth MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-colorPrimary MuiButton-fullWidth css-1k9hkw1-MuiButtonBase-root-MuiButton-root" tabindex="0" type="button" /> -------------------------------------------------- Ignored nodes: comments, script, style <body> <div> <div class="_pageContainer_134e31" > <div class="MuiStack-root _logoHeaders_134e31 css-niqf4j-MuiStack-root" > <div class="_clientLogo_134e31" > <img alt="Client logo" class="f1d5s45m undefined" height="64" src="https://content.moneydesktop.com/storage/MD_Client/oauth_logos/undefined.png" width="64" /> </div> <svg aria-hidden="true" class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1ofsbaj-MuiSvgIcon-root" focusable="false" height="20" viewBox="0 -960 960 960" width="20" > <path d="M440-440H240q-17 0-28.5-11.5T200-480q0-17 11.5-28.5T240-520h200v-200q0-17 11.5-28.5T480-760q17 0 28.5 11.5T520-720v200h200q17 0 28.5 11.5T760-480q0 17-11.5 28.5T720-440H520v200q0 17-11.5 28.5T480-200q-17 0-28.5-11.5T440-240v-200Z" /> </svg> <div class="_mxLogo_134e31" > <svg aria-hidden="true" class="mx-kmui-icon" focusable="false" height="64" viewBox="0 0 16 16" width="64" xmlns="http://www.w3.org/2000/svg" > <path clip-rule="evenodd" d="M16 0H0V16H16V0ZM13.979 5.5H12.7758C12.7703 5.5 12.7639 5.50299 12.7607 5.50897L11.3396 7.25908C11.3301 7.26805 11.3151 7.26805 11.3087 7.25908L9.8876 5.50897C9.88443 5.50299 9.87888 5.5 9.87254 5.5H8.66938C8.65353 5.5 8.64244 5.51719 8.65353 5.53139L10.6889 7.98543C10.6945 7.99141 10.6945 8.00336 10.6889 8.00859L8.65353 10.4626C8.64561 10.4738 8.65353 10.4948 8.66938 10.4948H9.87254C9.87888 10.4948 9.88443 10.4918 9.8876 10.4858L11.3087 8.73494C11.3182 8.72672 11.3333 8.72672 11.3396 8.73494L12.7607 10.4858C12.7639 10.4918 12.7703 10.4948 12.7758 10.4948H13.979C13.9948 10.4948 14.
expect(button).toBeInTheDocument()
expect(button).toHaveClass('MuiButton-contained')
})

it('should render the guest sign in button', () => {
render(<ReturnUserExperience />, { preloadedState })
const button = screen.getByRole('button', { name: /continue as guest/i })

Check failure on line 60 in src/ReturnUserExperience/ReturnUserExperience-test.tsx

View workflow job for this annotation

GitHub Actions / Unit tests

src/ReturnUserExperience/ReturnUserExperience-test.tsx > ReturnUserExperience > rendering > should render the guest sign in button

TestingLibraryElementError: Unable to find an accessible element with the role "button" and name `/continue as guest/i` Here are the accessible roles: img: Name "Client logo": <img alt="Client logo" class="f1d5s45m undefined" height="64" src="https://content.moneydesktop.com/storage/MD_Client/oauth_logos/undefined.png" width="64" /> -------------------------------------------------- heading: Name "Connect your accounts": <h2 class="MuiTypography-root MuiTypography-h2 mx-kmui-text _centerText_134e31 css-16sjf0p-MuiTypography-root" /> Name "Test Financial App uses MX to connect your accounts. Learn more about MX.": <h6 class="MuiTypography-root MuiTypography-subtitle1 mx-kmui-text _centerText_134e31 css-jtrj1p-MuiTypography-root" /> -------------------------------------------------- link: Name "Learn more about MX.": <a class="MuiTypography-root MuiTypography-subtitle1 MuiLink-root MuiLink-underlineAlways css-15auv2-MuiTypography-root-MuiLink-root" href="https://mx.com/learn-more" /> -------------------------------------------------- paragraph: Name "": <p class="MuiTypography-root MuiTypography-body1 mx-kmui-text css-18u46mh-MuiTypography-root" /> Name "": <p class="MuiTypography-root MuiTypography-body1 mx-kmui-text css-18u46mh-MuiTypography-root" /> Name "": <p class="MuiTypography-root MuiTypography-body1 mx-kmui-text css-18u46mh-MuiTypography-root" /> -------------------------------------------------- button: Name "Continue": <button class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-colorPrimary MuiButton-fullWidth MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-colorPrimary MuiButton-fullWidth css-1k9hkw1-MuiButtonBase-root-MuiButton-root" tabindex="0" type="button" /> -------------------------------------------------- Ignored nodes: comments, script, style <body> <div> <div class="_pageContainer_134e31" > <div class="MuiStack-root _logoHeaders_134e31 css-niqf4j-MuiStack-root" > <div class="_clientLogo_134e31" > <img alt="Client logo" class="f1d5s45m undefined" height="64" src="https://content.moneydesktop.com/storage/MD_Client/oauth_logos/undefined.png" width="64" /> </div> <svg aria-hidden="true" class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1ofsbaj-MuiSvgIcon-root" focusable="false" height="20" viewBox="0 -960 960 960" width="20" > <path d="M440-440H240q-17 0-28.5-11.5T200-480q0-17 11.5-28.5T240-520h200v-200q0-17 11.5-28.5T480-760q17 0 28.5 11.5T520-720v200h200q17 0 28.5 11.5T760-480q0 17-11.5 28.5T720-440H520v200q0 17-11.5 28.5T480-200q-17 0-28.5-11.5T440-240v-200Z" /> </svg> <div class="_mxLogo_134e31" > <svg aria-hidden="true" class="mx-kmui-icon" focusable="false" height="64" viewBox="0 0 16 16" width="64" xmlns="http://www.w3.org/2000/svg" > <path clip-rule="evenodd" d="M16 0H0V16H16V0ZM13.979 5.5H12.7758C12.7703 5.5 12.7639 5.50299 12.7607 5.50897L11.3396 7.25908C11.3301 7.26805 11.3151 7.26805 11.3087 7.25908L9.8876 5.50897C9.88443 5.50299 9.87888 5.5 9.87254 5.5H8.66938C8.65353 5.5 8.64244 5.51719 8.65353 5.53139L10.6889 7.98543C10.6945 7.99141 10.6945 8.00336 10.6889 8.00859L8.65353 10.4626C8.64561 10.4738 8.65353 10.4948 8.66938 10.4948H9.87254C9.87888 10.4948 9.88443 10.4918 9.8876 10.4858L11.3087 8.73494C11.3182 8.72672 11.3333 8.72672 11.3396 8.73494L12.7607 10.4858C12.7639 10.4918 12.7703 10.4948 12.7758 10.4948H13.979C13.9948 10.4948 14.0067 10.4768 13.
expect(button).toBeInTheDocument()
expect(button).toHaveClass('MuiButton-outlined')
})

it('should render both buttons as full width', () => {
render(<ReturnUserExperience />, { preloadedState })
const buttons = screen.getAllByRole('button')
buttons.forEach((button) => {
if (
button.textContent?.includes('Connect faster') ||
button.textContent?.includes('Continue as guest')
) {
expect(button).toHaveClass('MuiButton-fullWidth')
}
})
})
})

describe('Redux state integration', () => {
it('should use the oauth_app_name from Redux state', () => {
render(<ReturnUserExperience />, { preloadedState })
expect(screen.getByText(new RegExp(mockAppName))).toBeInTheDocument()
})

it('should display default app name when oauth_app_name is not provided', () => {
const emptyState = {
profiles: {
client: {},
},
}
render(<ReturnUserExperience />, { preloadedState: emptyState })
expect(screen.getByText(/This app uses MX to connect your accounts/)).toBeInTheDocument()
})

it('should display default app name when oauth_app_name is null', () => {
const nullState = {
profiles: {
client: {
oauth_app_name: null,
},
},
}
render(<ReturnUserExperience />, { preloadedState: nullState })
expect(screen.getByText(/This app uses MX to connect your accounts/)).toBeInTheDocument()
})
})

describe('button interactions', () => {
it('should render the MX sign in button as clickable', async () => {
const { user } = render(<ReturnUserExperience />, { preloadedState })
const button = screen.getByRole('button', { name: /connect faster by signing into mx/i })

Check failure on line 111 in src/ReturnUserExperience/ReturnUserExperience-test.tsx

View workflow job for this annotation

GitHub Actions / Unit tests

src/ReturnUserExperience/ReturnUserExperience-test.tsx > ReturnUserExperience > button interactions > should render the MX sign in button as clickable

TestingLibraryElementError: Unable to find an accessible element with the role "button" and name `/connect faster by signing into mx/i` Here are the accessible roles: img: Name "Client logo": <img alt="Client logo" class="f1d5s45m undefined" height="64" src="https://content.moneydesktop.com/storage/MD_Client/oauth_logos/undefined.png" width="64" /> -------------------------------------------------- heading: Name "Connect your accounts": <h2 class="MuiTypography-root MuiTypography-h2 mx-kmui-text _centerText_134e31 css-16sjf0p-MuiTypography-root" /> Name "Test Financial App uses MX to connect your accounts. Learn more about MX.": <h6 class="MuiTypography-root MuiTypography-subtitle1 mx-kmui-text _centerText_134e31 css-jtrj1p-MuiTypography-root" /> -------------------------------------------------- link: Name "Learn more about MX.": <a class="MuiTypography-root MuiTypography-subtitle1 MuiLink-root MuiLink-underlineAlways css-15auv2-MuiTypography-root-MuiLink-root" href="https://mx.com/learn-more" /> -------------------------------------------------- paragraph: Name "": <p class="MuiTypography-root MuiTypography-body1 mx-kmui-text css-18u46mh-MuiTypography-root" /> Name "": <p class="MuiTypography-root MuiTypography-body1 mx-kmui-text css-18u46mh-MuiTypography-root" /> Name "": <p class="MuiTypography-root MuiTypography-body1 mx-kmui-text css-18u46mh-MuiTypography-root" /> -------------------------------------------------- button: Name "Continue": <button class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-colorPrimary MuiButton-fullWidth MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-colorPrimary MuiButton-fullWidth css-1k9hkw1-MuiButtonBase-root-MuiButton-root" tabindex="0" type="button" /> -------------------------------------------------- Ignored nodes: comments, script, style <body> <div> <div class="_pageContainer_134e31" > <div class="MuiStack-root _logoHeaders_134e31 css-niqf4j-MuiStack-root" > <div class="_clientLogo_134e31" > <img alt="Client logo" class="f1d5s45m undefined" height="64" src="https://content.moneydesktop.com/storage/MD_Client/oauth_logos/undefined.png" width="64" /> </div> <svg aria-hidden="true" class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1ofsbaj-MuiSvgIcon-root" focusable="false" height="20" viewBox="0 -960 960 960" width="20" > <path d="M440-440H240q-17 0-28.5-11.5T200-480q0-17 11.5-28.5T240-520h200v-200q0-17 11.5-28.5T480-760q17 0 28.5 11.5T520-720v200h200q17 0 28.5 11.5T760-480q0 17-11.5 28.5T720-440H520v200q0 17-11.5 28.5T480-200q-17 0-28.5-11.5T440-240v-200Z" /> </svg> <div class="_mxLogo_134e31" > <svg aria-hidden="true" class="mx-kmui-icon" focusable="false" height="64" viewBox="0 0 16 16" width="64" xmlns="http://www.w3.org/2000/svg" > <path clip-rule="evenodd" d="M16 0H0V16H16V0ZM13.979 5.5H12.7758C12.7703 5.5 12.7639 5.50299 12.7607 5.50897L11.3396 7.25908C11.3301 7.26805 11.3151 7.26805 11.3087 7.25908L9.8876 5.50897C9.88443 5.50299 9.87888 5.5 9.87254 5.5H8.66938C8.65353 5.5 8.64244 5.51719 8.65353 5.53139L10.6889 7.98543C10.6945 7.99141 10.6945 8.00336 10.6889 8.00859L8.65353 10.4626C8.64561 10.4738 8.65353 10.4948 8.66938 10.4948H9.87254C9.87888 10.4948 9.88443 10.4918 9.8876 10.4858L11.3087 8.73494C11.3182 8.72672 11.3333 8.72672 11.3396 8.73494L12.7607 10.4858C12.7639 10.4918 12.7703 10.4948 12.7758 10.4948H13.979C13.9948 10.4948 14.
expect(button).not.toBeDisabled()
await user.click(button)
})

it('should render the guest continue button as clickable', async () => {
const { user } = render(<ReturnUserExperience />, { preloadedState })
const button = screen.getByRole('button', { name: /continue as guest/i })

Check failure on line 118 in src/ReturnUserExperience/ReturnUserExperience-test.tsx

View workflow job for this annotation

GitHub Actions / Unit tests

src/ReturnUserExperience/ReturnUserExperience-test.tsx > ReturnUserExperience > button interactions > should render the guest continue button as clickable

TestingLibraryElementError: Unable to find an accessible element with the role "button" and name `/continue as guest/i` Here are the accessible roles: img: Name "Client logo": <img alt="Client logo" class="f1d5s45m undefined" height="64" src="https://content.moneydesktop.com/storage/MD_Client/oauth_logos/undefined.png" width="64" /> -------------------------------------------------- heading: Name "Connect your accounts": <h2 class="MuiTypography-root MuiTypography-h2 mx-kmui-text _centerText_134e31 css-16sjf0p-MuiTypography-root" /> Name "Test Financial App uses MX to connect your accounts. Learn more about MX.": <h6 class="MuiTypography-root MuiTypography-subtitle1 mx-kmui-text _centerText_134e31 css-jtrj1p-MuiTypography-root" /> -------------------------------------------------- link: Name "Learn more about MX.": <a class="MuiTypography-root MuiTypography-subtitle1 MuiLink-root MuiLink-underlineAlways css-15auv2-MuiTypography-root-MuiLink-root" href="https://mx.com/learn-more" /> -------------------------------------------------- paragraph: Name "": <p class="MuiTypography-root MuiTypography-body1 mx-kmui-text css-18u46mh-MuiTypography-root" /> Name "": <p class="MuiTypography-root MuiTypography-body1 mx-kmui-text css-18u46mh-MuiTypography-root" /> Name "": <p class="MuiTypography-root MuiTypography-body1 mx-kmui-text css-18u46mh-MuiTypography-root" /> -------------------------------------------------- button: Name "Continue": <button class="MuiButtonBase-root MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-colorPrimary MuiButton-fullWidth MuiButton-root MuiButton-contained MuiButton-containedPrimary MuiButton-sizeMedium MuiButton-containedSizeMedium MuiButton-colorPrimary MuiButton-fullWidth css-1k9hkw1-MuiButtonBase-root-MuiButton-root" tabindex="0" type="button" /> -------------------------------------------------- Ignored nodes: comments, script, style <body> <div> <div class="_pageContainer_134e31" > <div class="MuiStack-root _logoHeaders_134e31 css-niqf4j-MuiStack-root" > <div class="_clientLogo_134e31" > <img alt="Client logo" class="f1d5s45m undefined" height="64" src="https://content.moneydesktop.com/storage/MD_Client/oauth_logos/undefined.png" width="64" /> </div> <svg aria-hidden="true" class="MuiSvgIcon-root MuiSvgIcon-fontSizeMedium css-1ofsbaj-MuiSvgIcon-root" focusable="false" height="20" viewBox="0 -960 960 960" width="20" > <path d="M440-440H240q-17 0-28.5-11.5T200-480q0-17 11.5-28.5T240-520h200v-200q0-17 11.5-28.5T480-760q17 0 28.5 11.5T520-720v200h200q17 0 28.5 11.5T760-480q0 17-11.5 28.5T720-440H520v200q0 17-11.5 28.5T480-200q-17 0-28.5-11.5T440-240v-200Z" /> </svg> <div class="_mxLogo_134e31" > <svg aria-hidden="true" class="mx-kmui-icon" focusable="false" height="64" viewBox="0 0 16 16" width="64" xmlns="http://www.w3.org/2000/svg" > <path clip-rule="evenodd" d="M16 0H0V16H16V0ZM13.979 5.5H12.7758C12.7703 5.5 12.7639 5.50299 12.7607 5.50897L11.3396 7.25908C11.3301 7.26805 11.3151 7.26805 11.3087 7.25908L9.8876 5.50897C9.88443 5.50299 9.87888 5.5 9.87254 5.5H8.66938C8.65353 5.5 8.64244 5.51719 8.65353 5.53139L10.6889 7.98543C10.6945 7.99141 10.6945 8.00336 10.6889 8.00859L8.65353 10.4626C8.64561 10.4738 8.65353 10.4948 8.66938 10.4948H9.87254C9.87888 10.4948 9.88443 10.4918 9.8876 10.4858L11.3087 8.73494C11.3182 8.72672 11.3333 8.72672 11.3396 8.73494L12.7607 10.4858C12.7639 10.4918 12.7703 10.4948 12.7758 10.4948H13.979C13.9948 10.4948 14.0067 10.4768 13.
expect(button).not.toBeDisabled()
await user.click(button)
})
})

describe('accessibility', () => {
it('should have proper heading hierarchy', () => {
render(<ReturnUserExperience />, { preloadedState })
const heading = screen.getByRole('heading', { level: 2 })
expect(heading).toHaveTextContent('Connect your accounts')
})

it('should have accessible buttons', () => {
render(<ReturnUserExperience />, { preloadedState })
const buttons = screen.getAllByRole('button')
expect(buttons.length).toBeGreaterThanOrEqual(2)

Check failure on line 134 in src/ReturnUserExperience/ReturnUserExperience-test.tsx

View workflow job for this annotation

GitHub Actions / Unit tests

src/ReturnUserExperience/ReturnUserExperience-test.tsx > ReturnUserExperience > accessibility > should have accessible buttons

AssertionError: expected 1 to be greater than or equal to 2 ❯ src/ReturnUserExperience/ReturnUserExperience-test.tsx:134:30
buttons.forEach((button) => {
expect(button).toHaveAccessibleName()
})
})

it('should have an accessible learn more link', () => {
render(<ReturnUserExperience />, { preloadedState })
const link = screen.getByRole('link', { name: /learn more about mx/i })
expect(link).toHaveAccessibleName()
})
})
})
152 changes: 152 additions & 0 deletions src/ReturnUserExperience/ReturnUserExperience.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import React from 'react'
import { render, screen } from 'src/utilities/testingLibrary'
import { ReturnUserExperience } from './ReturnUserExperience'
import { initialState } from 'src/services/mockedData'

describe('ReturnUserExperience', () => {
const mockAppName = 'Test Financial App'

const preloadedState = {
...initialState,
profiles: {
...initialState.profiles,
client: {
...initialState.profiles.client,
oauth_app_name: mockAppName,
},
},
}

describe('rendering', () => {
it('should render the component without crashing', () => {
render(<ReturnUserExperience />, { preloadedState })
expect(screen.getByText('Connect your accounts')).toBeInTheDocument()
})

it('should render the main heading', () => {
render(<ReturnUserExperience />, { preloadedState })
const heading = screen.getByRole('heading', { level: 2 })
expect(heading).toHaveTextContent('Connect your accounts')
})

it('should render the subtitle with app name interpolation', () => {
render(<ReturnUserExperience />, { preloadedState })
const subtitle = screen.getByText(new RegExp(mockAppName))
expect(subtitle).toBeInTheDocument()
expect(subtitle).toHaveTextContent(`${mockAppName} uses MX to connect your accounts.`)
})

it('should render the learn more link', () => {
render(<ReturnUserExperience />, { preloadedState })
const link = screen.getByRole('link', { name: /learn more about mx/i })
expect(link).toBeInTheDocument()
expect(link).toHaveAttribute('href', 'https://mx.com/learn-more')
expect(link).toHaveAttribute('target', '_blank')
expect(link).toHaveAttribute('rel', 'noopener noreferrer')
})

it('should render the MX sign in button', () => {
render(<ReturnUserExperience />, { preloadedState })
const button = screen.getByRole('button', { name: /connect faster by signing into mx/i })
expect(button).toBeInTheDocument()
expect(button).toHaveClass('MuiButton-contained')
})

it('should render the guest sign in button', () => {
render(<ReturnUserExperience />, { preloadedState })
const button = screen.getByRole('button', { name: /continue as guest/i })
expect(button).toBeInTheDocument()
expect(button).toHaveClass('MuiButton-outlined')
})

it('should render both buttons as full width', () => {
render(<ReturnUserExperience />, { preloadedState })
const buttons = screen.getAllByRole('button')
buttons.forEach((button) => {
if (
button.textContent?.includes('Connect faster') ||
button.textContent?.includes('Continue as guest')
) {
expect(button).toHaveClass('MuiButton-fullWidth')
}
})
})
})

describe('Redux state integration', () => {
const undefinedState = {
...initialState,
profiles: {
...initialState.profiles,
client: {
...initialState.profiles.client,
oauth_app_name: undefined,
},
},
}
const nullState = {
...initialState,
profiles: {
...initialState.profiles,
client: {
...initialState.profiles.client,
oauth_app_name: null,
},
},
}

it('should use the oauth_app_name from Redux state', () => {
render(<ReturnUserExperience />, { preloadedState })
expect(screen.getByText(new RegExp(mockAppName))).toBeInTheDocument()
})

it('should display default app name when oauth_app_name is not provided', () => {
render(<ReturnUserExperience />, { preloadedState: undefinedState })
expect(screen.getByText(/This app uses MX to connect your accounts/)).toBeInTheDocument()
})

it('should display default app name when oauth_app_name is null', () => {
render(<ReturnUserExperience />, { preloadedState: nullState })
expect(screen.getByText(/This app uses MX to connect your accounts/)).toBeInTheDocument()
})
})

describe('button interactions', () => {
it('should render the MX sign in button as clickable', async () => {
const { user } = render(<ReturnUserExperience />, { preloadedState })
const button = screen.getByRole('button', { name: /connect faster by signing into mx/i })
expect(button).not.toBeDisabled()
await user.click(button)
})

it('should render the guest continue button as clickable', async () => {
const { user } = render(<ReturnUserExperience />, { preloadedState })
const button = screen.getByRole('button', { name: /continue as guest/i })
expect(button).not.toBeDisabled()
await user.click(button)
})
})

describe('accessibility', () => {
it('should have proper heading hierarchy', () => {
render(<ReturnUserExperience />, { preloadedState })
const heading = screen.getByRole('heading', { level: 2 })
expect(heading).toHaveTextContent('Connect your accounts')
})

it('should have accessible buttons', () => {
render(<ReturnUserExperience />, { preloadedState })
const buttons = screen.getAllByRole('button')
expect(buttons.length).toBeGreaterThanOrEqual(2)
buttons.forEach((button) => {
expect(button).toHaveAccessibleName()
})
})

it('should have an accessible learn more link', () => {
render(<ReturnUserExperience />, { preloadedState })
const link = screen.getByRole('link', { name: /learn more about mx/i })
expect(link).toHaveAccessibleName()
})
})
})
34 changes: 29 additions & 5 deletions src/ReturnUserExperience/ReturnUserExperience.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react'
import { useSelector } from 'react-redux'
import { useDispatch, useSelector } from 'react-redux'

import styles from './returnUserExperience.module.css'
import RuxInfo from 'src/ReturnUserExperience/RuxInfo'
import { RuxPhoneNumber } from 'src/ReturnUserExperience/RuxPhoneNumber'

import { Stack } from '@mui/material'
import { Icon } from '@mxenabled/mxui'
Expand All @@ -12,6 +13,8 @@ import useAnalyticsEvent from 'src/hooks/useAnalyticsEvent'
import { __ } from 'src/utilities/Intl'
import { AnalyticEvents } from 'src/const/Analytics'
import { RootState } from 'src/redux/Store'
import { ActionTypes } from 'src/redux/actions/Connect'
import { selectInitialConfig } from 'src/redux/reducers/configSlice'
import { ClientLogo } from 'src/components/ClientLogo'

export const RUXViews = {
Expand All @@ -23,30 +26,51 @@ export const RUXViews = {

export const ReturnUserExperience = React.forwardRef(() => {
const [view, setView] = React.useState<(typeof RUXViews)[keyof typeof RUXViews]>(RUXViews.INFO)
const [userEnteredPhone, setUserEnteredPhone] = React.useState('')
const clientGuid = useSelector((state: RootState) => state.profiles.client.guid)
const connectConfig = useSelector(selectInitialConfig)
const dispatch = useDispatch()
const sendAnalyticsEvent = useAnalyticsEvent()

const handleRuxInfoContinue = () => {
// This is currently skipping the backend. See epic/ticket for more details.
sendAnalyticsEvent(AnalyticEvents.RUX_INFO_CONTINUE_CLICKED)
setView(RUXViews.PHONE_NUMBER)
}
const handleContinueWithoutPhone = () =>
dispatch({ type: ActionTypes.RESET_WIDGET_MFA_STEP, payload: connectConfig })

return (
<div className={styles.pageContainer}>
{view !== RUXViews.LIST && (
<Stack className={styles.logoHeaders} direction="row" spacing="8px">
<div className={styles.clientLogo}>
<ClientLogo alt="Client logo" clientGuid={clientGuid} size={64} />
</div>
<Icon name="add" size={20} />
{view === RUXViews.INFO && (
<>
<div className={styles.clientLogo}>
<ClientLogo alt="Client logo" clientGuid={clientGuid} size={64} />
</div>
<Icon name="add" size={20} />
</>
)}
<div className={styles.mxLogo}>
<MXLogoFilledIcon size={64} />
</div>
</Stack>
)}

{view === RUXViews.INFO && <RuxInfo handleRuxContinue={handleRuxInfoContinue} />}

{view === RUXViews.PHONE_NUMBER && (
<RuxPhoneNumber
handleContinueWithoutPhone={handleContinueWithoutPhone}
handleRuxContinue={() => {
// sendAnalyticsEvent(AnalyticEvents.RUX_PHONE_NUMBER_CONTINUE_CLICKED)
setView(RUXViews.OTP)
}}
setUserEnteredPhone={setUserEnteredPhone}
userEnteredPhone={userEnteredPhone}
/>
)}
</div>
)
})
Expand Down
Loading
Loading