|
1
|
|
|
import 'src/app/component/base/sw-address'; |
|
2
|
|
|
import { shallowMount } from '@vue/test-utils'; |
|
3
|
|
|
import type { Wrapper } from '@vue/test-utils'; |
|
4
|
|
|
import type Vue from 'vue'; |
|
5
|
|
|
|
|
6
|
|
|
async function createWrapper(): Promise<Wrapper<Vue>> { |
|
7
|
|
|
return shallowMount(await Shopware.Component.build('sw-address'), { |
|
8
|
|
|
propsData: { |
|
9
|
|
|
address: { |
|
10
|
|
|
salutation: 'Mr', |
|
11
|
|
|
title: 'Dr.', |
|
12
|
|
|
firstName: 'John', |
|
13
|
|
|
lastName: 'Doe', |
|
14
|
|
|
company: 'Shopware AG', |
|
15
|
|
|
street: 'Main Street', |
|
16
|
|
|
additionalAddressLine1: 'Floor 23', |
|
17
|
|
|
additionalAddressLine2: 'Secret room 1337', |
|
18
|
|
|
zipcode: '555 Nase', |
|
19
|
|
|
city: 'Miami', |
|
20
|
|
|
country: { |
|
21
|
|
|
name: 'USA', |
|
22
|
|
|
}, |
|
23
|
|
|
countryState: { |
|
24
|
|
|
name: 'Florida', |
|
25
|
|
|
}, |
|
26
|
|
|
} |
|
27
|
|
|
}, |
|
28
|
|
|
stubs: { |
|
29
|
|
|
'router-link': { |
|
30
|
|
|
template: '<a class="router-link" href="#"><slot></slot></a>', |
|
31
|
|
|
props: ['to'] |
|
32
|
|
|
} |
|
33
|
|
|
}, |
|
34
|
|
|
attachTo: document.body, |
|
35
|
|
|
}); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
describe('src/app/component/base/sw-address/index.ts', () => { |
|
39
|
|
|
let wrapper: Wrapper<Vue>; |
|
40
|
|
|
|
|
41
|
|
|
beforeEach(async () => { |
|
42
|
|
|
wrapper = await createWrapper(); |
|
43
|
|
|
|
|
44
|
|
|
await flushPromises; |
|
45
|
|
|
}); |
|
46
|
|
|
|
|
47
|
|
|
afterEach(async () => { |
|
48
|
|
|
if (wrapper) { |
|
49
|
|
|
await wrapper.destroy(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
await flushPromises; |
|
53
|
|
|
}); |
|
54
|
|
|
|
|
55
|
|
|
it('should be a Vue.js component', async () => { |
|
56
|
|
|
expect(wrapper.vm).toBeTruthy(); |
|
57
|
|
|
}); |
|
58
|
|
|
|
|
59
|
|
|
it('should render an address', async () => { |
|
60
|
|
|
expect(wrapper.get('.sw-address__company').text()).toBe('Shopware AG'); |
|
61
|
|
|
expect(wrapper.get('.sw-address__full-name').text()).toBe('Dr. John Doe'); |
|
62
|
|
|
expect(wrapper.get('.sw-address__street').text()).toBe('Main Street'); |
|
63
|
|
|
expect(wrapper.get('.sw-address__additional-line-1').text()).toBe('Floor 23'); |
|
64
|
|
|
expect(wrapper.get('.sw-address__additional-line-2').text()).toBe('Secret room 1337'); |
|
65
|
|
|
expect(wrapper.findAll('.sw-address__location span').at(0).text()).toBe('555 Nase'); |
|
66
|
|
|
expect(wrapper.findAll('.sw-address__location span').at(1).text()).toBe('Miami'); |
|
67
|
|
|
expect(wrapper.get('.sw-address__country').text()).toBe('USA'); |
|
68
|
|
|
}); |
|
69
|
|
|
|
|
70
|
|
|
it('should render address with headline', async () => { |
|
71
|
|
|
await wrapper.setProps({ |
|
72
|
|
|
headline: 'Super cool address' |
|
73
|
|
|
}); |
|
74
|
|
|
|
|
75
|
|
|
expect(wrapper.get('.sw-address__headline').text()).toBe('Super cool address'); |
|
76
|
|
|
}); |
|
77
|
|
|
|
|
78
|
|
|
it('should render address with edit button', async () => { |
|
79
|
|
|
await wrapper.setProps({ |
|
80
|
|
|
headline: 'Super cool address', |
|
81
|
|
|
showEditButton: true, |
|
82
|
|
|
editLink: { path: 'path/edit-address' } |
|
83
|
|
|
}); |
|
84
|
|
|
|
|
85
|
|
|
expect(wrapper.get('.sw-address-headline-link').text()).toBe('global.default.edit'); |
|
86
|
|
|
expect(wrapper.get('.sw-address-headline-link').props('to')).toEqual({ path: 'path/edit-address' }); |
|
87
|
|
|
}); |
|
88
|
|
|
}); |
|
89
|
|
|
|