Skip to content

Commit ab13912

Browse files
feat: separate text response view from editor
1 parent 2f4258b commit ab13912

File tree

11 files changed

+126
-4
lines changed

11 files changed

+126
-4
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<TextResponse /> render Rich Text Editor 1`] = `
4+
<div
5+
className="mt-2"
6+
>
7+
<RichTextEditor
8+
disabled={true}
9+
onChange={[MockFunction onChange]}
10+
value="value"
11+
/>
12+
</div>
13+
`;
14+
15+
exports[`<TextResponse /> render Text Editor 1`] = `
16+
<div
17+
className="mt-2"
18+
>
19+
<TextEditor
20+
disabled={false}
21+
onChange={[MockFunction onChange]}
22+
optional={false}
23+
value="value"
24+
/>
25+
</div>
26+
`;
27+
28+
exports[`<TextResponseEditor /> render Rich Text Editor 1`] = `
29+
<div
30+
className="mt-2"
31+
>
32+
<RichTextEditor
33+
disabled={true}
34+
onChange={[MockFunction onChange]}
35+
value="value"
36+
/>
37+
</div>
38+
`;
39+
40+
exports[`<TextResponseEditor /> render Text Editor 1`] = `
41+
<div
42+
className="mt-2"
43+
>
44+
<TextEditor
45+
disabled={false}
46+
onChange={[MockFunction onChange]}
47+
optional={false}
48+
value="value"
49+
/>
50+
</div>
51+
`;
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React from 'react';
2+
import PropTypes from 'prop-types';
3+
4+
import TextEditor from 'components/TextResponseEditor/TextEditor';
5+
import RichTextEditor from 'components/TextResponseEditor/RichTextEditor';
6+
7+
import './index.scss';
8+
9+
const TextResponseEditor = ({ submissionConfig, value, onChange }) => {
10+
const { textResponseConfig } = submissionConfig;
11+
const { optional, enabled } = textResponseConfig;
12+
const props = {
13+
optional,
14+
disabled: !enabled,
15+
value,
16+
onChange,
17+
};
18+
19+
return (
20+
<div className="mt-2">
21+
{
22+
textResponseConfig?.editorType === 'text' ? <TextEditor {...props} /> : <RichTextEditor {...props} />
23+
}
24+
</div>
25+
);
26+
};
27+
28+
TextResponseEditor.propTypes = {
29+
submissionConfig: PropTypes.shape({
30+
textResponseConfig: PropTypes.shape({
31+
optional: PropTypes.bool,
32+
enabled: PropTypes.bool,
33+
editorType: PropTypes.string,
34+
}),
35+
}).isRequired,
36+
value: PropTypes.string.isRequired,
37+
onChange: PropTypes.func.isRequired,
38+
};
39+
40+
export default TextResponseEditor;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.textarea-response {
2+
min-height: 200px;
3+
max-height: 300px;
4+
overflow-y: scroll;
5+
}

src/components/TextResponse/index.test.jsx renamed to src/components/TextResponseEditor/index.test.jsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { shallow } from '@edx/react-unit-test-utils';
2-
import TextResponse from '.';
2+
import TextResponseEditor from '.';
33

44
jest.mock('./TextEditor', () => 'TextEditor');
55
jest.mock('./RichTextEditor', () => 'RichTextEditor');
66

7-
describe('<TextResponse />', () => {
7+
describe('<TextResponseEditor />', () => {
88
const props = {
99
submissionConfig: {
1010
textResponseConfig: {
@@ -19,15 +19,15 @@ describe('<TextResponse />', () => {
1919
};
2020

2121
it('render Text Editor ', () => {
22-
const wrapper = shallow(<TextResponse {...props} />);
22+
const wrapper = shallow(<TextResponseEditor {...props} />);
2323
expect(wrapper.snapshot).toMatchSnapshot();
2424

2525
expect(wrapper.instance.findByType('TextEditor').length).toEqual(1);
2626
expect(wrapper.instance.findByType('RichTextEditor').length).toEqual(0);
2727
});
2828

2929
it('render Rich Text Editor ', () => {
30-
const wrapper = shallow(<TextResponse {...props} submissionConfig={{ textResponseConfig: { editorType: 'rich-text' } }} />);
30+
const wrapper = shallow(<TextResponseEditor {...props} submissionConfig={{ textResponseConfig: { editorType: 'rich-text' } }} />);
3131
expect(wrapper.snapshot).toMatchSnapshot();
3232

3333
expect(wrapper.instance.findByType('TextEditor').length).toEqual(0);

0 commit comments

Comments
 (0)