forked from HHS/Head-Start-TTADP
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Display my alerts #170
Merged
Merged
Display my alerts #170
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8f474ae
Merge branch 'js-145-activity-report-display-id' of https://github.co…
kryswisnaskas 8cfc965
Merge branch 'main' of https://github.com/adhocteam/Head-Start-TTADP …
kryswisnaskas 59e7621
Display My Alerts
kryswisnaskas 123f773
Fix lint errors
kryswisnaskas a22b5f7
Update class name for needs_action
kryswisnaskas f5508c7
Modified links to reports
kryswisnaskas 7a05073
Fix needs_status display
kryswisnaskas 49fbf96
Modify alerts query
kryswisnaskas c24af59
Merge branch 'main' into kw-my-alerts
kryswisnaskas 267041d
Use constants instead of hardcoding; fix props types
kryswisnaskas c3eb8c7
Merge branch 'kw-my-alerts' of https://github.com/adhocteam/Head-Star…
kryswisnaskas 09212e1
Merge branch 'main' into kw-my-alerts
kryswisnaskas 8cca514
Merge branch 'main' into kw-my-alerts
kryswisnaskas 721b6c7
Fix test coverage
kryswisnaskas b12e8e3
Merge branch 'main' into kw-my-alerts
kryswisnaskas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { Tag, Table } from '@trussworks/react-uswds'; | ||
import { Link } from 'react-router-dom'; | ||
import SimpleBar from 'simplebar-react'; | ||
import 'simplebar/dist/simplebar.min.css'; | ||
|
||
import Container from '../../components/Container'; | ||
import NewReport from './NewReport'; | ||
import 'uswds/dist/css/uswds.css'; | ||
import '@trussworks/react-uswds/lib/index.css'; | ||
import './index.css'; | ||
|
||
function renderReports(reports) { | ||
return reports.map((report) => { | ||
const { | ||
id, | ||
displayId, | ||
activityRecipients, | ||
startDate, | ||
author, | ||
collaborators, | ||
status, | ||
} = report; | ||
|
||
const recipientsTitle = activityRecipients.reduce( | ||
(result, ar) => `${result + (ar.grant ? ar.grant.grantee.name : ar.name)}\n`, | ||
'', | ||
); | ||
|
||
const recipients = activityRecipients.map((ar) => ( | ||
<Tag | ||
key={ar.name.slice(1, 3) + ar.id} | ||
className="smart-hub--table-collection" | ||
> | ||
{ar.grant ? ar.grant.grantee.name : ar.name} | ||
</Tag> | ||
)); | ||
|
||
const collaboratorsTitle = collaborators.reduce( | ||
(result, collaborator) => `${result + collaborator.fullName}\n`, | ||
'', | ||
); | ||
|
||
const collaboratorsWithTags = collaborators.map((collaborator) => ( | ||
<Tag | ||
key={collaborator.id} | ||
className="smart-hub--table-collection" | ||
> | ||
{collaborator.fullName} | ||
</Tag> | ||
)); | ||
|
||
return ( | ||
<tr key={`my_alerts_${id}`}> | ||
<td> | ||
<Link | ||
to={`/activity-reports/${id}`} | ||
href={`/activity-reports/${id}`} | ||
> | ||
{displayId} | ||
</Link> | ||
</td> | ||
<td> | ||
<span className="smart-hub--ellipsis" title={recipientsTitle}> | ||
{recipients} | ||
</span> | ||
</td> | ||
<td>{startDate}</td> | ||
<td> | ||
<span className="smart-hub--ellipsis" title={author.fullName}> | ||
{author.fullName} | ||
</span> | ||
</td> | ||
<td> | ||
<span className="smart-hub--ellipsis" title={collaboratorsTitle}> | ||
{collaboratorsWithTags} | ||
</span> | ||
</td> | ||
<td> | ||
<Tag | ||
className={`smart-hub--table-tag-status smart-hub--status-${status}`} | ||
> | ||
{status === 'Needs_action' ? 'Needs action' : status} | ||
</Tag> | ||
</td> | ||
</tr> | ||
); | ||
}); | ||
} | ||
|
||
function MyAlerts({ reports }) { | ||
return ( | ||
<> | ||
{ reports && reports.length === 0 && ( | ||
<Container className="landing" padding={0}> | ||
<div id="caughtUp"> | ||
<div><h2>You're all caught up!</h2></div> | ||
<p id="beginNew">Would you like to begin a new activity report?</p> | ||
<NewReport /> | ||
</div> | ||
</Container> | ||
) } | ||
{ reports && reports.length > 0 && ( | ||
<SimpleBar> | ||
<Container className="landing inline-size" padding={0}> | ||
<Table bordered={false}> | ||
<caption className="smart-hub--table-caption"> | ||
My activity report alerts | ||
</caption> | ||
<thead> | ||
<tr> | ||
<th scope="col">Report ID</th> | ||
<th | ||
scope="col" | ||
> | ||
Grantee | ||
</th> | ||
<th scope="col">Start date</th> | ||
<th | ||
scope="col" | ||
> | ||
Creator | ||
</th> | ||
<th scope="col">Collaborator(s)</th> | ||
<th | ||
scope="col" | ||
> | ||
Status | ||
</th> | ||
</tr> | ||
</thead> | ||
<tbody>{renderReports(reports)}</tbody> | ||
</Table> | ||
</Container> | ||
</SimpleBar> | ||
)} | ||
</> | ||
); | ||
} | ||
|
||
MyAlerts.propTypes = { | ||
reports: PropTypes.node.isRequired, | ||
}; | ||
|
||
export default MyAlerts; |
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,22 @@ | ||
import React from 'react'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import 'uswds/dist/css/uswds.css'; | ||
import '@trussworks/react-uswds/lib/index.css'; | ||
import './index.css'; | ||
|
||
function NewReport() { | ||
return ( | ||
<Link | ||
to="/activity-reports/new" | ||
referrerPolicy="same-origin" | ||
className="usa-button smart-hub--new-report-btn" | ||
variant="unstyled" | ||
> | ||
<span className="smart-hub--plus">+</span> | ||
<span className="smart-hub--new-report">New Activity Report</span> | ||
</Link> | ||
); | ||
} | ||
|
||
export default NewReport; |
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,86 @@ | ||
import '@testing-library/jest-dom'; | ||
import React from 'react'; | ||
import { | ||
render, screen, | ||
} from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router'; | ||
|
||
import MyAlerts from '../MyAlerts'; | ||
import activityReports from '../mocks'; | ||
|
||
describe('My Alerts', () => { | ||
beforeEach(() => { | ||
render( | ||
<MemoryRouter> | ||
<MyAlerts reports={activityReports} /> | ||
</MemoryRouter>, | ||
); | ||
}); | ||
|
||
test('displays report id column', async () => { | ||
const reportIdColumnHeader = await screen.findByRole('columnheader', { | ||
name: /report id/i, | ||
}); | ||
expect(reportIdColumnHeader).toBeVisible(); | ||
}); | ||
|
||
test('displays grantee column', async () => { | ||
const granteeColumnHeader = await screen.findByRole('columnheader', { | ||
name: /grantee/i, | ||
}); | ||
expect(granteeColumnHeader).toBeVisible(); | ||
}); | ||
|
||
test('displays start date column', async () => { | ||
const startDateColumnHeader = await screen.findByRole('columnheader', { | ||
name: /start date/i, | ||
}); | ||
expect(startDateColumnHeader).toBeVisible(); | ||
}); | ||
|
||
test('displays creator column', async () => { | ||
const creatorColumnHeader = await screen.findByRole('columnheader', { | ||
name: /creator/i, | ||
}); | ||
expect(creatorColumnHeader).toBeVisible(); | ||
}); | ||
|
||
test('displays the correct grantees', async () => { | ||
const grantees = await screen.findByRole('cell', { | ||
name: /johnston-romaguera\njohnston-romaguera\ngrantee name/i, | ||
}); | ||
const nonGrantees = await screen.findByRole('cell', { | ||
name: /qris system/i, | ||
}); | ||
|
||
expect(grantees).toBeVisible(); | ||
expect(nonGrantees).toBeVisible(); | ||
}); | ||
|
||
test('displays the correct start date', async () => { | ||
const startDate = await screen.findByRole('cell', { | ||
name: /02\/08\/2021/i, | ||
}); | ||
|
||
expect(startDate).toBeVisible(); | ||
}); | ||
|
||
test('displays the correct collaborators', async () => { | ||
const collaborators = await screen.findByRole('cell', { | ||
name: /cucumber user, gs\nhermione granger, ss/i, | ||
}); | ||
|
||
expect(collaborators).toBeVisible(); | ||
expect(collaborators.firstChild).toHaveClass('smart-hub--ellipsis'); | ||
expect(collaborators.firstChild.children.length).toBe(2); | ||
expect(collaborators.firstChild.firstChild).toHaveClass('usa-tag smart-hub--table-collection'); | ||
expect(collaborators.firstChild.firstChild).toHaveTextContent('Cucumber User'); | ||
expect(collaborators.firstChild.lastChild).toHaveTextContent('Hermione Granger'); | ||
}); | ||
|
||
test('displays the correct statuses', async () => { | ||
const statuses = await screen.findAllByText(/draft/i); | ||
|
||
expect(statuses.length).toBe(2); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -9,11 +9,11 @@ import fetchMock from 'fetch-mock'; | |
import UserContext from '../../../UserContext'; | ||
import Landing from '../index'; | ||
import activityReports from '../mocks'; | ||
import * as page from '../index'; | ||
|
||
describe('Landing Page', () => { | ||
beforeEach(() => { | ||
fetchMock.get('/api/activity-reports', activityReports); | ||
fetchMock.get('/api/activity-reports/alerts', []); | ||
const user = { | ||
name: '[email protected]', | ||
}; | ||
|
@@ -69,7 +69,7 @@ describe('Landing Page', () => { | |
|
||
test('displays the correct report id', async () => { | ||
const reportIdLink = await screen.findByRole('link', { | ||
name: /r14-000001/i, | ||
name: /r14-ar-1/i, | ||
}); | ||
|
||
expect(reportIdLink).toBeVisible(); | ||
|
@@ -80,15 +80,15 @@ describe('Landing Page', () => { | |
}); | ||
|
||
test('displays the correct grantees', async () => { | ||
const grantees = await screen.findByRole('cell', { | ||
const grantee = await screen.findByRole('cell', { | ||
name: /johnston-romaguera\njohnston-romaguera\ngrantee name/i, | ||
}); | ||
const nonGrantees = await screen.findByRole('cell', { | ||
const nonGrantee = await screen.findByRole('cell', { | ||
name: /qris system/i, | ||
}); | ||
|
||
expect(grantees).toBeVisible(); | ||
expect(nonGrantees).toBeVisible(); | ||
expect(grantee).toBeVisible(); | ||
expect(nonGrantee).toBeVisible(); | ||
}); | ||
|
||
test('displays the correct start date', async () => { | ||
|
@@ -138,24 +138,25 @@ describe('Landing Page', () => { | |
expect(optionButtons.length).toBe(2); | ||
}); | ||
|
||
test('activityReportId is correct', () => { | ||
const spy = jest.spyOn(page, 'activityReportId'); | ||
const reportId = page.activityReportId(333, 9); | ||
test('displays the new activity report button', async () => { | ||
const newActivityReportBtns = await screen.findAllByText(/New Activity Report/); | ||
|
||
expect(spy).toHaveBeenCalled(); | ||
expect(reportId).toBe('R09-000333'); | ||
|
||
spy.mockRestore(); | ||
expect(newActivityReportBtns.length).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('Landing Page error', () => { | ||
afterEach(() => fetchMock.restore()); | ||
|
||
beforeEach(() => { | ||
fetchMock.get('/api/activity-reports/alerts', []); | ||
}); | ||
|
||
it('handles errors by displaying an error message', async () => { | ||
fetchMock.get('/api/activity-reports', 500); | ||
render(<MemoryRouter><Landing authenticated /></MemoryRouter>); | ||
const alert = await screen.findByRole('alert'); | ||
expect(alert).toBeVisible(); | ||
expect(alert).toHaveTextContent('Unable to fetch reports'); | ||
}); | ||
|
||
|
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm getting this in the console:
Warning: Failed prop type: Invalid prop
reportssupplied to
MyAlerts, expected a ReactNode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed.