|
1
|
|
|
import { createLocalVue, shallowMount } from '@vue/test-utils'; |
|
2
|
|
|
import 'src/app/component/base/sw-tabs-item'; |
|
3
|
|
|
import 'src/app/component/base/sw-icon'; |
|
4
|
|
|
|
|
5
|
|
|
async function createWrapper(propsData = {}) { |
|
6
|
|
|
const localVue = createLocalVue(); |
|
7
|
|
|
localVue.directive('tooltip', { |
|
8
|
|
|
bind(el, binding) { |
|
9
|
|
|
el.setAttribute('data-tooltip-message', binding.value.message); |
|
10
|
|
|
el.setAttribute('data-tooltip-disabled', binding.value.disabled); |
|
11
|
|
|
}, |
|
12
|
|
|
inserted(el, binding) { |
|
13
|
|
|
el.setAttribute('data-tooltip-message', binding.value.message); |
|
14
|
|
|
el.setAttribute('data-tooltip-disabled', binding.value.disabled); |
|
15
|
|
|
}, |
|
16
|
|
|
update(el, binding) { |
|
17
|
|
|
el.setAttribute('data-tooltip-message', binding.value.message); |
|
18
|
|
|
el.setAttribute('data-tooltip-disabled', binding.value.disabled); |
|
19
|
|
|
} |
|
20
|
|
|
}); |
|
21
|
|
|
|
|
22
|
|
|
return shallowMount(await Shopware.Component.build('sw-tabs-item'), { |
|
23
|
|
|
propsData, |
|
24
|
|
|
|
|
25
|
|
|
localVue, |
|
26
|
|
|
|
|
27
|
|
|
stubs: { |
|
28
|
|
|
'sw-icon': await Shopware.Component.build('sw-icon'), |
|
29
|
|
|
} |
|
30
|
|
|
}); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
describe('component/base/sw-tabs-item', () => { |
|
34
|
|
|
it('should not have an error or warning state', async () => { |
|
35
|
|
|
const wrapper = await createWrapper(); |
|
36
|
|
|
|
|
37
|
|
|
const errorIcon = wrapper.find('.sw-tabs-item__error-badge'); |
|
38
|
|
|
expect(errorIcon.exists()).toBe(false); |
|
39
|
|
|
|
|
40
|
|
|
const warningIcon = wrapper.find('.sw-tabs-item__warning-badge'); |
|
41
|
|
|
expect(warningIcon.exists()).toBe(false); |
|
42
|
|
|
}); |
|
43
|
|
|
|
|
44
|
|
|
it('should have an error state', async () => { |
|
45
|
|
|
const wrapper = await createWrapper({ |
|
46
|
|
|
hasError: true, |
|
47
|
|
|
errorTooltip: 'Custom error message', |
|
48
|
|
|
}); |
|
49
|
|
|
|
|
50
|
|
|
expect(wrapper.classes().includes('sw-tabs-item--has-error')).toBe(true); |
|
51
|
|
|
|
|
52
|
|
|
const errorIcon = wrapper.find('.sw-tabs-item__error-badge'); |
|
53
|
|
|
expect(errorIcon.isVisible()).toBe(true); |
|
54
|
|
|
expect(errorIcon.find('[data-testid="sw-icon__solid-exclamation-circle"]').exists()).toBe(true); |
|
55
|
|
|
expect(errorIcon.attributes('data-tooltip-message')).toBe('Custom error message'); |
|
56
|
|
|
}); |
|
57
|
|
|
|
|
58
|
|
|
it('should have a warning state', async () => { |
|
59
|
|
|
const wrapper = await createWrapper({ |
|
60
|
|
|
hasWarning: true, |
|
61
|
|
|
warningTooltip: 'Custom warning message', |
|
62
|
|
|
}); |
|
63
|
|
|
|
|
64
|
|
|
expect(wrapper.classes().includes('sw-tabs-item--has-warning')).toBe(true); |
|
65
|
|
|
|
|
66
|
|
|
const warningIcon = wrapper.find('.sw-tabs-item__warning-badge'); |
|
67
|
|
|
expect(warningIcon.isVisible()).toBe(true); |
|
68
|
|
|
expect(warningIcon.find('[data-testid="sw-icon__solid-exclamation-triangle"]').exists()).toBe(true); |
|
69
|
|
|
expect(warningIcon.attributes('data-tooltip-message')).toBe('Custom warning message'); |
|
70
|
|
|
}); |
|
71
|
|
|
}); |
|
72
|
|
|
|