Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Commit

Permalink
[#427] [CLEANUP] Suppression de l'initializer ajax-interceptor (#427)
Browse files Browse the repository at this point in the history
* Remove shared-state test helper

* Replace one of the removed tests with a test using Mirage / Pretender features, as an example

* Make destroy-helper being exactly the same that for a new Ember + Mocha + Mirage project
  • Loading branch information
jbuget committed May 30, 2017
1 parent 7cf1fc8 commit 1db16c0
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 219 deletions.
23 changes: 0 additions & 23 deletions live/app/initializers/ajax-interceptor.js

This file was deleted.

57 changes: 41 additions & 16 deletions live/tests/acceptance/b1-epreuve-qcu-test.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,52 @@
import {describe, it, beforeEach, afterEach} from 'mocha';
import {expect} from 'chai';
import { describe, it, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import {resetTestingState, bodyOfLastPostRequest, urlOfLastPostRequest} from '../helpers/shared-state';
import _ from 'pix-live/utils/lodash-custom';

let application;

describe('Acceptance | b1 - Afficher un QCU | ', function() {

let application;

beforeEach(function() {
application = startApp();
visit('/assessments/ref_assessment_id/challenges/ref_qcu_challenge_id');
});

afterEach(function() {
destroyApp(application);
});

it('b1.1 Une liste de radiobuttons doit s\'afficher', function() {
it('b1.1 Une liste de radiobuttons doit s\'afficher', async function() {
// given
await visit('/assessments/ref_assessment_id/challenges/ref_qcu_challenge_id');

// then
const $proposals = $('input[type=radio][name="radio"]');
expect($proposals).to.have.lengthOf(4);
});

it('b1.2 Par défaut, le radiobutton de la réponse sauvegardée est affiché', function() {
it('b1.2 Par défaut, le radiobutton de la réponse sauvegardée est affiché', async function() {
// given
await visit('/assessments/ref_assessment_id/challenges/ref_qcu_challenge_id');

// then
expect($('input[type=radio][name="radio"]:checked')).to.have.lengthOf(1);
});

it('b1.3 Une liste ordonnée d\'instruction doit s\'afficher', function() {
it('b1.3 Une liste ordonnée d\'instruction doit s\'afficher', async function() {
// given
await visit('/assessments/ref_assessment_id/challenges/ref_qcu_challenge_id');

// then
expect($('.proposal-text:eq(0)').text().trim()).to.equal('1ere possibilite');
expect($('.proposal-text:eq(1)').text().trim()).to.equal('2eme possibilite');
expect($('.proposal-text:eq(2)').text().trim()).to.equal('3eme possibilite');
expect($('.proposal-text:eq(3)').text().trim()).to.equal('4eme possibilite');
});

it('b1.4 L\'alerte est affichée si l\'utilisateur valide, mais aucun radiobutton n\'est coché', async function() {

// given
await visit('/assessments/ref_assessment_id/challenges/ref_qcu_challenge_id');

$(':radio').prop('checked', false);

// when
Expand All @@ -49,8 +59,9 @@ describe('Acceptance | b1 - Afficher un QCU | ', function() {
});

it('b1.5 Si un utilisateur clique sur un radiobutton, il est le seul coché, et les autres sont décochés', async function() {

// Given
await visit('/assessments/ref_assessment_id/challenges/ref_qcu_challenge_id');

expect($('input[type=radio][name="radio"]:eq(0)').is(':checked')).to.equal(false);
expect($('input[type=radio][name="radio"]:eq(1)').is(':checked')).to.equal(true);
expect($('input[type=radio][name="radio"]:eq(2)').is(':checked')).to.equal(false);
Expand All @@ -68,9 +79,25 @@ describe('Acceptance | b1 - Afficher un QCU | ', function() {

it('b1.6 Si un utilisateur clique sur un radiobutton, et valide l\'épreuve, une demande de sauvegarde de sa réponse est envoyée à l\'API', async function() {
// Given
resetTestingState();
server.post('/answers', (schema, request) => {
const params = JSON.parse(request.requestBody);

expect(params.data.type).to.equal('answers');
expect(params.data.attributes.value).to.equal('4');

return {
data: {
type: 'answers',
id: 'ref_answer_qcm_id',
attributes: {
value: '4'
}
}
};
});

await visit('/assessments/ref_assessment_id/challenges/ref_qcu_challenge_id');

// Given
expect($('input[type=radio][name="radio"]:eq(0)').is(':checked')).to.equal(false);
expect($('input[type=radio][name="radio"]:eq(1)').is(':checked')).to.equal(true);
expect($('input[type=radio][name="radio"]:eq(2)').is(':checked')).to.equal(false);
Expand All @@ -81,7 +108,5 @@ describe('Acceptance | b1 - Afficher un QCU | ', function() {
await click('.challenge-actions__action-validate');

// Then
expect(urlOfLastPostRequest()).to.equal('/api/answers');
expect(_.get(bodyOfLastPostRequest(), 'data.attributes.value')).to.equal('4');
});
});
24 changes: 12 additions & 12 deletions live/tests/acceptance/b2-epreuve-qcm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { describe, it, before, after } from 'mocha';
import { expect } from 'chai';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import {resetTestingState, bodyOfLastPostRequest, urlOfLastPostRequest} from '../helpers/shared-state';
import _ from 'pix-live/utils/lodash-custom';

function visitTimedChallenge() {
visit('/assessments/ref_assessment_id/challenges/ref_qcm_challenge_id');
Expand Down Expand Up @@ -79,17 +77,19 @@ describe('Acceptance | b2 - Afficher un QCM | ', function() {
});
});

it('b2.9 If an user validate the challenge with two answers, the api is request to save the answer of the user', async function() {
// Given
resetTestingState();
it('b2.9 If an user check a checkbox, it is checked', function() {
expect($('input:checkbox:checked')).to.have.lengthOf(0);
$('.proposal-text:eq(1)').click();
$('.proposal-text:eq(2)').click();

// When
await click('.challenge-actions__action-validate');
andThen(() => {
expect($('input:checkbox:checked')).to.have.lengthOf(1);
});
});

// Then
expect(urlOfLastPostRequest()).to.equal('/api/answers');
expect(_.get(bodyOfLastPostRequest(), 'data.attributes.value')).to.equal('2,3');
it('b2.10 If an user check another checkbox, it is checked, the previous checked checkboxes remains checked', function() {
expect($('input:checkbox:checked')).to.have.lengthOf(1);
$('.proposal-text:eq(2)').click();
andThen(() => {
expect($('input:checkbox:checked')).to.have.lengthOf(2);
});
});
});
11 changes: 0 additions & 11 deletions live/tests/acceptance/b3-epreuve-qroc-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { describe, it, beforeEach, afterEach } from 'mocha';
import { expect } from 'chai';
import {resetTestingState, bodyOfLastPostRequest, urlOfLastPostRequest} from '../helpers/shared-state';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import _ from 'pix-live/utils/lodash-custom';

describe('Acceptance | b3 - Afficher un QROC | ', function() {

Expand Down Expand Up @@ -38,13 +36,4 @@ describe('Acceptance | b3 - Afficher un QROC | ', function() {
expect($('.alert').text().trim()).to.equal('Pour valider, saisir une réponse. Sinon, passer.');
});
});

it('b3.4 It should save the answer of the user when user validate', async function() {
resetTestingState();
fillIn('input[data-uid="qroc-proposal-uid"]', 'My New Answer');
await click('.challenge-actions__action-validate');
expect(urlOfLastPostRequest()).to.equal('/api/answers');
expect(_.get(bodyOfLastPostRequest(), 'data.attributes.value')).to.equal('My New Answer');
});

});
16 changes: 0 additions & 16 deletions live/tests/acceptance/b4-epreuve-qrocm-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import { describe, it, before, after } from 'mocha';
import { expect } from 'chai';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import {resetTestingState, bodyOfLastPostRequest, urlOfLastPostRequest} from '../helpers/shared-state';
import _ from 'pix-live/utils/lodash-custom';

describe('Acceptance | b4 - Afficher un QROCM | ', function() {

Expand Down Expand Up @@ -37,18 +35,4 @@ describe('Acceptance | b4 - Afficher un QROCM | ', function() {
expect($('.alert')).to.have.lengthOf(1);
expect($('.alert').text().trim()).to.equal('Pour valider, saisir au moins une réponse. Sinon, passer.');
});

it('b4.4 It should save the answer of the user when user validate', async function() {
resetTestingState();

$(':input:eq(0)').val('stuff1');
$(':input:eq(1)').val('stuff2');
$(':input:eq(2)').val('stuff3');

await click('.challenge-actions__action-validate');

expect(urlOfLastPostRequest()).to.equal('/api/answers');
expect(_.get(bodyOfLastPostRequest(), 'data.attributes.value')).to.equal('logiciel1: stuff1\nlogiciel2: stuff2\nlogiciel3: stuff3\n');
});

});
70 changes: 0 additions & 70 deletions live/tests/acceptance/e1-previsualisation-epreuve-test.js

This file was deleted.

54 changes: 0 additions & 54 deletions live/tests/acceptance/h1-timeout-jauge-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,6 @@ import { describe, it, before, after } from 'mocha';
import { expect } from 'chai';
import startApp from '../helpers/start-app';
import destroyApp from '../helpers/destroy-app';
import {resetTestingState, bodyOfLastPostRequest, urlOfLastPostRequest} from '../helpers/shared-state';
import _ from 'pix-live/utils/lodash-custom';

function getValidateActionLink() {
return $('.challenge-actions__action-validate');
}
function getSkipActionLink() {
return $('.challenge-actions__action-skip');
}

function visitTimedChallenge() {
visit(TIMED_CHALLENGE_URI);
Expand Down Expand Up @@ -48,49 +39,4 @@ describe('Acceptance | H1 - Timeout Jauge | ', function() {
});
});
});

describe('Test quand la jauge est affichée', function() {

beforeEach(function() {
resetTestingState();
visit('/');
});

afterEach(function() {
resetTestingState();
})
;
describe('Sauvegarde du temps passé | ', function() {

it('Si l\'utilisateur valide, demande la sauvegarde du temps restant en secondes', function() {
visitTimedChallenge();
andThen(() => {
const $countDown = findWithAssert('.timeout-jauge-remaining');
expect($countDown.text().trim()).to.equal('0:02');
});
andThen(() => {
click(getValidateActionLink());
});
andThen(() => {
expect(urlOfLastPostRequest()).to.equal('/api/answers');
expect(_.get(bodyOfLastPostRequest(), 'data.attributes.timeout')).to.equal(2);
expect(_.get(bodyOfLastPostRequest(), 'data.attributes.value')).to.equal('2,4');
});
});

it('Si l\'utilisateur ABANDONNE, demande la sauvegarde du temps restant en secondes', function() {
visitTimedChallenge();
andThen(() => {
click(getSkipActionLink());
});
andThen(() => {
expect(urlOfLastPostRequest()).to.equal('/api/answers');
expect(_.get(bodyOfLastPostRequest(), 'data.attributes.timeout')).to.equal(2);
expect(_.get(bodyOfLastPostRequest(), 'data.attributes.value')).to.equal('#ABAND#');
});
});

});

});
});
17 changes: 0 additions & 17 deletions live/tests/helpers/shared-state.js

This file was deleted.

0 comments on commit 1db16c0

Please sign in to comment.