-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
2. formatting changes and consolidating some additional data 3. datagrid column arrays are in process of being moved into separate .tsx file so that Typography formatting can be applied to headers when needed (if column names are too large, etc) 4. Updated personnel fixeddata and cmprevalidation API endpoints to correctly work with updated PersonnelRDS type/table 5. Playwright initialization added and setup. No tests currently added, but future proofing for use. 6. RolloverModal added to handle rollover process when creating a new census. Allows users to selectively choose personnel OR quadrats to rollover from one OR more past censuses (where data is present). 7. Instead of discarding testing component file, was instead converted into the RolloverStemsModal. Its function has not been enabled but has been integrated. Allows users to additionally rollover stems data if needed ONLY if quadrats data is already being rolled over. Still needs to be fully tested and repaired (assuming bugs are present) 8. area selection options macro added now that dedicated selection array for area measurements added SQL-side.
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
import RolloverModal from '@/components/client/rollovermodal'; | ||
import { render, screen, fireEvent, waitFor } from '@testing-library/react'; | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
|
||
// Mock the fetch API | ||
global.fetch = vi.fn(); | ||
|
||
// Mock contexts | ||
vi.mock('@/app/contexts/userselectionprovider', () => ({ | ||
useSiteContext: () => ({ schemaName: 'testSchema' }), | ||
usePlotContext: () => ({ plotID: 1 }), | ||
})); | ||
vi.mock('@/app/contexts/listselectionprovider', () => ({ | ||
useOrgCensusListContext: () => [ | ||
{ plotCensusNumber: 1, dateRanges: [{ censusID: 1 }] }, | ||
{ plotCensusNumber: 2, dateRanges: [{ censusID: 2 }] }, | ||
], | ||
})); | ||
|
||
// Mock Data | ||
const previousPersonnel = [ | ||
{ personnelID: 1, name: 'Person 1' }, | ||
{ personnelID: 2, name: 'Person 2' }, | ||
]; | ||
const previousQuadrats = [ | ||
{ quadratID: 1, name: 'Quadrat 1' }, | ||
{ quadratID: 2, name: 'Quadrat 2' }, | ||
]; | ||
|
||
describe('RolloverModal Component', () => { | ||
const setup = (props = {}) => render( | ||
<RolloverModal | ||
open={true} | ||
onClose={vi.fn()} | ||
onConfirm={vi.fn()} | ||
{...props} | ||
/> | ||
); | ||
|
||
beforeEach(() => { | ||
(global.fetch as jest.Mock).mockClear(); | ||
|
||
(global.fetch as jest.Mock).mockImplementation((url: string) => { | ||
if (url.includes('/fetchall/personnel/')) { | ||
return Promise.resolve({ | ||
status: 200, | ||
json: () => Promise.resolve(previousPersonnel), | ||
}); | ||
} | ||
if (url.includes('/fetchall/quadrats/')) { | ||
return Promise.resolve({ | ||
status: 200, | ||
json: () => Promise.resolve(previousQuadrats), | ||
}); | ||
} | ||
if (url.includes('/cmprevalidation/personnel/')) { | ||
return Promise.resolve({ | ||
status: 200, | ||
}); | ||
} | ||
if (url.includes('/cmprevalidation/quadrats/')) { | ||
return Promise.resolve({ | ||
status: 200, | ||
}); | ||
} | ||
return Promise.reject(new Error('Unknown API call')); | ||
}); | ||
}); | ||
|
||
it('should open modal and display title', async () => { | ||
setup(); | ||
await waitFor(() => { | ||
expect(screen.getByText(/Rollover Census Data/i)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should show error if no checkbox is selected and confirm is pressed', async () => { | ||
setup(); | ||
fireEvent.click(screen.getByText(/Confirm/i)); | ||
Check failure on line 79 in frontend/__tests__/rollovermodal.test.tsx GitHub Actions / build-and-deploy__tests__/rollovermodal.test.tsx > RolloverModal Component > should show error if no checkbox is selected and confirm is pressed
|
||
await waitFor(() => { | ||
expect(screen.getByText(/You must select at least one option to roll over or confirm no rollover/i)).toBeInTheDocument(); | ||
}); | ||
}); | ||
|
||
it('should allow selecting and confirming personnel rollover', async () => { | ||
setup(); | ||
await waitFor(() => { | ||
Check failure on line 87 in frontend/__tests__/rollovermodal.test.tsx GitHub Actions / build-and-deploy__tests__/rollovermodal.test.tsx > RolloverModal Component > should allow selecting and confirming personnel rollover
|
||
fireEvent.click(screen.getByLabelText(/Roll over personnel data/i)); | ||
}); | ||
fireEvent.click(screen.getByText(/Confirm/i)); | ||
await waitFor(() => { | ||
expect(screen.queryByText(/You must select at least one option to roll over or confirm no rollover/i)).toBeNull(); | ||
}); | ||
}); | ||
|
||
it('should allow selecting and confirming quadrats rollover', async () => { | ||
setup(); | ||
await waitFor(() => { | ||
Check failure on line 98 in frontend/__tests__/rollovermodal.test.tsx GitHub Actions / build-and-deploy__tests__/rollovermodal.test.tsx > RolloverModal Component > should allow selecting and confirming quadrats rollover
|
||
fireEvent.click(screen.getByLabelText(/Roll over quadrats data/i)); | ||
}); | ||
fireEvent.click(screen.getByText(/Confirm/i)); | ||
await waitFor(() => { | ||
expect(screen.queryByText(/You must select at least one option to roll over or confirm no rollover/i)).toBeNull(); | ||
}); | ||
}); | ||
|
||
it('should allow selecting and confirming both personnel and quadrats rollover', async () => { | ||
setup(); | ||
await waitFor(() => { | ||
Check failure on line 109 in frontend/__tests__/rollovermodal.test.tsx GitHub Actions / build-and-deploy__tests__/rollovermodal.test.tsx > RolloverModal Component > should allow selecting and confirming both personnel and quadrats rollover
|
||
fireEvent.click(screen.getByLabelText(/Roll over personnel data/i)); | ||
fireEvent.click(screen.getByLabelText(/Roll over quadrats data/i)); | ||
}); | ||
fireEvent.click(screen.getByText(/Confirm/i)); | ||
await waitFor(() => { | ||
expect(screen.queryByText(/You must select at least one option to roll over or confirm no rollover/i)).toBeNull(); | ||
}); | ||
}); | ||
|
||
it('should allow customizing personnel selection', async () => { | ||
setup(); | ||
await waitFor(() => { | ||
Check failure on line 121 in frontend/__tests__/rollovermodal.test.tsx GitHub Actions / build-and-deploy__tests__/rollovermodal.test.tsx > RolloverModal Component > should allow customizing personnel selection
|
||
fireEvent.click(screen.getByLabelText(/Roll over personnel data/i)); | ||
fireEvent.click(screen.getByText(/Customize personnel selection/i)); | ||
}); | ||
expect(screen.getByText(/Person 1/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Person 2/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should allow customizing quadrats selection', async () => { | ||
setup(); | ||
await waitFor(() => { | ||
Check failure on line 131 in frontend/__tests__/rollovermodal.test.tsx GitHub Actions / build-and-deploy__tests__/rollovermodal.test.tsx > RolloverModal Component > should allow customizing quadrats selection
|
||
fireEvent.click(screen.getByLabelText(/Roll over quadrats data/i)); | ||
fireEvent.click(screen.getByText(/Customize quadrats selection/i)); | ||
}); | ||
expect(screen.getByText(/Quadrat 1/i)).toBeInTheDocument(); | ||
expect(screen.getByText(/Quadrat 2/i)).toBeInTheDocument(); | ||
}); | ||
|
||
it('should confirm no rollover for personnel', async () => { | ||
setup(); | ||
fireEvent.mouseDown(screen.getByLabelText(/Do not roll over any Personnel data/i)); | ||
Check failure on line 141 in frontend/__tests__/rollovermodal.test.tsx GitHub Actions / build-and-deploy__tests__/rollovermodal.test.tsx > RolloverModal Component > should confirm no rollover for personnel
|
||
fireEvent.click(screen.getByText(/Confirm No Rollover/i)); | ||
fireEvent.click(screen.getByText(/Confirm/i)); | ||
await waitFor(() => { | ||
expect(screen.queryByText(/You must select at least one option to roll over or confirm no rollover/i)).toBeNull(); | ||
}); | ||
}); | ||
|
||
it('should confirm no rollover for quadrats', async () => { | ||
setup(); | ||
fireEvent.mouseDown(screen.getByLabelText(/Do not roll over any Quadrats data/i)); | ||
Check failure on line 151 in frontend/__tests__/rollovermodal.test.tsx GitHub Actions / build-and-deploy__tests__/rollovermodal.test.tsx > RolloverModal Component > should confirm no rollover for quadrats
|
||
fireEvent.click(screen.getByText(/Confirm No Rollover/i)); | ||
fireEvent.click(screen.getByText(/Confirm/i)); | ||
await waitFor(() => { | ||
expect(screen.queryByText(/You must select at least one option to roll over or confirm no rollover/i)).toBeNull(); | ||
}); | ||
}); | ||
|
||
it('should handle error during fetch data', async () => { | ||
(global.fetch as jest.Mock).mockImplementationOnce(() => Promise.reject(new Error('Failed to fetch'))); | ||
Check failure on line 160 in frontend/__tests__/rollovermodal.test.tsx GitHub Actions / build-and-deployUnhandled error
|
||
setup(); | ||
await waitFor(() => { | ||
Check failure on line 162 in frontend/__tests__/rollovermodal.test.tsx GitHub Actions / build-and-deploy__tests__/rollovermodal.test.tsx > RolloverModal Component > should handle error during fetch data
|
||
expect(screen.getByText(/Failed to fetch previous data. Please try again/i)).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |