Skip to content

Commit

Permalink
🐛 mon-pix: fix focus and time information page when challenge is both…
Browse files Browse the repository at this point in the history
… focused and timed

Co-authored-by: Andreia Pena Ferreira <[email protected]>
  • Loading branch information
P-Jeremy and AndreiaPena committed Nov 6, 2024
1 parent a438791 commit 17f1a35
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 0 deletions.
17 changes: 17 additions & 0 deletions mon-pix/app/controllers/assessments/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export default class ChallengeController extends Controller {
get couldDisplayInfoAlert() {
return (
!this.hasFocusedOutOfWindow &&
this.displayChallenge &&
!this.model.answer &&
this.model.challenge.focused &&
!this.model.assessment.hasFocusedOutChallenge
Expand Down Expand Up @@ -163,6 +164,13 @@ export default class ChallengeController extends Controller {
return true;
}

if (this._isTimedChallenge && this._isFocusedCertificationChallenge) {
return !!(
(this.hasConfirmedFocusChallengeWarningScreen && this.hasUserConfirmedTimedChallengeWarning) ||
this.model.assessment.hasTimeoutChallenge
);
}

if (this._isTimedChallenge) {
if (this.hasUserConfirmedTimedChallengeWarning || this.model.assessment.hasTimeoutChallenge) return true;
}
Expand Down Expand Up @@ -201,6 +209,15 @@ export default class ChallengeController extends Controller {
}

get displayTimedChallengeInstructions() {
if (this.isTimedChallengeWithoutAnswer && this.isFocusedCertificationChallengeWithoutAnswer) {
return (
this.hasConfirmedFocusChallengeWarningScreen &&
this.isTimedChallengeWithoutAnswer &&
!this.hasUserConfirmedTimedChallengeWarning &&
!this.model.assessment.hasTimeoutChallenge
);
}

return (
this.isTimedChallengeWithoutAnswer &&
!this.hasUserConfirmedTimedChallengeWarning &&
Expand Down
58 changes: 58 additions & 0 deletions mon-pix/tests/acceptance/challenge-item-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,64 @@ module('Acceptance | Displaying a challenge of any type', function (hooks) {
assert.dom(screen.getByText('Mode focus')).exists();
});
});

module('when a challenge is focused and timed', function () {
test('should display focus first then timer information page', async function (assert) {
// given
const user = server.create('user', 'withEmail');
await authenticate(user);

const focusedCertificationChallengeWarningManager = this.owner.lookup(
'service:focused-certification-challenge-warning-manager',
);
focusedCertificationChallengeWarningManager.reset();

assessment = server.create('assessment', 'ofCertificationType');
server.create('challenge', 'forCertification', 'QCM', 'withFocused', { timer: 60 });

const certificationCourse = server.create('certification-course', {
accessCode: 'ABCD12',
sessionId: 1,
nbChallenges: 2,
firstName: 'Alin',
lastName: 'Cendy',
});
assessment = certificationCourse.assessment;

// when
const screen = await visit(`/assessments/${assessment.id}/challenges/0`);

// then
assert
.dom(
screen.getByRole('heading', {
name: 'Mode focus',
level: 1,
}),
)
.exists();

// when
await click(screen.getByRole('button', { name: 'Je suis prêt' }));

// then
assert
.dom(
screen.getByRole('heading', {
name: 'Vous disposerez de 1 minute pour réussir la question suivante.',
level: 1,
}),
)
.exists();

// when
await click(screen.getByRole('button', { name: `Commencer l'épreuve` }));

// then
assert.dom(screen.getByRole('heading', { name: 'Mode Focus', level: 3 })).exists();
assert.dom(screen.getByText('1:00')).exists();
});
});
});

module('when assessment is v2 certification', function (hooks) {
Expand Down

0 comments on commit 17f1a35

Please sign in to comment.