-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add activity log retriveal network operation * Add loading state capabilities to ActivityLogOverview * Add ActivityLogPage * Mount ActivityLogPage in the application
- Loading branch information
1 parent
9b314a9
commit 68959f2
Showing
9 changed files
with
126 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { networkClient } from '@lib/network'; | ||
|
||
export const getActivityLog = () => networkClient.get(`/activity_log`); |
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,41 @@ | ||
import React, { useState, useEffect } from 'react'; | ||
|
||
import PageHeader from '@common/PageHeader'; | ||
import ActivityLogOverview from '@common/ActivityLogOverview'; | ||
|
||
import { getActivityLog } from '@lib/api/activityLogs'; | ||
|
||
function ActivityLogPage() { | ||
const [activityLog, setActivityLog] = useState([]); | ||
const [isLoading, setLoading] = useState(true); | ||
const [activityLogDetailModalOpen, setActivityLogDetailModalOpen] = | ||
useState(false); | ||
|
||
useEffect(() => { | ||
getActivityLog() | ||
.then((response) => { | ||
setActivityLog(response.data); | ||
}) | ||
.catch(() => setActivityLog([])) | ||
.finally(() => { | ||
setLoading(false); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<PageHeader className="font-bold">Activity Log</PageHeader> | ||
<ActivityLogOverview | ||
activityLogDetailModalOpen={activityLogDetailModalOpen} | ||
activityLog={activityLog} | ||
loading={isLoading} | ||
onActivityLogEntryClick={() => setActivityLogDetailModalOpen(true)} | ||
onCloseActivityLogEntryDetails={() => | ||
setActivityLogDetailModalOpen(false) | ||
} | ||
/> | ||
</> | ||
); | ||
} | ||
|
||
export default ActivityLogPage; |
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,52 @@ | ||
import React from 'react'; | ||
import { act, screen } from '@testing-library/react'; | ||
import '@testing-library/jest-dom'; | ||
|
||
import MockAdapter from 'axios-mock-adapter'; | ||
import { renderWithRouter } from '@lib/test-utils'; | ||
|
||
import { networkClient } from '@lib/network'; | ||
import { activityLogEntryFactory } from '@lib/test-utils/factories/activityLog'; | ||
|
||
import ActivityLogPage from './ActivityLogPage'; | ||
|
||
const axiosMock = new MockAdapter(networkClient); | ||
|
||
describe('ActivityLogPage', () => { | ||
it('should render table without data', async () => { | ||
axiosMock.onGet('/api/v1/activity_log').reply(200, []); | ||
await act(async () => renderWithRouter(<ActivityLogPage />)); | ||
expect(screen.getByText('No data available')).toBeVisible(); | ||
}); | ||
|
||
it.each` | ||
responseStatus | responseBody | ||
${404} | ${[]} | ||
${500} | ${{ error: 'Internal Server Error' }} | ||
${503} | ${null} | ||
${504} | ${''} | ||
`( | ||
'should render empty activity log on error `$responseStatus`', | ||
async ({ responseStatus, responseBody }) => { | ||
axiosMock | ||
.onGet('/api/v1/activity_log') | ||
.reply(responseStatus, responseBody); | ||
|
||
await act(() => renderWithRouter(<ActivityLogPage />)); | ||
|
||
expect(screen.getByText('No data available')).toBeVisible(); | ||
} | ||
); | ||
|
||
it('should render tracked activity log', async () => { | ||
axiosMock | ||
.onGet('/api/v1/activity_log') | ||
.reply(200, activityLogEntryFactory.buildList(5)); | ||
|
||
const { container } = await act(() => | ||
renderWithRouter(<ActivityLogPage />) | ||
); | ||
|
||
expect(container.querySelectorAll('tbody > tr')).toHaveLength(5); | ||
}); | ||
}); |
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,3 @@ | ||
import ActivityLogPage from './ActivityLogPage'; | ||
|
||
export default ActivityLogPage; |
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