-
Notifications
You must be signed in to change notification settings - Fork 7
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 #182 from adhocteam/kw-new-report
Add conditional display of the "New Activity Report" button
- Loading branch information
Showing
8 changed files
with
146 additions
and
54 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
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 |
---|---|---|
|
@@ -10,21 +10,31 @@ import UserContext from '../../../UserContext'; | |
import Landing from '../index'; | ||
import activityReports from '../mocks'; | ||
|
||
const renderLanding = (user) => { | ||
render( | ||
<MemoryRouter> | ||
<UserContext.Provider value={{ user }}> | ||
<Landing authenticated /> | ||
</UserContext.Provider> | ||
</MemoryRouter>, | ||
); | ||
}; | ||
|
||
describe('Landing Page', () => { | ||
beforeEach(() => { | ||
fetchMock.get('/api/activity-reports', activityReports); | ||
fetchMock.get('/api/activity-reports/alerts', []); | ||
const user = { | ||
name: '[email protected]', | ||
permissions: [ | ||
{ | ||
scopeId: 3, | ||
regionId: 1, | ||
}, | ||
], | ||
}; | ||
|
||
render( | ||
<MemoryRouter> | ||
<UserContext.Provider value={{ user }}> | ||
<Landing authenticated /> | ||
</UserContext.Provider> | ||
</MemoryRouter>, | ||
); | ||
renderLanding(user); | ||
}); | ||
afterEach(() => fetchMock.restore()); | ||
|
||
|
@@ -156,18 +166,52 @@ describe('Landing Page error', () => { | |
|
||
it('handles errors by displaying an error message', async () => { | ||
fetchMock.get('/api/activity-reports', 500); | ||
render(<MemoryRouter><Landing authenticated /></MemoryRouter>); | ||
const user = { | ||
name: '[email protected]', | ||
permissions: [ | ||
{ | ||
scopeId: 3, | ||
regionId: 1, | ||
}, | ||
], | ||
}; | ||
renderLanding(user); | ||
const alert = await screen.findByRole('alert'); | ||
expect(alert).toBeVisible(); | ||
expect(alert).toHaveTextContent('Unable to fetch reports'); | ||
}); | ||
|
||
it('displays an empty row if there are no reports', async () => { | ||
fetchMock.get('/api/activity-reports', []); | ||
render(<MemoryRouter><Landing authenticated /></MemoryRouter>); | ||
const user = { | ||
name: '[email protected]', | ||
permissions: [ | ||
{ | ||
scopeId: 3, | ||
regionId: 1, | ||
}, | ||
], | ||
}; | ||
renderLanding(user); | ||
const rowCells = await screen.findAllByRole('cell'); | ||
expect(rowCells.length).toBe(8); | ||
const grantee = rowCells[0]; | ||
expect(grantee).toHaveTextContent(''); | ||
}); | ||
|
||
it('does not displays new activity report button without permission', async () => { | ||
fetchMock.get('/api/activity-reports', activityReports); | ||
const user = { | ||
name: '[email protected]', | ||
permissions: [ | ||
{ | ||
scopeId: 2, | ||
regionId: 1, | ||
}, | ||
], | ||
}; | ||
renderLanding(user); | ||
|
||
await expect(screen.findAllByText(/New Activity Report/)).rejects.toThrow(); | ||
}); | ||
}); |
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