|
1 | | -import { test, expect } from "vitest" |
| 1 | +import { test, expect, describe } from "vitest" |
2 | 2 | import { screen, waitFor } from "@testing-library/react" |
3 | 3 | import { userEvent } from "@testing-library/user-event" |
4 | 4 | import type { JSONSchema } from "json-schema-to-ts" |
5 | 5 |
|
6 | 6 | import { render } from "../common/test-render" |
7 | | -import type { UISchema } from "../ui-schema" |
| 7 | +import type { TextControlOptions, UISchema } from "../ui-schema" |
8 | 8 | import type { JSONFormData } from "../common/schema-derived-types" |
9 | 9 |
|
10 | 10 | const textInputSchema = { |
@@ -130,3 +130,63 @@ test("renders error messages from rule validation", async () => { |
130 | 130 |
|
131 | 131 | await screen.findByText("Only letters are allowed") |
132 | 132 | }) |
| 133 | + |
| 134 | +describe("tooltips", () => { |
| 135 | + const getUiSchema = (options?: TextControlOptions) => ({ |
| 136 | + type: "VerticalLayout", |
| 137 | + elements: [ |
| 138 | + { |
| 139 | + type: "Control", |
| 140 | + scope: "#/properties/name", |
| 141 | + label: "Name", |
| 142 | + formItemProps: { |
| 143 | + tooltip: { |
| 144 | + title: ( |
| 145 | + <p> |
| 146 | + Choose{" "} |
| 147 | + <a |
| 148 | + href="https://wheelofnames.com/" |
| 149 | + target="_blank" |
| 150 | + rel="noopener noreferrer" |
| 151 | + > |
| 152 | + a random name |
| 153 | + </a> |
| 154 | + . |
| 155 | + </p> |
| 156 | + ), |
| 157 | + placement: "right", |
| 158 | + }, |
| 159 | + }, |
| 160 | + options, |
| 161 | + }, |
| 162 | + ], |
| 163 | + }) |
| 164 | + |
| 165 | + const schema = { |
| 166 | + type: "object", |
| 167 | + properties: { name: { type: "string", title: "Name" } }, |
| 168 | + } satisfies JSONSchema |
| 169 | + |
| 170 | + test("renders tooltip", async () => { |
| 171 | + render({ schema, uischema: getUiSchema() }) |
| 172 | + await screen.findByPlaceholderText(schema.properties.name.title, { |
| 173 | + exact: false, |
| 174 | + }) |
| 175 | + const svgEl = screen.getByRole("img", { name: /question-circle/i }) |
| 176 | + await userEvent.hover(svgEl) |
| 177 | + |
| 178 | + await screen.findByText("a random name", { exact: false }) |
| 179 | + }) |
| 180 | + |
| 181 | + test("renders right tooltip in case both are passed", async () => { |
| 182 | + const options = { tooltip: "You should see this tooltip" } |
| 183 | + render({ schema, uischema: getUiSchema(options) }) |
| 184 | + await screen.findByPlaceholderText(schema.properties.name.title, { |
| 185 | + exact: false, |
| 186 | + }) |
| 187 | + const svgEl = screen.getByRole("img", { name: /question-circle/i }) |
| 188 | + await userEvent.hover(svgEl) |
| 189 | + |
| 190 | + await screen.findByText("You should see this tooltip") |
| 191 | + }) |
| 192 | +}) |
0 commit comments