Skip to content

Commit

Permalink
feat(junior): use challenge validation indicators in challenge display
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelie-crouillebois authored Feb 4, 2025
1 parent b8535f3 commit 27b37a3
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
6 changes: 4 additions & 2 deletions junior/app/models/challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export default class Challenge extends Model {
@attr('boolean') shuffled;
@attr() webComponentProps;
@attr('string') webComponentTagName;
@attr('boolean') hasEmbedInternalValidation;
@attr('boolean') noValidationNeeded;

@hasMany('activity-answer', { async: true, inverse: 'challenge' }) activityAnswers;

Expand All @@ -52,7 +54,7 @@ export default class Challenge extends Model {
}

get isLesson() {
return !!this.focused;
return !!this.focused || !!this.noValidationNeeded;
}

get isQROC() {
Expand Down Expand Up @@ -80,7 +82,7 @@ export default class Challenge extends Model {
}

get isEmbedAutoValidated() {
return this.timer !== null && this.timer >= 0;
return (this.timer !== null && this.timer >= 0) || !!this.hasEmbedInternalValidation;
}

get hasMedia() {
Expand Down
50 changes: 50 additions & 0 deletions junior/tests/unit/models/challenge-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,56 @@ module('Unit | Model | Challenge', function (hooks) {
});
});

module('#isLesson', function () {
test('should be true if focused is true', function (assert) {
const challenge = store.createRecord('challenge', {
focused: true,
});
assert.true(challenge.isLesson);
});
test('should be true if noValidationNeeded is true', function (assert) {
const challenge = store.createRecord('challenge', {
noValidationNeeded: true,
});
assert.true(challenge.isLesson);
});
test('should be false if noValidationNeeded & focused are not set', function (assert) {
const challenge = store.createRecord('challenge');
assert.false(challenge.isLesson);
});
test('should be false if noValidationNeeded & focused are false', function (assert) {
const challenge = store.createRecord('challenge', {
focused: false,
noValidationNeeded: false,
});
assert.false(challenge.isLesson);
});
});
module('#isEmbedAutoValidated', function () {
test('should be true if timer is set', function (assert) {
const challenge = store.createRecord('challenge', {
timer: 1,
});
assert.true(challenge.isEmbedAutoValidated);
});
test('should be true if hasEmbedInternalValidation is true', function (assert) {
const challenge = store.createRecord('challenge', {
hasEmbedInternalValidation: true,
});
assert.true(challenge.isEmbedAutoValidated);
});
test('should be false if timer & hasEmbedInternalValidation are not set', function (assert) {
const challenge = store.createRecord('challenge');
assert.false(challenge.isEmbedAutoValidated);
});
test('should be false hasEmbedInternalValidation is false', function (assert) {
const challenge = store.createRecord('challenge', {
hasEmbedInternalValidation: false,
});
assert.false(challenge.isEmbedAutoValidated);
});
});

module('#hasWebComponent', function () {
test('should be true when web component name and web component props are fields', function (assert) {
const challenge = store.createRecord('challenge', {
Expand Down

0 comments on commit 27b37a3

Please sign in to comment.