Skip to content

Commit

Permalink
fix: wrong min count alert showing (#730) (#911)
Browse files Browse the repository at this point in the history
Co-authored-by: Kristin Aoki <[email protected]>
  • Loading branch information
dyudyunov and KristinAoki authored Mar 21, 2024
1 parent 0020597 commit 9192287
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
26 changes: 13 additions & 13 deletions src/grading-settings/assignment-section/AssignmentSection.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ describe('<AssignmentSection />', () => {
it('checking correct assignment weight of total grade value', async () => {
const { getByTestId } = render(<RootWrapper setGradingData={setGradingData} />);
await waitFor(() => {
const assignmentShortLabelInput = getByTestId('assignment-weight-input');
expect(assignmentShortLabelInput.value).toBe('100');
fireEvent.change(assignmentShortLabelInput, { target: { value: '123' } });
expect(testObj.graders[0].weight).toBe('123');
const assignmentWeightInput = getByTestId('assignment-weight-input');
expect(assignmentWeightInput.value).toBe('100');
fireEvent.change(assignmentWeightInput, { target: { value: '123' } });
expect(testObj.graders[0].weight).toBe(123);
});
});
it('checking correct assignment total number value', async () => {
Expand All @@ -74,7 +74,7 @@ describe('<AssignmentSection />', () => {
const assignmentTotalNumberInput = getByTestId('assignment-minCount-input');
expect(assignmentTotalNumberInput.value).toBe('1');
fireEvent.change(assignmentTotalNumberInput, { target: { value: '123' } });
expect(testObj.graders[0].minCount).toBe('123');
expect(testObj.graders[0].minCount).toBe(123);
});
});
it('checking correct assignment number of droppable value', async () => {
Expand All @@ -83,7 +83,7 @@ describe('<AssignmentSection />', () => {
const assignmentNumberOfDroppableInput = getByTestId('assignment-dropCount-input');
expect(assignmentNumberOfDroppableInput.value).toBe('1');
fireEvent.change(assignmentNumberOfDroppableInput, { target: { value: '2' } });
expect(testObj.graders[0].dropCount).toBe('2');
expect(testObj.graders[0].dropCount).toBe(2);
});
});
it('checking correct error msg if dropCount have negative number or empty string', async () => {
Expand All @@ -100,20 +100,20 @@ describe('<AssignmentSection />', () => {
it('checking correct error msg if minCount have negative number or empty string', async () => {
const { getByText, getByTestId } = render(<RootWrapper />);
await waitFor(() => {
const assignmentNumberOfDroppableInput = getByTestId('assignment-minCount-input');
expect(assignmentNumberOfDroppableInput.value).toBe('1');
fireEvent.change(assignmentNumberOfDroppableInput, { target: { value: '-2' } });
const assignmentMinCountInput = getByTestId('assignment-minCount-input');
expect(assignmentMinCountInput.value).toBe('1');
fireEvent.change(assignmentMinCountInput, { target: { value: '-2' } });
expect(getByText(messages.totalNumberErrorMessage.defaultMessage)).toBeInTheDocument();
fireEvent.change(assignmentNumberOfDroppableInput, { target: { value: '' } });
fireEvent.change(assignmentMinCountInput, { target: { value: '' } });
expect(getByText(messages.totalNumberErrorMessage.defaultMessage)).toBeInTheDocument();
});
});
it('checking correct error msg if total weight have negative number', async () => {
const { getByText, getByTestId } = render(<RootWrapper />);
await waitFor(() => {
const assignmentNumberOfDroppableInput = getByTestId('assignment-weight-input');
expect(assignmentNumberOfDroppableInput.value).toBe('100');
fireEvent.change(assignmentNumberOfDroppableInput, { target: { value: '-100' } });
const assignmentWeightInput = getByTestId('assignment-weight-input');
expect(assignmentWeightInput.value).toBe('100');
fireEvent.change(assignmentWeightInput, { target: { value: '-100' } });
expect(getByText(messages.weightOfTotalGradeErrorMessage.defaultMessage)).toBeInTheDocument();
});
});
Expand Down
11 changes: 8 additions & 3 deletions src/grading-settings/assignment-section/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,20 @@ const AssignmentSection = ({
}

const handleAssignmentChange = (e, assignmentId) => {
const { name, value } = e.target;
const { name, value, type: inputType } = e.target;

let inputValue = value;
if (inputType === 'number') {
inputValue = parseInt(value, 10);
}

setShowSavePrompt(true);

setGradingData(prevState => ({
...prevState,
graders: graders.map(grader => {
if (grader.id === assignmentId) {
return { ...grader, [name]: value };
return { ...grader, [name]: inputValue };
}
return grader;
}),
Expand All @@ -66,7 +71,7 @@ const AssignmentSection = ({
return (
<div className="assignment-items">
{graders?.map((gradeField) => {
const courseAssignmentUsage = courseAssignmentLists[gradeField.type.toLowerCase()];
const courseAssignmentUsage = courseAssignmentLists[gradeField.type];
const showDefinedCaseAlert = gradeField.minCount !== courseAssignmentUsage?.length
&& Boolean(courseAssignmentUsage?.length);
const showNotDefinedCaseAlert = !courseAssignmentUsage?.length && Boolean(gradeField.type);
Expand Down

0 comments on commit 9192287

Please sign in to comment.