-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:edx/frontend-app-admin-portal int…
…o ENT-9206/bulk-revoke-endpoint-changes
- Loading branch information
Showing
24 changed files
with
1,306 additions
and
291 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,49 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
import { | ||
Spinner, | ||
} from '@openedx/paragon'; | ||
import ScatterChart from './ScatterChart'; | ||
import LineChart from './LineChart'; | ||
import BarChart from './BarChart'; | ||
import EmptyChart from './EmptyChart'; | ||
|
||
const ChartWrapper = ({ | ||
isFetching, | ||
isError, | ||
chartType, | ||
chartProps, | ||
loadingMessage, | ||
}) => { | ||
if (isError) { | ||
return <EmptyChart />; | ||
} | ||
|
||
const chartMap = { | ||
ScatterChart: <ScatterChart {...chartProps} />, | ||
LineChart: <LineChart {...chartProps} />, | ||
BarChart: <BarChart {...chartProps} />, | ||
}; | ||
|
||
return ( | ||
<div className={classNames('analytics-chart-container', { chartType }, { 'is-fetching': isFetching })}> | ||
{isFetching && ( | ||
<div className="spinner-centered"> | ||
<Spinner animation="border" screenReaderText={loadingMessage} /> | ||
</div> | ||
)} | ||
{chartProps.data && chartMap[chartType]} | ||
</div> | ||
); | ||
}; | ||
|
||
ChartWrapper.propTypes = { | ||
isFetching: PropTypes.bool.isRequired, | ||
isError: PropTypes.bool.isRequired, | ||
chartType: PropTypes.oneOf(['ScatterChart', 'LineChart', 'BarChart']).isRequired, | ||
chartProps: PropTypes.object.isRequired, | ||
loadingMessage: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default ChartWrapper; |
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 |
---|---|---|
|
@@ -4,63 +4,142 @@ import MockAdapter from 'axios-mock-adapter'; | |
import { renderHook } from '@testing-library/react-hooks'; | ||
import { QueryClientProvider } from '@tanstack/react-query'; | ||
import { getAuthenticatedHttpClient } from '@edx/frontend-platform/auth'; | ||
import { camelCaseObject } from '@edx/frontend-platform/utils'; | ||
import { useEnterpriseSkillsAnalytics } from './hooks'; | ||
import { snakeCaseObject, camelCaseObject } from '@edx/frontend-platform/utils'; | ||
import { useEnterpriseAnalyticsData } from './hooks'; | ||
import EnterpriseDataApiService from '../../../data/services/EnterpriseDataApiService'; | ||
import { queryClient } from '../../test/testUtils'; | ||
|
||
jest.mock('@edx/frontend-platform/logging', () => ({ | ||
logError: jest.fn(), | ||
})); | ||
|
||
jest.spyOn(EnterpriseDataApiService, 'fetchAdminAnalyticsSkills'); | ||
jest.spyOn(EnterpriseDataApiService, 'fetchAdminAnalyticsData'); | ||
|
||
const axiosMock = new MockAdapter(axios); | ||
getAuthenticatedHttpClient.mockReturnValue(axios); | ||
|
||
const mockAnalyticsSkillsData = { | ||
top_skills: [], | ||
top_skills_by_enrollments: [], | ||
top_skills_by_completions: [], | ||
const mockAnalyticsCompletionsChartsData = { | ||
completions_over_time: [], | ||
top_courses_by_completions: [], | ||
top_subjects_by_completions: [], | ||
}; | ||
|
||
axiosMock.onAny().reply(200); | ||
axios.get = jest.fn(() => Promise.resolve({ data: mockAnalyticsSkillsData })); | ||
const mockAnalyticsLeaderboardTableData = [ | ||
{ | ||
email: '[email protected]', | ||
dailySessions: 243, | ||
learningTimeSeconds: 1111, | ||
learningTimeHours: 3.4, | ||
averageSessionLength: 1.6, | ||
courseCompletions: 4, | ||
}, | ||
]; | ||
|
||
const TEST_ENTERPRISE_ID = '33ce6562-95e0-4ecf-a2a7-7d407eb96f69'; | ||
|
||
describe('useEnterpriseSkillsAnalytics', () => { | ||
describe('useEnterpriseAnalyticsData', () => { | ||
afterEach(() => { | ||
axiosMock.reset(); | ||
}); | ||
|
||
const wrapper = ({ children }) => ( | ||
<QueryClientProvider client={queryClient()}> | ||
{children} | ||
</QueryClientProvider> | ||
); | ||
|
||
it('fetch skills analytics data', async () => { | ||
it('fetch analytics chart data', async () => { | ||
const startDate = '2021-01-01'; | ||
const endDate = '2021-12-31'; | ||
const requestOptions = { startDate, endDate }; | ||
const queryParams = new URLSearchParams(snakeCaseObject(requestOptions)); | ||
const baseURL = `${EnterpriseDataApiService.enterpriseAdminAnalyticsV2BaseUrl}${TEST_ENTERPRISE_ID}`; | ||
const analyticsCompletionsURL = `${baseURL}/completions/stats?${queryParams.toString()}`; | ||
axiosMock.onGet(`${analyticsCompletionsURL}`).reply(200, mockAnalyticsCompletionsChartsData); | ||
const { result, waitForNextUpdate } = renderHook( | ||
() => useEnterpriseAnalyticsData({ | ||
enterpriseCustomerUUID: TEST_ENTERPRISE_ID, | ||
key: 'completions', | ||
startDate, | ||
endDate, | ||
}), | ||
{ wrapper }, | ||
); | ||
|
||
expect(result.current).toEqual( | ||
expect.objectContaining({ | ||
isFetching: true, | ||
error: null, | ||
data: undefined, | ||
}), | ||
); | ||
|
||
await waitForNextUpdate(); | ||
|
||
expect(EnterpriseDataApiService.fetchAdminAnalyticsData).toHaveBeenCalled(); | ||
expect(EnterpriseDataApiService.fetchAdminAnalyticsData).toHaveBeenCalledWith( | ||
TEST_ENTERPRISE_ID, | ||
'completions', | ||
{ | ||
calculation: undefined, | ||
endDate: '2021-12-31', | ||
granularity: undefined, | ||
page: undefined, | ||
startDate: '2021-01-01', | ||
}, | ||
); | ||
expect(result.current).toEqual(expect.objectContaining({ | ||
isFetching: false, | ||
error: null, | ||
data: camelCaseObject(mockAnalyticsCompletionsChartsData), | ||
})); | ||
expect(axiosMock.history.get[0].url).toBe(analyticsCompletionsURL); | ||
}); | ||
it('fetch analytics table data', async () => { | ||
const startDate = '2021-01-01'; | ||
const endDate = '2021-12-31'; | ||
const requestOptions = { startDate, endDate }; | ||
const queryParams = new URLSearchParams(snakeCaseObject(requestOptions)); | ||
const baseURL = `${EnterpriseDataApiService.enterpriseAdminAnalyticsV2BaseUrl}${TEST_ENTERPRISE_ID}`; | ||
const analyticsLeaderboardURL = `${baseURL}/leaderboard?${queryParams.toString()}`; | ||
axiosMock.onGet(`${analyticsLeaderboardURL}`).reply(200, mockAnalyticsLeaderboardTableData); | ||
const { result, waitForNextUpdate } = renderHook( | ||
() => useEnterpriseSkillsAnalytics(TEST_ENTERPRISE_ID, startDate, endDate), | ||
() => useEnterpriseAnalyticsData({ | ||
enterpriseCustomerUUID: TEST_ENTERPRISE_ID, | ||
key: 'leaderboardTable', | ||
startDate, | ||
endDate, | ||
}), | ||
{ wrapper }, | ||
); | ||
|
||
expect(result.current).toEqual( | ||
expect.objectContaining({ | ||
isLoading: true, | ||
isFetching: true, | ||
error: null, | ||
data: undefined, | ||
}), | ||
); | ||
|
||
await waitForNextUpdate(); | ||
|
||
expect(EnterpriseDataApiService.fetchAdminAnalyticsSkills).toHaveBeenCalled(); | ||
expect(EnterpriseDataApiService.fetchAdminAnalyticsSkills).toHaveBeenCalledWith(TEST_ENTERPRISE_ID, requestOptions); | ||
expect(EnterpriseDataApiService.fetchAdminAnalyticsData).toHaveBeenCalled(); | ||
expect(EnterpriseDataApiService.fetchAdminAnalyticsData).toHaveBeenCalledWith( | ||
TEST_ENTERPRISE_ID, | ||
'completions', | ||
{ | ||
calculation: undefined, | ||
endDate: '2021-12-31', | ||
granularity: undefined, | ||
page: undefined, | ||
startDate: '2021-01-01', | ||
}, | ||
); | ||
expect(result.current).toEqual(expect.objectContaining({ | ||
isLoading: false, | ||
isFetching: false, | ||
error: null, | ||
data: camelCaseObject(mockAnalyticsSkillsData), | ||
data: camelCaseObject(mockAnalyticsLeaderboardTableData), | ||
})); | ||
expect(axiosMock.history.get[0].url).toBe(analyticsLeaderboardURL); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,3 +1,27 @@ | ||
.analytics-stat-number { | ||
font-size: 2.5rem; | ||
} | ||
|
||
.analytics-chart-container { | ||
position: relative; | ||
min-height: 40vh; | ||
|
||
&.is-fetching::before { | ||
content: ""; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba($white, .7); | ||
z-index: 1; | ||
} | ||
|
||
.spinner-centered { | ||
position: absolute; | ||
top: 50%; | ||
left: 50%; | ||
transform: translate(-50%, -50%); | ||
z-index: 2; | ||
} | ||
} |
Oops, something went wrong.