@saooti/octopus-sdk 42.0.0-beta → 42.0.0-beta2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/eslint-config.d.ts +3 -0
- package/eslint-config.mjs +54 -0
- package/package.json +5 -2
- package/tests/api/podcastApi.spec.ts +43 -0
- package/tests/api/transcriptionApi.spec.ts +58 -0
- package/tests/components/composable/player/usePlayerTranscript.spec.ts +238 -0
- package/tests/components/composable/useAdvancedParamInit.spec.ts +91 -0
- package/tests/components/composable/usePresentationItem.spec.ts +164 -0
- package/tests/components/composable/useRights.spec.ts +838 -0
- package/tests/components/composable/useSeasonsManagement.spec.ts +35 -0
- package/tests/components/composable/useTranslation.spec.ts +209 -0
- package/tests/components/display/RightsIndicator.spec.ts +481 -0
- package/tests/components/display/comments/item/CommentMoreActions.spec.ts +75 -0
- package/tests/components/display/comments/modal/RecaptchaModal.spec.ts +43 -0
- package/tests/components/display/emission/EmissionItem.spec.ts +54 -0
- package/tests/components/display/emission/EmissionPresentationItem.spec.ts +46 -0
- package/tests/components/display/filter/AdvancedSearch.spec.ts +187 -0
- package/tests/components/display/podcasts/PodcastFilterList.spec.ts +34 -0
- package/tests/components/display/podcasts/PodcastInlineListTemplate.spec.ts +24 -0
- package/tests/components/display/podcasts/PodcastItemInfo.spec.ts +99 -0
- package/tests/components/display/podcasts/PodcastModuleBox.spec.ts +279 -0
- package/tests/components/display/podcasts/PodcastPresentationList.spec.ts +108 -0
- package/tests/components/display/podcasts/PodcastRawTranscript.spec.ts +254 -0
- package/tests/components/display/sharing/ShareNewsletter.spec.ts +68 -0
- package/tests/components/display/sharing/SharePlayer.spec.ts +59 -0
- package/tests/components/display/sharing/SharePlayerRadio.spec.ts +55 -0
- package/tests/components/form/ClassicButtonGroup.spec.ts +78 -0
- package/tests/components/form/ClassicInputText.spec.ts +24 -0
- package/tests/components/form/OctopusMultiselect.spec.ts +506 -0
- package/tests/components/form/OctopusSelect.spec.ts +240 -0
- package/tests/components/layouts/PresentationItem.spec.ts +37 -0
- package/tests/components/misc/ClassicAvatar.spec.ts +68 -0
- package/tests/components/misc/ClassicPopover.spec.ts +260 -0
- package/tests/components/misc/FooterSection.spec.ts +49 -0
- package/tests/components/misc/HomeDropdown.spec.ts +44 -0
- package/tests/components/misc/modal/ClipboardModal.spec.ts +51 -0
- package/tests/components/misc/player/PlayerLarge.spec.ts +72 -0
- package/tests/components/pages/EmissionPage.spec.ts +253 -0
- package/tests/components/pages/EmissionsPage.spec.ts +18 -0
- package/tests/components/pages/ParticipantPage.spec.ts +65 -0
- package/tests/components/pages/PlaylistPage.spec.ts +60 -0
- package/tests/components/pages/PodcastPage.spec.ts +89 -0
- package/tests/components/pages/PodcastsPage.spec.ts +18 -0
- package/tests/components/pages/RadioPage.spec.ts +65 -0
- package/tests/components/pages/SmartLinkPage.spec.ts +90 -0
- package/tests/helper/language.spec.ts +45 -0
- package/tests/index.ts +9 -0
- package/tests/localisation.ts +10 -0
- package/tests/mocks/i18n.ts +13 -0
- package/tests/mocks/index.ts +11 -0
- package/tests/mocks/rights.ts +17 -0
- package/tests/mocks/useAdvancedParamInit.ts +22 -0
- package/tests/mocks/useRouter.ts +11 -0
- package/tests/stores/CacheStore.spec.ts +110 -0
- package/tests/utils.ts +178 -0
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
import { mockI18n } from '@tests/mocks';
|
|
2
|
+
vi.mock('vue-i18n', () => mockI18n());
|
|
3
|
+
|
|
4
|
+
import OctopusSelect from '@/components/form/OctopusSelect.vue';
|
|
5
|
+
import { DOMWrapper, type VueWrapper } from '@vue/test-utils';
|
|
6
|
+
import { mount } from '@tests/utils';
|
|
7
|
+
import { nextTick } from 'vue';
|
|
8
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
9
|
+
|
|
10
|
+
const options = [
|
|
11
|
+
{ id: 1, name: 'Alpha' },
|
|
12
|
+
{ id: 2, name: 'Beta' },
|
|
13
|
+
{ id: 3, name: 'Gamma' },
|
|
14
|
+
];
|
|
15
|
+
|
|
16
|
+
// The dropdown is teleported to .octopus-app — helper to query it from the document.
|
|
17
|
+
function getDropdown(): Element | null {
|
|
18
|
+
return document.body.querySelector('.octopus-select-dropdown');
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function getOptionLabels(): string[] {
|
|
22
|
+
return Array.from(document.body.querySelectorAll('.octopus-select-option'))
|
|
23
|
+
.map((el) => el.textContent?.trim() ?? '');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Simulates a click outside the component to trigger onClickOutside's closeDropdown.
|
|
27
|
+
async function clickOutside(): Promise<void> {
|
|
28
|
+
const outsideElement = document.createElement('div');
|
|
29
|
+
document.body.appendChild(outsideElement);
|
|
30
|
+
outsideElement.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
31
|
+
await nextTick();
|
|
32
|
+
document.body.removeChild(outsideElement);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
describe('OctopusSelect', () => {
|
|
36
|
+
// The dropdown teleports to .octopus-app, which is normally the app root (see App.vue).
|
|
37
|
+
// It doesn't exist in the test DOM, so it must be created before mount.
|
|
38
|
+
let appElement: HTMLElement;
|
|
39
|
+
|
|
40
|
+
beforeEach(() => {
|
|
41
|
+
appElement = document.createElement('div');
|
|
42
|
+
appElement.className = 'octopus-app';
|
|
43
|
+
document.body.appendChild(appElement);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Shared wrapper ref so afterEach can properly unmount it.
|
|
47
|
+
// Proper unmount lets Vue clean up the teleport target before the next test starts.
|
|
48
|
+
let wrapper: VueWrapper;
|
|
49
|
+
afterEach(() => {
|
|
50
|
+
wrapper?.unmount();
|
|
51
|
+
appElement.remove();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it('renders label when provided', async () => {
|
|
55
|
+
wrapper = await mount(OctopusSelect, {
|
|
56
|
+
props: { options, optionLabel: 'name', label: 'My label' },
|
|
57
|
+
});
|
|
58
|
+
expect(wrapper.find('label.form-label').text()).toBe('My label');
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
it('does not render label when not provided', async () => {
|
|
62
|
+
wrapper = await mount(OctopusSelect, {
|
|
63
|
+
props: { options, optionLabel: 'name' },
|
|
64
|
+
});
|
|
65
|
+
expect(wrapper.find('label.form-label').exists()).toBe(false);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('opens dropdown on input focus', async () => {
|
|
69
|
+
wrapper = await mount(OctopusSelect, {
|
|
70
|
+
props: { options, optionLabel: 'name' },
|
|
71
|
+
});
|
|
72
|
+
expect(getDropdown()).toBeNull();
|
|
73
|
+
await wrapper.find('input').trigger('focus');
|
|
74
|
+
expect(getDropdown()).not.toBeNull();
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('shows one button per option when open', async () => {
|
|
78
|
+
wrapper = await mount(OctopusSelect, {
|
|
79
|
+
props: { options, optionLabel: 'name' },
|
|
80
|
+
});
|
|
81
|
+
await wrapper.find('input').trigger('focus');
|
|
82
|
+
const optionButtons = document.body.querySelectorAll('.octopus-select-option');
|
|
83
|
+
expect(optionButtons).toHaveLength(3);
|
|
84
|
+
expect(optionButtons[0].textContent?.trim()).toBe('Alpha');
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it('filters options locally by search query', async () => {
|
|
88
|
+
wrapper = await mount(OctopusSelect, {
|
|
89
|
+
props: { options, optionLabel: 'name' },
|
|
90
|
+
});
|
|
91
|
+
await wrapper.find('input').trigger('focus');
|
|
92
|
+
await wrapper.find('input').setValue('al');
|
|
93
|
+
await wrapper.find('input').trigger('input');
|
|
94
|
+
expect(document.body.querySelectorAll('.octopus-select-option')).toHaveLength(1);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('shows no-results message when filter matches nothing', async () => {
|
|
98
|
+
wrapper = await mount(OctopusSelect, {
|
|
99
|
+
props: { options, optionLabel: 'name' },
|
|
100
|
+
});
|
|
101
|
+
await wrapper.find('input').trigger('focus');
|
|
102
|
+
await wrapper.find('input').setValue('zzz');
|
|
103
|
+
await wrapper.find('input').trigger('input');
|
|
104
|
+
expect(document.body.querySelector('.text-indic')).not.toBeNull();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('emits update:value with the clicked option', async () => {
|
|
108
|
+
wrapper = await mount(OctopusSelect, {
|
|
109
|
+
props: { options, optionLabel: 'name' },
|
|
110
|
+
});
|
|
111
|
+
await wrapper.find('input').trigger('focus');
|
|
112
|
+
await new DOMWrapper(document.body.querySelectorAll('.octopus-select-option')[1]).trigger('click');
|
|
113
|
+
expect(wrapper.emitted('update:value')?.[0]).toEqual([options[1]]);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('closes dropdown after selecting an option', async () => {
|
|
117
|
+
wrapper = await mount(OctopusSelect, {
|
|
118
|
+
props: { options, optionLabel: 'name' },
|
|
119
|
+
});
|
|
120
|
+
await wrapper.find('input').trigger('focus');
|
|
121
|
+
await new DOMWrapper(document.body.querySelectorAll('.octopus-select-option')[0]).trigger('click');
|
|
122
|
+
expect(getDropdown()).toBeNull();
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('shows selected item label in the field when closed', async () => {
|
|
126
|
+
wrapper = await mount(OctopusSelect, {
|
|
127
|
+
props: { options, optionLabel: 'name', value: options[0] },
|
|
128
|
+
});
|
|
129
|
+
expect(wrapper.find('.octopus-select-value').text()).toBe('Alpha');
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it('marks the selected option with the selected class', async () => {
|
|
133
|
+
wrapper = await mount(OctopusSelect, {
|
|
134
|
+
props: { options, optionLabel: 'name', value: options[0] },
|
|
135
|
+
});
|
|
136
|
+
await wrapper.find('.octopus-select-field').trigger('click');
|
|
137
|
+
const optionButtons = document.body.querySelectorAll('.octopus-select-option');
|
|
138
|
+
expect(optionButtons[0].classList).toContain('selected');
|
|
139
|
+
expect(optionButtons[1].classList).not.toContain('selected');
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('deselects the current option by default (allowDeselect defaults to true)', async () => {
|
|
143
|
+
wrapper = await mount(OctopusSelect, {
|
|
144
|
+
props: { options, optionLabel: 'name', optionKey: 'id', value: options[0] },
|
|
145
|
+
});
|
|
146
|
+
await wrapper.find('.octopus-select-field').trigger('click');
|
|
147
|
+
await new DOMWrapper(document.body.querySelectorAll('.octopus-select-option')[0]).trigger('click');
|
|
148
|
+
expect(wrapper.emitted('update:value')?.[0]).toEqual([undefined]);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('does not deselect when allowDeselect is false', async () => {
|
|
152
|
+
wrapper = await mount(OctopusSelect, {
|
|
153
|
+
props: { options, optionLabel: 'name', optionKey: 'id', value: options[0], allowDeselect: false as boolean },
|
|
154
|
+
});
|
|
155
|
+
await wrapper.find('.octopus-select-field').trigger('click');
|
|
156
|
+
await new DOMWrapper(document.body.querySelectorAll('.octopus-select-option')[0]).trigger('click');
|
|
157
|
+
expect(wrapper.emitted('update:value')?.[0]).toEqual([options[0]]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('does not open dropdown when disabled', async () => {
|
|
161
|
+
wrapper = await mount(OctopusSelect, {
|
|
162
|
+
props: { options, optionLabel: 'name', isDisabled: true },
|
|
163
|
+
});
|
|
164
|
+
await wrapper.find('input').trigger('focus');
|
|
165
|
+
expect(getDropdown()).toBeNull();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it('disables input when isDisabled is true', async () => {
|
|
169
|
+
wrapper = await mount(OctopusSelect, {
|
|
170
|
+
props: { options, optionLabel: 'name', isDisabled: true },
|
|
171
|
+
});
|
|
172
|
+
expect(wrapper.find('input').attributes('disabled')).toBeDefined();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
it('matches by optionKey when checking selection', async () => {
|
|
176
|
+
const value = { id: 1, name: 'Alpha' };
|
|
177
|
+
wrapper = await mount(OctopusSelect, {
|
|
178
|
+
props: { options, optionLabel: 'name', optionKey: 'id', value },
|
|
179
|
+
});
|
|
180
|
+
await wrapper.find('.octopus-select-field').trigger('click');
|
|
181
|
+
const optionButtons = document.body.querySelectorAll('.octopus-select-option');
|
|
182
|
+
expect(optionButtons[0].classList).toContain('selected');
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('pullSelectedToTop', () => {
|
|
186
|
+
it('does not reorder options when pullSelectedToTop is not set', async () => {
|
|
187
|
+
wrapper = await mount(OctopusSelect, {
|
|
188
|
+
props: { options, optionLabel: 'name', value: options[1] },
|
|
189
|
+
});
|
|
190
|
+
await wrapper.find('input').trigger('focus');
|
|
191
|
+
expect(getOptionLabels()).toEqual(['Alpha', 'Beta', 'Gamma']);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('moves the selected option to the top when pullSelectedToTop is true', async () => {
|
|
195
|
+
wrapper = await mount(OctopusSelect, {
|
|
196
|
+
props: { options, optionLabel: 'name', value: options[1], pullSelectedToTop: true },
|
|
197
|
+
});
|
|
198
|
+
await wrapper.find('input').trigger('focus');
|
|
199
|
+
expect(getOptionLabels()).toEqual(['Beta', 'Alpha', 'Gamma']);
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
it('does not reorder while the dropdown stays open as the value changes', async () => {
|
|
203
|
+
wrapper = await mount(OctopusSelect, {
|
|
204
|
+
props: { options, optionLabel: 'name', pullSelectedToTop: true },
|
|
205
|
+
});
|
|
206
|
+
await wrapper.find('input').trigger('focus');
|
|
207
|
+
await wrapper.setProps({ value: options[2] });
|
|
208
|
+
expect(getOptionLabels()).toEqual(['Alpha', 'Beta', 'Gamma']);
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('re-pins using the latest value after closing and reopening', async () => {
|
|
212
|
+
wrapper = await mount(OctopusSelect, {
|
|
213
|
+
props: { options, optionLabel: 'name', value: options[2], pullSelectedToTop: true },
|
|
214
|
+
});
|
|
215
|
+
await wrapper.find('input').trigger('focus');
|
|
216
|
+
await clickOutside();
|
|
217
|
+
await wrapper.find('input').trigger('focus');
|
|
218
|
+
expect(getOptionLabels()).toEqual(['Gamma', 'Alpha', 'Beta']);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it('pins by optionKey even when the value is a different reference', async () => {
|
|
222
|
+
const value = { id: 2, name: 'Beta' };
|
|
223
|
+
wrapper = await mount(OctopusSelect, {
|
|
224
|
+
props: { options, optionLabel: 'name', optionKey: 'id', value, pullSelectedToTop: true },
|
|
225
|
+
});
|
|
226
|
+
await wrapper.find('input').trigger('focus');
|
|
227
|
+
expect(getOptionLabels()).toEqual(['Beta', 'Alpha', 'Gamma']);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it('still respects the active search filter when pinning', async () => {
|
|
231
|
+
wrapper = await mount(OctopusSelect, {
|
|
232
|
+
props: { options, optionLabel: 'name', value: options[2], pullSelectedToTop: true },
|
|
233
|
+
});
|
|
234
|
+
await wrapper.find('input').trigger('focus');
|
|
235
|
+
await wrapper.find('input').setValue('be');
|
|
236
|
+
await wrapper.find('input').trigger('input');
|
|
237
|
+
expect(getOptionLabels()).toEqual(['Beta']);
|
|
238
|
+
});
|
|
239
|
+
});
|
|
240
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { mockI18n, mockUseRouter } from '@tests/mocks';
|
|
2
|
+
vi.mock('vue-i18n', () => mockI18n());
|
|
3
|
+
vi.mock('vue-router', () => mockUseRouter());
|
|
4
|
+
|
|
5
|
+
import PresentationItem from '@/components/layouts/PresentationItem.vue';
|
|
6
|
+
import { mount as testMount } from '@tests/utils';
|
|
7
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
8
|
+
|
|
9
|
+
const baseProps = {
|
|
10
|
+
route: 'podcast',
|
|
11
|
+
imageUrl: 'https://example.com/img.png',
|
|
12
|
+
name: 'Item name',
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const mount = (props: Record<string, unknown>) => testMount(PresentationItem, {
|
|
16
|
+
props: { ...baseProps, ...props },
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe('PresentationItem', () => {
|
|
20
|
+
describe('additionalInfo', () => {
|
|
21
|
+
it('renders each additionalInfo entry when a description is set', async () => {
|
|
22
|
+
const wrapper = await mount({ description: 'Some description', additionalInfo: ['1 décembre 2025', 'Saooti'] });
|
|
23
|
+
const info = wrapper.findAll('.text-secondary');
|
|
24
|
+
expect(info.map(el => el.text())).toEqual(['1 décembre 2025', 'Saooti']);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('does not render additionalInfo when it is not provided', async () => {
|
|
28
|
+
const wrapper = await mount({ description: 'Some description' });
|
|
29
|
+
expect(wrapper.find('.text-secondary').exists()).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('renders each additionalInfo even when there is no description', async () => {
|
|
33
|
+
const wrapper = await mount({ additionalInfo: ['Saooti'] });
|
|
34
|
+
expect(wrapper.find('.text-secondary').exists()).toBe(true);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import ClassicAvatar from '@/components/misc/ClassicAvatar.vue';
|
|
2
|
+
import { mount } from '@tests/utils';
|
|
3
|
+
import { describe, expect, it } from 'vitest';
|
|
4
|
+
|
|
5
|
+
const IMAGE_URL = 'https://example.com/avatar.png';
|
|
6
|
+
|
|
7
|
+
describe('ClassicAvatar', () => {
|
|
8
|
+
const mountAvatar = async (props: Record<string, unknown> = {}) =>
|
|
9
|
+
mount(ClassicAvatar, { props: { name: 'Spotify', ...props } });
|
|
10
|
+
|
|
11
|
+
describe('image rendering', () => {
|
|
12
|
+
it('renders an img with correct src when imageUrl is provided', async () => {
|
|
13
|
+
const wrapper = await mountAvatar({ imageUrl: IMAGE_URL });
|
|
14
|
+
expect(wrapper.find('img').exists()).toBe(true);
|
|
15
|
+
expect(wrapper.find('img').attributes('src')).toContain('example.com');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('does not render an img without imageUrl', async () => {
|
|
19
|
+
const wrapper = await mountAvatar();
|
|
20
|
+
expect(wrapper.find('img').exists()).toBe(false);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
describe('initial letter fallback', () => {
|
|
25
|
+
it('shows the first letter uppercased', async () => {
|
|
26
|
+
const wrapper = await mountAvatar({ name: 'spotify' });
|
|
27
|
+
expect(wrapper.text()).toBe('S');
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('shows ? when name is empty', async () => {
|
|
31
|
+
const wrapper = await mountAvatar({ name: '' });
|
|
32
|
+
expect(wrapper.text()).toBe('?');
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe('container style', () => {
|
|
37
|
+
it('applies size-based dimensions and font-size from size prop', async () => {
|
|
38
|
+
const wrapper = await mountAvatar({ size: 48 });
|
|
39
|
+
const style = (wrapper.element as HTMLElement).style;
|
|
40
|
+
expect(style.height).toBe('48px');
|
|
41
|
+
expect(style.width).toBe('48px');
|
|
42
|
+
expect(style.fontSize).toBe('24px');
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it('defaults to 24px size and applies a background-color', async () => {
|
|
46
|
+
const wrapper = await mountAvatar();
|
|
47
|
+
const style = (wrapper.element as HTMLElement).style;
|
|
48
|
+
expect(style.height).toBe('24px');
|
|
49
|
+
expect(style.width).toBe('24px');
|
|
50
|
+
expect(style.fontSize).toBe('12px');
|
|
51
|
+
expect(style.backgroundColor).toBeTruthy();
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
describe('accessibility', () => {
|
|
56
|
+
it('is aria-hidden and has empty alt on img when decorative', async () => {
|
|
57
|
+
const wrapper = await mountAvatar({ imageUrl: IMAGE_URL });
|
|
58
|
+
expect(wrapper.attributes('aria-hidden')).toBe('true');
|
|
59
|
+
expect(wrapper.find('img').attributes('alt')).toBe('');
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('is not aria-hidden and uses name as alt on img when nonDecorative', async () => {
|
|
63
|
+
const wrapper = await mountAvatar({ imageUrl: IMAGE_URL, nonDecorative: true });
|
|
64
|
+
expect(wrapper.attributes('aria-hidden')).not.toBe('true');
|
|
65
|
+
expect(wrapper.find('img').attributes('alt')).toBe('Spotify');
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
});
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { mockUseRouter } from '@tests/mocks';
|
|
2
|
+
vi.mock('vue-router', () => mockUseRouter());
|
|
3
|
+
|
|
4
|
+
import ClassicPopover from '@/components/misc/ClassicPopover.vue';
|
|
5
|
+
import { mount as testMount, VueWrapper } from '@tests/utils';
|
|
6
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
7
|
+
import { nextTick } from 'vue';
|
|
8
|
+
|
|
9
|
+
describe('ClassicPopover', () => {
|
|
10
|
+
let targetElement: HTMLElement;
|
|
11
|
+
let appElement: HTMLElement;
|
|
12
|
+
let wrapper: VueWrapper | undefined;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
appElement = document.createElement('div');
|
|
16
|
+
appElement.id = 'app';
|
|
17
|
+
document.body.appendChild(appElement);
|
|
18
|
+
|
|
19
|
+
targetElement = document.createElement('button');
|
|
20
|
+
targetElement.id = 'test-target';
|
|
21
|
+
targetElement.textContent = 'Trigger';
|
|
22
|
+
document.body.appendChild(targetElement);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
wrapper?.unmount();
|
|
27
|
+
wrapper = undefined;
|
|
28
|
+
if (targetElement?.parentNode) {
|
|
29
|
+
targetElement.parentNode.removeChild(targetElement);
|
|
30
|
+
}
|
|
31
|
+
if (appElement?.parentNode) {
|
|
32
|
+
appElement.parentNode.removeChild(appElement);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// The popover is teleported to #app; retrieve it by its deterministic id.
|
|
37
|
+
const getPopoverEl = (): HTMLElement =>
|
|
38
|
+
document.getElementById('popovertest-target') as HTMLElement;
|
|
39
|
+
|
|
40
|
+
// Helper: Check if popover is visible
|
|
41
|
+
const isVisible = (): boolean => {
|
|
42
|
+
const element = getPopoverEl();
|
|
43
|
+
if (!element) return false;
|
|
44
|
+
return element.style.display !== 'none' &&
|
|
45
|
+
window.getComputedStyle(element).display !== 'none';
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// Helper: Mount popover with default props
|
|
49
|
+
const mount = async (props: Record<string, unknown> = {}) => {
|
|
50
|
+
wrapper = await testMount(ClassicPopover, {
|
|
51
|
+
props: {
|
|
52
|
+
target: 'test-target',
|
|
53
|
+
content: 'Test content',
|
|
54
|
+
...props
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
return wrapper;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
// Helper: Open popover via hover
|
|
61
|
+
const openViaHover = async () => {
|
|
62
|
+
targetElement.dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
|
|
63
|
+
await nextTick();
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// Helper: Open popover via click
|
|
67
|
+
const openViaClick = async () => {
|
|
68
|
+
targetElement.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
69
|
+
await nextTick();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// Helper: Close via mouseleave with timeout
|
|
73
|
+
const closeViaHover = async () => {
|
|
74
|
+
targetElement.dispatchEvent(new MouseEvent('mouseleave', { bubbles: true }));
|
|
75
|
+
await new Promise(resolve => setTimeout(resolve, 600));
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
// Helper: Click outside and cleanup
|
|
79
|
+
const clickOutside = async () => {
|
|
80
|
+
const outsideElement = document.createElement('div');
|
|
81
|
+
document.body.appendChild(outsideElement);
|
|
82
|
+
outsideElement.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true }));
|
|
83
|
+
await nextTick();
|
|
84
|
+
document.body.removeChild(outsideElement);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
describe('hover behavior (onlyClick=false, default)', () => {
|
|
88
|
+
it('opens on mouseenter and closes on mouseleave of target', async () => {
|
|
89
|
+
await mount();
|
|
90
|
+
|
|
91
|
+
expect(isVisible()).toBe(false);
|
|
92
|
+
|
|
93
|
+
await openViaHover();
|
|
94
|
+
expect(isVisible()).toBe(true);
|
|
95
|
+
|
|
96
|
+
await closeViaHover();
|
|
97
|
+
expect(isVisible()).toBe(false);
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it('stays open when mouse moves from target to popover content', async () => {
|
|
101
|
+
await mount();
|
|
102
|
+
|
|
103
|
+
await openViaHover();
|
|
104
|
+
expect(isVisible()).toBe(true);
|
|
105
|
+
|
|
106
|
+
// Mouse enters popover
|
|
107
|
+
getPopoverEl().dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
|
|
108
|
+
await nextTick();
|
|
109
|
+
|
|
110
|
+
// Leave target
|
|
111
|
+
await closeViaHover();
|
|
112
|
+
|
|
113
|
+
// Should still be open because mouse is over popover
|
|
114
|
+
expect(isVisible()).toBe(true);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('closes when mouse leaves popover content', async () => {
|
|
118
|
+
await mount();
|
|
119
|
+
|
|
120
|
+
await openViaHover();
|
|
121
|
+
|
|
122
|
+
// Move to popover
|
|
123
|
+
getPopoverEl().dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
|
|
124
|
+
await nextTick();
|
|
125
|
+
|
|
126
|
+
// Leave popover
|
|
127
|
+
getPopoverEl().dispatchEvent(new MouseEvent('mouseleave', { bubbles: true }));
|
|
128
|
+
await nextTick();
|
|
129
|
+
|
|
130
|
+
expect(isVisible()).toBe(false);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it('closes via mouseleave even after clicking the target', async () => {
|
|
134
|
+
await mount();
|
|
135
|
+
|
|
136
|
+
await openViaHover();
|
|
137
|
+
expect(isVisible()).toBe(true);
|
|
138
|
+
|
|
139
|
+
// Click the target (sets isClick to true)
|
|
140
|
+
await openViaClick();
|
|
141
|
+
expect(isVisible()).toBe(true);
|
|
142
|
+
|
|
143
|
+
// Leave with mouse
|
|
144
|
+
await closeViaHover();
|
|
145
|
+
|
|
146
|
+
// Should be closed because it was opened by hover
|
|
147
|
+
expect(isVisible()).toBe(false);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe('click behavior (onlyClick=true)', () => {
|
|
152
|
+
it('opens on click of target', async () => {
|
|
153
|
+
await mount({ onlyClick: true });
|
|
154
|
+
|
|
155
|
+
expect(isVisible()).toBe(false);
|
|
156
|
+
|
|
157
|
+
await openViaClick();
|
|
158
|
+
expect(isVisible()).toBe(true);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it('does not open on mouseenter when onlyClick is true', async () => {
|
|
162
|
+
await mount({ onlyClick: true });
|
|
163
|
+
|
|
164
|
+
await openViaHover();
|
|
165
|
+
|
|
166
|
+
expect(isVisible()).toBe(false);
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it('stays open when clicking inside popover', async () => {
|
|
170
|
+
await mount({ onlyClick: true });
|
|
171
|
+
|
|
172
|
+
await openViaClick();
|
|
173
|
+
expect(isVisible()).toBe(true);
|
|
174
|
+
|
|
175
|
+
// Click inside popover
|
|
176
|
+
const insideElement = document.createElement('button');
|
|
177
|
+
getPopoverEl().appendChild(insideElement);
|
|
178
|
+
insideElement.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
179
|
+
await nextTick();
|
|
180
|
+
|
|
181
|
+
expect(isVisible()).toBe(true);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it('closes when clicking outside both popover and target', async () => {
|
|
185
|
+
await mount({ onlyClick: true });
|
|
186
|
+
|
|
187
|
+
await openViaClick();
|
|
188
|
+
expect(isVisible()).toBe(true);
|
|
189
|
+
|
|
190
|
+
await clickOutside();
|
|
191
|
+
|
|
192
|
+
expect(isVisible()).toBe(false);
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
it('closes when clicking inside popover then clicking outside', async () => {
|
|
196
|
+
await mount({ onlyClick: true });
|
|
197
|
+
|
|
198
|
+
await openViaClick();
|
|
199
|
+
expect(isVisible()).toBe(true);
|
|
200
|
+
|
|
201
|
+
// Click inside popover
|
|
202
|
+
const insideButton = document.createElement('button');
|
|
203
|
+
getPopoverEl().appendChild(insideButton);
|
|
204
|
+
insideButton.dispatchEvent(new MouseEvent('click', { bubbles: true }));
|
|
205
|
+
await nextTick();
|
|
206
|
+
|
|
207
|
+
expect(isVisible()).toBe(true);
|
|
208
|
+
|
|
209
|
+
// Click outside
|
|
210
|
+
await clickOutside();
|
|
211
|
+
|
|
212
|
+
expect(isVisible()).toBe(false);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it('toggles when clicking target while already open', async () => {
|
|
216
|
+
await mount({ onlyClick: true });
|
|
217
|
+
|
|
218
|
+
await openViaClick();
|
|
219
|
+
expect(isVisible()).toBe(true);
|
|
220
|
+
|
|
221
|
+
// Click target again
|
|
222
|
+
await openViaClick();
|
|
223
|
+
|
|
224
|
+
expect(isVisible()).toBe(false);
|
|
225
|
+
});
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
describe('mixed behavior (onlyMouse=false, onlyClick=false)', () => {
|
|
229
|
+
it('can open via hover or click', async () => {
|
|
230
|
+
await mount({ onlyClick: false, onlyMouse: false });
|
|
231
|
+
|
|
232
|
+
// Open via hover
|
|
233
|
+
await openViaHover();
|
|
234
|
+
expect(isVisible()).toBe(true);
|
|
235
|
+
|
|
236
|
+
// Close
|
|
237
|
+
await closeViaHover();
|
|
238
|
+
expect(isVisible()).toBe(false);
|
|
239
|
+
|
|
240
|
+
// Open via click
|
|
241
|
+
await openViaClick();
|
|
242
|
+
expect(isVisible()).toBe(true);
|
|
243
|
+
});
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
describe('expose clearClick method', () => {
|
|
247
|
+
it('exposes clearClick method to close popover programmatically', async () => {
|
|
248
|
+
await mount();
|
|
249
|
+
|
|
250
|
+
await openViaHover();
|
|
251
|
+
expect(isVisible()).toBe(true);
|
|
252
|
+
|
|
253
|
+
// Close programmatically
|
|
254
|
+
(wrapper!.vm as unknown as { clearClick: () => void }).clearClick();
|
|
255
|
+
await nextTick();
|
|
256
|
+
|
|
257
|
+
expect(isVisible()).toBe(false);
|
|
258
|
+
});
|
|
259
|
+
});
|
|
260
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { mockI18n, mockUseRouter } from '@tests/mocks';
|
|
2
|
+
vi.mock('vue-i18n', () => mockI18n());
|
|
3
|
+
vi.mock('vue-router', () => mockUseRouter());
|
|
4
|
+
|
|
5
|
+
import FooterSection from '@/components/misc/FooterSection.vue';
|
|
6
|
+
import { LOAD_LOCALE_MESSAGES_KEY } from '@/components/composable/keys';
|
|
7
|
+
import { loadLocaleMessages as loadSdkLocaleMessages } from '@/i18n';
|
|
8
|
+
import { mount } from '@tests/utils';
|
|
9
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
10
|
+
|
|
11
|
+
vi.mock('@/api/classicApi', () => ({
|
|
12
|
+
default: { fetchData: vi.fn().mockResolvedValue([]) },
|
|
13
|
+
}));
|
|
14
|
+
vi.mock('@/i18n', () => ({
|
|
15
|
+
loadLocaleMessages: vi.fn(),
|
|
16
|
+
}));
|
|
17
|
+
|
|
18
|
+
function changeLanguage(wrapper: Awaited<ReturnType<typeof mount>>, locale: string) {
|
|
19
|
+
return wrapper.findComponent({ name: 'ClassicSelect' }).vm.$emit('update:textInit', locale);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe('FooterSection', () => {
|
|
23
|
+
describe('loadLocaleMessages resolution', () => {
|
|
24
|
+
it('calls the app-provided implementation when a language is chosen', async () => {
|
|
25
|
+
const loadLocaleMessages = vi.fn();
|
|
26
|
+
const wrapper = await mount(FooterSection, {
|
|
27
|
+
shallow: true,
|
|
28
|
+
provide: { [LOAD_LOCALE_MESSAGES_KEY]: loadLocaleMessages }
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
await changeLanguage(wrapper, 'en');
|
|
32
|
+
|
|
33
|
+
expect(loadLocaleMessages).toHaveBeenCalledWith(
|
|
34
|
+
expect.anything(), 'en', expect.anything(), expect.anything()
|
|
35
|
+
);
|
|
36
|
+
expect(loadSdkLocaleMessages).not.toHaveBeenCalled();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('falls back to the SDK own loader when nothing is provided', async () => {
|
|
40
|
+
const wrapper = await mount(FooterSection, { shallow: true });
|
|
41
|
+
|
|
42
|
+
await changeLanguage(wrapper, 'en');
|
|
43
|
+
|
|
44
|
+
expect(loadSdkLocaleMessages).toHaveBeenCalledWith(
|
|
45
|
+
expect.anything(), 'en', expect.anything(), expect.anything()
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|