Skip to content

Commit

Permalink
fix: message error appears if the input is greater than the adjusted …
Browse files Browse the repository at this point in the history
…grade.
  • Loading branch information
lkatsikaris committed Oct 28, 2024
1 parent 3d2dd50 commit d0a26cc
Show file tree
Hide file tree
Showing 24 changed files with 102 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`HistoryTable component snapshot history table data (from bulkManagementHistory.map(this.formatHistoryRow) snapshot: maps resultsSummay to ResultsSummary, wraps filename and user, forwards the rest 1`] = `
[
{
Array [
Object {
"filename": <span
className="wrap-text-in-cell"
>
Expand All @@ -20,7 +20,7 @@ exports[`HistoryTable component snapshot history table data (from bulkManagement
Eifel
</span>,
},
{
Object {
"filename": <span
className="wrap-text-in-cell"
>
Expand All @@ -45,26 +45,26 @@ exports[`HistoryTable component snapshot snapshot - loads formatted table 1`] =
<DataTable
className="table-striped"
columns={
[
{
Array [
Object {
"Header": "Gradebook",
"accessor": "filename",
"columnSortable": false,
"width": "col-5",
},
{
Object {
"Header": "Download Summary",
"accessor": "resultsSummary",
"columnSortable": false,
"width": "col",
},
{
Object {
"Header": "Who",
"accessor": "user",
"columnSortable": false,
"width": "col-1",
},
{
Object {
"Header": "When",
"accessor": "timeUploaded",
"columnSortable": false,
Expand All @@ -73,8 +73,8 @@ exports[`HistoryTable component snapshot snapshot - loads formatted table 1`] =
]
}
data={
[
{
Array [
Object {
"filename": <span
className="wrap-text-in-cell"
>
Expand All @@ -92,7 +92,7 @@ exports[`HistoryTable component snapshot snapshot - loads formatted table 1`] =
Eifel
</span>,
},
{
Object {
"filename": <span
className="wrap-text-in-cell"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ exports[`ResultsSummary component snapshot - safe hyperlink with bulkGradesUrl w
<Hyperlink
destination="www.edx.org"
href={
{
"url": {
Object {
"url": Object {
"rowId": 42,
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`AssignmentFilter component render snapshot 1`] = `
label="Assignment"
onChange={[MockFunction]}
options={
[
Array [
<option
value=""
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ exports[`AssignmentFilterType component render snapshot 1`] = `
label="Assignment Types"
onChange={[MockFunction]}
options={
[
Array [
<option
value=""
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ exports[`StudentGroupsFilter component render snapshot 1`] = `
label="Tracks"
onChange={[MockFunction]}
options={
[
Array [
<option
value="Track-All"
>
Expand Down Expand Up @@ -43,7 +43,7 @@ exports[`StudentGroupsFilter component render snapshot 1`] = `
label="Cohorts"
onChange={[MockFunction]}
options={
[
Array [
<option
value="Cohort-All"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ exports[`BulkManagementControls render snapshot - show - network and import butt
>
<NetworkButton
label={
{
Object {
"defaultMessage": "Download Grades",
"description": "A labeled button that allows an admin user to download course grades all at once (in bulk).",
"id": "gradebook.GradesView.BulkManagementControls.bulkManagementLabel",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ exports[`AdjustedGradeInput component render snapshot 1`] = `
<Form.Control
name="adjustedGradeValue"
onChange={[MockFunction hook.onChange]}
type="text"
size="sm"
type="number"
value="test-value"
/>
some-hint-text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const useAdjustedGradeInputData = () => {
value,
onChange,
hintText,
possibleGrade,
};
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React from 'react';

import { Form } from '@openedx/paragon';
import { useIntl } from '@edx/frontend-platform/i18n';
import messages from '../messages';

import useAdjustedGradeInputData from './hooks';

Expand All @@ -13,17 +15,22 @@ export const AdjustedGradeInput = () => {
const {
value,
onChange,
possibleGrade,
hintText,
} = useAdjustedGradeInputData();

const { formatMessage } = useIntl();

return (
<span>
<Form.Control
type="text"
type="number"
name="adjustedGradeValue"
value={value}
onChange={onChange}
size="sm"
/>
{hintText}
{value > possibleGrade ? <div style={{ color: 'red' }}>{ formatMessage(messages.adjustedGradeError)}</div> : hintText}
</span>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ exports[`OverrideTable component render snapshot 1`] = `
<DataTable
columns="test-columns"
data={
[
{
Array [
Object {
"test": "data",
},
{
Object {
"andOther": "test-data",
},
{
Object {
"adjustedGrade": <AdjustedGradeInput />,
"date": {
"date": Object {
"formatted": 2000-01-01T00:00:00.000Z,
},
"reason": <ReasonInput />,
Expand Down
5 changes: 5 additions & 0 deletions src/components/GradesView/EditModal/OverrideTable/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ const messages = defineMessages({
defaultMessage: 'Reason',
description: 'Edit Modal Override Table Reason column header',
},
adjustedGradeError: {
id: 'gradebook.GradesView.EditModal.Overrides.adjustedGradeError',
defaultMessage: 'The value exceeds the maximum grade: {possibleGrade}',
description: 'Edit Modal Override Adjusted Grade Error',
},
});

export default messages;
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ exports[`EditModal component render with error snapshot 1`] = `
Cancel
</ModalDialog.CloseButton>
<Button
disabled={false}
onClick={[MockFunction hooks.handleAdjustedGradeClick]}
variant="primary"
>
Expand Down Expand Up @@ -80,6 +81,7 @@ exports[`EditModal component render without error snapshot 1`] = `
Cancel
</ModalDialog.CloseButton>
<Button
disabled={false}
onClick={[MockFunction hooks.handleAdjustedGradeClick]}
variant="primary"
>
Expand Down
8 changes: 7 additions & 1 deletion src/components/GradesView/EditModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import OverrideTable from './OverrideTable';
import ModalHeaders from './ModalHeaders';
import useEditModalData from './hooks';
import messages from './messages';
import useAdjustedGradeInputData from './OverrideTable/AdjustedGradeInput/hooks';

/**
* <EditModal />
Expand All @@ -31,6 +32,11 @@ export const EditModal = () => {
isOpen,
} = useEditModalData();

const {
value,
possibleGrade,
} = useAdjustedGradeInputData();

return (
<ModalDialog
title={formatMessage(messages.title)}
Expand All @@ -57,7 +63,7 @@ export const EditModal = () => {
<ModalDialog.CloseButton variant="tertiary">
{formatMessage(messages.closeText)}
</ModalDialog.CloseButton>
<Button variant="primary" onClick={handleAdjustedGradeClick}>
<Button variant="primary" onClick={handleAdjustedGradeClick} disabled={value > possibleGrade}>
{formatMessage(messages.saveGrade)}
</Button>
</ActionRow>
Expand Down
23 changes: 22 additions & 1 deletion src/components/GradesView/EditModal/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import OverrideTable from './OverrideTable';
import useEditModalData from './hooks';
import EditModal from '.';
import messages from './messages';
import useAdjustedGradeInputData from './OverrideTable/AdjustedGradeInput/hooks';

jest.mock('./hooks', () => jest.fn());
jest.mock('./ModalHeaders', () => 'ModalHeaders');
jest.mock('./OverrideTable', () => 'OverrideTable');
jest.mock('./OverrideTable/AdjustedGradeInput/hooks', () => jest.fn());

const hookProps = {
onClose: jest.fn().mockName('hooks.onClose'),
Expand All @@ -27,6 +29,12 @@ const hookProps = {
};
useEditModalData.mockReturnValue(hookProps);

const adjustedGradeProps = {
value: 50,
possibleGrade: 100,
};
useAdjustedGradeInputData.mockReturnValue(adjustedGradeProps);

let el;
describe('EditModal component', () => {
beforeEach(() => {
Expand All @@ -39,6 +47,7 @@ describe('EditModal component', () => {
});
it('initializes component hooks', () => {
expect(useEditModalData).toHaveBeenCalled();
expect(useAdjustedGradeInputData).toHaveBeenCalled();
});
});
describe('render', () => {
Expand Down Expand Up @@ -88,16 +97,18 @@ describe('EditModal component', () => {
expect(button.children[0].el).toEqual(formatMessage(messages.closeText));
expect(button.type).toEqual('ModalDialog.CloseButton');
});
test('adjusted grade button', () => {
test('adjusted grade button enabled', () => {
const button = footer[1].findByType(ActionRow)[0].children[1];
expect(button.children[0].el).toEqual(formatMessage(messages.saveGrade));
expect(button.type).toEqual('Button');
expect(button.props.onClick).toEqual(hookProps.handleAdjustedGradeClick);
expect(button.props.disabled).toEqual(false);
});
};
describe('without error', () => {
beforeEach(() => {
useEditModalData.mockReturnValueOnce({ ...hookProps, error: undefined });
useAdjustedGradeInputData.mockReturnValueOnce({ value: 50, possibleGrade: 100 });
el = shallow(<EditModal />);
});
test('snapshot', () => {
Expand All @@ -124,5 +135,15 @@ describe('EditModal component', () => {
});
testFooter();
});
describe('when the adjusted grade button is disabled', () => {
beforeEach(() => {
useAdjustedGradeInputData.mockReturnValueOnce({ value: 101, possibleGrade: 100 });
el = shallow(<EditModal />);
});
test('adjusted grade button is disabled', () => {
const button = el.instance.findByType(ActionRow)[0].children[1];
expect(button.props.disabled).toEqual(true);
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ exports[`FilterBadge render do not hide value snapshot 1`] = `
aria-label="close"
className="btn-info"
onClick={
{
"handleClose": [
Object {
"handleClose": Array [
"some",
"filters",
],
Expand Down Expand Up @@ -55,8 +55,8 @@ exports[`FilterBadge render hide Value snapshot 1`] = `
aria-label="close"
className="btn-info"
onClick={
{
"handleClose": [
Object {
"handleClose": Array [
"some",
"filters",
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
exports[`FilteredUsersLabel component render snapshot 1`] = `
<format-message-function
message={
{
Object {
"defaultMessage": "Showing {filteredUsers} of {totalUsers} total learners",
"description": "Users visibility label",
"id": "gradebook.GradesTab.usersVisibilityLabel",
}
}
values={
{
Object {
"filteredUsers": <BoldText
text={100}
/>,
Expand Down
Loading

0 comments on commit d0a26cc

Please sign in to comment.