From 982a02fc4f9ee163741da78dc3fb52b48981fde2 Mon Sep 17 00:00:00 2001 From: Alina Beck Date: Tue, 12 Nov 2019 14:24:32 +0300 Subject: [PATCH] query donations data in donation info component --- .../DonationInfo/DonationInfo.spec.js | 53 +++++++++++-------- .../components/DonationInfo/DonationInfo.vue | 28 ++++++---- 2 files changed, 49 insertions(+), 32 deletions(-) diff --git a/webapp/components/DonationInfo/DonationInfo.spec.js b/webapp/components/DonationInfo/DonationInfo.spec.js index 34be14836..ca719c19a 100644 --- a/webapp/components/DonationInfo/DonationInfo.spec.js +++ b/webapp/components/DonationInfo/DonationInfo.spec.js @@ -9,7 +9,8 @@ const mockDate = new Date(2019, 11, 6) global.Date = jest.fn(() => mockDate) describe('DonationInfo.vue', () => { - let mocks, propsData + let mocks, wrapper + beforeEach(() => { mocks = { $t: jest.fn(string => string), @@ -17,13 +18,9 @@ describe('DonationInfo.vue', () => { locale: () => 'de', }, } - propsData = { - goal: 50000, - progress: 10000, - } }) - const Wrapper = () => mount(DonationInfo, { propsData, mocks, localVue }) + const Wrapper = () => mount(DonationInfo, { mocks, localVue }) it('includes a link to the Human Connection donations website', () => { expect( @@ -46,25 +43,37 @@ describe('DonationInfo.vue', () => { expect(Wrapper().vm.title).toBe('Spenden für Dezember') }) - describe('given german locale', () => { - it('creates a label from the given amounts and a translation string', () => { - Wrapper() - expect(mocks.$t.mock.calls[1][0]).toBe('donations.amount-of-total') - expect(mocks.$t.mock.calls[1][1]).toStrictEqual({ - amount: '10.000', - total: '50.000', + describe('mount with data', () => { + beforeEach(() => { + wrapper = Wrapper() + wrapper.setData({ goal: 50000, progress: 10000 }) + }) + + describe('given german locale', () => { + it('creates a label from the given amounts and a translation string', () => { + expect(mocks.$t).toBeCalledWith( + 'donations.amount-of-total', + expect.objectContaining({ + amount: '10.000', + total: '50.000', + }), + ) }) }) - }) - describe('given english locale', () => { - it('creates a label from the given amounts and a translation string', () => { - mocks.$i18n.locale = () => 'en' - Wrapper() - expect(mocks.$t.mock.calls[1][0]).toBe('donations.amount-of-total') - expect(mocks.$t.mock.calls[1][1]).toStrictEqual({ - amount: '10,000', - total: '50,000', + describe('given english locale', () => { + beforeEach(() => { + mocks.$i18n.locale = () => 'en' + }) + + it('creates a label from the given amounts and a translation string', () => { + expect(mocks.$t).toBeCalledWith( + 'donations.amount-of-total', + expect.objectContaining({ + amount: '10,000', + total: '50,000', + }), + ) }) }) }) diff --git a/webapp/components/DonationInfo/DonationInfo.vue b/webapp/components/DonationInfo/DonationInfo.vue index f05258341..947f4bdbc 100644 --- a/webapp/components/DonationInfo/DonationInfo.vue +++ b/webapp/components/DonationInfo/DonationInfo.vue @@ -8,22 +8,18 @@