|
1
|
|
|
import Vue from 'vue'; |
|
2
|
|
|
import { shallowMount } from '@vue/test-utils'; |
|
3
|
|
|
import type { Wrapper } from '@vue/test-utils'; |
|
4
|
|
|
import swOrderStateSelectV2 from 'src/module/sw-order/component/sw-order-state-select-v2'; |
|
5
|
|
|
|
|
6
|
|
|
Shopware.Component.register('sw-order-state-select-v2', swOrderStateSelectV2); |
|
7
|
|
|
|
|
8
|
|
|
describe('src/module/sw-order/component/sw-order-state-select-v2', () => { |
|
9
|
|
|
async function createWrapper(): Promise<Wrapper<Vue>> { |
|
10
|
|
|
return shallowMount(await Shopware.Component.build('sw-order-state-select-v2'), { |
|
11
|
|
|
stubs: { |
|
12
|
|
|
'sw-single-select': { |
|
13
|
|
|
template: ` |
|
14
|
|
|
<input class='sw-single-select' :value="value" @input="$emit('input', $event.target.value)" />`, |
|
15
|
|
|
props: ['value'], |
|
16
|
|
|
}, |
|
17
|
|
|
}, |
|
18
|
|
|
propsData: { |
|
19
|
|
|
stateType: 'order' |
|
20
|
|
|
}, |
|
21
|
|
|
}); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
it('should be a Vue.js component', async () => { |
|
25
|
|
|
const wrapper = await createWrapper(); |
|
26
|
|
|
expect(wrapper.vm).toBeTruthy(); |
|
27
|
|
|
}); |
|
28
|
|
|
|
|
29
|
|
|
it('should disabled single select if transition options props are empty', async () => { |
|
30
|
|
|
const wrapper = await createWrapper(); |
|
31
|
|
|
const singleSelect = wrapper.find('.sw-single-select'); |
|
32
|
|
|
|
|
33
|
|
|
expect(singleSelect.attributes('disabled')).toBeTruthy(); |
|
34
|
|
|
}); |
|
35
|
|
|
|
|
36
|
|
|
it('should enable single select if transition options props has value', async () => { |
|
37
|
|
|
const wrapper = await createWrapper(); |
|
38
|
|
|
|
|
39
|
|
|
await wrapper.setProps({ |
|
40
|
|
|
transitionOptions: [ |
|
41
|
|
|
{ |
|
42
|
|
|
disabled: false, |
|
43
|
|
|
id: 'do_pay', |
|
44
|
|
|
name: 'In progress', |
|
45
|
|
|
stateName: 'in_progress', |
|
46
|
|
|
} |
|
47
|
|
|
] |
|
48
|
|
|
}); |
|
49
|
|
|
|
|
50
|
|
|
const singleSelect = wrapper.find('.sw-single-select'); |
|
51
|
|
|
expect(singleSelect.attributes('disabled')).toBeUndefined(); |
|
52
|
|
|
}); |
|
53
|
|
|
|
|
54
|
|
|
it('should emit state-select event', async () => { |
|
55
|
|
|
const wrapper = await createWrapper(); |
|
56
|
|
|
|
|
57
|
|
|
await wrapper.setProps({ |
|
58
|
|
|
transitionOptions: [ |
|
59
|
|
|
{ |
|
60
|
|
|
disabled: false, |
|
61
|
|
|
id: 'do_pay', |
|
62
|
|
|
name: 'In progress', |
|
63
|
|
|
stateName: 'in_progress', |
|
64
|
|
|
} |
|
65
|
|
|
] |
|
66
|
|
|
}); |
|
67
|
|
|
|
|
68
|
|
|
const singleSelect = wrapper.find('.sw-single-select'); |
|
69
|
|
|
|
|
70
|
|
|
await singleSelect.setValue('in_progress'); |
|
71
|
|
|
await singleSelect.trigger('input'); |
|
72
|
|
|
|
|
73
|
|
|
expect(wrapper.emitted('state-select')[0]).toEqual(['order', 'in_progress']); |
|
74
|
|
|
}); |
|
75
|
|
|
|
|
76
|
|
|
it('should show placeholder correctly', async () => { |
|
77
|
|
|
const wrapper = await createWrapper(); |
|
78
|
|
|
const singleSelect = wrapper.find('.sw-single-select'); |
|
79
|
|
|
|
|
80
|
|
|
expect(singleSelect.attributes('placeholder')) |
|
81
|
|
|
.toEqual('sw-order.stateCard.labelSelectStatePlaceholder'); |
|
82
|
|
|
|
|
83
|
|
|
await wrapper.setProps({ |
|
84
|
|
|
placeholder: 'Open', |
|
85
|
|
|
}); |
|
86
|
|
|
|
|
87
|
|
|
expect(singleSelect.attributes('placeholder')).toEqual('Open'); |
|
88
|
|
|
}); |
|
89
|
|
|
}); |
|
90
|
|
|
|