From 34894428604be94d9f5934c28e26edf9ceb5bac6 Mon Sep 17 00:00:00 2001 From: Pawel Szafranski Date: Fri, 20 Jul 2018 16:40:24 +0200 Subject: [PATCH 1/5] #91 - added shipping methods unit test --- .travis.yml | 1 + test/ShippingMethods.test.js | 72 +++++++++++++++++++ .../ShippingMethods.test.js.snap | 51 +++++++++++++ .../web/js/components/ShippingMethods.vue | 19 +++-- 4 files changed, 136 insertions(+), 7 deletions(-) create mode 100644 test/ShippingMethods.test.js create mode 100644 test/__snapshots__/ShippingMethods.test.js.snap diff --git a/.travis.yml b/.travis.yml index 59d148a..6c3cdb5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,3 +6,4 @@ cache: - node_modules script: - yarn lint + - yarn test diff --git a/test/ShippingMethods.test.js b/test/ShippingMethods.test.js new file mode 100644 index 0000000..f1009c3 --- /dev/null +++ b/test/ShippingMethods.test.js @@ -0,0 +1,72 @@ +import Vuex from 'vuex' +import { shallowMount, createLocalVue } from '@vue/test-utils' +import ShippingMethods from '../view/frontend/web/js/components/ShippingMethods.vue' +import VeeValidate from 'vee-validate' + +const localVue = createLocalVue() +localVue.use(Vuex) +localVue.use(VeeValidate) + +localVue.filter('currency', function (price) { + const pattern = '$%s' + price = parseFloat(price).toFixed(2) + return pattern.replace('%s', price) +}) + +describe('ShippingMethods.test.js', () => { + let store + let mutations + let wrapper + + const shippingMethod = { + amount: 5, + available: true, + base_amount: 5, + carrier_code: 'flatrate', + carrier_title: 'Flat Rate', + error_message: '', + method_code: 'flatrate', + method_title: 'Fixed', + price_excl_tax: 5, + price_incl_tax: 5 + } + + beforeEach(() => { + mutations = { + setItem: jest.fn() + } + store = new Vuex.Store({ + mutations + }) + + wrapper = shallowMount(ShippingMethods, { + propsData: { + shippingMethods: [ + shippingMethod + ] + }, + store, + localVue + }) + }) + + it('commits a setItem when a radiobutton is changed', () => { + wrapper + .find(`[data-testid="method-radiobutton-${shippingMethod.carrier_code}"]`) + .trigger('change') + + expect(mutations.setItem.mock.calls).toHaveLength(1) + expect(mutations.setItem.mock.calls[0][1]).toEqual({ + item: 'selectedShippingMethod', + value: shippingMethod + }) + }) + + it('renders a shipping methods list return from props', () => { + expect(wrapper.contains('[data-testid="shipping-methods')).toBe(true) + }) + + it('has the expected html structure', () => { + expect(wrapper.element).toMatchSnapshot() + }) +}) diff --git a/test/__snapshots__/ShippingMethods.test.js.snap b/test/__snapshots__/ShippingMethods.test.js.snap new file mode 100644 index 0000000..18d301e --- /dev/null +++ b/test/__snapshots__/ShippingMethods.test.js.snap @@ -0,0 +1,51 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ShippingMethods.test.js has the expected html structure 1`] = ` +
+

+ + Shipping methods + +

+ +
+
+ + + +
+ + +
+
+`; diff --git a/view/frontend/web/js/components/ShippingMethods.vue b/view/frontend/web/js/components/ShippingMethods.vue index 3b8477f..f9334bd 100644 --- a/view/frontend/web/js/components/ShippingMethods.vue +++ b/view/frontend/web/js/components/ShippingMethods.vue @@ -3,18 +3,23 @@

Shipping methods

- - + From 2eb30ad796488221a6a878985f6656c378e5b885 Mon Sep 17 00:00:00 2001 From: Pawel Szafranski Date: Fri, 20 Jul 2018 16:45:00 +0200 Subject: [PATCH 2/5] #91 - fail test --- .../ShippingMethods.test.js.snap | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/test/__snapshots__/ShippingMethods.test.js.snap b/test/__snapshots__/ShippingMethods.test.js.snap index 18d301e..2d27cc5 100644 --- a/test/__snapshots__/ShippingMethods.test.js.snap +++ b/test/__snapshots__/ShippingMethods.test.js.snap @@ -3,12 +3,13 @@ exports[`ShippingMethods.test.js has the expected html structure 1`] = `

- + Shipping methods - +

- +
- +
- +
From cdae79568d8eae179e078b73d6921f6125c54cfd Mon Sep 17 00:00:00 2001 From: Pawel Szafranski Date: Fri, 20 Jul 2018 16:52:40 +0200 Subject: [PATCH 3/5] Revert "#91 - fail test" This reverts commit 2eb30ad796488221a6a878985f6656c378e5b885. --- .../ShippingMethods.test.js.snap | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/test/__snapshots__/ShippingMethods.test.js.snap b/test/__snapshots__/ShippingMethods.test.js.snap index 2d27cc5..18d301e 100644 --- a/test/__snapshots__/ShippingMethods.test.js.snap +++ b/test/__snapshots__/ShippingMethods.test.js.snap @@ -3,13 +3,12 @@ exports[`ShippingMethods.test.js has the expected html structure 1`] = `

- + Shipping methods - +

- +
- +
- +
From 8f78bd46d80db416bea6bf3251e6d77f58456f49 Mon Sep 17 00:00:00 2001 From: Pawel Szafranski Date: Fri, 20 Jul 2018 17:04:38 +0200 Subject: [PATCH 4/5] #91 - added missing items to changelog --- CHANGELOG.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ceccf67..4b05611 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,12 +8,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - changelog file to start log changes (#72) +- basic unit test for App, ProductsList, ShippingMethods components +- proper unit test dependiences (vue/test-utils, jest) and configuration ### Changed -- +- currency vue filter +- presets in babelrc ### Removed -- +- ## [0.2.0] - 2018-05-21 From 86d2eff8d06420793f339172cd1de94b33d7a08f Mon Sep 17 00:00:00 2001 From: Pawel Szafranski Date: Fri, 20 Jul 2018 17:06:13 +0200 Subject: [PATCH 5/5] #91 - typo fix --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b05611..4af6bf4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - changelog file to start log changes (#72) - basic unit test for App, ProductsList, ShippingMethods components -- proper unit test dependiences (vue/test-utils, jest) and configuration +- proper unit test dependencies (vue/test-utils, jest) and configuration ### Changed - currency vue filter