Skip to content

Commit

Permalink
[TECH] Mise à jour de ember-mocha dans Pix App.
Browse files Browse the repository at this point in the history
Merge pull request #638 from 1024pix/ember-mocha-acceptance-tests-deprecation
  • Loading branch information
lisequesnel authored Aug 12, 2019
2 parents 33af5d7 + e07634d commit 407c6d0
Show file tree
Hide file tree
Showing 69 changed files with 1,283 additions and 1,947 deletions.
3 changes: 2 additions & 1 deletion mon-pix/mirage/factories/organization.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Factory, faker } from 'ember-cli-mirage';
import { Factory } from 'ember-cli-mirage';
import faker from 'faker';

export default Factory.extend({
name(i) {
Expand Down
5 changes: 3 additions & 2 deletions mon-pix/mirage/factories/snapshot.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Factory, faker } from 'ember-cli-mirage';
import { Factory } from 'ember-cli-mirage';
import faker from 'faker';

export default Factory.extend({

Expand All @@ -7,7 +8,7 @@ export default Factory.extend({
creationDate : faker.date.recent(),

testsFinished : () => {
return faker.list.random(2, 3, 4, 8, 10, 12)();
return faker.random.arrayElement([2, 3, 4, 8, 10, 12]);
}

});
3 changes: 2 additions & 1 deletion mon-pix/mirage/factories/user.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Factory, faker } from 'ember-cli-mirage';
import { Factory } from 'ember-cli-mirage';
import faker from 'faker';

export default Factory.extend({
firstName() {
Expand Down
758 changes: 206 additions & 552 deletions mon-pix/package-lock.json

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions mon-pix/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"codeclimate-test-reporter": "^0.5.1",
"coveralls": "^3.0.3",
"ember-ajax": "^5.0.0",
"ember-auto-import": "^1.4.0",
"ember-cli": "~3.9.0",
"ember-cli-app-version": "^3.2.0",
"ember-cli-autoprefixer": "^0.8.1",
Expand All @@ -63,7 +64,7 @@
"ember-cli-htmlbars-inline-precompile": "^1.0.5",
"ember-cli-inject-live-reload": "^2.0.1",
"ember-cli-matomo-tag-manager": "^1.1.2",
"ember-cli-mirage": "^0.4.15",
"ember-cli-mirage": "^1.0.0",
"ember-cli-moment-shim": "^3.7.1",
"ember-cli-sass": "^10.0.0",
"ember-cli-sentry": "^4.1.0",
Expand All @@ -85,7 +86,7 @@
"ember-lodash": "^4.19.4",
"ember-math-helpers": "^2.11.1",
"ember-maybe-import-regenerator": "^0.1.6",
"ember-mocha": "^0.14.0",
"ember-mocha": "^0.16.0",
"ember-modal-dialog": "^2.4.4",
"ember-moment": "^7.8.1",
"ember-resolver": "^5.1.3",
Expand All @@ -101,6 +102,7 @@
"eslint": "^5.16.0",
"eslint-plugin-ember": "^6.4.1",
"eslint-plugin-mocha": "^5.3.0",
"faker": "^4.1.0",
"js-yaml": "^3.13.1",
"loader.js": "^4.7.0",
"sass": "^1.20.1",
Expand Down
51 changes: 22 additions & 29 deletions mon-pix/tests/acceptance/board-organization-test.js
Original file line number Diff line number Diff line change
@@ -1,69 +1,63 @@
import { afterEach, beforeEach, describe, it } from 'mocha';
import { findAll, currentURL, find } from '@ember/test-helpers';
import { beforeEach, describe, it } from 'mocha';
import { expect } from 'chai';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import { authenticateAsPrescriber } from '../helpers/testing';
import visitWithAbortedTransition from '../helpers/visit';
import defaultScenario from '../../mirage/scenarios/default';
import { setupApplicationTest } from 'ember-mocha';
import { setupMirage } from 'ember-cli-mirage/test-support';

describe('Acceptance | Board organization', function() {
let application;
setupApplicationTest();
setupMirage();

beforeEach(function() {
application = startApp();
defaultScenario(server);
});

afterEach(function() {
destroyApp(application);
defaultScenario(this.server);
});

it('can visit /board', async function() {
// given
await authenticateAsPrescriber();

// when
await visit('/board');
await visitWithAbortedTransition('/board');

// then
andThen(() => {
expect(currentURL()).to.equal('/board');
});
expect(currentURL()).to.equal('/board');
});

it('should not be accessible while the user is not connected', async function() {
// when
await visit('/board');
await visitWithAbortedTransition('/board');

// then
andThen(() => {
expect(currentURL()).to.equal('/connexion');
});
expect(currentURL()).to.equal('/connexion');
});

it('should display the name and the code of my organization', async function() {
// given
await authenticateAsPrescriber();

// when
await visit('/board');
await visitWithAbortedTransition('/board');

// then
expect(find('.board-page__header-organisation__name').length).to.equal(1);
expect(find('.board-page__header-organisation__name').text().trim()).to.equal('Mon Entreprise');
expect(find('.board-page__header-code__text').length).to.equal(1);
expect(find('.board-page__header-code__text').text().trim()).to.equal('PRO001');
expect(findAll('.board-page__header-organisation__name').length).to.equal(1);
expect(find('.board-page__header-organisation__name').textContent.trim()).to.equal('Mon Entreprise');
expect(findAll('.board-page__header-code__text').length).to.equal(1);
expect(find('.board-page__header-code__text').textContent.trim()).to.equal('PRO001');
});

it('should display an empty list of snapshot', async function() {
// given
await authenticateAsPrescriber();

// when
await visit('/board');
await visitWithAbortedTransition('/board');

// then
expect(find('.snapshot-list').length).to.equal(1);
expect(find('.snapshot-list__no-profile').text()).to.equal('Aucun profil partagé pour le moment');
expect(findAll('.snapshot-list').length).to.equal(1);
expect(find('.snapshot-list__no-profile').textContent).to.equal('Aucun profil partagé pour le moment');

});

Expand All @@ -72,11 +66,10 @@ describe('Acceptance | Board organization', function() {
await authenticateAsPrescriber();

// when
await visit('/board');
await visitWithAbortedTransition('/board');

// then
const $exportLink = findWithAssert('.profiles-title__export-csv');
expect($exportLink.text()).to.contains('Exporter (.csv)');
expect(find('.profiles-title__export-csv').textContent).to.contains('Exporter (.csv)');
});

});
33 changes: 15 additions & 18 deletions mon-pix/tests/acceptance/certification-course-test.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import { afterEach, beforeEach, describe, it } from 'mocha';
import { click, fillIn, currentURL } from '@ember/test-helpers';
import { beforeEach, describe, it } from 'mocha';
import { expect } from 'chai';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import { authenticateAsSimpleUser } from '../helpers/testing';
import visitWithAbortedTransition from '../helpers/visit';
import defaultScenario from '../../mirage/scenarios/default';
import { setupApplicationTest } from 'ember-mocha';
import { setupMirage } from 'ember-cli-mirage/test-support';

describe('Acceptance | Certification | Start Course', function() {

let application;
setupApplicationTest();
setupMirage();

beforeEach(function() {
application = startApp();
defaultScenario(server);
});

afterEach(function() {
destroyApp(application);
defaultScenario(this.server);
});

describe('Start a certification course', function() {

context('When user is not logged in', function() {

beforeEach(async function() {
await visit('/certifications');
await visitWithAbortedTransition('/certifications');
});

it('should redirect to login page', function() {
Expand All @@ -37,12 +34,12 @@ describe('Acceptance | Certification | Start Course', function() {

beforeEach(async function() {
await authenticateAsSimpleUser();
await visit('/certifications');
await visitWithAbortedTransition('/certifications');
});
context('when user enter a correct code session', function() {
beforeEach(async function() {
// when
fillIn('#session-code', 'ABCD12');
await fillIn('#session-code', 'ABCD12');
await click('.certification-course-page__submit_button');
});

Expand Down Expand Up @@ -87,15 +84,15 @@ describe('Acceptance | Certification | Start Course', function() {
it('should be redirected on the second challenge of an assessment', async function() {
// given
await authenticateAsSimpleUser();
await visit('/certifications');
fillIn('#session-code', '10ue1');
await visitWithAbortedTransition('/certifications');
await fillIn('#session-code', '10ue1');
await click('.certification-course-page__submit_button');

await click('.challenge-actions__action-skip');
await visit('/compte');
await visitWithAbortedTransition('/compte');

// when
await visit('/certifications/certification-number');
await visitWithAbortedTransition('/certifications/certification-number');

// then
expect(currentURL()).to.match(/assessments\/\d+\/challenges\/recLt9uwa2dR3IYpi/);
Expand Down
53 changes: 23 additions & 30 deletions mon-pix/tests/acceptance/challenge-attachment-test.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,56 @@
import { afterEach, beforeEach, describe, it } from 'mocha';
import { click, find } from '@ember/test-helpers';
import { beforeEach, describe, it } from 'mocha';
import { expect } from 'chai';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import $ from 'jquery';

function visitTimedChallenge() {
visit('/assessments/ref_assessment_id/challenges/ref_qcm_challenge_id');
click('.challenge-item-warning button');
import visitWithAbortedTransition from '../helpers/visit';
import defaultScenario from '../../mirage/scenarios/default';
import { setupApplicationTest } from 'ember-mocha';
import { setupMirage } from 'ember-cli-mirage/test-support';

async function visitTimedChallenge() {
await visitWithAbortedTransition('/assessments/ref_assessment_id/challenges/ref_qcm_challenge_id');
await click('.challenge-item-warning button');
}

describe('Acceptance | Download an attachment from a challenge', function() {

let application;

const $ATTACHMENT_LINK = $('.challenge-statement__action-link');
setupApplicationTest();
setupMirage();

beforeEach(function() {
application = startApp();
});

afterEach(function() {
destroyApp(application);
defaultScenario(this.server);
});

describe('When the challenge has an attachment', function() {

beforeEach(function() {
visitTimedChallenge();
beforeEach(async function() {
await visitTimedChallenge();
});

it('should have a way to download the attachment', function() {
const $ATTACHMENT_LINK = findWithAssert('.challenge-statement__action-link');
expect($ATTACHMENT_LINK.length).to.equal(1);
expect(find('.challenge-statement__action-link')).to.exist;
});

it('should expose the correct attachment link', function() {
const $ATTACHMENT_LINK = $('.challenge-statement__action-link');
expect($ATTACHMENT_LINK.text()).to.contain('Télécharger');
expect($ATTACHMENT_LINK.attr('href')).to.equal('http://example_of_url');
expect(find('.challenge-statement__action-link').textContent).to.contain('Télécharger');
expect(find('.challenge-statement__action-link').getAttribute('href')).to.equal('http://example_of_url');
});

it('should only have one file downloadable', function() {
const $attachment = findWithAssert('.challenge-statement__action-link');
expect($attachment.length).to.equal(1);
expect(find('.challenge-statement__action-link')).to.exist;
});
});

describe('When the challenge does not contain an attachment', function() {

beforeEach(function() {
visit('/assessments/ref_assessment_id/challenges/ref_qroc_challenge_id');
beforeEach(async function() {
await visitWithAbortedTransition('/assessments/ref_assessment_id/challenges/ref_qroc_challenge_id');
});

it('should hide the download section for the attachment', function() {
// We are in a challenge...
findWithAssert('.challenge-item');
expect(find('.challenge-item')).to.exist;

// ... but attachment is hidden
expect($ATTACHMENT_LINK.length).to.equal(0);
expect(find('.challenge-statement__action-link')).not.to.exist;
});
});

Expand Down
Loading

0 comments on commit 407c6d0

Please sign in to comment.