Conditions | 7 |
Total Lines | 94 |
Code Lines | 70 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import { createLocalVue, shallowMount } from '@vue/test-utils'; |
||
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 | |||
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.