-
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.
Merge pull request #101 from CDLUC3/feature/86-build-changelog-histor…
…y-page [Feature] - Built template history page
- Loading branch information
Showing
20 changed files
with
1,059 additions
and
100 deletions.
There are no files selected for viewing
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
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
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
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
94 changes: 94 additions & 0 deletions
94
app/template/[templateId]/history/__tests__/mockedResponse.json
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,94 @@ | ||
{ | ||
"templateVersions": [ | ||
{ | ||
"name": "NIH-GDS: Genomic Data Sharing", | ||
"version": "v3.1", | ||
"created": "2024-08-02T02:03:01.000Z", | ||
"comment": "Added some additional requirements to Preservation section!", | ||
"versionedBy": { | ||
"givenName": "Severus", | ||
"surName": "Snape", | ||
"affiliation": { | ||
"name": "National Institutes of Health" | ||
}, | ||
"modified": "2024-08-21T18:05:57.000Z", | ||
"modifiedById": 459 | ||
} | ||
}, | ||
{ | ||
"name": "NIH-GDS: Genomic Data Sharing", | ||
"version": "v3", | ||
"created": "2024-04-01T02:03:00.000Z", | ||
"comment": "This is the initial version of our template!", | ||
"versionedBy": { | ||
"givenName": "Severus", | ||
"surName": "Snape", | ||
"affiliation": { | ||
"name": "National Institutes of Health" | ||
}, | ||
"modified": "2024-08-21T18:05:57.000Z", | ||
"modifiedById": 320 | ||
} | ||
}, | ||
{ | ||
"name": "NIH-GDS: Genomic Data Sharing", | ||
"version": "v2.2", | ||
"created": "2024-03-21T22:23:20.000Z", | ||
"comment": "Added some additional requirements to Preservation section!", | ||
"versionedBy": { | ||
"givenName": "Severus", | ||
"surName": "Snape", | ||
"affiliation": { | ||
"name": "National Institutes of Health" | ||
}, | ||
"modified": "2024-08-21T18:05:57.000Z", | ||
"modifiedById": 779 | ||
} | ||
}, | ||
{ | ||
"name": "NIH-GDS: Genomic Data Sharing", | ||
"version": "v2.1", | ||
"created": "2024-03-19T19:20:18.000Z", | ||
"comment": "Added some additional requirements to Preservation section!", | ||
"versionedBy": { | ||
"givenName": "Severus", | ||
"surName": "Snape", | ||
"affiliation": { | ||
"name": "National Institutes of Health" | ||
}, | ||
"modified": "2024-08-21T18:05:57.000Z", | ||
"modifiedById": 822 | ||
} | ||
}, | ||
{ | ||
"name": "NIH-GDS: Genomic Data Sharing", | ||
"version": "v2", | ||
"created": "2024-02-18T16:17:15.000Z", | ||
"comment": "This is the initial version of our template!", | ||
"versionedBy": { | ||
"givenName": "Severus", | ||
"surName": "Snape", | ||
"affiliation": { | ||
"name": "National Institutes of Health" | ||
}, | ||
"modified": "2024-08-21T18:05:57.000Z", | ||
"modifiedById": 89 | ||
} | ||
}, | ||
{ | ||
"name": "NIH-GDS: Genomic Data Sharing", | ||
"version": "v1", | ||
"created": "2024-01-17T13:14:15.000Z", | ||
"comment": "This is the initial version of our template!", | ||
"versionedBy": { | ||
"givenName": "Severus", | ||
"surName": "Snape", | ||
"affiliation": { | ||
"name": "National Institutes of Health" | ||
}, | ||
"modified": "2024-08-21T18:05:57.000Z", | ||
"modifiedById": 551 | ||
} | ||
} | ||
] | ||
} |
160 changes: 160 additions & 0 deletions
160
app/template/[templateId]/history/__tests__/page.spec.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,160 @@ | ||
import React, { ReactNode } from 'react'; | ||
import { render, screen } from '@testing-library/react'; | ||
import TemplateHistory from '../page'; | ||
import { useTemplateVersionsQuery } from '@/generated/graphql'; | ||
import { MockedProvider } from '@apollo/client/testing'; | ||
import { useParams } from 'next/navigation'; | ||
import { axe, toHaveNoViolations } from 'jest-axe'; | ||
import mockData from './mockedResponse.json' | ||
|
||
expect.extend(toHaveNoViolations); | ||
|
||
jest.mock('@/generated/graphql', () => ({ | ||
useTemplateVersionsQuery: jest.fn(), | ||
})); | ||
|
||
jest.mock('next/navigation', () => ({ | ||
useParams: jest.fn(), | ||
})) | ||
|
||
jest.mock('@/components/BackButton', () => { | ||
return { | ||
__esModule: true, | ||
default: () => <div>Mocked Back Button</div>, | ||
}; | ||
}); | ||
|
||
jest.mock('@/components/PageWrapper', () => { | ||
const mockPageWrapper = jest.fn(({ children }: { children: ReactNode, title: string }) => ( | ||
<div data-testid="mock-page-wrapper">{children}</div> | ||
)); | ||
return { | ||
__esModule: true, | ||
default: mockPageWrapper | ||
} | ||
}); | ||
|
||
describe('TemplateHistory', () => { | ||
beforeEach(() => { | ||
const mockTemplateId = 123; | ||
const mockUseParams = useParams as jest.Mock; | ||
|
||
// Mock the return value of useParams | ||
mockUseParams.mockReturnValue({ templateId: `${mockTemplateId}` }); | ||
}); | ||
|
||
it('should render the component with PageWrapper', async () => { | ||
const titleProp = 'Template History'; | ||
const pageWrapper = await import('@/components/PageWrapper'); | ||
const mockPageWrapper = pageWrapper.default; | ||
|
||
(useTemplateVersionsQuery as jest.Mock).mockReturnValue(mockData); | ||
|
||
const { getByTestId } = render(<TemplateHistory />); | ||
|
||
expect(getByTestId('mock-page-wrapper')).toBeInTheDocument(); | ||
expect(mockPageWrapper).toHaveBeenCalledWith(expect.objectContaining({ title: titleProp, }), {}) | ||
}) | ||
|
||
it('should use the templateId from the param in the call to useTemplateVersionsQuery', () => { | ||
|
||
(useTemplateVersionsQuery as jest.Mock).mockReturnValue({ | ||
data: mockData, | ||
loading: false, | ||
error: null, | ||
}); | ||
|
||
render( | ||
<MockedProvider> | ||
<TemplateHistory /> | ||
</MockedProvider> | ||
); | ||
|
||
expect(useTemplateVersionsQuery).toHaveBeenCalledWith({ "variables": { "templateId": 123 } }) | ||
}); | ||
|
||
it('should render loading state correctly', () => { | ||
(useTemplateVersionsQuery as jest.Mock).mockReturnValue({ loading: true }); | ||
|
||
render(<TemplateHistory />); | ||
expect(screen.getByText('Loading publication history...')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render error state correctly', () => { | ||
(useTemplateVersionsQuery as jest.Mock).mockReturnValue({ loading: false, error: new Error('Test Error') }); | ||
|
||
render(<TemplateHistory />); | ||
expect(screen.getByText('There was a problem.')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should render page heading and subheader correctly, which includes the title, by, version and date of latest publication', async () => { | ||
(useTemplateVersionsQuery as jest.Mock).mockReturnValue({ | ||
loading: false, | ||
data: mockData, | ||
}); | ||
|
||
const { getByTestId } = render(<TemplateHistory />); | ||
const h1Element = await screen.findByRole('heading', { level: 1 }); | ||
expect(h1Element).toHaveTextContent('NIH-GDS: Genomic Data Sharing'); | ||
expect(getByTestId('author')).toHaveTextContent('by National Institutes of Health') | ||
expect(getByTestId('latest-version')).toHaveTextContent('3.1') | ||
expect(getByTestId('publication-date')).toHaveTextContent('Published: Aug 1, 2024') | ||
}); | ||
|
||
it('should render correct headers for table', async () => { | ||
(useTemplateVersionsQuery as jest.Mock).mockReturnValue({ | ||
loading: false, | ||
data: mockData, | ||
}); | ||
|
||
render(<TemplateHistory />); | ||
|
||
// Check h2 header above table | ||
const h2Element = await screen.findByRole('heading', { level: 2 }); | ||
expect(h2Element).toHaveTextContent('History'); | ||
|
||
// Check table column headers | ||
const headers = screen.getAllByRole('columnheader'); | ||
expect(headers[0]).toHaveTextContent('Action'); | ||
expect(headers[1]).toHaveTextContent('User'); | ||
expect(headers[2]).toHaveTextContent('Time and Date'); | ||
}) | ||
|
||
it('should render correct content in table', async () => { | ||
(useTemplateVersionsQuery as jest.Mock).mockReturnValue({ | ||
loading: false, | ||
data: mockData, | ||
}); | ||
|
||
render(<TemplateHistory />); | ||
const table = screen.getByRole('grid'); | ||
// Get all rows in table body | ||
const rows = table.querySelectorAll('tbody tr'); | ||
|
||
// Second row in table | ||
const targetRow1 = rows[1]; | ||
|
||
const row1Cells = targetRow1.querySelectorAll('td'); | ||
expect(row1Cells[0].textContent).toBe('Published v3Change log:This is the initial version of our template!'); | ||
expect(row1Cells[1].textContent).toBe('Severus Snape'); | ||
expect(row1Cells[2].textContent).toBe('19:03 on Mar 31, 2024'); | ||
}) | ||
|
||
it('should render "No template history available" when no data is available', () => { | ||
(useTemplateVersionsQuery as jest.Mock).mockReturnValue({ | ||
loading: false, | ||
data: { templateVersions: [] }, | ||
}); | ||
|
||
render(<TemplateHistory />); | ||
expect(screen.getByText('No template history available.')).toBeInTheDocument(); | ||
}); | ||
|
||
it('should pass axe accessibility test', async () => { | ||
const { container } = render( | ||
<TemplateHistory /> | ||
); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}) | ||
}); |
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,10 @@ | ||
|
||
|
||
.historyVersion { | ||
margin-right: 10px; | ||
} | ||
|
||
.changeLog { | ||
color: var(--gray-500); | ||
font-size: 0.75rem; | ||
} |
Oops, something went wrong.