generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added test for the recentOpeningData table
- Loading branch information
1 parent
b540db6
commit 7b27b18
Showing
4 changed files
with
149 additions
and
104 deletions.
There are no files selected for viewing
96 changes: 0 additions & 96 deletions
96
backend/src/test/java/ca/bc/gov/restapi/results/oracle/endpoint/OpeningEndpointTest.java
This file was deleted.
Oops, something went wrong.
111 changes: 111 additions & 0 deletions
111
frontend/src/__test__/components/Dashboard/Opening/RecentOpeningsDataTable.test.tsx
This file contains 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,111 @@ | ||
// src/__test__/components/SilvicultureSearch/Openings/OpeningsSearchBar.test.tsx | ||
|
||
import React from "react"; | ||
import { render, screen } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import OpeningsSearchBar from "../../../../components/SilvicultureSearch/Openings/OpeningsSearchBar"; | ||
import { vi } from "vitest"; | ||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
import { OpeningsSearchProvider } from "../../../../contexts/search/OpeningsSearch"; | ||
import { Pagination } from "@carbon/react"; | ||
import {Provider } from "react-redux"; | ||
import PaginationProvider from "../../../../contexts/PaginationProvider"; | ||
import RecentOpeningsDataTable from "../../../../components/Dashboard/Opening/RecentOpeningsDataTable"; | ||
import { MemoryRouter } from "react-router-dom"; | ||
|
||
describe("OpeningsSearchBar", () => { | ||
// Create a new QueryClient instance for each test | ||
const queryClient = new QueryClient(); | ||
const handleCheckboxChange = vi.fn() | ||
const setLoadId = vi.fn() | ||
const toggleSpatial = vi.fn() | ||
const showSpatial = false | ||
const data = { data: [], perPage: 0, totalPages: 0 } | ||
const headers = [] | ||
|
||
it("renders the blank table when data array is empty", () => { | ||
render( | ||
<MemoryRouter> | ||
<QueryClientProvider client={queryClient}> | ||
<PaginationProvider> | ||
<RecentOpeningsDataTable | ||
rows={data?.data || []} | ||
headers={headers} | ||
defaultColumns={headers} | ||
handleCheckboxChange={handleCheckboxChange} | ||
setOpeningId={setLoadId} | ||
toggleSpatial={toggleSpatial} | ||
showSpatial={showSpatial} | ||
totalItems={(data?.perPage ?? 0) * (data?.totalPages ?? 0)} | ||
/> | ||
</PaginationProvider> | ||
</QueryClientProvider> | ||
</MemoryRouter> | ||
); | ||
// Check if the search input field is present with the correct placeholder text | ||
const searchInput = screen.getByText(/Total Search Results: 0/i); | ||
expect(searchInput).toBeInTheDocument(); | ||
}); | ||
|
||
it("renders the table with data", () => { | ||
const data = { data: [{ | ||
"openingId": 114203, | ||
"forestFileId": "TFL47", | ||
"categoryCode": "FTML", | ||
"categoryDescription": null, | ||
"statusCode": "Active", | ||
"statusDescription": "Active", | ||
"cuttingPermitId": "12T", | ||
"cutBlockId": "12-44A", | ||
"orgUnitName": "DCC - Cariboo chilcotin natural resources", | ||
"updateTimestamp": "2021-12-08" | ||
}], perPage: 1, totalPages: 1 } | ||
const headers = [{ | ||
key: 'openingId', | ||
header: 'Opening Id', | ||
selected: false | ||
}, | ||
{ | ||
key: 'forestFileId', | ||
header: 'File Id', | ||
selected: false | ||
}, | ||
{ | ||
key: 'cuttingPermit', | ||
header: 'Cutting permit', | ||
selected: false | ||
}, | ||
{ | ||
key: 'timberMark', | ||
header: 'Timber mark', | ||
selected: false | ||
}, | ||
{ | ||
key: 'cutBlock', | ||
header: 'Cut block', | ||
selected: false | ||
},] | ||
render( | ||
<MemoryRouter> | ||
<QueryClientProvider client={queryClient}> | ||
<PaginationProvider> | ||
<RecentOpeningsDataTable | ||
rows={data?.data || []} | ||
headers={headers} | ||
defaultColumns={headers} | ||
handleCheckboxChange={handleCheckboxChange} | ||
setOpeningId={setLoadId} | ||
toggleSpatial={toggleSpatial} | ||
showSpatial={showSpatial} | ||
totalItems={(data?.perPage ?? 0) * (data?.totalPages ?? 0)} | ||
/> | ||
</PaginationProvider> | ||
</QueryClientProvider> | ||
</MemoryRouter> | ||
); | ||
console.log(screen.debug()) | ||
// Check if the search input field is present with the correct placeholder text | ||
const searchInput = screen.getByText(/Total Search Results: 1/i); | ||
expect(searchInput).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains 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,38 @@ | ||
import { describe, it, expect } from 'vitest'; | ||
import { formatDate, dateStringToISO } from '../../utils/DateUtils'; | ||
|
||
describe('formatDate', () => { | ||
it('should format a valid date string to "Month Day, Year"', () => { | ||
const result = formatDate('2023-11-05'); | ||
expect(result).toBe('November 5, 2023'); | ||
}); | ||
|
||
it('should return "--" for an empty string', () => { | ||
const result = formatDate(''); | ||
expect(result).toBe('--'); | ||
}); | ||
|
||
it('should return "--" for a null value', () => { | ||
// @ts-ignore | ||
const result = formatDate(null); | ||
expect(result).toBe('--'); | ||
}); | ||
}); | ||
|
||
describe('dateStringToISO', () => { | ||
it('should convert a date string to ISO format', () => { | ||
const result = dateStringToISO('2023-11-05'); | ||
expect(result).toBe('2023-11-05T00:00:00.000Z'); | ||
}); | ||
|
||
it('should return an empty string for an invalid date', () => { | ||
const result = dateStringToISO(''); | ||
expect(result).toBe(''); | ||
}); | ||
|
||
it('should return an empty string for a null value', () => { | ||
// @ts-ignore | ||
const result = dateStringToISO(null); | ||
expect(result).toBe(''); | ||
}); | ||
}); |
This file contains 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