Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
515 changes: 87 additions & 428 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"semantic-release": "^24.2.3",
"typescript": "^5.2.2",
"typescript-eslint": "^8.2.0",
"vite": "^5.3.4",
"vite": "^7.1.2",
"vite-plugin-svgr": "^4.2.0",
"vitest": "^3.1.4"
},
Expand Down
21 changes: 17 additions & 4 deletions src/components/__tests__/DayOfMonthPicker-test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react'
import { act } from '@testing-library/react'

import { screen, render, waitFor } from 'src/utilities/testingLibrary'

Expand All @@ -14,24 +15,36 @@ const dayOfMonthPickerProps = {
}

describe('DayOfMonthPicker', () => {
beforeEach(() => {
handleClose.mockClear()
handleSelect.mockClear()
})

it('renders DayofMonthPicker and clicks a date', async () => {
const { user } = render(<DayOfMonthPicker {...dayOfMonthPickerProps} />)

expect(screen.getByText('Payment due day')).toBeInTheDocument()
expect(
screen.getByText('Choose what day of the month your payment is due.'),
).toBeInTheDocument()
await user.click(screen.getByTestId('date-picker-button-4'))
waitFor(() => {

await act(async () => {
await user.click(screen.getByTestId('date-picker-button-4'))
})

await waitFor(() => {
expect(handleSelect).toHaveBeenCalled()
})
})

it('renders DayofMonthPicker and closes it', async () => {
const { user } = render(<DayOfMonthPicker {...dayOfMonthPickerProps} />)

await user.click(screen.getByTestId('back-button'))
waitFor(() => {
await act(async () => {
await user.click(screen.getByTestId('back-button'))
})

await waitFor(() => {
expect(handleClose).toHaveBeenCalled()
})
})
Expand Down
9 changes: 6 additions & 3 deletions src/redux/reducers/Connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -560,15 +560,18 @@ const deleteMemberFromMembers = (guid, members) => members.filter((member) => me
* @param {boolean} reset This is optional, clears and sets location to only the passed step
* @returns Updated location array
*/
const pushLocation = (location, step, reset = false) =>
reset ? [{ step }] : [...location, { step }]
const pushLocation = (location, step, reset = false) => {
const locationArray = Array.isArray(location) ? location : []
return reset ? [{ step }] : [...locationArray, { step }]
}
/**
* popLocation - Util function
* @param {Array} state The current state of the application.
* @returns {Array} An array representing the new location of the user in the application.
*/
const popLocation = (state) => {
const newLocation = [...state.location]
const locationArray = Array.isArray(state.location) ? state.location : []
const newLocation = [...locationArray]

newLocation.pop()

Expand Down
71 changes: 70 additions & 1 deletion src/testSetup.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { configure } from '@testing-library/react'
import { configure, cleanup } from '@testing-library/react'
import '@testing-library/jest-dom/vitest'

// We are overriding the defaut DOM Testing Library attribute "data-testid" to be "data-test"
Expand All @@ -14,3 +14,72 @@ Object.defineProperty(global.document, 'fonts', {
},
writable: true,
})

// Mock window.open for JSDOM compatibility
Object.defineProperty(window, 'open', {
value: vi.fn(),
writable: true,
})

// Handle unhandled promise rejections in tests
const originalRejectionHandler = process.listeners('unhandledRejection')
beforeAll(() => {
process.removeAllListeners('unhandledRejection')
process.on('unhandledRejection', (reason) => {
// Only log if it's not an expected test error
if (
reason &&
typeof reason === 'object' &&
'name' in reason &&
reason.name !== 'TestingLibraryElementError'
) {
console.warn('Unhandled promise rejection in tests:', reason)
}
})
})

afterAll(() => {
process.removeAllListeners('unhandledRejection')
originalRejectionHandler.forEach((handler) => {
process.on('unhandledRejection', handler)
})
})

// Mock console.warn to suppress React act() warnings in tests
const originalWarn = console.warn
const originalError = console.error

beforeEach(() => {
console.warn = (...args: unknown[]) => {
if (
typeof args[0] === 'string' &&
args[0].includes('Warning: An update to') &&
args[0].includes('was not wrapped in act')
) {
return
}
originalWarn.call(console, ...args)
}

// Suppress Material-UI related warnings in tests
console.error = (...args: unknown[]) => {
if (
typeof args[0] === 'string' &&
(args[0].includes('Material-UI') || args[0].includes('MUI'))
) {
return
}
originalError.call(console, ...args)
}
})

afterEach(() => {
console.warn = originalWarn
console.error = originalError
// Clean up any pending timers
vi.clearAllTimers()
// Reset mocks
vi.clearAllMocks()
// Clean up DOM
cleanup()
})
32 changes: 26 additions & 6 deletions src/views/credentials/__tests__/Credentials-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,39 @@ describe('Credentials', () => {
expect(await screen.findByText('instructions')).toBeInTheDocument()
expect(await screen.findByText('do these things')).toBeInTheDocument()
})
it('renders credentials and makes sure that the powered by MX footer is present', () => {
it('renders credentials and makes sure that the powered by MX footer is present', async () => {
const ref = React.createRef()
render(<Credentials {...credentialProps} ref={ref} />, { preloadedState: initialStateCopy })
const stateWithBranding = {
...initialStateCopy,
profiles: {
...initialStateCopy.profiles,
widgetProfile: {
...initialStateCopy.profiles.widgetProfile,
show_mx_branding: true,
},
},
}
render(<Credentials {...credentialProps} ref={ref} />, { preloadedState: stateWithBranding })

waitFor(() => {
await waitFor(() => {
expect(screen.getByText('Data access by')).toBeInTheDocument()
})
})
it('renders credentials and makes sure that the powered by MX footer is not present', () => {
it('renders credentials and makes sure that the powered by MX footer is not present', async () => {
const ref = React.createRef()
render(<Credentials {...credentialProps} ref={ref} />, { preloadedState: initialStateCopy })
const stateWithoutBranding = {
...initialStateCopy,
profiles: {
...initialStateCopy.profiles,
widgetProfile: {
...initialStateCopy.profiles.widgetProfile,
show_mx_branding: false,
},
},
}
render(<Credentials {...credentialProps} ref={ref} />, { preloadedState: stateWithoutBranding })

waitFor(() => {
await waitFor(() => {
expect(screen.queryByText('Data access by')).not.toBeInTheDocument()
})
})
Expand Down
12 changes: 8 additions & 4 deletions src/views/oauth/__tests__/OAuthStep-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,20 @@ describe('OauthStep view', () => {
await user.click(loginButton)
const tryAgainButton = await screen.findByRole('button', { name: 'Try again' })
expect(tryAgainButton).toBeInTheDocument()
waitFor(
await waitFor(
async () => {
expect(tryAgainButton).not.toBeDisabled()
await user.click(tryAgainButton)
},
{ timeout: 2500 },
)
waitFor(() => {
expect(loginButton).toBeInTheDocument()
})
await waitFor(
() => {
const newLoginButton = screen.queryByTestId('continue-button')
expect(newLoginButton).toBeInTheDocument()
},
{ timeout: 3000 },
)
})
})
})
9 changes: 9 additions & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,5 +74,14 @@ export default defineConfig({
environment: 'jsdom',
setupFiles: './src/testSetup.ts',
include: ['**/*-{test,spec}.?(c|m)[jt]s?(x)'],
pool: 'forks',
poolOptions: {
forks: {
singleFork: true,
},
},
env: {
NODE_ENV: 'test',
},
},
})
Loading