-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: smoke test coverage
- Loading branch information
Showing
8 changed files
with
186 additions
and
126 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,64 @@ | ||
import { stepNames } from 'constants/index'; | ||
import { progressKeys } from 'constants/mockData'; | ||
|
||
const lmsBaseUrl = 'test-base-url'; | ||
export const courseId = 'test-course-id'; | ||
export const xblockId = 'test-xblock-id'; | ||
export const baseUrl = `${lmsBaseUrl}/courses/${courseId}/xblock/${xblockId}/handler`; | ||
export const config = { | ||
LMS_BASE_URL: lmsBaseUrl, | ||
}; | ||
|
||
const stepProgressKeys = { | ||
[stepNames.submission]: [ | ||
progressKeys.submissionUnsaved, | ||
progressKeys.submissionSaved, | ||
], | ||
[stepNames.studentTraining]: [ | ||
progressKeys.studentTraining, | ||
progressKeys.studentTrainingPartial, | ||
], | ||
[stepNames.self]: [progressKeys.selfAssessment], | ||
[stepNames.peer]: [ | ||
progressKeys.peerAssessment, | ||
progressKeys.peerAssessmentPartial, | ||
progressKeys.peerAssessmentWaiting, | ||
progressKeys.peerAssessmentWaitingForGrades, | ||
], | ||
[stepNames.done]: [progressKeys.graded], | ||
}; | ||
const viewProgressKeys = { | ||
[stepNames.xblock]: Object.values(progressKeys), | ||
[stepNames.submission]: [ | ||
...stepProgressKeys.submission, | ||
...stepProgressKeys.studentTraining, | ||
...stepProgressKeys.self, | ||
...stepProgressKeys.peer, | ||
...stepProgressKeys.done, | ||
], | ||
[stepNames.studentTraining]: stepProgressKeys.studentTraining, | ||
[stepNames.self]: stepProgressKeys.self, | ||
[stepNames.peer]: stepProgressKeys.peer, | ||
[stepNames.done]: stepProgressKeys.done, | ||
}; | ||
|
||
export const stepOrders = { | ||
self: [stepNames.self], | ||
peer: [stepNames.studentTraining, stepNames.peer], | ||
staff: [stepNames.staff], | ||
selfToPeer: [stepNames.studentTraining, stepNames.self, stepNames.peer], | ||
selfToStaff: [stepNames.self, stepNames.staff], | ||
peerToSelf: [stepNames.peer, stepNames.self], | ||
peerToSelfWithTraining: [stepNames.studentTraining, stepNames.peer, stepNames.self], | ||
peerToStaff: [stepNames.peer, stepNames.self, stepNames.staff], | ||
peerToStaffWithTraining: [stepNames.studentTraining, stepNames.peer, stepNames.self, stepNames.staff], | ||
}; | ||
|
||
const allSteps = (stepOrder) => [stepNames.submission, ...stepOrders[stepOrder]]; | ||
const loadKeys = (step) => stepProgressKeys[step]; | ||
const checkForProgressKeys = (steps) => (key) => steps.map(loadKeys).flat().includes(key); | ||
|
||
export const getProgressKeys = (stepOrder, stepName) => viewProgressKeys[stepName] | ||
.filter(checkForProgressKeys( | ||
stepName === stepNames.xblock ? allSteps(stepOrder) : stepOrders[stepOrder], | ||
)); |
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,53 @@ | ||
import React from 'react'; | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { render } from '@testing-library/react'; | ||
import { when } from 'jest-when'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { Provider } from 'react-redux'; | ||
|
||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
|
||
import { IntlProvider } from '@edx/frontend-platform/i18n'; | ||
|
||
import App from 'App'; | ||
|
||
import { stepRoutes } from 'constants/index'; | ||
|
||
import { createStore } from 'data/store'; | ||
import { | ||
courseId, | ||
xblockId, | ||
baseUrl, | ||
} from './constants'; | ||
|
||
export const mockQuerySelector = () => { | ||
jest.spyOn(document, 'querySelector').mockImplementation((selector) => ( | ||
selector === 'html' ? { scrollTo: jest.fn() } : selector | ||
)); | ||
}; | ||
|
||
export const post = jest.fn(); | ||
export const renderApp = (route) => { | ||
const store = createStore(false); | ||
const queryClient = new QueryClient({ queries: { retry: false } }); | ||
const location = `/${route}/${courseId}/${xblockId}/`; | ||
return ( | ||
<IntlProvider locale="en"> | ||
<Provider store={store}> | ||
<QueryClientProvider client={queryClient}> | ||
<MemoryRouter initialEntries={[location]}> | ||
<App /> | ||
</MemoryRouter> | ||
</QueryClientProvider> | ||
</Provider> | ||
</IntlProvider> | ||
); | ||
}; | ||
|
||
const basePageUrl = `${baseUrl}/get_learner_data/`; | ||
export const pageDataUrl = (view = undefined) => (view ? `${basePageUrl}${view}` : basePageUrl); | ||
export const loadApp = async (progressKey, step) => render(renderApp(stepRoutes[step])); | ||
|
||
export const mockPageData = (url, { response }) => when(post) | ||
.calledWith(url, expect.anything()).mockResolvedValue({ data: response }) | ||
.calledWith(url).mockResolvedValue({ data: response }); // eslint-disable-line newline-per-chained-call |
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 @@ | ||
.form-control.textarea-response { | ||
height: 500px; | ||
} |