From 72d66db2e0e700d244c9bb0bff4015a9083ab014 Mon Sep 17 00:00:00 2001 From: Swann KNANI Date: Tue, 27 Jun 2017 00:45:47 +0200 Subject: [PATCH] Prevent multiple request when clicking on the button card --- .editorconfig | 2 +- client/src/components/JobCard.vue | 387 +++++++++--------- .../unit/specs/components/JobCard.spec.js | 29 +- 3 files changed, 231 insertions(+), 187 deletions(-) diff --git a/.editorconfig b/.editorconfig index 106c2ec..bb44a3a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,7 +2,7 @@ root = true [*] charset = utf-8 -indent_style = space +indent_style = tab indent_size = 2 end_of_line = lf insert_final_newline = true diff --git a/client/src/components/JobCard.vue b/client/src/components/JobCard.vue index 0b6d931..0b455b1 100644 --- a/client/src/components/JobCard.vue +++ b/client/src/components/JobCard.vue @@ -3,245 +3,262 @@

{{ job.activity.title }}

- +
- +

{{ mission }}

pour {{ job.project.customer.name }}

à partir de {{ startDate }}

-

à {{ locations }}

+

à {{ locations }}

- -
-
- + + + + diff --git a/client/test/unit/specs/components/JobCard.spec.js b/client/test/unit/specs/components/JobCard.spec.js index 4ea06e2..75669c2 100644 --- a/client/test/unit/specs/components/JobCard.spec.js +++ b/client/test/unit/specs/components/JobCard.spec.js @@ -42,10 +42,17 @@ describe('Unit | Component | JobCard.vue', () => { component = new Constructor({ data: { job, + isClicked: false, }, }).$mount(); }); + describe('$data', () => { + it('should have isClicked property set to false', () => { + expect(component.$data.isClicked).to.be.false; + }); + }); + describe('rendering', () => { it('should display the appropriate project status', () => { expect(component.$el.querySelector('.job__status').getAttribute('class')).to.contain('job__status--proposal-in-progress'); @@ -71,6 +78,10 @@ describe('Unit | Component | JobCard.vue', () => { it('should display the locations', () => { expect(component.$el.querySelector('.job__locations').textContent.trim()).to.equal('OCTO'); }); + + it('should have enabled button', () => { + expect(component.$el.querySelector('.job__apply-button').disabled).to.be.false; + }); }); describe('method #trackEvent', () => { @@ -117,6 +128,23 @@ describe('Unit | Component | JobCard.vue', () => { interestsApi.sendInterest.restore(); }); + it('should set isClicked to true', () => { + // when + component.sendInterest(); + + // then + expect(component.$data.isClicked).to.be.true; + }); + + it('should disable the button', () => { + // When + component.$el.querySelector('button.job__apply-button').click(); + + Vue.nextTick().then(() => { + expect(component.$el.querySelector('.job__apply-button').disabled).to.be.true; + }); + }); + it('should call the API with good params', () => { // when component.sendInterest(); @@ -188,4 +216,3 @@ describe('Unit | Component | JobCard.vue', () => { }); }); }); -