|
1 | 1 | import { fireEvent, render, screen } from "@testing-library/svelte";
|
2 | 2 | import { userEvent } from "@testing-library/user-event";
|
3 | 3 | import { describe, expect, it, vi } from "vitest";
|
| 4 | +import { useFloating, useFocus, useId } from "../../src/index.js"; |
| 5 | +import { withRunes } from "../internal/with-runes.svelte.js"; |
4 | 6 | import App from "./wrapper-components/use-focus.svelte";
|
5 | 7 |
|
6 | 8 | /**
|
@@ -102,3 +104,43 @@ describe.skip("useFocus", () => {
|
102 | 104 | });
|
103 | 105 | });
|
104 | 106 | });
|
| 107 | + |
| 108 | +describe("focusWithin", () => { |
| 109 | + function createElements(): { reference: HTMLElement; floating: HTMLElement } { |
| 110 | + const reference = document.createElement("div"); |
| 111 | + const floating = document.createElement("div"); |
| 112 | + reference.id = useId(); |
| 113 | + floating.id = useId(); |
| 114 | + return { reference, floating }; |
| 115 | + } |
| 116 | + |
| 117 | + it( |
| 118 | + "Should not output onfocusin or onfocusout event handlers", |
| 119 | + withRunes(() => { |
| 120 | + expect.assertions(2); |
| 121 | + |
| 122 | + const elements = createElements(); |
| 123 | + const floating = useFloating({ elements }); |
| 124 | + const focus = useFocus(floating.context); |
| 125 | + const handlers = focus.reference; |
| 126 | + |
| 127 | + expect(handlers).not.toHaveProperty("onfocusin"); |
| 128 | + expect(handlers).not.toHaveProperty("onfocusout"); |
| 129 | + }), |
| 130 | + ); |
| 131 | + |
| 132 | + it( |
| 133 | + "Should output onfocusin or onfocusout event handlers", |
| 134 | + withRunes(() => { |
| 135 | + expect.assertions(2); |
| 136 | + |
| 137 | + const elements = createElements(); |
| 138 | + const floating = useFloating({ elements }); |
| 139 | + const focus = useFocus(floating.context, { focusWithin: true }); |
| 140 | + const handlers = focus.reference; |
| 141 | + |
| 142 | + expect(handlers).toHaveProperty("onfocusin"); |
| 143 | + expect(handlers).toHaveProperty("onfocusout"); |
| 144 | + }), |
| 145 | + ); |
| 146 | +}); |
0 commit comments