Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect field validation on the Course Grading page #1059

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const testObj = {};

const defaultAssignments = {
type: 'Test type',
minCount: 1,
minCount: 2,
dropCount: 1,
shortLabel: 'TT',
weight: 100,
Expand Down Expand Up @@ -59,6 +59,20 @@ describe('<AssignmentSection />', () => {
fireEvent.change(assignmentShortLabelInput, { target: { value: '123' } });
expect(testObj.graders[0].shortLabel).toBe('123');
});
it('checking correct assignmentTypeNameTitle value', () => {
const { getByTestId } = render(<RootWrapper setGradingData={setGradingData} />);
const assignmentShortLabelInput = getByTestId('assignment-type-name-input');
expect(assignmentShortLabelInput.value).toBe('Test type');
fireEvent.change(assignmentShortLabelInput, { target: { value: 'New test type' } });
expect(testObj.graders[0].type).toBe('New test type');
});
it('checking invalid assignmentTypeNameTitle value', () => {
const { getByText, getByTestId } = render(<RootWrapper setGradingData={setGradingData} />);
const assignmentShortLabelInput = getByTestId('assignment-type-name-input');
expect(assignmentShortLabelInput.value).toBe('Test type');
fireEvent.change(assignmentShortLabelInput, { target: { value: ' ' } });
expect(getByText(messages.assignmentTypeNameErrorMessage1.defaultMessage)).toBeInTheDocument();
});
it('checking correct assignment weight of total grade value', async () => {
const { getByTestId } = render(<RootWrapper setGradingData={setGradingData} />);
await waitFor(() => {
Expand All @@ -72,7 +86,7 @@ describe('<AssignmentSection />', () => {
const { getByTestId } = render(<RootWrapper setGradingData={setGradingData} />);
await waitFor(() => {
const assignmentTotalNumberInput = getByTestId('assignment-minCount-input');
expect(assignmentTotalNumberInput.value).toBe('1');
expect(assignmentTotalNumberInput.value).toBe('2');
fireEvent.change(assignmentTotalNumberInput, { target: { value: '123' } });
expect(testObj.graders[0].minCount).toBe(123);
});
Expand All @@ -82,26 +96,39 @@ describe('<AssignmentSection />', () => {
await waitFor(() => {
const assignmentNumberOfDroppableInput = getByTestId('assignment-dropCount-input');
expect(assignmentNumberOfDroppableInput.value).toBe('1');
fireEvent.change(assignmentNumberOfDroppableInput, { target: { value: '2' } });
expect(testObj.graders[0].dropCount).toBe(2);
fireEvent.change(assignmentNumberOfDroppableInput, { target: { value: '0' } });
expect(testObj.graders[0].dropCount).toBe(0);
});
});
it('checking correct error msg if dropCount have negative number or empty string', async () => {
it('checking correct error msg if dropCount is empty or negative integer', async () => {
const { getByText, getByTestId } = render(<RootWrapper />);
await waitFor(() => {
const assignmentNumberOfDroppableInput = getByTestId('assignment-dropCount-input');
expect(assignmentNumberOfDroppableInput.value).toBe('1');
fireEvent.change(assignmentNumberOfDroppableInput, { target: { value: '-2' } });
expect(getByText(messages.numberOfDroppableErrorMessage.defaultMessage)).toBeInTheDocument();
fireEvent.change(assignmentNumberOfDroppableInput, { target: { value: '' } });
expect(getByText(messages.numberOfDroppableErrorMessage.defaultMessage)).toBeInTheDocument();
fireEvent.change(assignmentNumberOfDroppableInput, { target: { value: '-5' } });
expect(getByText(messages.numberOfDroppableErrorMessage.defaultMessage)).toBeInTheDocument();
});
});
it('checking correct error msg if dropCount more than minCount', async () => {
const { getByTestId } = render(<RootWrapper />);
const assignmentMinCountInput = getByTestId('assignment-minCount-input');
expect(assignmentMinCountInput.value).toBe('2');
const assignmentNumberOfDroppableInput = getByTestId('assignment-dropCount-input');
expect(assignmentNumberOfDroppableInput.value).toBe('1');
expect(assignmentNumberOfDroppableInput.classList).not.toContain('is-invalid');
await waitFor(() => {
fireEvent.change(assignmentNumberOfDroppableInput, { target: { value: '50' } });
const dI = getByTestId('assignment-dropCount-input');
expect(dI.classList).toContain('is-invalid');
});
});
it('checking correct error msg if minCount have negative number or empty string', async () => {
const { getByText, getByTestId } = render(<RootWrapper />);
await waitFor(() => {
const assignmentMinCountInput = getByTestId('assignment-minCount-input');
expect(assignmentMinCountInput.value).toBe('1');
expect(assignmentMinCountInput.value).toBe('2');
fireEvent.change(assignmentMinCountInput, { target: { value: '-2' } });
expect(getByText(messages.totalNumberErrorMessage.defaultMessage)).toBeInTheDocument();
fireEvent.change(assignmentMinCountInput, { target: { value: '' } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ const AssignmentItem = ({
{descriptions}
</Form.Control.Feedback>
{errorEffort && (
<Form.Control.Feedback className="feedback-error" type="invalid">
{errorMsg}
</Form.Control.Feedback>
)}
{gradeField?.dropCount !== 0 && gradeField?.dropCount > gradeField?.minCount && (
<Form.Control.Feedback className="feedback-error" type="invalid">
{secondErrorMsg}
</Form.Control.Feedback>
gradeField?.dropCount ? (
<Form.Control.Feedback className="feedback-error" type="invalid">
{gradeField?.dropCount !== 0 && gradeField?.dropCount >= gradeField?.minCount ? secondErrorMsg : errorMsg}
</Form.Control.Feedback>
) : (
<Form.Control.Feedback className="feedback-error" type="invalid">
{errorMsg}
</Form.Control.Feedback>
)
)}
</Form.Group>
</li>
Expand Down
12 changes: 9 additions & 3 deletions src/grading-settings/assignment-section/utils/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ export const validationAssignmentFields = (
assignmentDropCount,
) => {
const courseGradingTypes = courseGraders?.map(grade => grade.type);
const minCountValue = courseGraders?.find(grade => grade.id === assignmentId).minCount;

switch (assignmentName) {
case assignmentType:
if (assignmentValue === '') {
if (assignmentValue.trim() === '') {
updateAssignmentErrorList(assignmentName, assignmentId, setErrorList, setShowSavePrompt);
return;
}
Expand All @@ -77,7 +78,7 @@ export const validationAssignmentFields = (
);
break;
case weightOfTotalGrade:
if (assignmentValue < 0 || assignmentValue > 100 || assignmentValue === '-0') {
if (assignmentValue === '' || assignmentValue < 0 || assignmentValue > 100 || assignmentValue === '-0') {
updateAssignmentErrorList(
assignmentName,
assignmentId,
Expand Down Expand Up @@ -113,7 +114,12 @@ export const validationAssignmentFields = (
);
break;
case assignmentDropCount:
if (assignmentValue < 0 || assignmentValue === '' || assignmentValue === '-0') {
if (
assignmentValue >= minCountValue
|| assignmentValue < 0
|| assignmentValue === ''
|| assignmentValue === '-0'
) {
updateAssignmentErrorList(
assignmentName,
assignmentId,
Expand Down
Loading