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

PSP-9923, PSP-9924 Fix UTC dates in Research Files and Notes #4651

Merged
merged 7 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@
using MapsterMapper;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Pims.Core.Api.Exceptions;
using Pims.Api.Models.Concepts.ResearchFile;
using Pims.Core.Api.Policies;
using Pims.Api.Services;
using Pims.Core.Api.Exceptions;
using Pims.Core.Api.Policies;
using Pims.Core.Json;
using Pims.Core.Security;
using Pims.Dal.Entities;
using Pims.Dal.Exceptions;
using Pims.Core.Security;
using Swashbuckle.AspNetCore.Annotations;
using Pims.Core.Api.Exceptions;

namespace Pims.Api.Areas.ResearchFile.Controllers
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ namespace Pims.Api.Areas.Research.Controllers
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.AspNetCore.Mvc;
using Pims.Api.Areas.Research.Models.Search;
using Pims.Core.Api.Exceptions;
using Pims.Api.Helpers.Extensions;
using Pims.Api.Models.Base;
using Pims.Api.Models.Concepts.ResearchFile;
using Pims.Core.Api.Policies;
using Pims.Api.Services;
using Pims.Core.Api.Exceptions;
using Pims.Core.Api.Policies;
using Pims.Core.Json;
using Pims.Dal.Entities.Models;
using Pims.Core.Security;
using Pims.Dal.Entities.Models;
using Swashbuckle.AspNetCore.Annotations;

/// <summary>
Expand Down
7 changes: 3 additions & 4 deletions source/frontend/src/AppRouter.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,20 @@ import { useApiGeocoder } from './hooks/pims-api/useApiGeocoder';
import { useApiLeases } from './hooks/pims-api/useApiLeases';
import { useApiProperties } from './hooks/pims-api/useApiProperties';
import { useApiResearchFile } from './hooks/pims-api/useApiResearchFile';
import { useApiTenants } from './hooks/pims-api/useApiTenants';
import { useApiUsers } from './hooks/pims-api/useApiUsers';
import { IResearchSearchResult } from './interfaces/IResearchSearchResult';
import { mockLookups } from './mocks/lookups.mock';
import { getMockPagedUsers, getUserMock } from './mocks/user.mock';
import { ApiGen_Base_Page } from './models/api/generated/ApiGen_Base_Page';
import { ApiGen_Concepts_AcquisitionFile } from './models/api/generated/ApiGen_Concepts_AcquisitionFile';
import { ApiGen_Concepts_Lease } from './models/api/generated/ApiGen_Concepts_Lease';
import { ApiGen_Concepts_Property } from './models/api/generated/ApiGen_Concepts_Property';
import { ApiGen_Concepts_ResearchFile } from './models/api/generated/ApiGen_Concepts_ResearchFile';
import { lookupCodesSlice } from './store/slices/lookupCodes';
import { networkSlice } from './store/slices/network/networkSlice';
import { tenantsSlice, useTenants } from './store/slices/tenants';
import { defaultTenant } from './tenants/config/defaultTenant';
import { act, renderAsync, RenderOptions, screen, waitFor } from './utils/test-utils';
import { vi } from 'vitest';
import { useApiTenants } from './hooks/pims-api/useApiTenants';

vi.mock('axios');
const mockedAxios = vi.mocked(axios);
Expand Down Expand Up @@ -167,7 +166,7 @@ vi.mocked(useApiResearchFile).mockReturnValue({
page: 1,
total: 1,
quantity: 1,
} as ApiGen_Base_Page<IResearchSearchResult>,
} as ApiGen_Base_Page<ApiGen_Concepts_ResearchFile>,
}),
getResearchFile: vi.fn(),
postResearchFile: vi.fn(),
Expand Down
26 changes: 26 additions & 0 deletions source/frontend/src/components/Table/DateCell.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { render, RenderOptions, screen } from '@/utils/test-utils';
import { CellProps } from 'react-table';

import { UtcDateCell } from './DateCell';

describe('DateCell table renderer', () => {
// render component under test
const setup = (
renderOptions: RenderOptions & {
props?: Partial<CellProps<any, string | Date | undefined | null>>;
} = {},
) => {
const utils = render(<UtcDateCell {...(renderOptions?.props ?? ({} as any))} />, {
...renderOptions,
});

return { ...utils };
};

it('UtcDateCell displays the correct date when the date is after 5pm PST', async () => {
setup({
props: { cell: { value: '2025-02-12T00:59:37.953' } } as any,
});
expect(await screen.findByText('Feb 11, 2025')).toBeVisible();
});
});
12 changes: 11 additions & 1 deletion source/frontend/src/components/Table/DateCell.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import { CellProps } from 'react-table';

import { prettyFormatDate, prettyFormatDateTime, stringToFragment } from '@/utils';
import {
prettyFormatDate,
prettyFormatDateTime,
prettyFormatUTCDate,
stringToFragment,
} from '@/utils';

export const UtcDateCell = ({
cell: { value },
}: CellProps<any, string | Date | undefined | null>) =>
stringToFragment(prettyFormatUTCDate(value));

export const DateCell = ({ cell: { value } }: CellProps<any, string | Date | undefined | null>) =>
stringToFragment(prettyFormatDate(value));
Expand Down
6 changes: 3 additions & 3 deletions source/frontend/src/features/notes/NoteContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createMemoryHistory } from 'history';

import { Claims, NoteTypes } from '@/constants/index';
import { mockLookups } from '@/mocks/lookups.mock';
import { mockNoteResponse } from '@/mocks/noteResponses.mock';
import { getMockApiNote } from '@/mocks/noteResponses.mock';
import { lookupCodesSlice } from '@/store/slices/lookupCodes';
import {
act,
Expand Down Expand Up @@ -63,7 +63,7 @@ describe('NoteContainer component', () => {

beforeEach(() => {
mockAxios.onGet(new RegExp('users/info/*')).reply(200, {});
mockAxios.onGet(new RegExp('notes/*')).reply(200, mockNoteResponse(1));
mockAxios.onGet(new RegExp('notes/*')).reply(200, getMockApiNote(1));
});

afterEach(() => {
Expand Down Expand Up @@ -208,7 +208,7 @@ describe('NoteContainer component', () => {
userEvent.type(textarea, 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.'),
);

mockAxios.onPut().reply(200, mockNoteResponse(1));
mockAxios.onPut().reply(200, getMockApiNote(1));
await act(async () => userEvent.click(getSaveButton()));

expect(closeModal).toBeCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import MockAdapter from 'axios-mock-adapter';

import { Claims } from '@/constants/index';
import { mockLookups } from '@/mocks/lookups.mock';
import { mockNoteResponse } from '@/mocks/noteResponses.mock';
import { getMockApiNote } from '@/mocks/noteResponses.mock';
import { ApiGen_Concepts_Note } from '@/models/api/generated/ApiGen_Concepts_Note';
import { lookupCodesSlice } from '@/store/slices/lookupCodes';
import { act, render, RenderOptions, userEvent, waitFor } from '@/utils/test-utils';
import { act, render, RenderOptions, userEvent } from '@/utils/test-utils';

import { INoteDetailsFormModalProps, NoteDetailsFormModal } from './NoteDetailsFormModal';

Expand All @@ -20,7 +20,7 @@ const onClose = vi.fn();
const BASIC_PROPS: INoteDetailsFormModalProps = {
isOpened: true,
loading: false,
note: mockNoteResponse(1),
note: getMockApiNote(1),
onCloseClick: onClose,
onEdit,
};
Expand Down Expand Up @@ -84,7 +84,7 @@ describe('NoteDetailsFormModal component', () => {

it(`should not display the Last Updated info for system-generated notes`, async () => {
const systemNote: ApiGen_Concepts_Note = {
...mockNoteResponse(1),
...getMockApiNote(1),
isSystemGenerated: true,
};
const { queryByText } = setup({ ...BASIC_PROPS, note: systemNote }, { claims: [] });
Expand All @@ -107,7 +107,7 @@ describe('NoteDetailsFormModal component', () => {
const { getEditButton } = setup({ ...BASIC_PROPS }, { claims: [Claims.NOTE_EDIT] });
await act(async () => userEvent.click(getEditButton()));

expect(onEdit).toBeCalledWith(mockNoteResponse(1));
expect(onEdit).toBeCalledWith(getMockApiNote(1));
expect(onClose).not.toBeCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import thunk from 'redux-thunk';
import { ValidationError } from 'yup';

import { NoteTypes } from '@/constants/index';
import { mockNoteResponse } from '@/mocks/noteResponses.mock';
import { getMockApiNote } from '@/mocks/noteResponses.mock';
import { fakeText } from '@/utils/test-utils';
import TestCommonWrapper from '@/utils/TestCommonWrapper';

Expand All @@ -26,7 +26,7 @@ const onSuccess = vi.fn();

const BASIC_PROPS: IUseUpdateNotesFormManagementProps = {
type: NoteTypes.Activity,
note: mockNoteResponse(1),
note: getMockApiNote(1),
onSuccess,
};

Expand All @@ -45,7 +45,7 @@ describe('useUpdateNotesFormManagement hook', () => {

beforeEach(() => {
mockAxios.reset();
mockAxios.onPut('/notes/1').reply(200, mockNoteResponse(1));
mockAxios.onPut('/notes/1').reply(200, getMockApiNote(1));
});

afterEach(() => {
Expand All @@ -54,7 +54,7 @@ describe('useUpdateNotesFormManagement hook', () => {

it('should return valid initial values', async () => {
const { initialValues } = setup();
expect(initialValues).toEqual(NoteForm.fromApi(mockNoteResponse(1)));
expect(initialValues).toEqual(NoteForm.fromApi(getMockApiNote(1)));
});

it('should provide form validation schema', async () => {
Expand All @@ -75,7 +75,7 @@ describe('useUpdateNotesFormManagement hook', () => {
it('should provide form submission handler', async () => {
const { handleSubmit } = setup();

const formValues = NoteForm.fromApi(mockNoteResponse(1));
const formValues = NoteForm.fromApi(getMockApiNote(1));

const formikHelpers: Partial<FormikHelpers<NoteForm>> = {
setSubmitting: vi.fn(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import noop from 'lodash/noop';

import { Claims } from '@/constants/claims';
import { mockNotesResponse } from '@/mocks/noteResponses.mock';
import { mockKeycloak, render, RenderOptions } from '@/utils/test-utils';
import { getMockApiNote, mockNotesResponse } from '@/mocks/noteResponses.mock';
import { act, render, RenderOptions, screen, userEvent } from '@/utils/test-utils';

import { INoteResultProps, NoteResults } from './NoteResults';

const setSort = vi.fn();
const onShowDetails = vi.fn();
const onDelete = vi.fn();

// mock auth library

Expand All @@ -18,11 +18,12 @@ const setup = (renderOptions: RenderOptions & Partial<INoteResultProps> = { resu
sort={{}}
results={results ?? []}
setSort={setSort}
onDelete={noop}
onShowDetails={noop}
onDelete={onDelete}
onShowDetails={onShowDetails}
/>,
{
...rest,
claims: rest.claims ?? [Claims.NOTE_VIEW],
},
);
const tableRows = utils.container.querySelectorAll('.table .tbody .tr-wrapper');
Expand All @@ -39,7 +40,6 @@ const setup = (renderOptions: RenderOptions & Partial<INoteResultProps> = { resu

describe('Note Results Table', () => {
beforeEach(() => {
mockKeycloak({ claims: [Claims.NOTE_DELETE] });
setSort.mockClear();
});

Expand All @@ -55,4 +55,34 @@ describe('Note Results Table', () => {
const toasts = await findAllByText('No matching Notes found');
expect(toasts[0]).toBeVisible();
});

it('displays the eye icon-button to open note details popup', async () => {
setup({
results: [getMockApiNote()],
});

const viewButton = await screen.findByTitle(/View Note/i);
expect(viewButton).toBeVisible();
await act(async () => userEvent.click(viewButton));
expect(onShowDetails).toHaveBeenCalled();
});

it('displays the trashcan button to delete note, when the user has permissions', async () => {
setup({
results: [getMockApiNote()],
claims: [Claims.NOTE_VIEW, Claims.NOTE_DELETE],
});

const deleteButton = await screen.findByTitle(/Delete Note/i);
expect(deleteButton).toBeVisible();
await act(async () => userEvent.click(deleteButton));
expect(onDelete).toHaveBeenCalled();
});

it('displays the correct date when note is created after 5pm PST', async () => {
setup({
results: [{ ...getMockApiNote(), appCreateTimestamp: '2025-02-12T00:59:37.953' }],
});
expect(await screen.findByText('Feb 11, 2025')).toBeVisible();
});
});
Loading
Loading