chore: Enhance backend test coverage and add new functional tests for Security page
- Added tests to `proxyhost_service_validation_test.go` to validate fallback parsing and handle invalid hostname characters. - Introduced new tests for DNS challenge validation in `proxyhost_service_validation_test.go`. - Updated `current_spec.md` to reflect changes in testing strategy and coverage goals for PR #729. - Enhanced `Security.functional.test.tsx` to include navigation test for Notifications button. - Mocked `useNavigate` from `react-router-dom` to verify navigation behavior in Security page tests.
This commit is contained in:
@@ -14,6 +14,16 @@ import * as securityApi from '../../api/security'
|
||||
import * as crowdsecApi from '../../api/crowdsec'
|
||||
import * as settingsApi from '../../api/settings'
|
||||
|
||||
const mockNavigate = vi.hoisted(() => vi.fn())
|
||||
|
||||
vi.mock('react-router-dom', async () => {
|
||||
const actual = await vi.importActual<typeof import('react-router-dom')>('react-router-dom')
|
||||
return {
|
||||
...actual,
|
||||
useNavigate: () => mockNavigate,
|
||||
}
|
||||
})
|
||||
|
||||
vi.mock('../../api/security')
|
||||
vi.mock('../../api/crowdsec')
|
||||
vi.mock('../../api/settings')
|
||||
@@ -168,6 +178,7 @@ describe('Security Page - Functional Tests', () => {
|
||||
},
|
||||
})
|
||||
vi.clearAllMocks()
|
||||
mockNavigate.mockReset()
|
||||
vi.mocked(crowdsecApi.statusCrowdsec).mockResolvedValue({ running: false, pid: 0, lapi_ready: false })
|
||||
vi.mocked(settingsApi.updateSetting).mockResolvedValue()
|
||||
})
|
||||
@@ -433,6 +444,21 @@ describe('Security Page - Functional Tests', () => {
|
||||
expect(screen.getByRole('button', { name: /Notifications/i })).not.toBeDisabled()
|
||||
})
|
||||
})
|
||||
|
||||
it('should navigate to notifications settings when Notifications button is clicked', async () => {
|
||||
const user = userEvent.setup()
|
||||
vi.mocked(securityApi.getSecurityStatus).mockResolvedValue(mockSecurityStatusAllEnabled)
|
||||
|
||||
await renderSecurityPage()
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('button', { name: /Notifications/i })).toBeInTheDocument()
|
||||
})
|
||||
|
||||
await user.click(screen.getByRole('button', { name: /Notifications/i }))
|
||||
|
||||
expect(mockNavigate).toHaveBeenCalledWith('/settings/notifications')
|
||||
})
|
||||
})
|
||||
|
||||
// NOTE: CrowdSec Bouncer Key Display moved to CrowdSecConfig page (Sprint 3)
|
||||
|
||||
Reference in New Issue
Block a user