Skip to content

Commit

Permalink
🚧 (mon-pix): wip
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreiaPena authored and P-Jeremy committed Jul 4, 2024
1 parent 231c583 commit f9cfb4c
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 45 deletions.
19 changes: 13 additions & 6 deletions mon-pix/app/components/certification-instructions/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,27 @@ export default class Steps extends Component {
}

@action
nextStep() {
async nextStep() {
if (this.pageId < this.pageCount) {
this.pageId = this.pageId + 1;
}

if (this.isConfirmationCheckboxChecked) {
this.router.transitionTo('authenticated.certifications.start', this.args.candidateId, {
queryParams: {
isConfirmationCheckboxChecked: this.isConfirmationCheckboxChecked,
},
});
await this.submit();

this.router.transitionTo('authenticated.certifications.start', this.args.candidate.id);
}
}

@action
async submit() {
await this.args.candidate.save({
adapterOptions: {
hasSeenCertificationInstructions: true,
},
});
}

@action
enableNextButton(checked) {
this.isConfirmationCheckboxChecked = checked;
Expand Down
1 change: 1 addition & 0 deletions mon-pix/app/models/certification-candidate.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default class CertificationCandidate extends Model {
@attr('string') firstName;
@attr('string') lastName;
@attr('date-only') birthdate;
@attr('boolean') hasSeenCertificationInstructions;

// references
@attr('number') sessionId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,15 @@ import { service } from '@ember/service';

export default class InformationRoute extends Route {
@service store;
@service router;

async model(params) {
return this.store.peekRecord('certification-candidate', params.certification_candidate_id);
const certificationCandidate = this.store.peekRecord('certification-candidate', params.certification_candidate_id);

if (!certificationCandidate) {
this.router.replaceWith('authenticated.certifications.join');
}

return certificationCandidate;
}
}
14 changes: 8 additions & 6 deletions mon-pix/app/routes/authenticated/certifications/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@ export default class StartRoute extends Route {
@service store;
@service router;
@service featureToggles;
hasSeenCertificationInstructions = false;

beforeModel(transition) {
this.hasSeenCertificationInstructions = transition.to.queryParams.isConfirmationCheckboxChecked;
}

async model(params) {
const certificationCandidateSubscription = await this.store.findRecord(
'certification-candidate-subscription',
params.certification_candidate_id,
);

const certificationCandidate = await this.store.peekRecord(
'certification-candidate',
params.certification_candidate_id,
);

const hasSeenCertificationInstructions = certificationCandidate?.hasSeenCertificationInstructions;

if (
!this.hasSeenCertificationInstructions &&
!hasSeenCertificationInstructions &&
certificationCandidateSubscription.isSessionVersion3 &&
this.featureToggles.featureToggles.areV3InfoScreensEnabled
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
<h1 class="instructions-header__title">{{t "pages.certification-instructions.title"}}</h1>
</header>
<PixBlock @shadow="heavy" class="instructions-step">
<CertificationInstructions::Steps @candidateId={{this.model.id}} />
<CertificationInstructions::Steps @candidate={{this.model}} />
</PixBlock>
</main>
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ module('Unit | Adapters | certification-candidate', function (hooks) {
const url = await adapter.urlForUpdateRecord(456, 'certification-candidate', options);

// then
assert.true(url.endsWith('/certification-candidate/456/validate-certification-instructions'));
assert.true(url.endsWith('/certification-candidates/456/validate-certification-instructions'));
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module('Unit | Component | certification-instruction | steps', function (hooks)

module('when pageId equal pageCount', function () {
module('when confirmation checkbox is checked', function () {
test('should redirect to certificartion starter', async function (assert) {
test.only('should redirect to certificartion starter', async function (assert) {
// given
const component = createGlimmerComponent('certification-instructions/steps');

Expand All @@ -38,21 +38,20 @@ module('Unit | Component | certification-instruction | steps', function (hooks)
};
component.isConfirmationCheckboxChecked = true;
const transitionToStub = sinon.stub();
const saveStub = sinon.stub();
saveStub.resolves();
component.router = {
transitionTo: transitionToStub,
};
component.args.candidate = {
save: saveStub,
};

// when
await component.nextStep();

// then
assert.ok(
transitionToStub.calledWith('authenticated.certifications.start', 123, {
queryParams: {
isConfirmationCheckboxChecked: true,
},
}),
);
assert.ok(transitionToStub.calledWith('authenticated.certifications.start', 123));
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ module('Unit | Route | Certification | Start', function (hooks) {
module('when hasSeenCertificationInstructions is false', function () {
test('should redirect to certification information page', async function (assert) {
// given
const certificationCandidateId = 'certification-candidate-id';
const params = { certification_candidate_id: certificationCandidateId };
const store = this.owner.lookup('service:store');
const certificationCandidate = store.createRecord('certification-candidate', {
sessionId: 1234,
hasSeenCertificationInstructions: false,
});
const params = { certification_candidate_id: certificationCandidate.id };

const certificationCandidateSubscription = store.createRecord('certification-candidate-subscription', {
id: certificationCandidateId,
id: certificationCandidate.id,
sessionId: 1234,
sessionVersion: 3,
});
Expand All @@ -27,13 +30,13 @@ module('Unit | Route | Certification | Start', function (hooks) {
});

const findRecordStub = sinon.stub().returns(certificationCandidateSubscription);
const storeStub = Service.create({ findRecord: findRecordStub });
const peekRecordStub = sinon.stub().returns(certificationCandidate);
const storeStub = Service.create({ findRecord: findRecordStub, peekRecord: peekRecordStub });

const route = this.owner.lookup('route:authenticated/certifications.start');
route.set('store', storeStub);
route.set('featureToggles', featureToggles);
route.router = { replaceWith: sinon.stub() };
route.hasSeenCertificationInstructions = false;

// when
await route.model(params);
Expand All @@ -42,7 +45,7 @@ module('Unit | Route | Certification | Start', function (hooks) {
sinon.assert.calledWithExactly(
route.router.replaceWith,
'authenticated.certifications.information',
certificationCandidateId,
certificationCandidate.id,
);
assert.ok(true);
});
Expand All @@ -51,12 +54,15 @@ module('Unit | Route | Certification | Start', function (hooks) {
module('when hasSeenCertificationInstructions is true', function () {
test('should not redirect to certification information page', async function (assert) {
// given
const certificationCandidateId = 'certification-candidate-id';
const params = { certification_candidate_id: certificationCandidateId };
const store = this.owner.lookup('service:store');
const certificationCandidate = store.createRecord('certification-candidate', {
sessionId: 1234,
hasSeenCertificationInstructions: true,
});
const params = { certification_candidate_id: certificationCandidate.id };

const certificationCandidateSubscription = store.createRecord('certification-candidate-subscription', {
id: certificationCandidateId,
id: certificationCandidate.id,
sessionId: 1234,
sessionVersion: 3,
});
Expand All @@ -67,7 +73,8 @@ module('Unit | Route | Certification | Start', function (hooks) {
});

const findRecordStub = sinon.stub().returns(certificationCandidateSubscription);
const storeStub = Service.create({ findRecord: findRecordStub });
const peekRecordStub = sinon.stub().returns(certificationCandidate);
const storeStub = Service.create({ findRecord: findRecordStub, peekRecord: peekRecordStub });

const route = this.owner.lookup('route:authenticated/certifications.start');
route.set('store', storeStub);
Expand All @@ -88,12 +95,15 @@ module('Unit | Route | Certification | Start', function (hooks) {
module('when session is V3 and toggle is not enabled', function () {
test('should not redirect to certification information page', async function (assert) {
// given
const certificationCandidateId = 'certification-candidate-id';
const params = { certification_candidate_id: certificationCandidateId };
const store = this.owner.lookup('service:store');
const certificationCandidate = store.createRecord('certification-candidate', {
sessionId: 1234,
hasSeenCertificationInstructions: false,
});
const params = { certification_candidate_id: certificationCandidate.id };

const certificationCandidateSubscription = store.createRecord('certification-candidate-subscription', {
id: certificationCandidateId,
id: certificationCandidate.id,
sessionId: 1234,
sessionVersion: 3,
});
Expand All @@ -104,7 +114,8 @@ module('Unit | Route | Certification | Start', function (hooks) {
});

const findRecordStub = sinon.stub().returns(certificationCandidateSubscription);
const storeStub = Service.create({ findRecord: findRecordStub });
const peekRecordStub = sinon.stub().returns(certificationCandidate);
const storeStub = Service.create({ findRecord: findRecordStub, peekRecord: peekRecordStub });

const route = this.owner.lookup('route:authenticated/certifications.start');
route.set('store', storeStub);
Expand All @@ -123,12 +134,15 @@ module('Unit | Route | Certification | Start', function (hooks) {
module('when session is not V3 and toggle is enabled', function () {
test('should not redirect to certification information page', async function (assert) {
// given
const certificationCandidateId = 'certification-candidate-id';
const params = { certification_candidate_id: certificationCandidateId };
const store = this.owner.lookup('service:store');
const certificationCandidate = store.createRecord('certification-candidate', {
sessionId: 1234,
hasSeenCertificationInstructions: false,
});
const params = { certification_candidate_id: certificationCandidate.id };

const certificationCandidateSubscription = store.createRecord('certification-candidate-subscription', {
id: certificationCandidateId,
id: certificationCandidate.id,
sessionId: 1234,
sessionVersion: 2,
});
Expand All @@ -139,7 +153,8 @@ module('Unit | Route | Certification | Start', function (hooks) {
});

const findRecordStub = sinon.stub().returns(certificationCandidateSubscription);
const storeStub = Service.create({ findRecord: findRecordStub });
const peekRecordStub = sinon.stub().returns(certificationCandidate);
const storeStub = Service.create({ findRecord: findRecordStub, peekRecord: peekRecordStub });

const route = this.owner.lookup('route:authenticated/certifications.start');
route.set('store', storeStub);
Expand All @@ -158,12 +173,15 @@ module('Unit | Route | Certification | Start', function (hooks) {
module('when session is not V3 and toggle is not enabled', function () {
test('should not redirect to certification information page', async function (assert) {
// given
const certificationCandidateId = 'certification-candidate-id';
const params = { certification_candidate_id: certificationCandidateId };
const store = this.owner.lookup('service:store');
const certificationCandidate = store.createRecord('certification-candidate', {
sessionId: 1234,
hasSeenCertificationInstructions: false,
});
const params = { certification_candidate_id: certificationCandidate.id };

const certificationCandidateSubscription = store.createRecord('certification-candidate-subscription', {
id: certificationCandidateId,
id: certificationCandidate.id,
sessionId: 1234,
sessionVersion: 2,
});
Expand All @@ -174,7 +192,8 @@ module('Unit | Route | Certification | Start', function (hooks) {
});

const findRecordStub = sinon.stub().returns(certificationCandidateSubscription);
const storeStub = Service.create({ findRecord: findRecordStub });
const peekRecordStub = sinon.stub().returns(certificationCandidate);
const storeStub = Service.create({ findRecord: findRecordStub, peekRecord: peekRecordStub });

const route = this.owner.lookup('route:authenticated/certifications.start');
route.set('store', storeStub);
Expand Down

0 comments on commit f9cfb4c

Please sign in to comment.