Skip to content

Commit

Permalink
♻️ mon-pix: use getter to retrieve subscription title
Browse files Browse the repository at this point in the history
  • Loading branch information
P-Jeremy committed Oct 9, 2024
1 parent 7d7c6ea commit 9598462
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 54 deletions.
2 changes: 1 addition & 1 deletion mon-pix/app/components/certification-starter.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="certification-starter-subscriptions">
<div class="certification-starter-subscriptions-container">
<p class="certification-starter-subscriptions-container-title">
{{t "pages.certification-start.subscription"}}
{{this.subscriptionTitle}}
</p>
<div class="certification-starter-subscriptions-container-items">

Expand Down
11 changes: 11 additions & 0 deletions mon-pix/app/components/certification-starter.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ export default class CertificationStarter extends Component {
).label;
}

get subscriptionTitle() {
if (
!this.args.certificationCandidateSubscription.isSessionVersion3 ||
this.args.certificationCandidateSubscription.isV3CoreAndComplementary
) {
return this.intl.t('pages.certification-start.core-and-complementary-subscriptions');
} else {
return this.intl.t('pages.certification-start.complementary-subscription');
}
}

@action
async submit(e) {
e.preventDefault();
Expand Down
9 changes: 9 additions & 0 deletions mon-pix/app/models/certification-candidate-subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ export default class CertificationCandidateSubscription extends Model {
);
}

get isV3CoreAndComplementary() {
return (
this.isSessionVersion3 &&
this.eligibleSubscriptions.length === 2 &&
this.eligibleSubscriptions.some((eligibleSubscription) => eligibleSubscription.type === 'CORE') &&
this.eligibleSubscriptions.some((eligibleSubscription) => eligibleSubscription.type === 'COMPLEMENTARY')
);
}

get isSessionVersion3() {
return this.sessionVersion === 3;
}
Expand Down
161 changes: 112 additions & 49 deletions mon-pix/tests/integration/components/certification-starter-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,20 @@ module('Integration | Component | certification-starter', function (hooks) {
);
});
});
});
module('when the candidate has complementary certification subscription', function () {
module('when the candidate is eligible', function () {

module('when the candidate has core and complementary subscriptions', function () {
test('should display subscription eligible panel', async function (assert) {
// given
const store = this.owner.lookup('service:store');
this.set(
'certificationCandidateSubscription',
store.createRecord('certification-candidate-subscription', {
eligibleSubscriptions: [{ label: 'Certif complémentaire 1' }],
eligibleSubscriptions: [
{ label: null, type: 'CORE' },
{ label: 'Pix+ toto', type: 'COMPLEMENTARY' },
],
nonEligibleSubscription: null,
sessionVersion: 3,
}),
);

Expand All @@ -88,22 +91,26 @@ module('Integration | Component | certification-starter', function (hooks) {
);

// then
assert.notOk(screen.queryByText('Vous n’êtes pas éligible à'));
assert.ok(
screen.getByText(
screen.queryByText(
'Vous êtes inscrit à la certification complémentaire suivante en plus de la certification Pix :',
),
);
assert.ok(screen.getByText('Certif complémentaire 1'));
assert.ok(screen.getByText('Pix+ toto'));
});
});

test('should not display subscription non eligible panel', async function (assert) {
module('when the candidate has only a complementary subscriptions', function () {
test('should display subscription eligible panel', async function (assert) {
// given
const store = this.owner.lookup('service:store');
this.set(
'certificationCandidateSubscription',
store.createRecord('certification-candidate-subscription', {
eligibleSubscriptions: [{ label: 'Certif complémentaire 1' }],
eligibleSubscriptions: [{ label: 'Pix+ toto', type: 'COMPLEMENTARY' }],
nonEligibleSubscription: null,
sessionVersion: 3,
}),
);

Expand All @@ -114,56 +121,112 @@ module('Integration | Component | certification-starter', function (hooks) {

// then
assert.notOk(screen.queryByText('Vous n’êtes pas éligible à'));
assert.ok(screen.queryByText('Vous êtes inscrit à la certification complémentaire suivante :'));
assert.ok(screen.getByText('Pix+ toto'));
});
});
});

module('when the candidate is not eligible', function () {
test('should display subscription non eligible panel', async function (assert) {
// given
const store = this.owner.lookup('service:store');
this.set(
'certificationCandidateSubscription',
store.createRecord('certification-candidate-subscription', {
eligibleSubscriptions: null,
nonEligibleSubscription: { label: 'Certif complémentaire 1' },
}),
);
module('when the session is v2', function () {
module('when the candidate has complementary certification subscription', function () {
module('when the candidate is eligible', function () {
test('should display subscription eligible panel', async function (assert) {
// given
const store = this.owner.lookup('service:store');
this.set(
'certificationCandidateSubscription',
store.createRecord('certification-candidate-subscription', {
eligibleSubscriptions: [{ label: 'Certif complémentaire 1', type: 'COMPLEMENTARY' }],
nonEligibleSubscription: null,
sessionVersion: 2,
}),
);

// when
const screen = await render(
hbs`<CertificationStarter @certificationCandidateSubscription={{this.certificationCandidateSubscription}} />`,
);
// when
const screen = await render(
hbs`<CertificationStarter @certificationCandidateSubscription={{this.certificationCandidateSubscription}} />`,
);

// then
assert.ok(
screen.getByText(
"Vous n'êtes pas éligible à Certif complémentaire 1. Vous pouvez néanmoins passer votre certification Pix.",
),
);
// then
assert.ok(
screen.getByText(
'Vous êtes inscrit à la certification complémentaire suivante en plus de la certification Pix :',
),
);
assert.ok(screen.getByText('Certif complémentaire 1'));
});

test('should not display subscription non eligible panel', async function (assert) {
// given
const store = this.owner.lookup('service:store');
this.set(
'certificationCandidateSubscription',
store.createRecord('certification-candidate-subscription', {
eligibleSubscriptions: [{ label: 'Certif complémentaire 1', type: 'COMPLEMENTARY' }],
nonEligibleSubscription: null,
}),
);

// when
const screen = await render(
hbs`<CertificationStarter @certificationCandidateSubscription={{this.certificationCandidateSubscription}} />`,
);

// then
assert.notOk(screen.queryByText('Vous n’êtes pas éligible à'));
});
});

test('should not display subscription eligible panel', async function (assert) {
// given
const store = this.owner.lookup('service:store');
this.set(
'certificationCandidateSubscription',
store.createRecord('certification-candidate-subscription', {
eligibleSubscriptions: null,
nonEligibleSubscription: { label: 'Certif complémentaire 1' },
}),
);
module('when the candidate is not eligible', function () {
test('should display subscription non eligible panel', async function (assert) {
// given
const store = this.owner.lookup('service:store');
this.set(
'certificationCandidateSubscription',
store.createRecord('certification-candidate-subscription', {
eligibleSubscriptions: null,
nonEligibleSubscription: { label: 'Certif complémentaire 1' },
sessionVersion: 2,
}),
);

// when
const screen = await render(
hbs`<CertificationStarter @certificationCandidateSubscription={{this.certificationCandidateSubscription}} />`,
);
// when
const screen = await render(
hbs`<CertificationStarter @certificationCandidateSubscription={{this.certificationCandidateSubscription}} />`,
);

// then
assert.notOk(
screen.queryByText(
'Vous êtes inscrit aux certifications complémentaires suivantes en plus de la certification Pix :',
),
);
// then
assert.ok(
screen.getByText(
"Vous n'êtes pas éligible à Certif complémentaire 1. Vous pouvez néanmoins passer votre certification Pix.",
),
);
});

test('should not display subscription eligible panel', async function (assert) {
// given
const store = this.owner.lookup('service:store');
this.set(
'certificationCandidateSubscription',
store.createRecord('certification-candidate-subscription', {
eligibleSubscriptions: null,
nonEligibleSubscription: { label: 'Certif complémentaire 1' },
sessionVersion: 2,
}),
);

// when
const screen = await render(
hbs`<CertificationStarter @certificationCandidateSubscription={{this.certificationCandidateSubscription}} />`,
);

// then
assert.notOk(
screen.queryByText(
'Vous êtes inscrit aux certifications complémentaires suivantes en plus de la certification Pix :',
),
);
});
});
});
});
Expand Down
3 changes: 2 additions & 1 deletion mon-pix/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@
"first-title": "You are about to begin your certification test.",
"link-to-user-certification": "See my certificates",
"non-eligible-subscription": "You are not eligible to {nonEligibleSubscriptionLabel}. However, you can still take your Pix Certification.",
"subscription": "You are registered for the following additional certification in combination with the Pix Certification:"
"core-and-complementary-subscriptions": "You are registered for the following additional certification in combination with the Pix Certification:",
"complementary-subscription": "You are registered for the following additional certification :"
},
"certifications-list": {
"title": "My Certifications",
Expand Down
2 changes: 1 addition & 1 deletion mon-pix/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@
"first-title": "Estás a punto de empezar tu prueba de certificación",
"link-to-user-certification": "Ver mis certificaciones",
"non-eligible-subscription": "No eres elegible para {nonEligibleSubscriptionLabel}. Sin embargo, puedes presentarte a la certificación Pix.",
"subscription": "Además de la certificación Pix, estás inscrito en la siguiente certificación complementaria:",
"core-and-complementary-subscriptions": "Además de la certificación Pix, estás inscrito en la siguiente certificación complementaria:",
"title": "Unirse a una sesión de certificación"
},
"certifications-list": {
Expand Down
3 changes: 2 additions & 1 deletion mon-pix/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,8 @@
"first-title": "Vous allez commencer votre test de certification",
"link-to-user-certification": "Voir mes certifications",
"non-eligible-subscription": "Vous n'êtes pas éligible à {nonEligibleSubscriptionLabel}. Vous pouvez néanmoins passer votre certification Pix.",
"subscription": "Vous êtes inscrit à la certification complémentaire suivante en plus de la certification Pix :"
"core-and-complementary-subscriptions": "Vous êtes inscrit à la certification complémentaire suivante en plus de la certification Pix :",
"complementary-subscription": "Vous êtes inscrit à la certification complémentaire suivante :"
},
"certifications-list": {
"title": "Mes Certifications",
Expand Down
2 changes: 1 addition & 1 deletion mon-pix/translations/nl.json
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@
"first-title": "Je staat op het punt om aan je certificeringstest te beginnen",
"link-to-user-certification": "Bekijk mijn certificaten",
"non-eligible-subscription": "Je komt niet in aanmerking voor {nonEligibleSubscriptionLabel}. Je kunt echter wel je Pix-certificering behalen.",
"subscription": "Je bent geregistreerd voor de volgende aanvullende certificering naast de Pix-certificering:",
"core-and-complementary-subscriptions": "Je bent geregistreerd voor de volgende aanvullende certificering naast de Pix-certificering:",
"title": "Doe mee aan een certificeringssessie"
},
"certifications-list": {
Expand Down

0 comments on commit 9598462

Please sign in to comment.