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

Commit

Permalink
Add unit test for closeForm and reset + refacto feedback-panel
Browse files Browse the repository at this point in the history
  • Loading branch information
MBrandone committed Apr 27, 2017
1 parent f184fe0 commit 7750f19
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 18 deletions.
4 changes: 2 additions & 2 deletions live/app/components/feedback-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default Ember.Component.extend({

assessment: null,
challenge: null,
default_status: null,
default_status: FORM_CLOSED,

_status: null,
_email: null,
Expand All @@ -31,7 +31,7 @@ export default Ember.Component.extend({
},

reset() {
const default_status = this.get('default_status') || FORM_CLOSED;
const default_status = this.get('default_status');
this.set('_email', null);
this.set('_content', null);
this.set('_error', null);
Expand Down
2 changes: 1 addition & 1 deletion live/app/templates/components/challenge-item-qcm.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@

{{#if canDisplayFeedbackPanel}}
<div class="challenge-item__feedback">
{{feedback-panel assessment=assessment challenge=challenge default_status='FORM_CLOSED'}}
{{feedback-panel assessment=assessment challenge=challenge}}
</div>
{{/if}}
2 changes: 1 addition & 1 deletion live/app/templates/components/challenge-item-qcu.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@

{{#if canDisplayFeedbackPanel}}
<div class="challenge-item__feedback">
{{feedback-panel assessment=assessment challenge=challenge default_status='FORM_CLOSED'}}
{{feedback-panel assessment=assessment challenge=challenge}}
</div>
{{/if}}
2 changes: 1 addition & 1 deletion live/app/templates/components/challenge-item-qroc.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@

{{#if canDisplayFeedbackPanel}}
<div class="challenge-item__feedback">
{{feedback-panel assessment=assessment challenge=challenge default_status='FORM_CLOSED'}}
{{feedback-panel assessment=assessment challenge=challenge}}
</div>
{{/if}}
2 changes: 1 addition & 1 deletion live/app/templates/components/challenge-item-qrocm.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@

{{#if canDisplayFeedbackPanel}}
<div class="challenge-item__feedback">
{{feedback-panel assessment=assessment challenge=challenge default_status='FORM_CLOSED'}}
{{feedback-panel assessment=assessment challenge=challenge}}
</div>
{{/if}}
21 changes: 12 additions & 9 deletions live/tests/integration/components/comparison-window-test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {expect} from 'chai';
import {describe, it, beforeEach} from 'mocha';
import {setupComponentTest} from 'ember-mocha';
import { expect } from 'chai';
import { describe, it, beforeEach } from 'mocha';
import { setupComponentTest } from 'ember-mocha';
import hbs from 'htmlbars-inline-precompile';
import Ember from 'ember';

const FEEDBACK_FORM = '.feedback-panel__view--form';
const LINK_OPEN_FORM = '.feedback-panel__view--link';

describe('Integration | Component | comparison-window', function () {

setupComponentTest('comparison-window', {
Expand Down Expand Up @@ -64,7 +67,7 @@ describe('Integration | Component | comparison-window', function () {

it('should render corrected answers when challenge type is QROC', function () {
// given
challenge = Ember.Object.create({type: 'QROC'});
challenge = Ember.Object.create({ type: 'QROC' });
this.set('challenge', challenge);
// when
this.render(hbs`{{comparison-window answer=answer challenge=challenge solution=solution index=index}}`);
Expand All @@ -74,8 +77,8 @@ describe('Integration | Component | comparison-window', function () {

it('should render corrected answers when challenge type is QROCM-ind', function () {
// given
challenge = Ember.Object.create({type: 'QROCM-ind', proposals: ''});
solution = Ember.Object.create({value:''});
challenge = Ember.Object.create({ type: 'QROCM-ind', proposals: '' });
solution = Ember.Object.create({ value: '' });
this.set('challenge', challenge);
this.set('solution', solution);
// when
Expand All @@ -86,7 +89,7 @@ describe('Integration | Component | comparison-window', function () {

it('should render corrected answers when challenge type is QCM', function () {
// given
challenge = Ember.Object.create({type: 'QCM'});
challenge = Ember.Object.create({ type: 'QCM' });
this.set('challenge', challenge);
// when
this.render(hbs`{{comparison-window answer=answer challenge=challenge solution=solution index=index}}`);
Expand All @@ -99,8 +102,8 @@ describe('Integration | Component | comparison-window', function () {
this.render(hbs`{{comparison-window answer=answer challenge=challenge solution=solution index=index}}`);
//then
expect(this.$('.comparison-window__feedback-panel')).to.have.length(1);
expect(this.$('.feedback-panel__view--form')).to.have.lengthOf(1);
expect(this.$('.feedback-panel__view--link')).to.have.lengthOf(0);
expect(this.$(FEEDBACK_FORM)).to.have.lengthOf(1);
expect(this.$(LINK_OPEN_FORM)).to.have.lengthOf(0);
});

it('should have a max width of 900px and a margin auto in order to quit by clicking beside', function () {
Expand Down
6 changes: 3 additions & 3 deletions live/tests/integration/components/feedback-panel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('Integration | Component | feedback-panel', function () {
describe('Link view (available only when form is closed by default)', function () {

beforeEach(function () {
this.render(hbs`{{feedback-panel default_status='FORM_CLOSED'}}`);
this.render(hbs`{{feedback-panel}}`);
});

it('should display only the "link" view', function () {
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('Integration | Component | feedback-panel', function () {
// render component
this.set('assessment', assessment);
this.set('challenge', challenge);
this.render(hbs`{{feedback-panel assessment=assessment challenge=challenge default_status='FORM_CLOSED'}}`);
this.render(hbs`{{feedback-panel assessment=assessment challenge=challenge}}`);
});

it('should contain "cancel" button with label "Annuler" and placeholder "Votre message"', function () {
Expand Down Expand Up @@ -241,7 +241,7 @@ describe('Integration | Component | feedback-panel', function () {

it('should not display error if "form" view (with error) was closed and re-opened', function () {
// given
this.render(hbs`{{feedback-panel default_status='FORM_CLOSED'}}`);
this.render(hbs`{{feedback-panel}}`);
this.$(OPEN_LINK).click();
this.$('.feedback-panel__field--content').val(' ');
this.$('.feedback-panel__field--content').change();
Expand Down
65 changes: 65 additions & 0 deletions live/tests/unit/components/feedback-panel-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,69 @@ describe('Unit | Component | feedback-panel', function () {

});

describe('#isFormClosedByDefault', function () {

it('should return true if no specification', function () {
// given
const component = this.subject();

// when
const isFormClosedByDefault = component.get('isFormClosedByDefault');

// then
expect(isFormClosedByDefault).to.be.true;
});

it('should return false if we specified FORM_OPENED', function () {
// given
const component = this.subject();
component.set('default_status', 'FORM_OPENED');

// when
const isFormClosedByDefault = component.get('isFormClosedByDefault');

// then
expect(isFormClosedByDefault).to.be.false;
});
});

describe('#reset', function () {

it('should return empty mail, text, error and back to the default status', function () {
// given
const component = this.subject();
component.set('default_status', 'FORM_OPENED');
component.set('_email', 'un@email.com');
component.set('_content', 'un contenu');
component.set('_error', 'une erreur');
component.set('_status', 'FORM_CLOSED');

// when
component.reset();

// then
expect(component.get('_email')).to.be.null;
expect(component.get('_content')).to.be.null;
expect(component.get('_error')).to.be.null;
expect(component.get('_status')).to.be.equal(component.get('default_status'));
});
});

describe('#closeForm', function () {

it('should set status to CLOSED and set errors to null', function () {
// given
const component = this.subject();
component.set('_error', 'une erreur');
component.set('_status', 'FORM_OPENED');

// when
component.closeForm();

// then
expect(component.get('_error')).to.be.null;
expect(component.get('_status')).to.be.equal('FORM_CLOSED');
});
});

});

0 comments on commit 7750f19

Please sign in to comment.