Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(SILVA-502): fixing map on silviculture search screen #472

Merged
merged 13 commits into from
Nov 18, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void getRecentOpenings_fetchNoUserPaginated_shouldSucceed() {

Assertions.assertNotNull(paginatedResult);
Assertions.assertEquals(1, paginatedResult.getPageIndex());
Assertions.assertEquals(3, paginatedResult.getTotalPages());
Assertions.assertEquals(5, paginatedResult.getTotalPages());
Assertions.assertFalse(paginatedResult.getData().isEmpty());
Assertions.assertEquals(1, paginatedResult.getData().size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,24 +151,9 @@ INSERT INTO THE.RESULTS_AUDIT_EVENT
ENTRY_USERID,
ENTRY_TIMESTAMP
)
VALUES(1, 101, NULL, NULL, 'SUB', TO_DATE('2024-01-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'Forest Cover 0000000', NULL, 'Y', 101, 101, 'TEST\OTTOMATED', TO_DATE('2024-01-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'));
INSERT INTO THE.RESULTS_AUDIT_EVENT
(
RESULTS_AUDIT_EVENT_ID,
OPENING_ID,
STANDARDS_REGIME_ID,
SILVICULTURE_PROJECT_ID,
RESULTS_AUDIT_ACTION_CODE,
ACTION_DATE,
DESCRIPTION,
USER_ID,
EMAIL_SENT_IND,
XML_SUBMISSION_ID,
OPENING_AMENDMENT_NUMBER,
ENTRY_USERID,
ENTRY_TIMESTAMP
)
VALUES(2, 102, NULL, NULL, 'SUB', TO_DATE('2024-01-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'Forest Cover 0000000', NULL, 'Y', 102, 102, 'IDIR@TEST', TO_DATE('2024-01-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'));
VALUES
(1, 101, NULL, NULL, 'SUB', TO_DATE('2024-01-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'Forest Cover 0000000', NULL, 'Y', 101, 101, 'TEST\OTTOMATED', TO_DATE('2024-01-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS')),
(2, 102, NULL, NULL, 'SUB', TO_DATE('2024-01-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'), 'Forest Cover 0000000', NULL, 'Y', 102, 102, 'IDIR@TEST', TO_DATE('2024-01-20 00:00:00', 'YYYY-MM-DD HH24:MI:SS'));

INSERT INTO THE.ACTIVITY_TREATMENT_UNIT
(
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,60 @@ describe('OpeningSearchTab', () => {
await act(async () => (await screen.findByTestId('search-button')).click());
expect(screen.getByText('There are no openings to show yet')).toBeInTheDocument();
});

it('should display spatial/map view when the spatial toggle is clicked', async () => {
(useOpeningsQuery as vi.Mock).mockReturnValue({ data, isFetching: false });

await act(async() => render(
<BrowserRouter>
<QueryClientProvider client={queryClient}>
<PaginationProvider>
<OpeningsSearchProvider>
<NotificationProvider>
<OpeningSearchTab />
</NotificationProvider>
</OpeningsSearchProvider>
</PaginationProvider>
</QueryClientProvider>
</BrowserRouter>
));
const searchInput = screen.getByPlaceholderText('Search by opening ID, opening number, timber mark or file ID');
await act(async () => await userEvent.type(searchInput, 'test'));
await act(async () => (await screen.findByTestId('search-button')).click());
await act(async () => await screen.findByText('Actions'));
const spatialToggle = screen.getByTestId('toggle-spatial');
await act(async () => fireEvent.click(spatialToggle));
expect(screen.getByTestId('openings-map')).toBeInTheDocument();
});

it('should display more or less columns when checkboxes are clicked', async () => {
(useOpeningsQuery as vi.Mock).mockReturnValue({ data, isFetching: false });

let container;
await act(async() => ({ container } = render(
<BrowserRouter>
<QueryClientProvider client={queryClient}>
<PaginationProvider>
<OpeningsSearchProvider>
<NotificationProvider>
<OpeningSearchTab />
</NotificationProvider>
</OpeningsSearchProvider>
</PaginationProvider>
</QueryClientProvider>
</BrowserRouter>
)));

const searchInput = screen.getByPlaceholderText('Search by opening ID, opening number, timber mark or file ID');
await act(async () => await userEvent.type(searchInput, 'test'));
await act(async () => (await screen.findByTestId('search-button')).click());
await act(async () => await screen.findByText('Actions'));
expect(screen.getByTestId('Opening Id')).toBeInTheDocument();
const editColumnsBtn = screen.getByTestId('edit-columns');
await act(async () => fireEvent.click(editColumnsBtn));
const checkbox = container.querySelector('input[type="checkbox"]#checkbox-label-openingId');
await act(async () => fireEvent.click(checkbox));
expect(screen.queryByTestId('Opening Id')).not.toBeInTheDocument();

});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { render, screen, fireEvent } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import SearchScreenDataTable from '../../../../components/SilvicultureSearch/Openings/SearchScreenDataTable';
import { columns } from '../../../../components/SilvicultureSearch/Openings/SearchScreenDataTable/headerData';
Expand All @@ -11,6 +11,7 @@ import { OpeningsSearchProvider } from '../../../../contexts/search/OpeningsSear

const handleCheckboxChange = vi.fn();
const toggleSpatial = vi.fn();
const setOpeningIds = vi.fn((openingIds: number[]) => {});
const queryClient = new QueryClient();

export const rows:any = [
Expand Down Expand Up @@ -259,6 +260,7 @@ describe('Search Screen Data table test', () => {
handleCheckboxChange={handleCheckboxChange}
toggleSpatial={toggleSpatial}
totalItems={rows.length}
setOpeningIds={setOpeningIds}
/>
</NotificationProvider>
</OpeningsSearchProvider>
Expand Down Expand Up @@ -289,6 +291,7 @@ describe('Search Screen Data table test', () => {
handleCheckboxChange={handleCheckboxChange}
toggleSpatial={toggleSpatial}
totalItems={0}
setOpeningIds={setOpeningIds}
/>
</NotificationProvider>
</OpeningsSearchProvider>
Expand All @@ -303,7 +306,7 @@ describe('Search Screen Data table test', () => {
expect(container.querySelector('.total-search-results')).toContainHTML('0');
});

it('should render the checkbox for showSPatial being true', () => {
it('should render the checkbox for showSpatial being true', () => {
render(
<BrowserRouter>
<QueryClientProvider client={queryClient}>
Expand All @@ -318,6 +321,7 @@ describe('Search Screen Data table test', () => {
handleCheckboxChange={handleCheckboxChange}
toggleSpatial={toggleSpatial}
totalItems={0}
setOpeningIds={setOpeningIds}
/>
</NotificationProvider>
</OpeningsSearchProvider>
Expand All @@ -329,6 +333,40 @@ describe('Search Screen Data table test', () => {
expect(checkbox).toBeInTheDocument();

});

it('should check the checkbox for showSpatial', () => {
render(
<BrowserRouter>
<QueryClientProvider client={queryClient}>
<PaginationProvider>
<OpeningsSearchProvider>
<NotificationProvider>
<SearchScreenDataTable
rows={rows}
headers={columns}
defaultColumns={columns}
showSpatial={true}
handleCheckboxChange={handleCheckboxChange}
toggleSpatial={toggleSpatial}
totalItems={rows.length}
setOpeningIds={setOpeningIds}
/>
</NotificationProvider>
</OpeningsSearchProvider>
</PaginationProvider>
</QueryClientProvider>
</BrowserRouter>
);
const checkboxGroup = document.querySelector('.cds--checkbox-group');
expect(checkboxGroup).toBeInTheDocument();

expect(screen.getByTestId(`checkbox-${rows[0].openingId}`)).toBeInTheDocument();
const checkbox = screen.getByTestId(`checkbox-${rows[0].openingId}`);
fireEvent.click(checkbox);
expect(checkbox).toBeChecked();
expect(setOpeningIds).toHaveBeenCalledWith([parseFloat(rows[0].openingId)]);

});


});
4 changes: 1 addition & 3 deletions frontend/src/components/FriendlyDate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ const FriendlyDate: React.FC<FriendlyDateProps> = ({ date }) => {
const formattedDate = isFuture(parsedDate)
? formatFutureDateAtlassianStyle(parsedDate)
: formatDateAtlassianStyle(parsedDate);

if(cleanDate === formattedDate)
console.log(`cleanDate: ${cleanDate} formattedDate: ${formattedDate}`);

return (
<>
{(cleanDate === formattedDate) ? (<span>{formattedDate}</span>) : (
Expand Down
Loading
Loading