-
Notifications
You must be signed in to change notification settings - Fork 1
Add demo connect guard screen #289
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
base: master
Are you sure you want to change the base?
Changes from all commits
646d6d9
7146fd9
7abd932
b5a87f2
6be4205
ae13301
12251c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| import React from 'react' | ||
| import { render, screen } from 'src/utilities/testingLibrary' | ||
| import RenderConnectStep from 'src/components/RenderConnectStep' | ||
| import { STEPS } from 'src/const/Connect' | ||
|
|
||
| describe('RenderConnectStep', () => { | ||
| const defaultProps = { | ||
| availableAccountTypes: [], | ||
| handleConsentGoBack: vi.fn(), | ||
| handleCredentialsGoBack: vi.fn(), | ||
| navigationRef: React.createRef(), | ||
| onManualAccountAdded: vi.fn(), | ||
| onUpsertMember: vi.fn(), | ||
| setConnectLocalState: vi.fn(), | ||
| } | ||
|
|
||
| const mockInstitution = { | ||
| guid: 'INS-123', | ||
| name: 'Test Bank', | ||
| logo_url: 'https://example.com/logo.png', | ||
| code: 'TEST', | ||
| url: 'https://testbank.com', | ||
| } | ||
|
|
||
| const createInitialState = (step) => ({ | ||
| browser: { | ||
| height: 768, | ||
| width: 1024, | ||
| size: 'large', | ||
| }, | ||
| connect: { | ||
| location: [{ step }], | ||
| selectedInstitution: mockInstitution, | ||
| updateCredentials: false, | ||
| error: null, | ||
| }, | ||
| config: { | ||
| mode: 'aggregation', | ||
| initialConfig: {}, | ||
| }, | ||
| profiles: { | ||
| client: { has_atrium_api: false }, | ||
| clientProfile: { | ||
| uses_oauth: false, | ||
| account_verification_is_enabled: true, | ||
| is_microdeposits_enabled: true, | ||
| }, | ||
| widgetProfile: { | ||
| enable_support_requests: true, | ||
| show_microdeposits_in_connect: false, | ||
| display_delete_option_in_connect: true, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| it('should render DemoConnectGuard when step is DEMO_CONNECT_GUARD', () => { | ||
| const initialState = createInitialState(STEPS.DEMO_CONNECT_GUARD) | ||
|
|
||
| const { container } = render(<RenderConnectStep {...defaultProps} />, { | ||
| preloadedState: initialState, | ||
| }) | ||
|
|
||
| expect(screen.getByText('Demo mode active')).toBeInTheDocument() | ||
| expect( | ||
| screen.getByText(/Live institutions are not available in the demo environment/i), | ||
| ).toBeInTheDocument() | ||
| expect(screen.getByText('MX Bank')).toBeInTheDocument() | ||
|
|
||
| const logo = screen.getByAltText('Logo for Test Bank') | ||
| expect(logo).toBeInTheDocument() | ||
| expect(logo).toHaveAttribute('src', mockInstitution.logo_url) | ||
|
|
||
| const errorIcon = container.querySelector('svg.MuiSvgIcon-colorError') | ||
| expect(errorIcon).toBeInTheDocument() | ||
|
|
||
| const button = screen.getByRole('button', { name: /return to institution selection/i }) | ||
| expect(button).toBeInTheDocument() | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import React from 'react' | ||
| import { useDispatch } from 'react-redux' | ||
| import { render, screen } from 'src/utilities/testingLibrary' | ||
| import { DemoConnectGuard } from './DemoConnectGuard' | ||
| import { initialState } from 'src/services/mockedData' | ||
| import * as connectActions from 'src/redux/actions/Connect' | ||
|
|
||
| // Mock useDispatch | ||
| vitest.mock('react-redux', async () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These tests feel very mocky, so they don't give me much confidence that things will work when they're actually put together. How can you mock as little as possible while ensuring the functionality is tested?
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless you have better ideas, I couldn’t think of another way to test the action dispatch without mocking useDispatch.
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah we can pair on this |
||
| const actual = await vitest.importActual('react-redux') | ||
| return { ...actual, useDispatch: vitest.fn() } | ||
| }) | ||
| const mockDispatch = vitest.fn() | ||
| const mockedUseDispatch = vitest.mocked(useDispatch) | ||
|
|
||
| describe('DemoConnectGuard', () => { | ||
| const mockInstitution = { | ||
| guid: 'INS-test-123', | ||
| name: 'Test Bank', | ||
| logo_url: 'https://example.com/logo.png', | ||
| code: 'TEST', | ||
| url: 'https://testbank.com', | ||
| } | ||
|
|
||
| const mockInitialState = { | ||
| ...initialState, | ||
| connect: { | ||
| ...initialState.connect, | ||
| selectedInstitution: mockInstitution, | ||
| }, | ||
| } | ||
|
|
||
| beforeEach(() => { | ||
| mockDispatch.mockClear() | ||
| mockedUseDispatch.mockReturnValue(mockDispatch) | ||
| }) | ||
|
|
||
| it('renders all component elements correctly', () => { | ||
| const { container } = render(<DemoConnectGuard />, { preloadedState: mockInitialState }) | ||
|
|
||
| expect(screen.getByText('Demo mode active')).toBeInTheDocument() | ||
| expect( | ||
| screen.getByText(/Live institutions are not available in the demo environment/i), | ||
| ).toBeInTheDocument() | ||
| expect(screen.getByText('MX Bank')).toBeInTheDocument() | ||
|
|
||
| const logo = screen.getByAltText('Logo for Test Bank') | ||
| expect(logo).toBeInTheDocument() | ||
|
|
||
| const errorIcon = container.querySelector('svg.MuiSvgIcon-colorError') | ||
| expect(errorIcon).toBeInTheDocument() | ||
|
|
||
| const button = screen.getByRole('button', { name: /return to institution selection/i }) | ||
| expect(button).toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('dispatches the correct action when return button is clicked', async () => { | ||
| const { user } = render(<DemoConnectGuard />, { preloadedState: mockInitialState }) | ||
|
|
||
| const returnButton = screen.getByRole('button', { name: /return to institution selection/i }) | ||
| await user.click(returnButton) | ||
|
|
||
| expect(mockDispatch).toHaveBeenCalledWith({ | ||
| type: connectActions.ActionTypes.DEMO_CONNECT_GUARD_RETURN_TO_SEARCH, | ||
| payload: {}, | ||
| }) | ||
| }) | ||
| }) | ||
Uh oh!
There was an error while loading. Please reload this page.