@wikala/spmkt 2.15.0 → 2.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -179,10 +179,9 @@ export default {
179
179
  if(!this.validate()) {
180
180
  return
181
181
  }
182
- //console.log('validate ok')
183
- this.scrollToElement('.cart-top')
184
182
  this.setGuestMode(true)
185
183
  this.setActiveStep(this.steps.delivery)
184
+ this.scrollToElement('.cart-top')
186
185
  },
187
186
 
188
187
  clearError(field) {
@@ -0,0 +1,128 @@
1
+ import { shallowMount, createLocalVue } from '@vue/test-utils'
2
+ import DeliveryAddressGuest from './DeliveryAddressGuest.vue'
3
+
4
+ fdescribe('DeliveryAddressGuest', () => {
5
+ let wrapper
6
+
7
+ beforeEach(() => {
8
+ const localVue = createLocalVue()
9
+ wrapper = shallowMount(DeliveryAddressGuest, {
10
+ localVue,
11
+ mocks: {
12
+ $t: jest.fn(),
13
+ $buefy: {
14
+ loading: {
15
+ open: jest.fn(),
16
+ close: jest.fn()
17
+ },
18
+ dialog: {
19
+ alert: jest.fn()
20
+ },
21
+ toast: {
22
+ open: jest.fn()
23
+ }
24
+ }
25
+ },
26
+ stubs: {
27
+ Address: true,
28
+ EditAddress: true,
29
+ DeliveryMethods: true
30
+ }
31
+ })
32
+ })
33
+
34
+ afterEach(() => {
35
+ wrapper.destroy()
36
+ })
37
+
38
+ it('renders the component', () => {
39
+ expect(wrapper.exists()).toBe(true)
40
+ })
41
+
42
+ it('initializes with correct data', () => {
43
+ expect(wrapper.vm.addressValid).toBe(false)
44
+ expect(wrapper.vm.validationErrors).toEqual({})
45
+ expect(wrapper.vm.editAutocompleteAddress).toBe(false)
46
+ })
47
+
48
+ it('calls onGmapsPlaceInput method correctly', () => {
49
+ const pl = {
50
+ street: '123 Main St',
51
+ city: 'New York',
52
+ state: 'NY',
53
+ country: 'USA'
54
+ }
55
+ wrapper.vm.checkoutRequestData.shipping_address = {
56
+ street: '',
57
+ city: '',
58
+ state: '',
59
+ country: ''
60
+ }
61
+ wrapper.vm.onGmapsPlaceInput(pl)
62
+ expect(wrapper.vm.validationErrors).toEqual({})
63
+ expect(wrapper.vm.editAutocompleteAddress).toBe(false)
64
+ expect(wrapper.vm.checkoutRequestData.shipping_address).toEqual(pl)
65
+ })
66
+
67
+ it('calls onAddressContinue method correctly', async () => {
68
+ const geocodeResult = 'OK'
69
+ const validateAddressResult = {
70
+ valid: true
71
+ }
72
+ const getAvailableDeliveryMethodsResult = [
73
+ { id: 1, name: 'Standard Delivery' },
74
+ { id: 2, name: 'Express Delivery' }
75
+ ]
76
+ wrapper.vm.geocodeAddress = jest.fn().mockResolvedValue(geocodeResult)
77
+ wrapper.vm.validateAddress = jest.fn().mockResolvedValue(validateAddressResult)
78
+ wrapper.vm.getAvailableDeliveryMethods = jest.fn().mockResolvedValue(getAvailableDeliveryMethodsResult)
79
+
80
+ await wrapper.vm.onAddressContinue()
81
+
82
+ expect(wrapper.vm.addressValid).toBe(true)
83
+ expect(wrapper.emitted('addressValidation')[0]).toEqual([true])
84
+ expect(wrapper.vm.setBillingAddress).toHaveBeenCalledWith(wrapper.vm.checkoutRequestData.shipping_address)
85
+ expect(wrapper.vm.getAvailableDeliveryMethods).toHaveBeenCalledWith(wrapper.vm.checkoutRequestData.shipping_address)
86
+ expect(wrapper.vm.scrollToElement).toHaveBeenCalledWith('.delivery-method')
87
+ })
88
+
89
+ it('calls onChangeDeliveryAddress method correctly', () => {
90
+ wrapper.vm.onChangeDeliveryAddress()
91
+ expect(wrapper.vm.addressValid).toBe(false)
92
+ expect(wrapper.vm.editAutocompleteAddress).toBe(true)
93
+ expect(wrapper.emitted('addressValidation')[0]).toEqual([false])
94
+ })
95
+
96
+ it('calls deliveryMethodSelected method correctly', () => {
97
+ const deliveryCost = { id: 1, name: 'Standard Delivery' }
98
+ wrapper.vm.deliveryMethodSelected(deliveryCost)
99
+ expect(wrapper.vm.getSummary).toHaveBeenCalledWith({
100
+ country_id: wrapper.vm.checkoutRequestData.shipping_address.country_id,
101
+ state_id: wrapper.vm.checkoutRequestData.shipping_address.state_id,
102
+ delivery_cost_id: deliveryCost.id
103
+ })
104
+ expect(wrapper.emitted('deliveryMethodSelected')[0]).toEqual([deliveryCost])
105
+ })
106
+
107
+ it('calls setDeliveryAddressUserIdentity method correctly', () => {
108
+ const initialState = {
109
+ orderAsBusiness: '0'
110
+ }
111
+ const userIdentity = {
112
+ first_name: 'John',
113
+ last_name: 'Doe',
114
+ phone: '1234567890'
115
+ }
116
+ const countryList = ['USA', 'Canada']
117
+ wrapper.vm.initialState = initialState
118
+ wrapper.vm.userIdentity = userIdentity
119
+ wrapper.vm.countryList = countryList
120
+
121
+ wrapper.vm.setDeliveryAddressUserIdentity()
122
+
123
+ expect(wrapper.vm.setDeliveryAddress).toHaveBeenCalledWith(expect.any(Object))
124
+ expect(wrapper.vm.checkoutRequestData.shipping_address.first_name).toBe(userIdentity.first_name)
125
+ expect(wrapper.vm.checkoutRequestData.shipping_address.last_name).toBe(userIdentity.last_name)
126
+ expect(wrapper.vm.checkoutRequestData.shipping_address.phone).toBe(userIdentity.phone)
127
+ })
128
+ })
@@ -117,7 +117,6 @@ export default {
117
117
  await this.validateAddress(this.checkoutRequestData.shipping_address)
118
118
  this.addressValid = true
119
119
  this.$emit('addressValidation', true)
120
- this.scrollToElement('.delivery-method')
121
120
  } catch (e) {
122
121
  this.validationErrors = e.errors
123
122
  this.$buefy.toast.open({
@@ -136,6 +135,7 @@ export default {
136
135
  this.setBillingAddress(this.checkoutRequestData.shipping_address)
137
136
  try {
138
137
  await this.getAvailableDeliveryMethods(this.checkoutRequestData.shipping_address)
138
+ this.scrollToElement('.delivery-method')
139
139
  } catch (error) {
140
140
  this.addressValid = false
141
141
  this.$emit('addressValidation', false)
@@ -0,0 +1,83 @@
1
+
2
+ import { mount } from '@vue/test-utils'
3
+ import DeliveryTypes from '@/components/Cart/Delivery/DeliveryTypes.vue'
4
+
5
+ describe('DeliveryTypes', () => {
6
+ let wrapper
7
+ const deliveryTypesMock = [
8
+ { type: 'pickup', name: 'Pickup', description: 'Pick up your order from the store' },
9
+ { type: 'delivery', name: 'Delivery', description: 'Get your order delivered to your address' }
10
+ ]
11
+
12
+ beforeEach(() => {
13
+ wrapper = mount(DeliveryTypes, {
14
+ propsData: {
15
+ value: 'pickup',
16
+ error: false
17
+ },
18
+ computed: {
19
+ deliveryTypes: () => deliveryTypesMock
20
+ },
21
+
22
+ })
23
+ })
24
+
25
+ it('renders the delivery types', () => {
26
+ const deliveryMethods = wrapper.findAll('.delivery-methods .b-radio')
27
+ expect(deliveryMethods.length).toBe(2)
28
+
29
+ const firstDeliveryMethod = deliveryMethods.at(0)
30
+ expect(firstDeliveryMethod.find('div').text()).toBe('Pickup')
31
+
32
+ const secondDeliveryMethod = deliveryMethods.at(1)
33
+ expect(secondDeliveryMethod.find('div').text()).toBe('Delivery')
34
+ })
35
+
36
+ it('emits the selected delivery type on input', async () => {
37
+ const deliveryMethodInputs = wrapper.findAll('.delivery-methods .b-radio input')
38
+ const secondDeliveryMethodInput = deliveryMethodInputs.at(1)
39
+
40
+ await secondDeliveryMethodInput.setChecked(true)
41
+
42
+ expect(wrapper.emitted().input).toBeTruthy()
43
+ expect(wrapper.emitted().input[1]).toEqual(['delivery'])
44
+ })
45
+
46
+ it('sets the default delivery type if deliveryTypes is not empty', () => {
47
+ expect(wrapper.emitted().input).toBeTruthy()
48
+ expect(wrapper.emitted().input[0]).toEqual(['pickup'])
49
+ })
50
+
51
+ it('does not set the default delivery type if deliveryTypes is empty', () => {
52
+ wrapper = mount(DeliveryTypes, {
53
+ propsData: {
54
+ value: 'pickup',
55
+ error: false
56
+ },
57
+ computed: {
58
+ deliveryTypes: () => []
59
+ }
60
+ })
61
+
62
+ expect(wrapper.emitted().input).toBeFalsy()
63
+ })
64
+
65
+ it('renders the error message if error is true', () => {
66
+ wrapper = mount(DeliveryTypes, {
67
+ propsData: {
68
+ value: 'pickup',
69
+ error: true
70
+ },
71
+ computed: {
72
+ deliveryTypes: () => deliveryTypesMock
73
+ }
74
+ })
75
+
76
+ expect(wrapper.find('.help.is-danger').text()).toBe('Please choose delivery method')
77
+ })
78
+
79
+ it('does not render the error message if error is false', () => {
80
+ expect(wrapper.find('.help.is-danger').exists()).toBe(false)
81
+ })
82
+
83
+ })
@@ -14,7 +14,7 @@
14
14
  alignItems: 'flex-start',
15
15
  padding: '2rem',
16
16
  fontSize: '1.2rem',
17
- borderBottom: index === 0 ? '1px #ddd solid' : '',
17
+ borderBottom: '1px #ddd solid',
18
18
  marginRight: 0
19
19
  }"
20
20
  :class="[{ 'dm-selected': value === dm.type }]"
@@ -15,7 +15,7 @@
15
15
  alignItems: 'flex-start',
16
16
  padding: '2rem',
17
17
  fontSize: '1.2rem',
18
- borderBottom: index === 0 ? '1px #ddd solid' : '',
18
+ borderBottom: '1px #ddd solid',
19
19
  marginRight: 0
20
20
  }"
21
21
  >
package/jest.config.js ADDED
@@ -0,0 +1,16 @@
1
+ module.exports = {
2
+ preset: '@vue/cli-plugin-unit-jest',
3
+ testMatch: [
4
+ '**/*.spec.[jt]s?(x)'
5
+ ],
6
+ modulePathIgnorePatterns: ["<rootDir>/test/"],
7
+ moduleNameMapper: {
8
+ '@/(.*)': '<rootDir>/$1'
9
+ },
10
+ collectCoverage: true,
11
+ coverageReporters: ['html', 'text-summary'],
12
+ setupFilesAfterEnv: ['<rootDir>/tests/vueBuefy.js'],
13
+ transformIgnorePatterns: [
14
+ "!node_modules/"
15
+ ]
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wikala/spmkt",
3
- "version": "2.15.0",
3
+ "version": "2.17.0",
4
4
  "private": false,
5
5
  "description": "supermarket",
6
6
  "scripts": {
@@ -29,8 +29,10 @@
29
29
  "devDependencies": {
30
30
  "@babel/plugin-proposal-optional-chaining": "^7.14.5",
31
31
  "@vue/cli-plugin-babel": "^4.5.13",
32
+ "@vue/cli-plugin-unit-jest": "~4.5.11",
32
33
  "@vue/cli-service": "^4.5.13",
33
34
  "@vue/runtime-dom": "^3.3.8",
35
+ "@vue/test-utils": "^1.3.6",
34
36
  "axios": "^0.21.1",
35
37
  "babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
36
38
  "bootstrap-sass": "^3.4.1",
@@ -0,0 +1,4 @@
1
+ import Vue from 'vue';
2
+ import Buefy from 'buefy';
3
+
4
+ Vue.use(Buefy);
@@ -1,6 +1,6 @@
1
1
  class GoogleAnalyticsEEC {
2
2
  constructor() {
3
- if (!dataLayer) {
3
+ if (!window.dataLayer) {
4
4
  console.log('No dataLayer defined.')
5
5
  return false
6
6
  }