|
1
|
|
|
import Vuex from 'vuex'; |
|
2
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils'; |
|
3
|
|
|
import swOrderDetailGeneral from 'src/module/sw-order/view/sw-order-detail-general'; |
|
4
|
|
|
import orderDetailStore from 'src/module/sw-order/state/order-detail.store'; |
|
5
|
|
|
|
|
6
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
|
7
|
|
|
import type Vue from 'vue'; |
|
8
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars |
|
9
|
|
|
import type { Wrapper } from '@vue/test-utils'; |
|
10
|
|
|
|
|
11
|
|
|
const orderMock = { |
|
12
|
|
|
orderCustomer: { |
|
13
|
|
|
email: '[email protected]' |
|
14
|
|
|
}, |
|
15
|
|
|
shippingCosts: { |
|
16
|
|
|
calculatedTaxes: [ |
|
17
|
|
|
{ |
|
18
|
|
|
tax: 1, |
|
19
|
|
|
taxRate: 10, |
|
20
|
|
|
}, |
|
21
|
|
|
{ |
|
22
|
|
|
tax: 1.9, |
|
23
|
|
|
taxRate: 19, |
|
24
|
|
|
} |
|
25
|
|
|
], |
|
26
|
|
|
totalPrice: 10 |
|
27
|
|
|
}, |
|
28
|
|
|
currency: { |
|
29
|
|
|
shortName: 'EUR', |
|
30
|
|
|
translated: { |
|
31
|
|
|
shortName: 'EUR' |
|
32
|
|
|
} |
|
33
|
|
|
}, |
|
34
|
|
|
deliveries: [ |
|
35
|
|
|
{ |
|
36
|
|
|
stateMachineState: { |
|
37
|
|
|
translated: { |
|
38
|
|
|
name: 'Open' |
|
39
|
|
|
} |
|
40
|
|
|
}, |
|
41
|
|
|
shippingCosts: { |
|
42
|
|
|
calculatedTaxes: [], |
|
43
|
|
|
totalPrice: 10 |
|
44
|
|
|
}, |
|
45
|
|
|
shippingOrderAddress: { |
|
46
|
|
|
id: 'address1' |
|
47
|
|
|
}, |
|
48
|
|
|
} |
|
49
|
|
|
], |
|
50
|
|
|
price: { |
|
51
|
|
|
calculatedTaxes: [ |
|
52
|
|
|
{ |
|
53
|
|
|
tax: 10, |
|
54
|
|
|
taxRate: 10, |
|
55
|
|
|
}, |
|
56
|
|
|
{ |
|
57
|
|
|
tax: 19, |
|
58
|
|
|
taxRate: 19, |
|
59
|
|
|
} |
|
60
|
|
|
], |
|
61
|
|
|
taxStatus: 'gross', |
|
62
|
|
|
totalPrice: 139, |
|
63
|
|
|
}, |
|
64
|
|
|
totalRounding: { |
|
65
|
|
|
interval: 0.01, |
|
66
|
|
|
decimals: 2 |
|
67
|
|
|
}, |
|
68
|
|
|
itemRounding: { |
|
69
|
|
|
interval: 0.01, |
|
70
|
|
|
decimals: 2 |
|
71
|
|
|
}, |
|
72
|
|
|
amountNet: 100, |
|
73
|
|
|
lineItems: [], |
|
74
|
|
|
}; |
|
75
|
|
|
|
|
76
|
|
|
Shopware.Component.register('sw-order-detail-general', swOrderDetailGeneral); |
|
77
|
|
|
|
|
78
|
|
|
async function createWrapper(privileges = []): Promise<Wrapper<Vue>> { |
|
79
|
|
|
const localVue = createLocalVue(); |
|
80
|
|
|
localVue.use(Vuex); |
|
81
|
|
|
localVue.directive('tooltip', { |
|
82
|
|
|
bind(el, binding) { |
|
83
|
|
|
el.setAttribute('tooltip-message', binding.value.message); |
|
84
|
|
|
}, |
|
85
|
|
|
inserted(el, binding) { |
|
86
|
|
|
el.setAttribute('tooltip-message', binding.value.message); |
|
87
|
|
|
}, |
|
88
|
|
|
update(el, binding) { |
|
89
|
|
|
el.setAttribute('tooltip-message', binding.value.message); |
|
90
|
|
|
} |
|
91
|
|
|
}); |
|
92
|
|
|
localVue.filter('currency', Shopware.Filter.getByName('currency')); |
|
93
|
|
|
|
|
94
|
|
|
return shallowMount(await Shopware.Component.build('sw-order-detail-general'), { |
|
95
|
|
|
localVue, |
|
96
|
|
|
stubs: { |
|
97
|
|
|
'sw-container': { |
|
98
|
|
|
template: ` |
|
99
|
|
|
<div class="sw-container"><slot></slot></div> |
|
100
|
|
|
` |
|
101
|
|
|
}, |
|
102
|
|
|
'sw-card-section': { |
|
103
|
|
|
template: ` |
|
104
|
|
|
<div class="sw-card-section"><slot></slot></div> |
|
105
|
|
|
` |
|
106
|
|
|
}, |
|
107
|
|
|
'sw-description-list': { |
|
108
|
|
|
template: ` |
|
109
|
|
|
<div class="sw-description-list"><slot></slot></div> |
|
110
|
|
|
` |
|
111
|
|
|
}, |
|
112
|
|
|
'sw-card': { |
|
113
|
|
|
template: ` |
|
114
|
|
|
<div class="sw-card"> |
|
115
|
|
|
<slot></slot> |
|
116
|
|
|
<slot name="grid"></slot> |
|
117
|
|
|
</div> |
|
118
|
|
|
` |
|
119
|
|
|
}, |
|
120
|
|
|
'sw-order-general-info': true, |
|
121
|
|
|
'sw-order-line-items-grid': true, |
|
122
|
|
|
'sw-order-saveable-field': { |
|
123
|
|
|
props: ['value'], |
|
124
|
|
|
template: '<input class="sw-order-saveable-field" :value="value" @input="$emit(\'value-change\', $event.target.value)" />', |
|
125
|
|
|
}, |
|
126
|
|
|
}, |
|
127
|
|
|
mocks: { |
|
128
|
|
|
$tc: (key, number, value) => { |
|
129
|
|
|
if (!value) { |
|
130
|
|
|
return key; |
|
131
|
|
|
} |
|
132
|
|
|
return key + JSON.stringify(value); |
|
133
|
|
|
}, |
|
134
|
|
|
}, |
|
135
|
|
|
provide: { |
|
136
|
|
|
acl: { |
|
137
|
|
|
can: (key) => { |
|
138
|
|
|
if (!key) { return true; } |
|
139
|
|
|
|
|
140
|
|
|
return privileges.includes(key); |
|
141
|
|
|
} |
|
142
|
|
|
}, |
|
143
|
|
|
}, |
|
144
|
|
|
propsData: { |
|
145
|
|
|
orderId: '1a2b3c', |
|
146
|
|
|
isSaveSuccessful: false |
|
147
|
|
|
} |
|
148
|
|
|
}); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
describe('src/module/sw-order/view/sw-order-detail-details', () => { |
|
152
|
|
|
let wrapper; |
|
153
|
|
|
|
|
154
|
|
|
beforeAll(() => { |
|
155
|
|
|
Shopware.State.registerModule('swOrderDetail', { |
|
156
|
|
|
...orderDetailStore, |
|
157
|
|
|
state: { |
|
158
|
|
|
...orderDetailStore.state, |
|
159
|
|
|
order: orderMock, |
|
160
|
|
|
orderAddressIds: [], |
|
161
|
|
|
}, |
|
162
|
|
|
}); |
|
163
|
|
|
}); |
|
164
|
|
|
|
|
165
|
|
|
beforeEach(async () => { |
|
166
|
|
|
wrapper = await createWrapper(); |
|
167
|
|
|
}); |
|
168
|
|
|
|
|
169
|
|
|
afterEach(async () => { |
|
170
|
|
|
await wrapper.destroy(); |
|
171
|
|
|
}); |
|
172
|
|
|
|
|
173
|
|
|
it('should be a Vue.js component', async () => { |
|
174
|
|
|
expect(wrapper.vm).toBeTruthy(); |
|
175
|
|
|
}); |
|
176
|
|
|
|
|
177
|
|
|
it('should tax description correctly for shipping cost if taxStatus is not tax-free', async () => { |
|
178
|
|
|
const shippingCostField = wrapper.find('.sw-order-saveable-field'); |
|
179
|
|
|
expect(shippingCostField.attributes()['tooltip-message']) |
|
180
|
|
|
.toEqual('sw-order.detailBase.tax<br>sw-order.detailBase.shippingCostsTax{"taxRate":10,"tax":"€1.00"}<br>sw-order.detailBase.shippingCostsTax{"taxRate":19,"tax":"€1.90"}'); |
|
181
|
|
|
}); |
|
182
|
|
|
|
|
183
|
|
|
it('should tax description correctly if taxStatus is not tax-free', async () => { |
|
184
|
|
|
const descriptionTitles = wrapper.findAll('dt'); |
|
185
|
|
|
const descriptionInfos = wrapper.findAll('dd'); |
|
186
|
|
|
|
|
187
|
|
|
expect(descriptionTitles.at(3).text()).toEqual('sw-order.detailBase.summaryLabelTaxes{"taxRate":10}'); |
|
188
|
|
|
expect(descriptionInfos.at(3).text()).toEqual('€10.00'); |
|
189
|
|
|
|
|
190
|
|
|
expect(descriptionTitles.at(4).text()).toEqual('sw-order.detailBase.summaryLabelTaxes{"taxRate":19}'); |
|
191
|
|
|
expect(descriptionInfos.at(4).text()).toEqual('€19.00'); |
|
192
|
|
|
}); |
|
193
|
|
|
|
|
194
|
|
|
it('should able to edit shipping cost', async () => { |
|
195
|
|
|
wrapper = await createWrapper(['order.editor']); |
|
196
|
|
|
const shippingCostField = wrapper.find('.sw-order-saveable-field'); |
|
197
|
|
|
await shippingCostField.setValue(20); |
|
198
|
|
|
await shippingCostField.trigger('input'); |
|
199
|
|
|
|
|
200
|
|
|
expect(wrapper.vm.delivery.shippingCosts.unitPrice).toEqual('20'); |
|
201
|
|
|
expect(wrapper.vm.delivery.shippingCosts.totalPrice).toEqual('20'); |
|
202
|
|
|
expect(wrapper.emitted('save-and-recalculate')).toBeTruthy(); |
|
203
|
|
|
}); |
|
204
|
|
|
|
|
205
|
|
|
it('should emit event save-edits when saving general info', async () => { |
|
206
|
|
|
wrapper = await createWrapper(['order.editor']); |
|
207
|
|
|
const generalInfo = wrapper.find('sw-order-general-info-stub'); |
|
208
|
|
|
await generalInfo.vm.$emit('save-edits'); |
|
209
|
|
|
|
|
210
|
|
|
expect(wrapper.emitted('save-edits')).toBeTruthy(); |
|
211
|
|
|
}); |
|
212
|
|
|
|
|
213
|
|
|
it('should emit event recalculate-and-reload when adding line item delete item successfully', async () => { |
|
214
|
|
|
wrapper = await createWrapper(['order.editor']); |
|
215
|
|
|
const generalInfo = wrapper.find('sw-order-line-items-grid-stub'); |
|
216
|
|
|
await generalInfo.vm.$emit('item-edit'); |
|
217
|
|
|
|
|
218
|
|
|
expect(wrapper.emitted('recalculate-and-reload')).toBeTruthy(); |
|
219
|
|
|
}); |
|
220
|
|
|
|
|
221
|
|
|
it('should emit event recalculate-and-reload when deleting line item successfully', async () => { |
|
222
|
|
|
wrapper = await createWrapper(['order.editor']); |
|
223
|
|
|
const generalInfo = wrapper.find('sw-order-line-items-grid-stub'); |
|
224
|
|
|
await generalInfo.vm.$emit('item-delete'); |
|
225
|
|
|
|
|
226
|
|
|
expect(wrapper.emitted('recalculate-and-reload')).toBeTruthy(); |
|
227
|
|
|
}); |
|
228
|
|
|
|
|
229
|
|
|
it('should emit event recalculate-and-reload when cancel editing line item successfully', async () => { |
|
230
|
|
|
wrapper = await createWrapper(['order.editor']); |
|
231
|
|
|
const generalInfo = wrapper.find('sw-order-line-items-grid-stub'); |
|
232
|
|
|
await generalInfo.vm.$emit('item-cancel'); |
|
233
|
|
|
|
|
234
|
|
|
expect(wrapper.emitted('recalculate-and-reload')).toBeTruthy(); |
|
235
|
|
|
}); |
|
236
|
|
|
|
|
237
|
|
|
it('should emit event save-and-recalculate when editing line item successfully', async () => { |
|
238
|
|
|
wrapper = await createWrapper(['order.editor']); |
|
239
|
|
|
const generalInfo = wrapper.find('sw-order-line-items-grid-stub'); |
|
240
|
|
|
await generalInfo.vm.$emit('existing-item-edit'); |
|
241
|
|
|
|
|
242
|
|
|
expect(wrapper.emitted('save-and-recalculate')).toBeTruthy(); |
|
243
|
|
|
}); |
|
244
|
|
|
}); |
|
245
|
|
|
|