Skip to content
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
14 changes: 2 additions & 12 deletions src/editors/data/redux/thunkActions/problem.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from './problem';
import { checkboxesOLXWithFeedbackAndHintsOLX, advancedProblemOlX, blankProblemOLX } from '../../../containers/ProblemEditor/data/mockData/olxTestData';
import { ProblemTypeKeys } from '../../constants/problem';
import * as requests from './requests';

const mockOlx = 'SOmEVALue';
const mockBuildOlx = jest.fn(() => mockOlx);
Expand Down Expand Up @@ -72,22 +71,13 @@ describe('problem thunkActions', () => {
);
});
test('switchToMarkdownEditor dispatches correct actions', () => {
switchToMarkdownEditor()(dispatch, getState);
switchToMarkdownEditor()(dispatch);

expect(dispatch).toHaveBeenCalledWith(
actions.problem.updateField({
isMarkdownEditorEnabled: true,
}),
);

expect(dispatch).toHaveBeenCalledWith(
requests.saveBlock({
content: {
settings: { markdown_edited: true },
olx: blockValue.data.data,
},
}),
);
});

describe('switchEditor', () => {
Expand All @@ -110,7 +100,7 @@ describe('problem thunkActions', () => {

test('dispatches switchToMarkdownEditor when editorType is markdown', () => {
switchEditor('markdown')(dispatch, getState);
expect(switchToMarkdownEditorMock).toHaveBeenCalledWith(dispatch, getState);
expect(switchToMarkdownEditorMock).toHaveBeenCalledWith(dispatch);
});
});

Expand Down
16 changes: 8 additions & 8 deletions src/editors/data/redux/thunkActions/problem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ export const switchToAdvancedEditor = () => (dispatch, getState) => {
dispatch(actions.problem.updateField({ problemType: ProblemTypeKeys.ADVANCED, rawOLX }));
};

export const switchToMarkdownEditor = () => (dispatch, getState) => {
const state = getState();
export const switchToMarkdownEditor = () => (dispatch) => {
dispatch(actions.problem.updateField({ isMarkdownEditorEnabled: true }));
const { blockValue } = state.app;
const olx = get(blockValue, 'data.data', '');
const content = { settings: { markdown_edited: true }, olx };

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just confirming... it is not necessary to set markdown_editor: true? Does something else take care of this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we’re also setting the markdown_edited value in the parseState function. That’s what returns the payload used when saving a problem.

// Sending a request to save the problem block with the updated markdown_edited value
dispatch(requests.saveBlock({ content }));
};

export const switchEditor = (editorType) => (dispatch, getState) => (editorType === 'advanced' ? switchToAdvancedEditor : switchToMarkdownEditor)()(dispatch, getState);
export const switchEditor = (editorType) => (dispatch, getState) => {
if (editorType === 'advanced') {
switchToAdvancedEditor()(dispatch, getState);
} else {
switchToMarkdownEditor()(dispatch);
}
};

export const isBlankProblem = ({ rawOLX }) => {
if (['<problem></problem>', '<problem/>'].includes(rawOLX.replace(/\s/g, ''))) {
Expand Down