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

feat(SILVA-570): recent openings history for the nr-silva application front-end Only #463

Merged
merged 37 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
3f4f9bd
added the PUT request query for recording user recent openings when c…
jazzgrewal Nov 12, 2024
a297fb3
added the recent Openings view table component
jazzgrewal Nov 13, 2024
6e3c63a
added recent openings test from previous pr
jazzgrewal Nov 13, 2024
fc8c106
Merge branch 'main' into feat/userRecentOpeningsFront
jazzgrewal Nov 13, 2024
a01e6cb
fixed test files
jazzgrewal Nov 13, 2024
bf9c41b
Merge branch 'main' into feat/userRecentOpeningsFront
jazzgrewal Nov 13, 2024
f99932f
fixed the cuttingPermit line
jazzgrewal Nov 13, 2024
7c3c791
fixed SearchScreenDataTable test
jazzgrewal Nov 13, 2024
bac31bb
fixed the test for the OpeningSearchTab.test
jazzgrewal Nov 13, 2024
4bd9db1
removed the test for deleted component openingScreenDataTable
jazzgrewal Nov 13, 2024
825fdd0
fix(SILVA-550): added description to orgunit and category (#457)
paulushcgcj Nov 13, 2024
fcb0e44
fix(SILVA-567): fixing label (#465)
paulushcgcj Nov 13, 2024
bc2c547
fix(SILVA-538): fixing checkbox label (#466)
paulushcgcj Nov 13, 2024
a152a9d
added the PUT request query for recording user recent openings when c…
jazzgrewal Nov 12, 2024
3dbe899
added the recent Openings view table component
jazzgrewal Nov 13, 2024
28c2cd5
Merge branch 'main' into feat/userRecentOpeningsFront
jazzgrewal Nov 13, 2024
7b97015
fixed the build issue, setOpeningId not required
jazzgrewal Nov 13, 2024
becdc28
added test for OpeningsTab
jazzgrewal Nov 14, 2024
36cd8db
added the test file for dashboardQueries
jazzgrewal Nov 14, 2024
e9e4d0d
swtiched to Notification context for following notifications
jazzgrewal Nov 14, 2024
96029c1
removed the toasText
jazzgrewal Nov 14, 2024
cb3d619
cgheck if table is rendered test
jazzgrewal Nov 14, 2024
7bd6d7d
added more test for the opening.tst file
jazzgrewal Nov 14, 2024
f51de24
testing the column data
jazzgrewal Nov 14, 2024
0172b33
removed lil unreachable code
jazzgrewal Nov 14, 2024
d04f728
added more checks in the recentOpening table test
jazzgrewal Nov 14, 2024
c2f14d0
resolved import for testData
jazzgrewal Nov 14, 2024
b5237ec
added moretests
jazzgrewal Nov 14, 2024
5e78e42
Merge branch 'main' into feat/userRecentOpeningsFront
paulushcgcj Nov 14, 2024
0a69402
removed the nested ternory making code more readable ans split into s…
jazzgrewal Nov 14, 2024
cc4ff7a
added more test and resolve headerData duplication
jazzgrewal Nov 14, 2024
f0c1e3c
Merge branch 'main' into feat/userRecentOpeningsFront
jazzgrewal Nov 14, 2024
a5f0fd1
added the truncatedText, and changed test for that
jazzgrewal Nov 14, 2024
3c4e989
made flyway changes and some resolutions
jazzgrewal Nov 14, 2024
043719b
resolved all conversations from Paulo
jazzgrewal Nov 14, 2024
229ad5d
updated imports
jazzgrewal Nov 14, 2024
8ca2443
changed the way env is consumed
jazzgrewal Nov 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 127 additions & 51 deletions frontend/package-lock.json

Large diffs are not rendered by default.

39 changes: 39 additions & 0 deletions frontend/src/__test__/components/ActionButtons.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// ActionButtons.test.tsx
import React from "react";
import { vi } from "vitest";
import { render, screen, fireEvent } from "@testing-library/react";
import ActionButtons from "../../components/ActionButtons";

// Mock console.log
const consoleLogMock = vi.spyOn(console, "log").mockImplementationOnce(() =>vi.fn()) ;

afterEach(() => {
consoleLogMock.mockClear();
});

afterAll(() => {
consoleLogMock.mockRestore();
});

describe("ActionButtons", () => {
const rowId = "test-row-id";

it("renders the 'View' and 'Document Download' buttons", () => {
render(<ActionButtons rowId={rowId} />);

// Check that both buttons are in the document
expect(screen.getByRole("button", { name: /View/i })).toBeInTheDocument();
expect(screen.getByRole("button", { name: /Document Download/i })).toBeInTheDocument();
});

it("calls console.log with rowId when the 'View' button is clicked", () => {
render(<ActionButtons rowId={rowId} />);

// Find the "View" button and click it
const viewButton = screen.getByRole("button", { name: /View/i });
fireEvent.click(viewButton);

// Check if console.log was called with the correct rowId
expect(consoleLogMock).toHaveBeenCalledWith(rowId);
});
});
52 changes: 33 additions & 19 deletions frontend/src/__test__/components/BarChartGrouped.test.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { render, screen } from '@testing-library/react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import BarChartGrouped from '../../components/BarChartGrouped';
import { fetchOpeningsPerYear } from '../../services/OpeningService';

vi.mock('../../services/OpeningService', () => ({
fetchOpeningsPerYear: vi.fn(() => Promise.resolve([
{ group: '2022', key: 'Openings', value: 10 },
{ group: '2023', key: 'Openings', value: 15 },
])),
import { useDistrictListQuery, useFetchOpeningsPerYear } from '../../services/queries/dashboard/dashboardQueries';
import { describe, expect, it } from 'vitest';
import { vi } from 'vitest';
import '@testing-library/jest-dom';
// Mock the hook
vi.mock('../../services/queries/dashboard/dashboardQueries', () => ({
useFetchOpeningsPerYear: vi.fn(),
useDistrictListQuery: vi.fn(),
}));

describe('BarChartGrouped component tests', () => {
it('should render loading state while fetching data and clean it after', async () => {
render(<BarChartGrouped />);
const queryClient = new QueryClient();

const element = await waitFor(() => screen.getByText('Loading...'));
describe('BarChartGrouped component', () => {
it('should display loading state when data is fetching', () => {
// Mock loading state for openings data
(useFetchOpeningsPerYear as any).mockReturnValue({
data: [],
isLoading: true,
});

expect(element).toBeDefined();

expect(fetchOpeningsPerYear).toHaveBeenCalled();
expect(screen.queryByTestId('bar-chart')).toBeDefined();
});
// If you're using useDistrictListQuery, mock it too
(useDistrictListQuery as any).mockReturnValue({
data: [],
isLoading: false,
});

});
render(
<QueryClientProvider client={queryClient}>
<BarChartGrouped />
</QueryClientProvider>
);

// Check if loading text is displayed
expect(screen.getByText('Loading...')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// 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 { vi } from "vitest";
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import PaginationProvider from "../../../../contexts/PaginationProvider";
import RecentOpeningsDataTable from "../../../../components/Dashboard/Opening/RecentOpeningsDataTable";
import { MemoryRouter } from "react-router-dom";
import exp from "constants";

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("shows appropriate message when no data is in the table", () => {
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>
);
expect(screen.getByText(/There are no openings to show yet/i)).toBeInTheDocument();
expect(screen.queryByText(/Your recent openings will appear here once you generate one/i)).toBeInTheDocument();
});

it("renders a blank table when rows is empty array", () => {
render(
<MemoryRouter>
<QueryClientProvider client={queryClient}>
<PaginationProvider>
<RecentOpeningsDataTable
rows={[]}
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 table is present
const table = screen.getByRole('table');
expect(table).toBeInTheDocument();
});
});

This file was deleted.

73 changes: 53 additions & 20 deletions frontend/src/__test__/components/OpeningsTab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { render, act, waitFor, screen } from '@testing-library/react';
import OpeningsTab from '../../components/OpeningsTab';
import { AuthProvider } from '../../contexts/AuthProvider';
import { getWmsLayersWhitelistUsers } from '../../services/SecretsService';
import { fetchRecentOpenings } from '../../services/OpeningService';
import { RecentOpening } from '../../types/RecentOpening';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import PaginationProvider from '../../contexts/PaginationProvider';


Expand All @@ -20,32 +19,66 @@ vi.mock('../../services/OpeningService', async () => {
fetchRecentOpenings: vi.fn(),
};
});


const rows: RecentOpening[] = [{
id: '123',
openingId: '123',
fileId: '1',
cuttingPermit: '1',
timberMark: '1',
cutBlock: '1',
grossAreaHa: 1,
statusDesc: 'Approved',
categoryDesc: 'Another:Another',
disturbanceStart: '1',
entryTimestamp: '1',
updateTimestamp: '1',
}];
const queryClient = new QueryClient();

describe('Openings Tab test',() => {

it('should render properly',async () =>{
(getWmsLayersWhitelistUsers as vi.Mock).mockResolvedValue([{userName: 'TEST'}]);
(fetchRecentOpenings as vi.Mock).mockResolvedValue(rows);

await act(async () => {
render(<AuthProvider><PaginationProvider><OpeningsTab showSpatial={false} setShowSpatial={vi.fn()}/></PaginationProvider></AuthProvider>);
render(
<AuthProvider>
<QueryClientProvider client={queryClient}>
<PaginationProvider>
<OpeningsTab showSpatial={false} setShowSpatial={vi.fn()} />
</PaginationProvider>
</QueryClientProvider>
</AuthProvider>
);
});
expect(screen.getByText('Recent openings')).toBeInTheDocument();
});

it('should have Hide map when the showSpatial is true',async () =>{
(getWmsLayersWhitelistUsers as vi.Mock).mockResolvedValue([{userName: 'TEST'}]);

await act(async () => {
render(
<AuthProvider>
<QueryClientProvider client={queryClient}>
<PaginationProvider>
<OpeningsTab showSpatial={true} setShowSpatial={vi.fn()} />
</PaginationProvider>
</QueryClientProvider>
</AuthProvider>
);
});
expect(screen.getByText('Hide map')).toBeInTheDocument();
});

it('should render the table', async () => {
// Mocking state values
vi.spyOn(React, 'useState')
.mockImplementationOnce(() => [null, vi.fn()]) // for loadId
.mockImplementationOnce(() => [true, vi.fn()]) // for openingPolygonNotFound
.mockImplementationOnce(() => [{ userName: 'TEST' }, vi.fn()]) // for wmsUsersWhitelist
.mockImplementationOnce(() => [[], vi.fn()]); // for headers

(getWmsLayersWhitelistUsers as vi.Mock).mockResolvedValue([{ userName: 'TEST' }]);

await act(async () => {
render(
<AuthProvider>
<QueryClientProvider client={queryClient}>
<PaginationProvider>
<OpeningsTab showSpatial={true} setShowSpatial={vi.fn()} />
</PaginationProvider>
</QueryClientProvider>
</AuthProvider>
);
});
expect(screen.getByRole('table')).toBeInTheDocument();
});

});
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,6 @@ describe('OpeningSearchTab', () => {
const searchInput = screen.getByPlaceholderText('Search by opening ID, opening number, timber mark or file ID');
await act(async () => await userEvent.type(searchInput, 'potato'));
await act(async () => (await screen.findByTestId('search-button')).click());
expect(screen.getByText('Results not found')).toBeInTheDocument();
expect(screen.getByText('There are no openings to show yet')).toBeInTheDocument();
});
});
Loading
Loading