@saooti/octopus-sdk 41.10.9 → 41.11.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.
@@ -0,0 +1,345 @@
1
+ // Must be before any other imports so vitest can hoist the mock correctly.
2
+ // We override the i18n mock here (rather than importing @tests/mocks/i18n)
3
+ // because RightsIndicator also calls `te`, which the shared mock does not provide.
4
+ import { vi } from 'vitest';
5
+
6
+ vi.mock('vue-i18n', () => {
7
+ const { ref } = require('vue');
8
+ // `te` returns true for entity-specific keys so we can verify that branch.
9
+ return {
10
+ useI18n: () => ({
11
+ t: (key: string) => key,
12
+ te: (key: string) => key.startsWith('RightsIndicator -'),
13
+ locale: ref('fr')
14
+ }),
15
+ createI18n: () => {}
16
+ };
17
+ });
18
+
19
+ import { describe, expect, it } from 'vitest';
20
+ import { mount, setupAuthStore } from '@tests/utils';
21
+ import { useAuthStore } from '@/stores/AuthStore';
22
+ import RightsIndicator from '@/components/display/RightsIndicator.vue';
23
+ import type { Podcast } from '@/stores/class/general/podcast';
24
+ import type { Mix } from '@/stores/class/radio/mix';
25
+ import type { PlaylistMedia } from '@/stores/class/radio/playlistMedia';
26
+ import type { Cartouchier } from '@/stores/class/cartouchier/cartouchier';
27
+ import type { Media } from '@/stores/class/general/media';
28
+
29
+ // ── Fixtures ─────────────────────────────────────────────────────────────────
30
+
31
+ const ownUserId = 'test-user-123';
32
+
33
+ const ownPodcast = { podcastId: 1, createdByUserId: ownUserId, valid: true } as Podcast;
34
+ const otherPodcast = { podcastId: 2, createdByUserId: 'other-user', valid: true } as Podcast;
35
+
36
+ const ownCartouchier = {
37
+ cartouchierId: 1, ownerId: ownUserId,
38
+ title: 'c', organisationId: 'o', cartouches: {}
39
+ } as Cartouchier;
40
+ const otherCartouchier = {
41
+ cartouchierId: 2, ownerId: 'other-user',
42
+ title: 'c', organisationId: 'o', cartouches: {}
43
+ } as Cartouchier;
44
+
45
+ const ownMix = {
46
+ mixId: 1, ownerId: ownUserId,
47
+ color: '', description: '', name: '', organisationId: 'o', samplings: []
48
+ } as Mix;
49
+ const otherMix = {
50
+ mixId: 2, ownerId: 'other-user',
51
+ color: '', description: '', name: '', organisationId: 'o', samplings: []
52
+ } as Mix;
53
+
54
+ const ownPlaylistMedia = {
55
+ playlistId: 1, ownerId: ownUserId,
56
+ color: '', description: '', name: '', organisationId: 'o', medias: []
57
+ } as PlaylistMedia;
58
+ const otherPlaylistMedia = {
59
+ playlistId: 2, ownerId: 'other-user',
60
+ color: '', description: '', name: '', organisationId: 'o', medias: []
61
+ } as PlaylistMedia;
62
+
63
+ const ownMedia = { mediaId: 1, ownerId: ownUserId } as Media;
64
+ const otherMedia = { mediaId: 2, ownerId: 'other-user' } as Media;
65
+
66
+ // ── Helper ───────────────────────────────────────────────────────────────────
67
+
68
+ async function mountWith(props: Record<string, unknown>, roles: string[]) {
69
+ return mount(RightsIndicator, {
70
+ props: { text: true, ...props },
71
+ beforeMount: async () => {
72
+ await setupAuthStore({ roles })();
73
+ useAuthStore().$patch({
74
+ authProfile: { userId: ownUserId },
75
+ authParam: { accessToken: 'test-token', refreshToken: undefined, expiration: undefined },
76
+ });
77
+ }
78
+ });
79
+ }
80
+
81
+ // ─────────────────────────────────────────────────────────────────────────────
82
+ describe('RightsIndicator', () => {
83
+
84
+ // ── Entity detection ─────────────────────────────────────────────────────
85
+ describe('entity detection', () => {
86
+ it('detects podcast entity and grants access for privileged role', async () => {
87
+ const wrapper = await mountWith({ action: 'create', podcast: ownPodcast }, ['PRODUCTION']);
88
+ expect(wrapper.find('.alert').exists()).toBe(false);
89
+ });
90
+
91
+ it('detects cartouchier entity and grants access for privileged role', async () => {
92
+ const wrapper = await mountWith({ action: 'create', cartouchier: ownCartouchier }, ['PRODUCTION']);
93
+ expect(wrapper.find('.alert').exists()).toBe(false);
94
+ });
95
+
96
+ it('detects mix entity and grants access for privileged role', async () => {
97
+ const wrapper = await mountWith({ action: 'create', mix: ownMix }, ['ADMIN']);
98
+ expect(wrapper.find('.alert').exists()).toBe(false);
99
+ });
100
+
101
+ it('detects playlistMedia entity and grants access for privileged role', async () => {
102
+ const wrapper = await mountWith({ action: 'create', playlistMedia: ownPlaylistMedia }, ['PRODUCTION']);
103
+ expect(wrapper.find('.alert').exists()).toBe(false);
104
+ });
105
+
106
+ it('detects media entity and grants access for privileged role', async () => {
107
+ const wrapper = await mountWith({ action: 'create', media: ownMedia }, ['PRODUCTION']);
108
+ expect(wrapper.find('.alert').exists()).toBe(false);
109
+ });
110
+
111
+ it('shows alert when entity prop is boolean false (no entity)', async () => {
112
+ // `podcast: false` — no real entity, so entity segment is undefined → DeniedNoRight
113
+ const wrapper = await mountWith({ action: 'create', podcast: false }, ['ADMIN']);
114
+ expect(wrapper.find('.alert').exists()).toBe(true);
115
+ });
116
+ });
117
+
118
+ // ── action = 'create' ────────────────────────────────────────────────────
119
+ describe("action = 'create'", () => {
120
+ it('hides alert when user has create right for podcast', async () => {
121
+ const wrapper = await mountWith({ action: 'create', podcast: ownPodcast }, ['PRODUCTION']);
122
+ expect(wrapper.find('.alert').exists()).toBe(false);
123
+ });
124
+
125
+ it('shows alert when user lacks create right for podcast', async () => {
126
+ const wrapper = await mountWith({ action: 'create', podcast: ownPodcast }, ['PLAYLISTS']);
127
+ expect(wrapper.find('.alert').exists()).toBe(true);
128
+ });
129
+
130
+ it('hides alert when user has create right for mix', async () => {
131
+ const wrapper = await mountWith({ action: 'create', mix: ownMix }, ['RADIO']);
132
+ expect(wrapper.find('.alert').exists()).toBe(false);
133
+ });
134
+
135
+ it('shows alert when user lacks create right for mix', async () => {
136
+ // PRODUCTION is not in the mix create allowlist (only ADMIN and RADIO)
137
+ const wrapper = await mountWith({ action: 'create', mix: ownMix }, ['PRODUCTION']);
138
+ expect(wrapper.find('.alert').exists()).toBe(true);
139
+ });
140
+
141
+ it('hides alert when user has create right for media', async () => {
142
+ const wrapper = await mountWith({ action: 'create', media: ownMedia }, ['RADIO']);
143
+ expect(wrapper.find('.alert').exists()).toBe(false);
144
+ });
145
+
146
+ it('shows alert when user lacks create right for media', async () => {
147
+ const wrapper = await mountWith({ action: 'create', media: ownMedia }, ['PLAYLISTS']);
148
+ expect(wrapper.find('.alert').exists()).toBe(true);
149
+ });
150
+ });
151
+
152
+ // ── action = 'edit' ──────────────────────────────────────────────────────
153
+ describe("action = 'edit'", () => {
154
+ it('hides alert when user can edit their own podcast', async () => {
155
+ const wrapper = await mountWith({ action: 'edit', podcast: ownPodcast }, ['RESTRICTED_PRODUCTION']);
156
+ expect(wrapper.find('.alert').exists()).toBe(false);
157
+ });
158
+
159
+ it('shows alert when restricted user cannot edit another user\'s podcast', async () => {
160
+ const wrapper = await mountWith({ action: 'edit', podcast: otherPodcast }, ['RESTRICTED_PRODUCTION']);
161
+ expect(wrapper.find('.alert').exists()).toBe(true);
162
+ });
163
+
164
+ it('returns DeniedNoRight when arg is boolean true (not an object)', async () => {
165
+ // edit/delete require a real entity object; a boolean is rejected
166
+ const wrapper = await mountWith({ action: 'edit', podcast: true as unknown as Podcast }, ['ADMIN']);
167
+ expect(wrapper.find('.alert').exists()).toBe(true);
168
+ });
169
+
170
+ it('hides alert when admin edits another user\'s cartouchier', async () => {
171
+ const wrapper = await mountWith({ action: 'edit', cartouchier: otherCartouchier }, ['ADMIN']);
172
+ expect(wrapper.find('.alert').exists()).toBe(false);
173
+ });
174
+
175
+ it('shows alert when restricted user edits another user\'s cartouchier', async () => {
176
+ const wrapper = await mountWith({ action: 'edit', cartouchier: otherCartouchier }, ['RESTRICTED_PRODUCTION']);
177
+ expect(wrapper.find('.alert').exists()).toBe(true);
178
+ });
179
+
180
+ it('hides alert when admin edits another user\'s media', async () => {
181
+ const wrapper = await mountWith({ action: 'edit', media: otherMedia }, ['ADMIN']);
182
+ expect(wrapper.find('.alert').exists()).toBe(false);
183
+ });
184
+
185
+ it('shows alert when restricted user edits another user\'s media', async () => {
186
+ const wrapper = await mountWith({ action: 'edit', media: otherMedia }, ['RESTRICTED_PRODUCTION']);
187
+ expect(wrapper.find('.alert').exists()).toBe(true);
188
+ });
189
+ });
190
+
191
+ // ── action = 'delete' ────────────────────────────────────────────────────
192
+ describe("action = 'delete'", () => {
193
+ it('hides alert when user can delete their own playlistMedia', async () => {
194
+ const wrapper = await mountWith({ action: 'delete', playlistMedia: ownPlaylistMedia }, ['RESTRICTED_ANIMATION']);
195
+ expect(wrapper.find('.alert').exists()).toBe(false);
196
+ });
197
+
198
+ it('shows alert when restricted user deletes another user\'s playlistMedia', async () => {
199
+ const wrapper = await mountWith({ action: 'delete', playlistMedia: otherPlaylistMedia }, ['RESTRICTED_ANIMATION']);
200
+ expect(wrapper.find('.alert').exists()).toBe(true);
201
+ });
202
+
203
+ it('returns DeniedNoRight when arg is boolean true (not an object)', async () => {
204
+ const wrapper = await mountWith({ action: 'delete', mix: true as unknown as Mix }, ['ADMIN']);
205
+ expect(wrapper.find('.alert').exists()).toBe(true);
206
+ });
207
+ });
208
+
209
+ // ── action = 'any' with object arg ───────────────────────────────────────
210
+ describe("action = 'any' with object arg", () => {
211
+ it('returns Allowed if Create check passes (short-circuits on first Allowed)', async () => {
212
+ // RESTRICTED_ANIMATION can create cartouchier → returns Allowed immediately
213
+ const wrapper = await mountWith({ action: 'any', cartouchier: otherCartouchier }, ['RESTRICTED_ANIMATION']);
214
+ expect(wrapper.find('.alert').exists()).toBe(false);
215
+ });
216
+
217
+ it('returns Allowed when all three checks (Create/Edit/Delete) pass', async () => {
218
+ const wrapper = await mountWith({ action: 'any', podcast: ownPodcast }, ['PRODUCTION']);
219
+ expect(wrapper.find('.alert').exists()).toBe(false);
220
+ });
221
+
222
+ it('returns DeniedNoRight when no check passes and no DeniedNotOwner accrues', async () => {
223
+ // PLAYLISTS has no right for mix at all → stays at DeniedNoRight
224
+ const wrapper = await mountWith({ action: 'any', mix: otherMix }, ['PLAYLISTS']);
225
+ expect(wrapper.find('.alert').exists()).toBe(true);
226
+ });
227
+ });
228
+
229
+ // ── action = 'any' with boolean arg ─────────────────────────────────────
230
+ describe("action = 'any' with boolean arg", () => {
231
+ it('only checks Create when arg is boolean true, grants access when allowed', async () => {
232
+ // RADIO can create mix
233
+ const wrapper = await mountWith({ action: 'any', mix: true as unknown as Mix }, ['RADIO']);
234
+ expect(wrapper.find('.alert').exists()).toBe(false);
235
+ });
236
+
237
+ it('only checks Create when arg is boolean true, shows alert when denied', async () => {
238
+ // PLAYLISTS cannot create mix
239
+ const wrapper = await mountWith({ action: 'any', mix: true as unknown as Mix }, ['PLAYLISTS']);
240
+ expect(wrapper.find('.alert').exists()).toBe(true);
241
+ });
242
+ });
243
+
244
+ // ── message computation ──────────────────────────────────────────────────
245
+ describe('message computation', () => {
246
+ it('renders nothing when hasAccess is true (ActionRight.Allowed)', async () => {
247
+ const wrapper = await mountWith({ action: 'create', podcast: ownPodcast }, ['PRODUCTION']);
248
+ expect(wrapper.find('.alert').exists()).toBe(false);
249
+ });
250
+
251
+ it('renders "insufficient rights" for ActionRight.DeniedNoRight', async () => {
252
+ const wrapper = await mountWith({ action: 'create', podcast: ownPodcast }, ['PLAYLISTS']);
253
+ expect(wrapper.text()).toContain('insufficient rights');
254
+ });
255
+
256
+ it('renders entity-specific i18n key for ActionRight.DeniedNotOwner on podcast', async () => {
257
+ // te('RightsIndicator - Podcast - Not owner') returns true per our mock
258
+ const wrapper = await mountWith({ action: 'edit', podcast: otherPodcast }, ['RESTRICTED_PRODUCTION']);
259
+ expect(wrapper.text()).toContain('RightsIndicator - Podcast - Not owner');
260
+ });
261
+
262
+ it('renders entity-specific i18n key for ActionRight.DeniedNotOwner on cartouchier', async () => {
263
+ const wrapper = await mountWith({ action: 'edit', cartouchier: otherCartouchier }, ['RESTRICTED_PRODUCTION']);
264
+ expect(wrapper.text()).toContain('RightsIndicator - Cartouchier - Not owner');
265
+ });
266
+
267
+ it('renders entity-specific i18n key for ActionRight.DeniedNotOwner on playlistMedia', async () => {
268
+ const wrapper = await mountWith({ action: 'edit', playlistMedia: otherPlaylistMedia }, ['RESTRICTED_PRODUCTION']);
269
+ expect(wrapper.text()).toContain('RightsIndicator - PlaylistMedia - Not owner');
270
+ });
271
+ });
272
+
273
+ // ── hasAccess computed ───────────────────────────────────────────────────
274
+ describe('hasAccess', () => {
275
+ it('is true only for ActionRight.Allowed (hides alert)', async () => {
276
+ const wrapper = await mountWith({ action: 'create', podcast: ownPodcast }, ['PRODUCTION']);
277
+ expect(wrapper.find('.alert').exists()).toBe(false);
278
+ });
279
+
280
+ it('is false for ActionRight.DeniedNoRight (shows alert)', async () => {
281
+ const wrapper = await mountWith({ action: 'create', podcast: ownPodcast }, ['PLAYLISTS']);
282
+ expect(wrapper.find('.alert').exists()).toBe(true);
283
+ });
284
+
285
+ it('is false for ActionRight.DeniedNotOwner (shows alert)', async () => {
286
+ const wrapper = await mountWith({ action: 'edit', podcast: otherPodcast }, ['RESTRICTED_PRODUCTION']);
287
+ expect(wrapper.find('.alert').exists()).toBe(true);
288
+ });
289
+ });
290
+
291
+ // ── Method dispatch ───────────────────────────────────────────────────────
292
+ describe('right method dispatch', () => {
293
+ it('calls getCreateCartouchierRight for action=create + cartouchier', async () => {
294
+ // RADIO can create cartouchier
295
+ const allowed = await mountWith({ action: 'create', cartouchier: ownCartouchier }, ['RADIO']);
296
+ expect(allowed.find('.alert').exists()).toBe(false);
297
+
298
+ // PLAYLISTS cannot
299
+ const denied = await mountWith({ action: 'create', cartouchier: ownCartouchier }, ['PLAYLISTS']);
300
+ expect(denied.find('.alert').exists()).toBe(true);
301
+ });
302
+
303
+ it('calls getDeletePlaylistMediaRight for action=delete + playlistMedia', async () => {
304
+ const allowed = await mountWith({ action: 'delete', playlistMedia: ownPlaylistMedia }, ['ANIMATION']);
305
+ expect(allowed.find('.alert').exists()).toBe(false);
306
+
307
+ const denied = await mountWith({ action: 'delete', playlistMedia: ownPlaylistMedia }, ['PLAYLISTS']);
308
+ expect(denied.find('.alert').exists()).toBe(true);
309
+ });
310
+
311
+ it('calls getCreateMixRight for action=create + mix', async () => {
312
+ const allowed = await mountWith({ action: 'create', mix: ownMix }, ['ADMIN']);
313
+ expect(allowed.find('.alert').exists()).toBe(false);
314
+
315
+ // PRODUCTION is not in the mix create allowlist
316
+ const denied = await mountWith({ action: 'create', mix: ownMix }, ['PRODUCTION']);
317
+ expect(denied.find('.alert').exists()).toBe(true);
318
+ });
319
+
320
+ it('calls getDeleteCartouchierRight for action=delete + cartouchier', async () => {
321
+ const allowed = await mountWith({ action: 'delete', cartouchier: ownCartouchier }, ['ANIMATION']);
322
+ expect(allowed.find('.alert').exists()).toBe(false);
323
+
324
+ // PODCAST_CRUD on another user's cartouchier → DeniedNotOwner → no access
325
+ const denied = await mountWith({ action: 'delete', cartouchier: otherCartouchier }, ['PODCAST_CRUD']);
326
+ expect(denied.find('.alert').exists()).toBe(true);
327
+ });
328
+
329
+ it('calls getEditMediaRight for action=edit + media', async () => {
330
+ const allowed = await mountWith({ action: 'edit', media: ownMedia }, ['RESTRICTED_PRODUCTION']);
331
+ expect(allowed.find('.alert').exists()).toBe(false);
332
+
333
+ const denied = await mountWith({ action: 'edit', media: otherMedia }, ['RESTRICTED_PRODUCTION']);
334
+ expect(denied.find('.alert').exists()).toBe(true);
335
+ });
336
+
337
+ it('calls getDeleteMediaRight for action=delete + media', async () => {
338
+ const allowed = await mountWith({ action: 'delete', media: ownMedia }, ['PODCAST_CRUD']);
339
+ expect(allowed.find('.alert').exists()).toBe(false);
340
+
341
+ const denied = await mountWith({ action: 'delete', media: otherMedia }, ['PODCAST_CRUD']);
342
+ expect(denied.find('.alert').exists()).toBe(true);
343
+ });
344
+ });
345
+ });
@@ -7,8 +7,14 @@ import { nextTick } from 'vue';
7
7
 
8
8
  describe('ClassicPopover', () => {
9
9
  let targetElement: HTMLElement;
10
+ let appElement: HTMLElement;
11
+ let wrapper: VueWrapper | undefined;
10
12
 
11
13
  beforeEach(() => {
14
+ appElement = document.createElement('div');
15
+ appElement.id = 'app';
16
+ document.body.appendChild(appElement);
17
+
12
18
  targetElement = document.createElement('button');
13
19
  targetElement.id = 'test-target';
14
20
  targetElement.textContent = 'Trigger';
@@ -16,27 +22,38 @@ describe('ClassicPopover', () => {
16
22
  });
17
23
 
18
24
  afterEach(() => {
25
+ wrapper?.unmount();
26
+ wrapper = undefined;
19
27
  if (targetElement?.parentNode) {
20
28
  targetElement.parentNode.removeChild(targetElement);
21
29
  }
30
+ if (appElement?.parentNode) {
31
+ appElement.parentNode.removeChild(appElement);
32
+ }
22
33
  });
23
34
 
35
+ // The popover is teleported to #app; retrieve it by its deterministic id.
36
+ const getPopoverEl = (): HTMLElement =>
37
+ document.getElementById('popovertest-target') as HTMLElement;
38
+
24
39
  // Helper: Check if popover is visible
25
- const isVisible = (wrapper: VueWrapper): boolean => {
26
- const element = wrapper.element as HTMLElement;
40
+ const isVisible = (): boolean => {
41
+ const element = getPopoverEl();
42
+ if (!element) return false;
27
43
  return element.style.display !== 'none' &&
28
44
  window.getComputedStyle(element).display !== 'none';
29
45
  };
30
46
 
31
47
  // Helper: Mount popover with default props
32
48
  const mount = async (props: Record<string, unknown> = {}) => {
33
- return testMount(ClassicPopover, {
49
+ wrapper = await testMount(ClassicPopover, {
34
50
  props: {
35
51
  target: 'test-target',
36
52
  content: 'Test content',
37
53
  ...props
38
54
  }
39
55
  });
56
+ return wrapper;
40
57
  };
41
58
 
42
59
  // Helper: Open popover via hover
@@ -68,179 +85,175 @@ describe('ClassicPopover', () => {
68
85
 
69
86
  describe('hover behavior (onlyClick=false, default)', () => {
70
87
  it('opens on mouseenter and closes on mouseleave of target', async () => {
71
- const wrapper = await mount();
88
+ await mount();
72
89
 
73
- expect(isVisible(wrapper)).toBe(false);
90
+ expect(isVisible()).toBe(false);
74
91
 
75
92
  await openViaHover();
76
- expect(isVisible(wrapper)).toBe(true);
93
+ expect(isVisible()).toBe(true);
77
94
 
78
95
  await closeViaHover();
79
- expect(isVisible(wrapper)).toBe(false);
96
+ expect(isVisible()).toBe(false);
80
97
  });
81
98
 
82
99
  it('stays open when mouse moves from target to popover content', async () => {
83
- const wrapper = await mount();
100
+ await mount();
84
101
 
85
102
  await openViaHover();
86
- expect(isVisible(wrapper)).toBe(true);
103
+ expect(isVisible()).toBe(true);
87
104
 
88
105
  // Mouse enters popover
89
- const popoverElement = wrapper.element as HTMLElement;
90
- popoverElement.dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
106
+ getPopoverEl().dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
91
107
  await nextTick();
92
108
 
93
109
  // Leave target
94
110
  await closeViaHover();
95
111
 
96
112
  // Should still be open because mouse is over popover
97
- expect(isVisible(wrapper)).toBe(true);
113
+ expect(isVisible()).toBe(true);
98
114
  });
99
115
 
100
116
  it('closes when mouse leaves popover content', async () => {
101
- const wrapper = await mount();
117
+ await mount();
102
118
 
103
119
  await openViaHover();
104
120
 
105
121
  // Move to popover
106
- const popoverElement = wrapper.element as HTMLElement;
107
- popoverElement.dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
122
+ getPopoverEl().dispatchEvent(new MouseEvent('mouseenter', { bubbles: true }));
108
123
  await nextTick();
109
124
 
110
125
  // Leave popover
111
- popoverElement.dispatchEvent(new MouseEvent('mouseleave', { bubbles: true }));
126
+ getPopoverEl().dispatchEvent(new MouseEvent('mouseleave', { bubbles: true }));
112
127
  await nextTick();
113
128
 
114
- expect(isVisible(wrapper)).toBe(false);
129
+ expect(isVisible()).toBe(false);
115
130
  });
116
131
 
117
132
  it('closes via mouseleave even after clicking the target', async () => {
118
- const wrapper = await mount();
133
+ await mount();
119
134
 
120
135
  await openViaHover();
121
- expect(isVisible(wrapper)).toBe(true);
136
+ expect(isVisible()).toBe(true);
122
137
 
123
138
  // Click the target (sets isClick to true)
124
139
  await openViaClick();
125
- expect(isVisible(wrapper)).toBe(true);
140
+ expect(isVisible()).toBe(true);
126
141
 
127
142
  // Leave with mouse
128
143
  await closeViaHover();
129
144
 
130
145
  // Should be closed because it was opened by hover
131
- expect(isVisible(wrapper)).toBe(false);
146
+ expect(isVisible()).toBe(false);
132
147
  });
133
148
  });
134
149
 
135
150
  describe('click behavior (onlyClick=true)', () => {
136
151
  it('opens on click of target', async () => {
137
- const wrapper = await mount({ onlyClick: true });
152
+ await mount({ onlyClick: true });
138
153
 
139
- expect(isVisible(wrapper)).toBe(false);
154
+ expect(isVisible()).toBe(false);
140
155
 
141
156
  await openViaClick();
142
- expect(isVisible(wrapper)).toBe(true);
157
+ expect(isVisible()).toBe(true);
143
158
  });
144
159
 
145
160
  it('does not open on mouseenter when onlyClick is true', async () => {
146
- const wrapper = await mount({ onlyClick: true });
161
+ await mount({ onlyClick: true });
147
162
 
148
163
  await openViaHover();
149
164
 
150
- expect(isVisible(wrapper)).toBe(false);
165
+ expect(isVisible()).toBe(false);
151
166
  });
152
167
 
153
168
  it('stays open when clicking inside popover', async () => {
154
- const wrapper = await mount({ onlyClick: true });
169
+ await mount({ onlyClick: true });
155
170
 
156
171
  await openViaClick();
157
- expect(isVisible(wrapper)).toBe(true);
172
+ expect(isVisible()).toBe(true);
158
173
 
159
174
  // Click inside popover
160
- const popoverElement = wrapper.element as HTMLElement;
161
175
  const insideElement = document.createElement('button');
162
- popoverElement.appendChild(insideElement);
176
+ getPopoverEl().appendChild(insideElement);
163
177
  insideElement.dispatchEvent(new MouseEvent('click', { bubbles: true }));
164
178
  await nextTick();
165
179
 
166
- expect(isVisible(wrapper)).toBe(true);
180
+ expect(isVisible()).toBe(true);
167
181
  });
168
182
 
169
183
  it('closes when clicking outside both popover and target', async () => {
170
- const wrapper = await mount({ onlyClick: true });
184
+ await mount({ onlyClick: true });
171
185
 
172
186
  await openViaClick();
173
- expect(isVisible(wrapper)).toBe(true);
187
+ expect(isVisible()).toBe(true);
174
188
 
175
189
  await clickOutside();
176
190
 
177
- expect(isVisible(wrapper)).toBe(false);
191
+ expect(isVisible()).toBe(false);
178
192
  });
179
193
 
180
194
  it('closes when clicking inside popover then clicking outside', async () => {
181
- const wrapper = await mount({ onlyClick: true });
195
+ await mount({ onlyClick: true });
182
196
 
183
197
  await openViaClick();
184
- expect(isVisible(wrapper)).toBe(true);
198
+ expect(isVisible()).toBe(true);
185
199
 
186
200
  // Click inside popover
187
- const popoverElement = wrapper.element as HTMLElement;
188
201
  const insideButton = document.createElement('button');
189
- popoverElement.appendChild(insideButton);
202
+ getPopoverEl().appendChild(insideButton);
190
203
  insideButton.dispatchEvent(new MouseEvent('click', { bubbles: true }));
191
204
  await nextTick();
192
205
 
193
- expect(isVisible(wrapper)).toBe(true);
206
+ expect(isVisible()).toBe(true);
194
207
 
195
208
  // Click outside
196
209
  await clickOutside();
197
210
 
198
- expect(isVisible(wrapper)).toBe(false);
211
+ expect(isVisible()).toBe(false);
199
212
  });
200
213
 
201
214
  it('toggles when clicking target while already open', async () => {
202
- const wrapper = await mount({ onlyClick: true });
215
+ await mount({ onlyClick: true });
203
216
 
204
217
  await openViaClick();
205
- expect(isVisible(wrapper)).toBe(true);
218
+ expect(isVisible()).toBe(true);
206
219
 
207
220
  // Click target again
208
221
  await openViaClick();
209
222
 
210
- expect(isVisible(wrapper)).toBe(false);
223
+ expect(isVisible()).toBe(false);
211
224
  });
212
225
  });
213
226
 
214
227
  describe('mixed behavior (onlyMouse=false, onlyClick=false)', () => {
215
228
  it('can open via hover or click', async () => {
216
- const wrapper = await mount({ onlyClick: false, onlyMouse: false });
229
+ await mount({ onlyClick: false, onlyMouse: false });
217
230
 
218
231
  // Open via hover
219
232
  await openViaHover();
220
- expect(isVisible(wrapper)).toBe(true);
233
+ expect(isVisible()).toBe(true);
221
234
 
222
235
  // Close
223
236
  await closeViaHover();
224
- expect(isVisible(wrapper)).toBe(false);
237
+ expect(isVisible()).toBe(false);
225
238
 
226
239
  // Open via click
227
240
  await openViaClick();
228
- expect(isVisible(wrapper)).toBe(true);
241
+ expect(isVisible()).toBe(true);
229
242
  });
230
243
  });
231
244
 
232
245
  describe('expose clearClick method', () => {
233
246
  it('exposes clearClick method to close popover programmatically', async () => {
234
- const wrapper = await mount();
247
+ await mount();
235
248
 
236
249
  await openViaHover();
237
- expect(isVisible(wrapper)).toBe(true);
250
+ expect(isVisible()).toBe(true);
238
251
 
239
252
  // Close programmatically
240
- (wrapper.vm as any).clearClick();
253
+ (wrapper!.vm as unknown as { clearClick: () => void }).clearClick();
241
254
  await nextTick();
242
255
 
243
- expect(isVisible(wrapper)).toBe(false);
256
+ expect(isVisible()).toBe(false);
244
257
  });
245
258
  });
246
259
  });