|
1
|
|
|
/** |
|
2
|
|
|
* @package admin |
|
3
|
|
|
*/ |
|
4
|
|
|
|
|
5
|
|
|
import { shallowMount, createLocalVue } from '@vue/test-utils'; |
|
6
|
|
|
import EntityCollection from 'src/core/data/entity-collection.data'; |
|
7
|
|
|
import Criteria from 'src/core/data/criteria.data'; |
|
8
|
|
|
import utils from 'src/core/service/util.service'; |
|
9
|
|
|
import type { Wrapper } from '@vue/test-utils'; |
|
10
|
|
|
import type Vue from 'vue'; |
|
11
|
|
|
import 'src/app/component/form/select/entity/sw-entity-multi-id-select'; |
|
12
|
|
|
import 'src/app/component/form/select/entity/sw-entity-multi-select'; |
|
13
|
|
|
import 'src/app/component/form/select/base/sw-select-base'; |
|
14
|
|
|
|
|
15
|
|
|
const { Component } = Shopware; |
|
16
|
|
|
|
|
17
|
|
|
const fixture = [ |
|
18
|
|
|
{ |
|
19
|
|
|
id: utils.createId(), |
|
20
|
|
|
name: 'first entry', |
|
21
|
|
|
active: true, |
|
22
|
|
|
}, |
|
23
|
|
|
{ |
|
24
|
|
|
id: utils.createId(), |
|
25
|
|
|
name: 'second entry', |
|
26
|
|
|
active: false, |
|
27
|
|
|
}, |
|
28
|
|
|
]; |
|
29
|
|
|
|
|
30
|
|
|
function getCollection() { |
|
31
|
|
|
return new EntityCollection( |
|
32
|
|
|
'/test-entity', |
|
33
|
|
|
'testEntity', |
|
34
|
|
|
null, |
|
35
|
|
|
new Criteria(1, 25), |
|
36
|
|
|
fixture, |
|
37
|
|
|
fixture.length, |
|
38
|
|
|
null |
|
39
|
|
|
); |
|
40
|
|
|
} |
|
41
|
|
|
async function createWrapper(): Promise<Wrapper<Vue>> { |
|
42
|
|
|
const localVue = createLocalVue(); |
|
43
|
|
|
return shallowMount(await Component.build('sw-entity-multi-id-select'), { |
|
44
|
|
|
localVue, |
|
45
|
|
|
propsData: { |
|
46
|
|
|
ids: getCollection(), |
|
47
|
|
|
repository: { |
|
48
|
|
|
search: () => { |
|
49
|
|
|
return Promise.resolve(getCollection()); |
|
50
|
|
|
} |
|
51
|
|
|
}, |
|
52
|
|
|
}, |
|
53
|
|
|
provide: { |
|
54
|
|
|
repositoryFactory: { |
|
55
|
|
|
create: () => { |
|
56
|
|
|
return { |
|
57
|
|
|
get: (value) => Promise.resolve({ id: value, name: value }), |
|
58
|
|
|
search: () => { |
|
59
|
|
|
return Promise.resolve(); |
|
60
|
|
|
} |
|
61
|
|
|
}; |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
}, |
|
65
|
|
|
stubs: { |
|
66
|
|
|
'sw-block-field': true, |
|
67
|
|
|
'sw-select-selection-list': true, |
|
68
|
|
|
'sw-icon': true, |
|
69
|
|
|
'sw-select-base': await Component.build('sw-select-base'), |
|
70
|
|
|
'sw-entity-multi-select': await Component.build('sw-entity-multi-select') |
|
71
|
|
|
}, |
|
72
|
|
|
}); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
describe('components/sw-entity-multi-id-select', () => { |
|
76
|
|
|
it('should be a Vue.js component', async () => { |
|
77
|
|
|
const wrapper = await createWrapper(); |
|
78
|
|
|
expect(wrapper.vm).toBeTruthy(); |
|
79
|
|
|
}); |
|
80
|
|
|
|
|
81
|
|
|
it('should able to update ids', async () => { |
|
82
|
|
|
const wrapper = await createWrapper(); |
|
83
|
|
|
wrapper.vm.updateIds(getCollection()); |
|
84
|
|
|
await flushPromises(); |
|
85
|
|
|
|
|
86
|
|
|
expect(wrapper.vm.ids.length).toBe(fixture.length); |
|
87
|
|
|
expect(wrapper.vm.collection.length).toBe(fixture.length); |
|
88
|
|
|
|
|
89
|
|
|
await wrapper.setProps({ ids: [] }); |
|
90
|
|
|
expect(wrapper.vm.ids.length).toBe(0); |
|
91
|
|
|
expect(wrapper.vm.collection.length).toBe(0); |
|
92
|
|
|
}); |
|
93
|
|
|
|
|
94
|
|
|
it('should reset selected ids if it is invalid value', async () => { |
|
95
|
|
|
const wrapper = await createWrapper(); |
|
96
|
|
|
wrapper.vm.updateIds = jest.fn(); |
|
97
|
|
|
await wrapper.setProps( |
|
98
|
|
|
{ |
|
99
|
|
|
ids: [{ id: '123', name: 'random' }], |
|
100
|
|
|
repository: { |
|
101
|
|
|
search: () => { |
|
102
|
|
|
return Promise.resolve([]); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
} |
|
106
|
|
|
); |
|
107
|
|
|
|
|
108
|
|
|
expect(wrapper.vm.updateIds).toBeCalled(); |
|
109
|
|
|
}); |
|
110
|
|
|
}); |
|
111
|
|
|
|