fix: isolate EventCard tests and clean compose refs hook
This commit is contained in:
@@ -54,9 +54,12 @@ function composeRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T> {
|
|||||||
* A custom hook that composes multiple refs
|
* A custom hook that composes multiple refs
|
||||||
* Accepts callback refs and RefObject(s)
|
* Accepts callback refs and RefObject(s)
|
||||||
*/
|
*/
|
||||||
function useComposedRefs<T>(...refs: PossibleRef<T>[]): React.RefCallback<T> {
|
function useComposedRefs<T>(
|
||||||
// biome-ignore lint/correctness/useExhaustiveDependencies: we want to memoize by all values
|
ref1: PossibleRef<T>,
|
||||||
return React.useCallback(composeRefs(...refs), refs);
|
ref2: PossibleRef<T>,
|
||||||
|
ref3?: PossibleRef<T>,
|
||||||
|
): React.RefCallback<T> {
|
||||||
|
return React.useMemo(() => composeRefs(ref1, ref2, ref3), [ref1, ref2, ref3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { composeRefs, useComposedRefs };
|
export { composeRefs, useComposedRefs };
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, expect, test } from "bun:test";
|
import { afterEach, beforeEach, describe, expect, test } from "bun:test";
|
||||||
import { renderToStaticMarkup } from "react-dom/server";
|
import { renderToStaticMarkup } from "react-dom/server";
|
||||||
import { EventCard } from "@/components/event-card";
|
import { EventCard } from "@/components/event-card";
|
||||||
import type { CalendarEvent } from "@/lib/types";
|
import type { CalendarEvent } from "@/lib/types";
|
||||||
@@ -15,6 +15,17 @@ const sampleEvent: CalendarEvent = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe("EventCard actions trigger", () => {
|
describe("EventCard actions trigger", () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
globalThis.document = {
|
||||||
|
addEventListener: () => {},
|
||||||
|
removeEventListener: () => {},
|
||||||
|
} as unknown as Document;
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
delete (globalThis as { document?: Document }).document;
|
||||||
|
});
|
||||||
|
|
||||||
test("shows the triple-dots trigger without requiring hover and exposes an aria-label for the icon-only button", () => {
|
test("shows the triple-dots trigger without requiring hover and exposes an aria-label for the icon-only button", () => {
|
||||||
const markup = renderToStaticMarkup(
|
const markup = renderToStaticMarkup(
|
||||||
EventCard({
|
EventCard({
|
||||||
|
|||||||
Reference in New Issue
Block a user