-
Notifications
You must be signed in to change notification settings - Fork 1
fix: added login error tests #346
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
Merged
ash-wright123
merged 3 commits into
aw/CT-2264_src_tests
from
aw/CT-2264_login_error_tests
Jul 1, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| import React from 'react' | ||
| import { afterEach, beforeEach, describe, expect, it, vi, type MockInstance } from 'vitest' | ||
| import { render, screen } from 'src/utilities/testingLibrary' | ||
| import RenderConnectStep from 'src/components/RenderConnectStep' | ||
| import { LoginError as LoginErrorComponent } from 'src/views/loginError/LoginError' | ||
| import { initialState, institutionData } from 'src/services/mockedData' | ||
| import { ReadableStatuses } from 'src/const/Statuses' | ||
| import { STEPS } from 'src/const/Connect' | ||
|
|
||
| const LoginError = LoginErrorComponent as unknown as React.ComponentType<Record<string, unknown>> | ||
|
|
||
| describe('<ImpededMemberError />', () => { | ||
| const impededMember = { | ||
| guid: 'MBR-123', | ||
| error: {}, | ||
| name: 'Test Member', | ||
| connection_status: ReadableStatuses.IMPEDED, | ||
| } | ||
|
|
||
| const preloadedState = { | ||
| ...initialState, | ||
| connect: { | ||
| ...initialState.connect, | ||
| selectedInstitution: institutionData.institution, | ||
| currentMemberGuid: impededMember.guid, | ||
| members: [impededMember], | ||
| location: [{ step: 'LOGIN_ERROR' }], | ||
| }, | ||
| } | ||
|
|
||
| const defaultProps = { | ||
| institution: institutionData.institution, | ||
| isDeleteInstitutionOptionEnabled: true, | ||
| member: impededMember, | ||
| onDeleteConnectionClick: vi.fn(), | ||
| onRefreshClick: vi.fn(), | ||
| onUpdateCredentialsClick: vi.fn(), | ||
| showExternalLinkPopup: false, | ||
| showSupport: true, | ||
| size: 'medium', | ||
| } | ||
|
|
||
| let openSpy: MockInstance<typeof window.open> | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| openSpy = vi.spyOn(window, 'open').mockReturnValue(null) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| openSpy.mockRestore() | ||
| }) | ||
|
|
||
| const renderImpededMemberError = (props: Partial<typeof defaultProps> = {}) => | ||
| render( | ||
| <div id="connect-wrapper"> | ||
| <LoginError {...defaultProps} {...props} /> | ||
| </div>, | ||
| { preloadedState }, | ||
| ) | ||
|
|
||
| const renderStepProps = { | ||
| availableAccountTypes: [], | ||
| handleConsentGoBack: vi.fn(), | ||
| handleCredentialsGoBack: vi.fn(), | ||
| navigationRef: React.createRef(), | ||
| onManualAccountAdded: vi.fn(), | ||
| onUpsertMember: vi.fn(), | ||
| setConnectLocalState: vi.fn(), | ||
| } | ||
|
|
||
| const renderImpededErrorStep = () => | ||
| render(<RenderConnectStep {...renderStepProps} />, { | ||
| preloadedState: { | ||
| ...preloadedState, | ||
| connect: { | ||
| ...preloadedState.connect, | ||
| location: [{ step: STEPS.ACTIONABLE_ERROR }], | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| describe('Content Display', () => { | ||
| it('renders the impeded error with both resolution steps', () => { | ||
| renderImpededMemberError() | ||
|
|
||
| expect(screen.getByText('Your attention is needed')).toBeInTheDocument() | ||
| expect( | ||
| screen.getByText( | ||
| 'Your login info was correct, but your attention is needed at Test Bank before we can proceed. You need to:', | ||
| ), | ||
| ).toBeInTheDocument() | ||
|
|
||
| expect(screen.getByText('1')).toBeInTheDocument() | ||
| expect( | ||
| screen.getByText("Log in to Test Bank's website and resolve the issue."), | ||
| ).toBeInTheDocument() | ||
| expect(screen.getByText('Visit website')).toBeInTheDocument() | ||
|
|
||
| expect(screen.getByText('2')).toBeInTheDocument() | ||
| expect( | ||
| screen.getByText('Come back here and try to connect your account again.'), | ||
| ).toBeInTheDocument() | ||
| expect(screen.getByText('Try again')).toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| describe('Try Again Link', () => { | ||
| it('leaves the error view and returns to connecting when clicked', async () => { | ||
| const { user } = renderImpededErrorStep() | ||
|
|
||
| expect(await screen.findByText('Your attention is needed')).toBeInTheDocument() | ||
|
|
||
| await user.click(screen.getByText('Try again')) | ||
|
|
||
| expect(screen.queryByText('Your attention is needed')).not.toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| describe('Visit Website Link', () => { | ||
| it('opens the institution login URL in a new tab when external link popup is disabled', async () => { | ||
| const { user } = renderImpededMemberError({ showExternalLinkPopup: false }) | ||
|
|
||
| await user.click(screen.getByText('Visit website')) | ||
|
|
||
| expect(openSpy).toHaveBeenCalledWith('https://test.com', '_blank') | ||
| expect(screen.queryByTestId('leaving-notice-flat-header')).not.toBeInTheDocument() | ||
| }) | ||
|
|
||
| it('shows the leaving notice instead of navigating when external link popup is enabled', async () => { | ||
| const { user } = renderImpededMemberError({ showExternalLinkPopup: true }) | ||
|
|
||
| await user.click(screen.getByText('Visit website')) | ||
|
|
||
| expect(screen.getByTestId('leaving-notice-flat-header')).toBeInTheDocument() | ||
| expect(openSpy).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
| }) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import React from 'react' | ||
| import { afterEach, beforeEach, describe, expect, it, vi, type MockInstance } from 'vitest' | ||
| import { render, screen } from 'src/utilities/testingLibrary' | ||
| import RenderConnectStep from 'src/components/RenderConnectStep' | ||
| import { initialState, institutionData } from 'src/services/mockedData' | ||
| import { ReadableStatuses } from 'src/const/Statuses' | ||
| import { STEPS } from 'src/const/Connect' | ||
|
|
||
| describe('<LeavingAction />', () => { | ||
| const impededMember = { | ||
| guid: 'MBR-123', | ||
| error: {}, | ||
| name: 'Test Member', | ||
| connection_status: ReadableStatuses.IMPEDED, | ||
| } | ||
|
|
||
| const preloadedState = { | ||
| ...initialState, | ||
| connect: { | ||
| ...initialState.connect, | ||
| location: [{ step: STEPS.ACTIONABLE_ERROR }], | ||
| selectedInstitution: institutionData.institution, | ||
| currentMemberGuid: impededMember.guid, | ||
| members: [impededMember], | ||
| }, | ||
| } | ||
|
|
||
| const renderStepProps = { | ||
| availableAccountTypes: [], | ||
| handleConsentGoBack: vi.fn(), | ||
| handleCredentialsGoBack: vi.fn(), | ||
| navigationRef: React.createRef(), | ||
| onManualAccountAdded: vi.fn(), | ||
| onUpsertMember: vi.fn(), | ||
| setConnectLocalState: vi.fn(), | ||
| } | ||
|
|
||
| let openSpy: MockInstance<typeof window.open> | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks() | ||
| openSpy = vi.spyOn(window, 'open').mockReturnValue(null) | ||
| }) | ||
|
|
||
| afterEach(() => { | ||
| openSpy.mockRestore() | ||
| }) | ||
|
|
||
| const renderLeavingNotice = async () => { | ||
| const view = render( | ||
| <div id="connect-wrapper"> | ||
| <RenderConnectStep {...renderStepProps} /> | ||
| </div>, | ||
| { preloadedState }, | ||
| ) | ||
|
|
||
| await view.user.click(screen.getByText('Visit website')) | ||
|
|
||
| return view | ||
| } | ||
|
|
||
| describe('Content Display', () => { | ||
| it('renders the leaving notice with continue and cancel actions', async () => { | ||
| await renderLeavingNotice() | ||
|
|
||
| expect(screen.getByTestId('leaving-notice-flat-header')).toBeInTheDocument() | ||
| expect(screen.getByTestId('leaving-notice-flat-continue-button')).toBeInTheDocument() | ||
| expect(screen.getByTestId('leaving-notice-flat-cancel-button')).toBeInTheDocument() | ||
| }) | ||
| }) | ||
|
|
||
| describe('Cancel Button', () => { | ||
| it('dismisses the leaving notice and returns to the error without navigating', async () => { | ||
| const { user } = await renderLeavingNotice() | ||
|
|
||
| await user.click(screen.getByTestId('leaving-notice-flat-cancel-button')) | ||
|
|
||
| expect(await screen.findByText('Your attention is needed')).toBeInTheDocument() | ||
| expect(screen.queryByTestId('leaving-notice-flat-header')).not.toBeInTheDocument() | ||
| expect(openSpy).not.toHaveBeenCalled() | ||
| }) | ||
| }) | ||
|
|
||
| describe('Continue Button', () => { | ||
| it("opens the institution's login page in a new tab", async () => { | ||
| const { user } = await renderLeavingNotice() | ||
|
|
||
| await user.click(screen.getByTestId('leaving-notice-flat-continue-button')) | ||
|
|
||
| expect(openSpy).toHaveBeenCalledWith('https://test.com', '_blank') | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.