-
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.
chore: update logic and rewrite in typescript
- Loading branch information
1 parent
b9cf1d9
commit 1087da2
Showing
29 changed files
with
1,188 additions
and
408 deletions.
There are no files selected for viewing
67 changes: 0 additions & 67 deletions
67
src/components/Rubric/CriterionContainer/CriterionFeedback.jsx
This file was deleted.
Oops, something went wrong.
27 changes: 27 additions & 0 deletions
27
src/components/Rubric/CriterionContainer/CriterionFeedback.test.tsx
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,27 @@ | ||
import React from 'react'; | ||
import { shallow } from '@edx/react-unit-test-utils'; | ||
|
||
import CriterionFeedback from './CriterionFeedback'; | ||
|
||
describe('<CriterionFeedback />', () => { | ||
const props = { | ||
criterion: { | ||
feedbackValue: 'feedback-1', | ||
feedbackIsInvalid: false, | ||
feedbackOnChange: jest.fn().mockName('feedbackOnChange'), | ||
feedbackEnabled: true, | ||
feedbackRequired: true, | ||
}, | ||
}; | ||
describe('renders', () => { | ||
test('feedbackEnabled', () => { | ||
const wrapper = shallow(<CriterionFeedback {...props} />); | ||
expect(wrapper.snapshot).toMatchSnapshot(); | ||
}); | ||
|
||
test('feedbackDisabled', () => { | ||
const wrapper = shallow(<CriterionFeedback {...props} criterion={{ ...props.criterion, feedbackEnabled: false }} />); | ||
expect(wrapper.snapshot).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
src/components/Rubric/CriterionContainer/CriterionFeedback.tsx
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,61 @@ | ||
import React from 'react'; | ||
import { InferProps } from 'prop-types'; | ||
|
||
import { Form } from '@edx/paragon'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
|
||
import { feedbackRequirement } from 'data/services/lms/constants'; | ||
|
||
import messages from './messages'; | ||
import { Criterion } from '../hooks'; | ||
|
||
type CriterionFeedbackProps = { | ||
criterion: Pick< | ||
Criterion, | ||
| 'feedbackValue' | ||
| 'feedbackIsInvalid' | ||
| 'feedbackOnChange' | ||
| 'feedbackEnabled' | ||
| 'feedbackRequired' | ||
>; | ||
}; | ||
|
||
/** | ||
* <CriterionFeedback /> | ||
*/ | ||
const CriterionFeedback = ({ criterion }: CriterionFeedbackProps) => { | ||
const { formatMessage } = useIntl(); | ||
|
||
let commentMessage = formatMessage(messages.addComments); | ||
if (criterion.feedbackRequired === feedbackRequirement.optional) { | ||
commentMessage += ` ${formatMessage(messages.optional)}`; | ||
} | ||
|
||
const { feedbackValue, feedbackIsInvalid, feedbackOnChange } = criterion; | ||
|
||
if ( | ||
!criterion.feedbackEnabled || | ||
criterion.feedbackRequired === feedbackRequirement.disabled | ||
) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<Form.Group isInvalid={feedbackIsInvalid}> | ||
<Form.Control | ||
as='textarea' | ||
className='criterion-feedback feedback-input' | ||
floatingLabel={commentMessage} | ||
value={feedbackValue} | ||
onChange={feedbackOnChange} | ||
/> | ||
{feedbackIsInvalid && ( | ||
<Form.Control.Feedback type='invalid' className='feedback-error-msg'> | ||
{formatMessage(messages.criterionFeedbackError)} | ||
</Form.Control.Feedback> | ||
)} | ||
</Form.Group> | ||
); | ||
}; | ||
|
||
export default CriterionFeedback; |
65 changes: 0 additions & 65 deletions
65
src/components/Rubric/CriterionContainer/RadioCriterion.jsx
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
src/components/Rubric/CriterionContainer/RadioCriterion.test.tsx
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,44 @@ | ||
import React from 'react'; | ||
import { shallow } from '@edx/react-unit-test-utils'; | ||
|
||
import RadioCriterion from './RadioCriterion'; | ||
|
||
describe('<RadioCriterion />', () => { | ||
const props = { | ||
isGrading: true, | ||
criterion: { | ||
name: "criterion-1", | ||
optionsValue: 'option-1', | ||
optionsIsInvalid: true, | ||
optionsOnChange: jest.fn().mockName('optionsOnChange'), | ||
options: [ | ||
{ | ||
name: 'option-1', | ||
description: 'description-1', | ||
points: 1, | ||
}, | ||
{ | ||
name: 'option-2', | ||
description: 'description-2', | ||
points: 2, | ||
}, | ||
], | ||
}, | ||
}; | ||
describe('renders', () => { | ||
test('optins is invalid', () => { | ||
const wrapper = shallow(<RadioCriterion {...props} />); | ||
expect(wrapper.snapshot).toMatchSnapshot(); | ||
}); | ||
|
||
test('options is valid', () => { | ||
const wrapper = shallow(<RadioCriterion {...props} />); | ||
expect(wrapper.snapshot).toMatchSnapshot(); | ||
}); | ||
|
||
test('not isGrading', () => { | ||
const wrapper = shallow(<RadioCriterion {...props} isGrading={false} />); | ||
expect(wrapper.snapshot).toMatchSnapshot(); | ||
}); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
src/components/Rubric/CriterionContainer/RadioCriterion.tsx
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,50 @@ | ||
import React from 'react'; | ||
|
||
import { Form } from '@edx/paragon'; | ||
import { useIntl } from '@edx/frontend-platform/i18n'; | ||
|
||
import messages from './messages'; | ||
import { Criterion } from '../hooks'; | ||
|
||
type RadioCriterionProps = { | ||
isGrading: boolean; | ||
criterion: Pick< | ||
Criterion, | ||
'optionsValue' | 'optionsIsInvalid' | 'optionsOnChange' | 'name' | 'options' | ||
>; | ||
}; | ||
|
||
/** | ||
* <RadioCriterion /> | ||
*/ | ||
const RadioCriterion = ({ isGrading, criterion }: RadioCriterionProps) => { | ||
const { formatMessage } = useIntl(); | ||
|
||
const { optionsValue, optionsIsInvalid, optionsOnChange } = criterion; | ||
|
||
return ( | ||
<Form.RadioSet name={criterion.name} value={optionsValue}> | ||
{criterion.options.map((option) => ( | ||
<Form.Radio | ||
className='criteria-option' | ||
key={option.name} | ||
value={option.name} | ||
description={formatMessage(messages.optionPoints, { | ||
points: option.points, | ||
})} | ||
onChange={optionsOnChange} | ||
disabled={!isGrading} | ||
> | ||
{option.name} | ||
</Form.Radio> | ||
))} | ||
{optionsIsInvalid && ( | ||
<Form.Control.Feedback type='invalid' className='feedback-error-msg'> | ||
{formatMessage(messages.rubricSelectedError)} | ||
</Form.Control.Feedback> | ||
)} | ||
</Form.RadioSet> | ||
); | ||
}; | ||
|
||
export default RadioCriterion; |
28 changes: 28 additions & 0 deletions
28
src/components/Rubric/CriterionContainer/ReviewCriterion.test.tsx
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,28 @@ | ||
import React from 'react'; | ||
import { shallow } from '@edx/react-unit-test-utils'; | ||
|
||
import ReviewCriterion from './ReviewCriterion'; | ||
|
||
describe('<ReviewCriterion />', () => { | ||
const props = { | ||
criterion: { | ||
options: [ | ||
{ | ||
name: 'option-1', | ||
description: 'description-1', | ||
points: 1, | ||
}, | ||
{ | ||
name: 'option-2', | ||
description: 'description-2', | ||
points: 2, | ||
}, | ||
], | ||
}, | ||
}; | ||
|
||
test('renders', () => { | ||
const wrapper = shallow(<ReviewCriterion {...props} />); | ||
expect(wrapper.snapshot).toMatchSnapshot(); | ||
}); | ||
}); |
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
5 changes: 5 additions & 0 deletions
5
src/components/Rubric/CriterionContainer/__snapshots__/CriterionFeedback.test.tsx.snap
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,5 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`<CriterionFeedback /> renders feedbackDisabled 1`] = `null`; | ||
|
||
exports[`<CriterionFeedback /> renders feedbackEnabled 1`] = `null`; |
Oops, something went wrong.