Skip to content
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

feat: set initial value for pacing_type in course run create form #997

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/components/CreateCourseRunPage/CreateCourseRunForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ const BaseCreateCourseRunForm = ({
helpText={pacingHelp}
/>
)}
props={{
name: 'pacing_type',
}}
/>
<ButtonToolbar>
<Link to={`/courses/${uuid}`}>
Expand Down
54 changes: 53 additions & 1 deletion src/components/CreateCourseRunPage/CreateCourseRunPage.test.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount, shallow } from 'enzyme';
import { shallowToJson } from 'enzyme-to-json';
import { MemoryRouter } from 'react-router-dom';
import { Provider } from 'react-redux';
import { createStore } from 'redux';
import { IntlProvider } from '@edx/frontend-platform/i18n';
import { Alert } from '@openedx/paragon';

import { CreateCourseRunForm } from './CreateCourseRunForm';
import CreateCourseRunPage from './index';
import { courseOptions } from '../../data/constants/testData';
import createRootReducer from '../../data/reducers';

describe('CreateCourseRunPage', () => {
it('renders html correctly', () => {
Expand Down Expand Up @@ -99,4 +104,51 @@ describe('CreateCourseRunPage', () => {
const form = component.find(CreateCourseRunForm);
expect(form).toHaveLength(0);
});

it.each(['instructor_paced', 'self_paced'])('default pacing options match last run', (pacing) => {
const store = createStore(createRootReducer());
const CreateCourseRunPageWrapper = () => (
<MemoryRouter>
<Provider store={store}>
<IntlProvider locale="en">
<CreateCourseRunPage
id="00000000-0000-0000-0000-000000000001"
courseInfo={{
data: {
course_runs: [{
status: 'unpublished',
key: 'course-v1:edX+cs101+2T2019',
pacing_type: pacing,
}],
title: 'Test Course',
},
isFetching: false,
isCreating: false,
error: null,
}}
courseRunOptions={{
data: {
actions: {
POST: {
pacing_type: {
choices: [
{ value: 'instructor_paced', display_name: 'Instructor-paced' },
{ value: 'self_paced', display_name: 'Self-paced' },
],
},
},
},
},
}}
/>
</IntlProvider>
</Provider>
</MemoryRouter>
);

const component = mount(CreateCourseRunPageWrapper());

const pacingSelect = component.find({ name: 'pacing_type' }).hostNodes().find('select');
expect(pacingSelect.props().value).toEqual(pacing);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ exports[`CreateCourseRunForm renders html correctly 1`] = `
},
]
}
props={
{
"name": "pacing_type",
}
}
type="text"
/>
<ButtonToolbar
Expand Down Expand Up @@ -372,6 +377,11 @@ exports[`CreateCourseRunForm renders html correctly when creating 1`] = `
},
]
}
props={
{
"name": "pacing_type",
}
}
type="text"
/>
<ButtonToolbar
Expand Down Expand Up @@ -590,6 +600,11 @@ exports[`CreateCourseRunForm renders html correctly with Course Type 1`] = `
},
]
}
props={
{
"name": "pacing_type",
}
}
type="text"
/>
<ButtonToolbar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ exports[`CreateCourseRunPage renders html correctly 1`] = `
getFormState={[Function]}
initialValues={
{
"pacing_type": undefined,
"rerun": "",
"run_type": undefined,
}
Expand Down Expand Up @@ -449,6 +450,7 @@ exports[`CreateCourseRunPage renders html correctly when creating 1`] = `
getFormState={[Function]}
initialValues={
{
"pacing_type": undefined,
"rerun": "",
"run_type": undefined,
}
Expand Down Expand Up @@ -500,6 +502,7 @@ exports[`CreateCourseRunPage renders html correctly when error 1`] = `
getFormState={[Function]}
initialValues={
{
"pacing_type": undefined,
"rerun": "",
"run_type": undefined,
}
Expand Down Expand Up @@ -984,6 +987,7 @@ exports[`CreateCourseRunPage renders html correctly with Course Type 1`] = `
getFormState={[Function]}
initialValues={
{
"pacing_type": undefined,
"rerun": "",
"run_type": "4e260c57-24ef-46c1-9a0d-5ec3a30f6b0c",
}
Expand Down
2 changes: 2 additions & 0 deletions src/components/CreateCourseRunPage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class CreateCourseRunPage extends React.Component {
const courseRunTypeOptions = parsedTypeOptions && parsedTypeOptions.courseRunTypeOptions;
const defaultRunType = courseRunTypeOptions && courseRunTypeOptions[type]
&& courseRunTypeOptions[type][1] && courseRunTypeOptions[type][1].value;
const defaultPacingType = course_runs && defaultRun && course_runs.find(run => run.key === defaultRun).pacing_type;

return (
<>
Expand Down Expand Up @@ -173,6 +174,7 @@ class CreateCourseRunPage extends React.Component {
initialValues={{
rerun: defaultRun,
run_type: defaultRunType,
pacing_type: defaultPacingType,
}}
courseTypeUuid={type}
canSetRunKey={canSetRunKey}
Expand Down
Loading