Move automatic media actions out of carousels

This commit is contained in:
Dermot Duffy
2024-09-07 15:04:23 -07:00
parent 81177478db
commit 1a0e219c61
15 changed files with 994 additions and 777 deletions
+27 -2
View File
@@ -385,13 +385,20 @@ export const requestAnimationFrameMock = (callback: FrameRequestCallback) => {
return 1;
};
export const callIntersectionHandler = (intersecting = true, n = 0): void => {
export const callIntersectionHandler = async (
intersecting = true,
n = 0,
): Promise<void> => {
const mockResult = vi.mocked(IntersectionObserver).mock.results[n];
if (mockResult.type !== 'return') {
return;
}
const observer = mockResult.value;
vi.mocked(IntersectionObserver).mock.calls[n][0](
await (
vi.mocked(IntersectionObserver).mock.calls[n][0] as
| IntersectionObserverCallback
| ((_: unknown) => Promise<void>)
)(
// Note this is a very incomplete / invalid IntersectionObserverEntry that
// just provides the bare basics current implementation uses.
intersecting ? [{ isIntersecting: true } as IntersectionObserverEntry] : [],
@@ -399,6 +406,24 @@ export const callIntersectionHandler = (intersecting = true, n = 0): void => {
);
};
export const callMutationHandler = async (n = 0): Promise<void> => {
const mockResult = vi.mocked(MutationObserver).mock.results[n];
if (mockResult.type !== 'return') {
return;
}
const observer = mockResult.value;
await (
vi.mocked(MutationObserver).mock.calls[n][0] as
| MutationCallback
| ((_: unknown) => Promise<void>)
)(
// Note this is a very incomplete / invalid IntersectionObserverEntry that
// just provides the bare basics current implementation uses.
[],
observer,
);
};
export const createSlotHost = (options?: {
slot?: HTMLSlotElement;
children?: HTMLElement[];