Skip to content

Commit

Permalink
fix: resolve failing front-end tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hamed-valiollahi committed Jan 14, 2025
1 parent 336ed05 commit ec8733c
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 0 deletions.
6 changes: 6 additions & 0 deletions frontend/src/components/__tests__/Logout.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import {
} from '@testing-library/react'
import { describe, vi } from 'vitest'

vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({
setForbidden: vi.fn()
})
}))

const keycloak = vi.hoisted(() => ({
useKeycloak: vi.fn()
}))
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/__tests__/RequireAuth.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ const keycloak = vi.hoisted(() => ({
}))
vi.mock('@react-keycloak/web', () => keycloak)

vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({
setForbidden: vi.fn()
})
}))

describe('RequireAuth', () => {
afterEach(() => {
vi.resetAllMocks()
Expand Down
6 changes: 6 additions & 0 deletions frontend/src/components/__tests__/Role.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ vi.mock('@react-keycloak/web', () => ({
})
}))

vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({
setForbidden: vi.fn()
})
}))

describe('Role.jsx', () => {
describe('currentUser is null', () => {
it('should render loading', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ vi.mock('@react-keycloak/web', () => ({
})
}))

vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({
setForbidden: vi.fn()
})
}))

describe('Navbar', () => {
const mockUser = {
isGovernmentUser: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ vi.mock('@/components/BCDataGrid/BCGridEditor', () => ({
)
}))

vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({
setForbidden: vi.fn()
})
}))

describe('AddEditAllocationAgreements', () => {
beforeEach(() => {
vi.resetAllMocks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ vi.mock('react-i18next', () => ({
})
}))

vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({
setForbidden: vi.fn()
})
}))

describe('AssessmentCard', () => {
const mockHistory = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ vi.mock('@mui/material', async (importOriginal) => {
}
})

vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({
setForbidden: vi.fn()
})
}))

describe('ComplianceReportSummary', () => {
const mockReportID = '123'
const mockSetHasMet = vi.fn() // Mock setHasMet function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ vi.mock('@/components/BCDataGrid/BCDataGridServer', () => ({
default: () => <div data-test="mockedBCDataGridServer"></div>
}))

vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({
setForbidden: vi.fn()
})
}))

const WrapperComponent = (props) => {
const queryClient = new QueryClient()
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,12 @@ vi.mock('@/hooks/useOrganization', () => ({
})
}))

vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({
setForbidden: vi.fn()
})
}))

const renderComponent = (
handleMode = 'edit',
txnType = INITIATIVE_AGREEMENT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ vi.mock('@react-keycloak/web', () => ({
})
}))

vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({
setForbidden: vi.fn()
})
}))

const renderComponent = (props) => {
const queryClient = new QueryClient()
return render(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ vi.mock('@mui/material', async (importOriginal) => {
}
})

vi.mock('@/contexts/AuthContext', () => ({
useAuth: () => ({
setForbidden: vi.fn()
})
}))

describe('TransferDetailsCard Component', () => {
const mockUseTheme = {
breakpoints: {
Expand Down

0 comments on commit ec8733c

Please sign in to comment.