1
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils'; |
2
|
|
|
import 'src/module/sw-promotion-v2/view/sw-promotion-v2-conditions'; |
3
|
|
|
|
4
|
|
|
function createWrapper(privileges = []) { |
5
|
|
|
const localVue = createLocalVue(); |
6
|
|
|
localVue.directive('tooltip', {}); |
7
|
|
|
|
8
|
|
|
return shallowMount(Shopware.Component.build('sw-promotion-v2-conditions'), { |
|
|
|
|
9
|
|
|
localVue, |
10
|
|
|
stubs: { |
11
|
|
|
'sw-card': { |
12
|
|
|
template: '<div class="sw-card"><slot></slot></div>' |
13
|
|
|
}, |
14
|
|
|
'sw-container': { |
15
|
|
|
template: '<div class="sw-container"><slot></slot></div>' |
16
|
|
|
}, |
17
|
|
|
'sw-text-field': { |
18
|
|
|
template: '<div class="sw-text-field"></div>' |
19
|
|
|
}, |
20
|
|
|
'sw-number-field': { |
21
|
|
|
template: '<div class="sw-number-field"></div>' |
22
|
|
|
}, |
23
|
|
|
'sw-entity-multi-select': { |
24
|
|
|
template: '<div class="sw-entity-multi-select"></div>' |
25
|
|
|
}, |
26
|
|
|
'sw-promotion-v2-sales-channel-select': { |
27
|
|
|
template: '<div class="sw-promotion-v2-sales-channel-select"></div>' |
28
|
|
|
}, |
29
|
|
|
'sw-promotion-v2-rule-select': { |
30
|
|
|
template: '<div class="sw-promotion-v2-rule-select"></div>' |
31
|
|
|
} |
32
|
|
|
}, |
33
|
|
|
provide: { |
34
|
|
|
acl: { |
35
|
|
|
can: (key) => { |
36
|
|
|
if (!key) { return true; } |
37
|
|
|
|
38
|
|
|
return privileges.includes(key); |
39
|
|
|
} |
40
|
|
|
}, |
41
|
|
|
repositoryFactory: { |
42
|
|
|
create: () => ({ |
43
|
|
|
search: () => Promise.resolve([{ id: 'promotionId1' }]) |
44
|
|
|
}) |
45
|
|
|
} |
46
|
|
|
}, |
47
|
|
|
mocks: { |
48
|
|
|
$tc: v => v |
49
|
|
|
}, |
50
|
|
|
propsData: { |
51
|
|
|
promotion: { |
52
|
|
|
name: 'Test Promotion', |
53
|
|
|
active: true, |
54
|
|
|
validFrom: '2020-07-28T12:00:00.000+00:00', |
55
|
|
|
validUntil: '2020-08-11T12:00:00.000+00:00', |
56
|
|
|
maxRedemptionsGlobal: 45, |
57
|
|
|
maxRedemptionsPerCustomer: 12, |
58
|
|
|
exclusive: false, |
59
|
|
|
code: null, |
60
|
|
|
useCodes: true, |
61
|
|
|
useIndividualCodes: false, |
62
|
|
|
individualCodePattern: 'code-%d', |
63
|
|
|
useSetGroups: false, |
64
|
|
|
customerRestriction: true, |
65
|
|
|
orderCount: 0, |
66
|
|
|
ordersPerCustomerCount: null, |
67
|
|
|
exclusionIds: ['d671d6d3efc74d2a8b977e3be3cd69c7'], |
68
|
|
|
translated: { |
69
|
|
|
name: 'Test Promotion' |
70
|
|
|
}, |
71
|
|
|
apiAlias: null, |
72
|
|
|
id: 'promotionId', |
73
|
|
|
setgroups: [], |
74
|
|
|
salesChannels: [ |
75
|
|
|
{ |
76
|
|
|
promotionId: 'promotionId', |
77
|
|
|
salesChannelId: 'salesChannelId', |
78
|
|
|
priority: 1, |
79
|
|
|
createdAt: '2020-08-17T13:24:52.692+00:00', |
80
|
|
|
id: 'promotionSalesChannelId' |
81
|
|
|
} |
82
|
|
|
], |
83
|
|
|
discounts: [], |
84
|
|
|
individualCodes: [], |
85
|
|
|
personaRules: [], |
86
|
|
|
personaCustomers: [], |
87
|
|
|
orderRules: [], |
88
|
|
|
cartRules: [], |
89
|
|
|
translations: [], |
90
|
|
|
hasOrders: false, |
91
|
|
|
isNew() { |
92
|
|
|
return true; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
}); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
describe('src/module/sw-promotion-v2/component/sw-promotion-v2-conditions', () => { |
100
|
|
|
let wrapper; |
101
|
|
|
|
102
|
|
|
beforeEach(() => { |
103
|
|
|
wrapper = createWrapper(); |
104
|
|
|
}); |
105
|
|
|
|
106
|
|
|
afterEach(() => { |
107
|
|
|
wrapper.destroy(); |
108
|
|
|
}); |
109
|
|
|
|
110
|
|
|
it('should be a Vue.js component', () => { |
111
|
|
|
expect(wrapper.vm).toBeTruthy(); |
112
|
|
|
}); |
113
|
|
|
|
114
|
|
|
it('should disable adding discounts when privileges not set', () => { |
115
|
|
|
expect( |
116
|
|
|
wrapper.find('.sw-promotion-v2-conditions__sales-channel-selection').attributes().disabled |
117
|
|
|
).toBeTruthy(); |
118
|
|
|
expect( |
119
|
|
|
wrapper.find('.sw-promotion-v2-conditions__rules-exclusion-selection').attributes().disabled |
120
|
|
|
).toBeTruthy(); |
121
|
|
|
expect( |
122
|
|
|
wrapper.find('.sw-promotion-v2-conditions__rule-select-customer').attributes().disabled |
123
|
|
|
).toBeTruthy(); |
124
|
|
|
expect( |
125
|
|
|
wrapper.find('.sw-promotion-v2-conditions__rule-select-cart-conditions').attributes().disabled |
126
|
|
|
).toBeTruthy(); |
127
|
|
|
expect( |
128
|
|
|
wrapper.find('.sw-promotion-v2-conditions__rule-select-order-conditions').attributes().disabled |
129
|
|
|
).toBeTruthy(); |
130
|
|
|
}); |
131
|
|
|
|
132
|
|
|
it('should enable adding discounts when privilege is set', () => { |
133
|
|
|
wrapper = createWrapper([ |
134
|
|
|
'promotion.editor' |
135
|
|
|
]); |
136
|
|
|
|
137
|
|
|
expect( |
138
|
|
|
wrapper.find('.sw-promotion-v2-conditions__sales-channel-selection').attributes().disabled |
139
|
|
|
).toBeFalsy(); |
140
|
|
|
expect( |
141
|
|
|
wrapper.find('.sw-promotion-v2-conditions__rules-exclusion-selection').attributes().disabled |
142
|
|
|
).toBeFalsy(); |
143
|
|
|
expect( |
144
|
|
|
wrapper.find('.sw-promotion-v2-conditions__rule-select-customer').attributes().disabled |
145
|
|
|
).toBeFalsy(); |
146
|
|
|
expect( |
147
|
|
|
wrapper.find('.sw-promotion-v2-conditions__rule-select-cart-conditions').attributes().disabled |
148
|
|
|
).toBeFalsy(); |
149
|
|
|
expect( |
150
|
|
|
wrapper.find('.sw-promotion-v2-conditions__rule-select-order-conditions').attributes().disabled |
151
|
|
|
).toBeFalsy(); |
152
|
|
|
}); |
153
|
|
|
}); |
154
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.