Skip to content

Commit

Permalink
fix: displaying the correct default randomization value (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroAlipov authored Nov 30, 2023
1 parent 8928d35 commit 60439d5
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ export const SettingsWidget = ({
{
problemType === ProblemTypeKeys.ADVANCED && (
<div className="my-3">
<Randomization randomization={settings.randomization} updateSettings={updateSettings} />
<Randomization
randomization={settings.randomization}
defaultValue={defaultSettings.rerandomize}
updateSettings={updateSettings}
/>
</div>
)
}
Expand Down Expand Up @@ -162,6 +166,7 @@ SettingsWidget.propTypes = {
maxAttempts: PropTypes.number,
showanswer: PropTypes.string,
showReseButton: PropTypes.bool,
rerandomize: PropTypes.string,
}).isRequired,
// eslint-disable-next-line
settings: PropTypes.any.isRequired,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,58 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`RandomizationCard snapshot snapshot: renders randonmization setting card with randomization defined 1`] = `
exports[`RandomizationCard snapshot snapshot: renders randomization setting card with default randomization 1`] = `
<SettingsOption
className=""
extraSections={Array []}
hasExpandableTextArea={false}
none={true}
summary="sUmmary"
title="Randomization"
>
<div
className="mb-3"
>
{randomization, select,
null {No Python based randomization is present in this problem.}
other {Defines when to randomize the variables specified in the associated Python script. For problems that do not randomize values, specify "Never".}
}
</div>
<Form.Group>
<Form.Control
as="select"
onChange={[MockFunction randomizationCardHooks.handleChange]}
value="default_vAlUE"
>
<option
key="never"
value="never"
>
Never
</option>
<option
key="always"
value="always"
>
Always
</option>
<option
key="onreset"
value="onreset"
>
On Reset
</option>
<option
key="per_student"
value="per_student"
>
Per Student
</option>
</Form.Control>
</Form.Group>
</SettingsOption>
`;

exports[`RandomizationCard snapshot snapshot: renders randomization setting card with randomization defined 1`] = `
<SettingsOption
className=""
extraSections={Array []}
Expand Down Expand Up @@ -36,8 +88,8 @@ exports[`RandomizationCard snapshot snapshot: renders randonmization setting car
Always
</option>
<option
key="on_reset"
value="on_reset"
key="onreset"
value="onreset"
>
On Reset
</option>
Expand All @@ -52,7 +104,7 @@ exports[`RandomizationCard snapshot snapshot: renders randonmization setting car
</SettingsOption>
`;

exports[`RandomizationCard snapshot snapshot: renders randonmization setting card with randomization null 1`] = `
exports[`RandomizationCard snapshot snapshot: renders randomization setting card with randomization null 1`] = `
<SettingsOption
className=""
extraSections={Array []}
Expand Down Expand Up @@ -88,8 +140,8 @@ exports[`RandomizationCard snapshot snapshot: renders randonmization setting car
Always
</option>
<option
key="on_reset"
value="on_reset"
key="onreset"
value="onreset"
>
On Reset
</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ import { RandomizationTypesKeys, RandomizationTypes } from '../../../../../../..

export const RandomizationCard = ({
randomization,
defaultValue,
updateSettings,
// inject
intl,
}) => {
const { summary, handleChange } = useRandomizationSettingStatus({ randomization, updateSettings });
const curretRandomization = randomization || defaultValue;
const { summary, handleChange } = useRandomizationSettingStatus({
randomization: curretRandomization,
updateSettings,
});
return (
<SettingsOption
title={intl.formatMessage(messages.randomizationSettingTitle)}
Expand All @@ -27,7 +32,7 @@ export const RandomizationCard = ({
<Form.Group>
<Form.Control
as="select"
value={randomization}
value={curretRandomization}
onChange={handleChange}
>
{
Expand All @@ -48,6 +53,7 @@ export const RandomizationCard = ({
};

RandomizationCard.propTypes = {
defaultValue: PropTypes.string.isRequired,
randomization: PropTypes.string.isRequired,
updateSettings: PropTypes.func.isRequired,
intl: intlShape.isRequired,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jest.mock('./hooks', () => ({
describe('RandomizationCard', () => {
const props = {
randomization: 'sOmE_vAlUE',
defaultValue: 'default_vAlUE',
updateSettings: jest.fn().mockName('args.updateSettings'),
intl: { formatMessage },
};
Expand All @@ -32,11 +33,14 @@ describe('RandomizationCard', () => {
});

describe('snapshot', () => {
test('snapshot: renders randonmization setting card with randomization defined', () => {
test('snapshot: renders randomization setting card with randomization defined', () => {
expect(shallow(<RandomizationCard {...props} />)).toMatchSnapshot();
});
test('snapshot: renders randonmization setting card with randomization null', () => {
test('snapshot: renders randomization setting card with default randomization', () => {
expect(shallow(<RandomizationCard {...props} randomization={null} />)).toMatchSnapshot();
});
test('snapshot: renders randomization setting card with randomization null', () => {
expect(shallow(<RandomizationCard {...props} randomization={null} defaultValue={null} />)).toMatchSnapshot();
});
});
});
2 changes: 1 addition & 1 deletion src/editors/data/constants/problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ export const ShowAnswerTypes = StrictDict({
export const RandomizationTypesKeys = StrictDict({
NEVER: 'never',
ALWAYS: 'always',
ONRESET: 'on_reset',
ONRESET: 'onreset',
PERSTUDENT: 'per_student',
});

Expand Down
3 changes: 2 additions & 1 deletion src/editors/data/redux/thunkActions/problem.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export const getDataFromOlx = ({ rawOLX, rawSettings, defaultSettings }) => {
olxParser = new OLXParser(rawOLX);
parsedProblem = olxParser.getParsedOLXData();
} catch (error) {
// eslint-disable-next-line no-console
console.error('The Problem Could Not Be Parsed from OLX. redirecting to Advanced editor.', error);
return { problemType: ProblemTypeKeys.ADVANCED, rawOLX, settings: parseSettings(rawSettings, defaultSettings) };
}
Expand All @@ -55,7 +56,7 @@ export const loadProblem = ({ rawOLX, rawSettings, defaultSettings }) => (dispat
};

export const fetchAdvancedSettings = ({ rawOLX, rawSettings }) => (dispatch) => {
const advancedProblemSettingKeys = ['max_attempts', 'showanswer', 'show_reset_button'];
const advancedProblemSettingKeys = ['max_attempts', 'showanswer', 'show_reset_button', 'rerandomize'];
dispatch(requests.fetchAdvancedSettings({
onSuccess: (response) => {
const defaultSettings = {};
Expand Down
5 changes: 5 additions & 0 deletions src/editors/data/redux/thunkActions/video.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export const loadVideoData = (selectedVideoId, selectedVideoUrl) => (dispatch, g
// Use the selected video url first
const videoSourceUrl = selectedVideoUrl != null ? selectedVideoUrl : videoUrl;
const [licenseType, licenseOptions] = module.parseLicense({ licenseData: studioView, level: 'block' });
// eslint-disable-next-line no-console
console.log(licenseType);
const transcripts = rawVideoData.transcriptsFromSelected ? rawVideoData.transcriptsFromSelected
: module.parseTranscripts({ transcriptsData: studioView });
Expand Down Expand Up @@ -168,6 +169,7 @@ export const parseTranscripts = ({ transcriptsData }) => {
return Object.keys(transcriptsObj.value);
} catch (error) {
if (error instanceof SyntaxError) {
// eslint-disable-next-line no-console
console.error('Invalid JSON:', error.message);
} else {
throw error;
Expand Down Expand Up @@ -265,6 +267,7 @@ export const uploadThumbnail = ({ thumbnail, emptyCanvas }) => (dispatch, getSta
}));
}
},
// eslint-disable-next-line no-console
onFailure: (e) => console.log({ UploadFailure: e }, 'Resampling thumbnail upload'),
}));
};
Expand Down Expand Up @@ -404,6 +407,7 @@ export const uploadVideo = ({ supportedFiles, setLoadSpinner, postUploadRedirect
const uploadUrl = fileObj.upload_url;
const uploadFile = supportedFiles.find((file) => file.get('file').name === fileName);
if (!uploadFile) {
// eslint-disable-next-line no-console
console.error(`Could not find file object with name "${fileName}" in supportedFiles array.`);
return;
}
Expand All @@ -417,6 +421,7 @@ export const uploadVideo = ({ supportedFiles, setLoadSpinner, postUploadRedirect
},
})
.then(() => postUploadRedirect(edxVideoId))
// eslint-disable-next-line no-console
.catch((error) => console.error('Error uploading file:', error));
}));
setLoadSpinner(false);
Expand Down
1 change: 1 addition & 0 deletions src/editors/data/services/cms/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const problemDataProps = {
max_attempts: PropTypes.number,
showanswer: PropTypes.string,
show_reset_button: PropTypes.bool,
rerandomize: PropTypes.string,
}),
}),
};
Expand Down

0 comments on commit 60439d5

Please sign in to comment.