Skip to content

Commit

Permalink
refactor: opt. donut test, rename field to optionalCompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielVZ96 committed Mar 10, 2024
1 parent 6d3359f commit 57f0f6c
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/course-home/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ export function normalizeOutlineBlocks(courseId, blocks) {
title: block.display_name,
resumeBlock: block.resume_block,
sequenceIds: block.children || [],
optional: block.optional_completion,
optionalCompletion: block.optional_completion,
};
break;

Expand All @@ -153,7 +153,7 @@ export function normalizeOutlineBlocks(courseId, blocks) {
// link in the outline (even though we ignore the given url and use an internal <Link> to ourselves).
showLink: !!block.lms_web_url,
title: block.display_name,
optional: block.optional_completion,
optionalCompletion: block.optional_completion,
};
break;

Expand Down
4 changes: 2 additions & 2 deletions src/course-home/outline-tab/Section.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Section = ({
complete,
sequenceIds,
title,
optional,
optionalCompletion,
} = section;
const {
courseBlocks: {
Expand Down Expand Up @@ -75,7 +75,7 @@ const Section = ({
</div>
<div className="col-10 ml-3 p-0 font-weight-bold text-dark-500">
<span className="align-middle">{title}</span>
<Badge className="ml-2" variant="light" hidden={!optional}>{intl.formatMessage(messages.optionalCompletion)}</Badge>
<Badge className="ml-2" variant="light" hidden={!optionalCompletion}>{intl.formatMessage(messages.optionalCompletion)}</Badge>
<span className="sr-only">
, {intl.formatMessage(complete ? messages.completedSection : messages.incompleteSection)}
</span>
Expand Down
12 changes: 8 additions & 4 deletions src/course-home/outline-tab/SequenceLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useModel } from '../../generic/model-store';
import { useScrollTo } from './hooks';
import messages from './messages';
import './SequenceLink.scss';
import { Badge } from '@edx/paragon';

Check failure on line 20 in src/course-home/outline-tab/SequenceLink.jsx

View workflow job for this annotation

GitHub Actions / tests

`@edx/paragon` import should occur before import of `../../shared/effort-estimate`

const SequenceLink = ({
id,
Expand All @@ -33,7 +34,7 @@ const SequenceLink = ({
due,
showLink,
title,
optional,
optionalCompletion,
} = sequence;
const {
userTimezone,
Expand Down Expand Up @@ -129,12 +130,15 @@ const SequenceLink = ({
, {intl.formatMessage(complete ? messages.completedAssignment : messages.incompleteAssignment)}
</span>
<EffortEstimate className="ml-3 align-middle" block={sequence} />
{
optionalCompletion &&

Check failure on line 134 in src/course-home/outline-tab/SequenceLink.jsx

View workflow job for this annotation

GitHub Actions / tests

'&&' should be placed at the beginning of the line

Check failure on line 134 in src/course-home/outline-tab/SequenceLink.jsx

View workflow job for this annotation

GitHub Actions / tests

Trailing spaces not allowed
<Badge className="ml-2" variant="light">

Check failure on line 135 in src/course-home/outline-tab/SequenceLink.jsx

View workflow job for this annotation

GitHub Actions / tests

Missing parentheses around multilines JSX
{intl.formatMessage(messages.optionalCompletion)}
</Badge>
}
</div>
</div>
<div className="row w-100 m-0 ml-3 pl-3">
<small className="text-body pl-2 pr-0">
{optional ? intl.formatMessage(messages.optionalCompletion) : ''}
</small>
<small className="text-body pl-2">
{due ? dueDateMessage : noDueDateMessage}
</small>
Expand Down
2 changes: 1 addition & 1 deletion src/course-home/outline-tab/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ const messages = defineMessages({
optionalCompletion: {
id: 'learning.outline.optionalBlock',
defaultMessage: 'Optional',
description: 'Used as a label to indicate that a section, sequence, or unit is optional.',
description: 'Used as a label to indicate that a section or sequence is optional.',
},
proctoringInfoPanel: {
id: 'learning.proctoringPanel.header',
Expand Down
92 changes: 92 additions & 0 deletions src/course-home/progress-tab/ProgressTab.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -1379,4 +1379,96 @@ describe('Progress Tab', () => {
expect(screen.getByText('Course progress for otherstudent')).toBeInTheDocument();
});
});

describe('Completion Donut Chart', () => {
it('Renders optional completion donut chart', async () => {
setTabData({
completion_summary: {
complete_count: 1,
incomplete_count: 1,
locked_count: 1,
},
optional_completion_summary: {
complete_count: 1,
incomplete_count: 1,
locked_count: 0,
},
verified_mode: {
access_expiration_date: '2050-01-01T12:00:00',
currency: 'USD',
currency_symbol: '$',
price: 149,
sku: 'ABCD1234',
upgrade_url: 'edx.org/upgrade',
},
section_scores: [
{
display_name: 'First section',
subsections: [
{
assignment_type: 'Homework',
block_key: 'block-v1:edX+DemoX+Demo_Course+type@sequential+block@12345',
display_name: 'First subsection',
learner_has_access: false,
has_graded_assignment: true,
num_points_earned: 8,
num_points_possible: 10,
percent_graded: 1.0,
show_correctness: 'always',
show_grades: true,
url: 'http://learning.edx.org/course/course-v1:edX+Test+run/first_subsection',
},
],
},
],
});
await fetchAndRender();
expect(screen.getByText('optional')).toBeInTheDocument();
});

Check failure on line 1428 in src/course-home/progress-tab/ProgressTab.test.jsx

View workflow job for this annotation

GitHub Actions / tests

Trailing spaces not allowed
it('Hides optional completion donut chart', async () => {
setTabData({
completion_summary: {
complete_count: 1,
incomplete_count: 1,
locked_count: 1,
},
optional_completion_summary: {
complete_count: 0,
incomplete_count: 0,
locked_count: 0,
},
verified_mode: {
access_expiration_date: '2050-01-01T12:00:00',
currency: 'USD',
currency_symbol: '$',
price: 149,
sku: 'ABCD1234',
upgrade_url: 'edx.org/upgrade',
},
section_scores: [
{
display_name: 'First section',
subsections: [
{
assignment_type: 'Homework',
block_key: 'block-v1:edX+DemoX+Demo_Course+type@sequential+block@12345',
display_name: 'First subsection',
learner_has_access: false,
has_graded_assignment: true,
num_points_earned: 8,
num_points_possible: 10,
percent_graded: 1.0,
show_correctness: 'always',
show_grades: true,
url: 'http://learning.edx.org/course/course-v1:edX+Test+run/first_subsection',
},
],
},
],
});
await fetchAndRender();
expect(screen.queryByText('optional')).not.toBeInTheDocument();
});
});
});
2 changes: 1 addition & 1 deletion src/courseware/course/sequence/Unit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ const Unit = ({
return (
<div className="unit">
<h1 className="mb-0 h3">{unit.title}</h1>
<Badge className="ml-2" variant="light" hidden={!unit.optional}>{intl.formatMessage(messages.optionalCompletion)}</Badge>
<Badge className="ml-2" variant="light" hidden={!unit.optionalCompletion}>{intl.formatMessage(messages.optionalCompletion)}</Badge>
<h2 className="sr-only">{intl.formatMessage(messages.headerPlaceholder)}</h2>
<BookmarkButton
unitId={unit.id}
Expand Down
2 changes: 1 addition & 1 deletion src/courseware/course/sequence/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const messages = defineMessages({
optionalCompletion: {
id: 'learn.sequence.optionalBlock',
defaultMessage: 'Optional',
description: 'Used as a label to indicate that a section, sequence, or unit is optional.',
description: 'Used as a label to indicate that a unit is optional.',
},
});

Expand Down
2 changes: 1 addition & 1 deletion src/courseware/data/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ function normalizeSequenceMetadata(sequence) {
contentType: unit.type,
graded: unit.graded,
containsContentTypeGatedContent: unit.contains_content_type_gated_content,
optional: unit.optional_completion,
optionalCompletion: unit.optional_completion,
})),
};
}
Expand Down

0 comments on commit 57f0f6c

Please sign in to comment.