Skip to content

Commit

Permalink
[FEATURE] Pix Junior - Utiliser les options de validation de challeng…
Browse files Browse the repository at this point in the history
…e provenant de Pix Editor

 #11296
  • Loading branch information
pix-service-auto-merge authored Feb 4, 2025
2 parents 5e7e72c + 27b37a3 commit 33fef72
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const serialize = function (challenges) {
'focused',
'timer',
'shuffled',
'hasEmbedInternalValidation',
'noValidationNeeded',
],
transform: (challenge) => {
return {
Expand Down
4 changes: 4 additions & 0 deletions api/src/shared/domain/models/Challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ class Challenge {
alternativeVersion,
blindnessCompatibility,
colorBlindnessCompatibility,
hasEmbedInternalValidation,
noValidationNeeded,
} = {}) {
this.id = id;
this.answer = answer;
Expand Down Expand Up @@ -121,6 +123,8 @@ class Challenge {
this.alternativeVersion = alternativeVersion;
this.blindnessCompatibility = blindnessCompatibility;
this.colorBlindnessCompatibility = colorBlindnessCompatibility;
this.hasEmbedInternalValidation = hasEmbedInternalValidation;
this.noValidationNeeded = noValidationNeeded;
}

isTimed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ function toDomain({ challengeDto, webComponentTagName, webComponentProps, skill,
blindnessCompatibility: challengeDto.accessibility1,
colorBlindnessCompatibility: challengeDto.accessibility2,
successProbabilityThreshold,
hasEmbedInternalValidation: challengeDto.hasEmbedInternalValidation,
noValidationNeeded: challengeDto.noValidationNeeded,
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ describe('Unit | Serializer | challenge-serializer', function () {
focused: false,
illustrationAlt: 'alt',
autoReply: false,
hasEmbedInternalValidation: true,
noValidationNeeded: true,
});

// when
Expand Down Expand Up @@ -58,6 +60,8 @@ describe('Unit | Serializer | challenge-serializer', function () {
timer: 300,
'illustration-alt': 'alt',
'auto-reply': false,
'has-embed-internal-validation': true,
'no-validation-needed': true,
},
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ describe('Integration | Repository | challenge-repository', function () {
locales: ['fr', 'nl'],
competenceId: 'competenceId00',
skillId: 'skillId00',
hasEmbedInternalValidation: true,
noValidationNeeded: true,
};
const challengeData01_skill00_qcu_valide_flashCompatible_fren_withEmbedJson = {
id: 'challengeId01',
Expand Down Expand Up @@ -83,6 +85,8 @@ describe('Integration | Repository | challenge-repository', function () {
locales: ['fr', 'en'],
competenceId: 'competenceId00',
skillId: 'skillId00',
hasEmbedInternalValidation: true,
noValidationNeeded: true,
};
const challengeData02_skill00_qcm_archive_flashCompatible_en_noEmbedJson = {
id: 'challengeId02',
Expand Down Expand Up @@ -531,6 +535,8 @@ describe('Integration | Repository | challenge-repository', function () {
}),
webComponentTagName: 'web-component',
webComponentProps: { prop1: 'value1', prop2: 'value2' },
hasEmbedInternalValidation: true,
noValidationNeeded: true,
}),
);
});
Expand Down Expand Up @@ -584,6 +590,8 @@ describe('Integration | Repository | challenge-repository', function () {
difficulty: skillData00_tube00competence00_actif.level,
hint: skillData00_tube00competence00_actif.hint_i18n.fr,
}),
hasEmbedInternalValidation: true,
noValidationNeeded: true,
}),
);
});
Expand Down
8 changes: 8 additions & 0 deletions api/tests/tooling/domain-builder/factory/build-challenge.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const buildChallenge = function ({
competenceId = 'recCOMP1',
webComponentTagName,
webComponentProps,
hasEmbedInternalValidation = false,
noValidationNeeded = false,
} = {}) {
return new Challenge({
id,
Expand Down Expand Up @@ -73,6 +75,8 @@ const buildChallenge = function ({
skill,
// references
competenceId,
hasEmbedInternalValidation,
noValidationNeeded,
});
};

Expand Down Expand Up @@ -109,6 +113,8 @@ const buildChallengeWithWebComponent = function ({
skill = buildSkill(),
// references
competenceId = 'recCOMP1',
hasEmbedInternalValidation,
noValidationNeeded,
} = {}) {
return new Challenge({
id,
Expand Down Expand Up @@ -143,6 +149,8 @@ const buildChallengeWithWebComponent = function ({
skill,
// references
competenceId,
hasEmbedInternalValidation,
noValidationNeeded,
});
};

Expand Down
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 33fef72

Please sign in to comment.