Skip to content

Commit 8fef36c

Browse files
feat(api): add new attribute on Assessment to indicate if question counter should be displayed and use it front
1 parent 95ff4df commit 8fef36c

File tree

15 files changed

+77
-35
lines changed

15 files changed

+77
-35
lines changed

api/src/shared/domain/models/Assessment.js

+6
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ class Assessment {
100100
this.showProgressBar = false;
101101
this.hasCheckpoints = false;
102102
this.showLevelup = false;
103+
this.showQuestionCounter = true;
103104
this.title = this.certificationCourseId;
104105
break;
105106
}
@@ -108,19 +109,22 @@ class Assessment {
108109
this.showProgressBar = true;
109110
this.hasCheckpoints = true;
110111
this.showLevelup = true;
112+
this.showQuestionCounter = true;
111113
break;
112114
}
113115

114116
case Assessment.types.DEMO: {
115117
this.showProgressBar = true;
116118
this.hasCheckpoints = false;
117119
this.showLevelup = false;
120+
this.showQuestionCounter = true;
118121
break;
119122
}
120123
case Assessment.types.PREVIEW: {
121124
this.showProgressBar = false;
122125
this.hasCheckpoints = false;
123126
this.showLevelup = false;
127+
this.showQuestionCounter = true;
124128
this.title = 'Preview';
125129
break;
126130
}
@@ -130,6 +134,7 @@ class Assessment {
130134
this.showProgressBar = isAssessmentCampaignNoFlash;
131135
this.hasCheckpoints = isAssessmentCampaignNoFlash;
132136
this.showLevelup = isAssessmentCampaignNoFlash;
137+
this.showQuestionCounter = this.isFlash() || campaign.isAssessment;
133138
this.title = campaign.title;
134139
break;
135140
}
@@ -138,6 +143,7 @@ class Assessment {
138143
this.showProgressBar = false;
139144
this.hasCheckpoints = false;
140145
this.showLevelup = false;
146+
this.showQuestionCounter = false;
141147
this.title = '';
142148
}
143149
}

api/src/shared/infrastructure/serializers/jsonapi/assessment-serializer.js

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const serialize = function (assessments) {
5454
'showProgressBar',
5555
'hasCheckpoints',
5656
'showLevelup',
57+
'showQuestionCounter',
5758
],
5859
answers: {
5960
ref: 'id',

api/tests/shared/acceptance/application/assessments/assessment-controller-get_test.js

+2
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ describe('Acceptance | API | assessment-controller-get', function () {
172172
'has-checkpoints': false,
173173
'show-levelup': false,
174174
'show-progress-bar': false,
175+
'show-question-counter': true,
175176
},
176177
relationships: {
177178
course: {
@@ -298,6 +299,7 @@ describe('Acceptance | API | assessment-controller-get', function () {
298299
'has-checkpoints': false,
299300
'show-levelup': false,
300301
'show-progress-bar': false,
302+
'show-question-counter': true,
301303
},
302304
relationships: {
303305
course: { data: { type: 'courses', id: courseId } },

api/tests/shared/unit/domain/models/Assessment_test.js

+7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ describe('Unit | Domain | Models | Assessment', function () {
2323
hasCheckpoints: true,
2424
showProgressBar: true,
2525
showLevelup: true,
26+
showQuestionCounter: true,
2627
expectedTitle: 'Ma Compétence',
2728
attributes: { title: 'Ma Compétence' },
2829
},
@@ -32,6 +33,7 @@ describe('Unit | Domain | Models | Assessment', function () {
3233
hasCheckpoints: false,
3334
showProgressBar: false,
3435
showLevelup: false,
36+
showQuestionCounter: true,
3537
expectedTitle: 'certificationCourseId',
3638
attributes: { certificationCourseId: 'certificationCourseId' },
3739
},
@@ -41,6 +43,7 @@ describe('Unit | Domain | Models | Assessment', function () {
4143
hasCheckpoints: false,
4244
showProgressBar: true,
4345
showLevelup: false,
46+
showQuestionCounter: true,
4447
expectedTitle: 'Mon Course',
4548
attributes: { title: 'Mon Course' },
4649
},
@@ -50,6 +53,7 @@ describe('Unit | Domain | Models | Assessment', function () {
5053
hasCheckpoints: false,
5154
showProgressBar: false,
5255
showLevelup: false,
56+
showQuestionCounter: true,
5357
expectedTitle: 'Preview',
5458
attributes: {},
5559
},
@@ -59,6 +63,7 @@ describe('Unit | Domain | Models | Assessment', function () {
5963
hasCheckpoints: true,
6064
showProgressBar: true,
6165
showLevelup: true,
66+
showQuestionCounter: true,
6267
expectedTitle: 'Ma Campagne',
6368
// eslint-disable-next-line mocha/no-setup-in-describe
6469
attributes: { campaign: domainBuilder.buildCampaign({ title: 'Ma Campagne', type: CampaignTypes.ASSESSMENT }) },
@@ -69,6 +74,7 @@ describe('Unit | Domain | Models | Assessment', function () {
6974
hasCheckpoints: false,
7075
showProgressBar: false,
7176
showLevelup: false,
77+
showQuestionCounter: false,
7278
expectedTitle: 'Ma Campagne',
7379
// eslint-disable-next-line mocha/no-setup-in-describe
7480
attributes: { campaign: domainBuilder.buildCampaign({ title: 'Ma Campagne', type: CampaignTypes.EXAM }) },
@@ -79,6 +85,7 @@ describe('Unit | Domain | Models | Assessment', function () {
7985
hasCheckpoints: false,
8086
showProgressBar: false,
8187
showLevelup: false,
88+
showQuestionCounter: true,
8289
expectedTitle: 'Ma Campagne',
8390
attributes: {
8491
// eslint-disable-next-line mocha/no-setup-in-describe

api/tests/shared/unit/infrastructure/serializers/jsonapi/assessment-serializer_test.js

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ describe('Unit | Serializer | JSONAPI | assessment-serializer', function () {
1212
assessment.hasCheckpoints = false;
1313
assessment.showProgressBar = false;
1414
assessment.showLevelup = false;
15+
assessment.showQuestionCounter = false;
1516
const expectedJson = {
1617
data: {
1718
id: assessment.id.toString(),
@@ -28,7 +29,9 @@ describe('Unit | Serializer | JSONAPI | assessment-serializer', function () {
2829
method: Assessment.methods.CERTIFICATION_DETERMINED,
2930
'show-progress-bar': false,
3031
'show-levelup': false,
32+
'show-question-counter': false,
3133
'has-checkpoints': false,
34+
'show-question-counter': true,
3235
'code-campaign': undefined,
3336
},
3437
relationships: {
+36-32
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,42 @@
1-
{{#if this.showProgressBar}}
2-
<div class="progress-bar-container">
3-
<div
4-
class="progress-bar-current-step"
5-
role="progressbar"
6-
aria-valuenow={{this.currentStepNumber}}
7-
aria-valuemin="1"
8-
aria-valuemax="5"
9-
aria-label="{{t 'pages.challenge.parts.progress'}}"
10-
>
11-
{{t "pages.challenge.progress-bar.label"}}
12-
{{this.currentStepNumber}}
13-
/
14-
{{this.maxStepsNumber}}
15-
</div>
1+
<div class="progress-bar">
2+
{{#if this.showProgressBar}}
3+
<div class="progress-bar-container">
4+
{{#if this.showQuestionCounterInsideProgressBar}}
5+
<div
6+
class="progress-bar-current-step"
7+
role="progressbar"
8+
aria-valuenow={{this.currentStepNumber}}
9+
aria-valuemin="1"
10+
aria-valuemax="5"
11+
aria-label="{{t 'pages.challenge.parts.progress'}}"
12+
>
13+
{{t "pages.challenge.progress-bar.label"}}
14+
{{this.currentStepNumber}}
15+
/
16+
{{this.maxStepsNumber}}
17+
</div>
18+
{{/if}}
1619

17-
<div class="progress-bar-content">
18-
<div class="progress-bar-background"></div>
20+
<div class="progress-bar-content">
21+
<div class="progress-bar-background"></div>
1922

20-
<div class="progress-bar-progression" style={{this.progressionWidth}}></div>
23+
<div class="progress-bar-progression" style={{this.progressionWidth}}></div>
2124

22-
<div class="progress-bar-steps">
23-
{{#each this.steps as |step|}}
24-
<span class="progress-bar-step" style={{step.background}}></span>
25-
{{/each}}
25+
<div class="progress-bar-steps">
26+
{{#each this.steps as |step|}}
27+
<span class="progress-bar-step" style={{step.background}}></span>
28+
{{/each}}
29+
</div>
2630
</div>
2731
</div>
28-
</div>
29-
{{else}}
30-
<div class="assessment-progress" role="progressbar" aria-label="{{t 'pages.challenge.parts.progress'}}">
31-
<div class="assessment-progress__label">{{t "pages.challenge.progress-bar.label"}}</div>
32-
<div class="assessment-progress__value">
33-
{{this.currentStepNumber}}
34-
/
35-
{{this.maxStepsNumber}}
32+
{{else if this.showQuestionCounterOutside}}
33+
<div class="assessment-progress" role="progressbar" aria-label="{{t 'pages.challenge.parts.progress'}}">
34+
<div class="assessment-progress__label">{{t "pages.challenge.progress-bar.label"}}</div>
35+
<div class="assessment-progress__value">
36+
{{this.currentStepNumber}}
37+
/
38+
{{this.maxStepsNumber}}
39+
</div>
3640
</div>
37-
</div>
38-
{{/if}}
41+
{{/if}}
42+
</div>

mon-pix/app/components/progress-bar.js

+8
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ export default class ProgressBar extends Component {
1414
return this.args.assessment.showProgressBar && this.media.isDesktop;
1515
}
1616

17+
get showQuestionCounterInsideProgressBar() {
18+
return this.showProgressBar && this.args.assessment.showQuestionCounter;
19+
}
20+
21+
get showQuestionCounterOutside() {
22+
return !this.showProgressBar && this.args.assessment.showQuestionCounter;
23+
}
24+
1725
get currentStepIndex() {
1826
return progressInAssessment.getCurrentStepIndex(this.args.assessment, this.args.currentChallengeNumber);
1927
}

mon-pix/app/models/assessment.js

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default class Assessment extends Model {
2525
@attr('boolean') hasCheckpoints;
2626
@attr('boolean') showProgressBar;
2727
@attr('boolean') showLevelup;
28+
@attr('boolean') showQuestionCounter;
2829

2930
// references
3031
@attr('string') competenceId;

mon-pix/app/styles/components/_progress-bar.scss

+4
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,7 @@
5858
font-size: 1.875rem;
5959
}
6060
}
61+
62+
.progress-bar {
63+
min-height: var(--pix-spacing-4x);
64+
}

mon-pix/mirage/factories/assessment.js

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default Factory.extend({
5454
type: 'CAMPAIGN',
5555
method: 'FLASH',
5656
showProgressBar: false,
57+
showQuestionCounter: true,
5758
}),
5859

5960
withCurrentChallengeTimeout: trait({

mon-pix/mirage/factories/certification-course.js

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export default Factory.extend({
2323
hasCheckpoints: false,
2424
showProgressBar: false,
2525
showLevelup: false,
26+
showQuestionCounter: true,
2627
}),
2728
});
2829
}

mon-pix/mirage/routes/assessments/post-assessments.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default function (schema, request) {
1515
hasCheckpoints: false,
1616
showProgressBar: true,
1717
showLevelup: false,
18+
showQuestionCounter: true,
1819
});
1920
}
2021

mon-pix/mirage/routes/campaign-participations/post-campaign-participation.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,10 @@ export default function (schema, request) {
4343
const newAssessment = {
4444
type: 'CAMPAIGN',
4545
codeCampaign: campaign.code,
46-
hasCheckpoints: true,
47-
showProgressBar: true,
48-
showLevelup: true,
46+
hasCheckpoints: campaign.type === 'ASSESSMENT',
47+
showProgressBar: campaign.type === 'ASSESSMENT',
48+
showLevelup: campaign.type === 'ASSESSMENT',
49+
showQuestionCounter: campaign.type === 'ASSESSMENT',
4950
};
5051

5152
const assessment = schema.assessments.create(newAssessment);

mon-pix/mirage/routes/post-competence-evaluation.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default function (schema, request) {
1515
hasCheckpoints: true,
1616
showProgressBar: true,
1717
showLevelup: true,
18+
showQuestionCounter: true,
1819
});
1920
return schema.competenceEvaluations.create({ assessment, competenceId });
2021
}

mon-pix/tests/integration/components/progress-bar-test.js

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ module('Integration | Component | progress-bar', function (hooks) {
2222
type: 'CAMPAIGN',
2323
showProgressBar: true,
2424
hasCheckpoints: true,
25+
showQuestionCounter: true,
2526
});
2627
mockAssessment.answers = answers;
2728

0 commit comments

Comments
 (0)