-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Format Selector Improvements (#566)
* WIP * fix: data format field UI imporvements * fix: listbox had no focus
- Loading branch information
Showing
5 changed files
with
267 additions
and
15 deletions.
There are no files selected for viewing
232 changes: 232 additions & 0 deletions
232
client/src/lib/components/DatasetForm/_FormatSelector.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import "@testing-library/jest-dom"; | ||
import { fireEvent, render } from "@testing-library/svelte"; | ||
import type { DataFormat } from "src/definitions/dataformat"; | ||
import FormatSelector from "./_FormatSelector.svelte"; | ||
|
||
const formatOptions: DataFormat[] = [ | ||
{ | ||
name: "label-1", | ||
id: 1, | ||
}, | ||
{ | ||
name: "label-2", | ||
id: 2, | ||
}, | ||
{ | ||
name: "label-3", | ||
id: 3, | ||
}, | ||
]; | ||
|
||
describe("Test the select component", () => { | ||
test("should display a select input with 3 options", () => { | ||
const props = { | ||
formatOptions, | ||
}; | ||
|
||
const { getAllByRole } = render(FormatSelector, { props }); | ||
|
||
expect(getAllByRole("listbox").length).toBe(1); | ||
}); | ||
|
||
test("should display a select input with 3 options after start to type", async () => { | ||
const props = { | ||
formatOptions, | ||
}; | ||
|
||
const { getByRole, getAllByRole } = render(FormatSelector, { props }); | ||
|
||
const combobox = getByRole("combobox"); | ||
|
||
await fireEvent.input(combobox, { | ||
target: { | ||
value: "label", | ||
}, | ||
}); | ||
expect(getAllByRole("option").length).toBe(3); | ||
}); | ||
|
||
test("should display a select input with 3 options after hitting alt + down arrow", async () => { | ||
const props = { | ||
formatOptions, | ||
}; | ||
|
||
const { getByRole, getAllByRole } = render(FormatSelector, { props }); | ||
|
||
const combobox = getByRole("combobox"); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "ArrowDown", | ||
altKey: true, | ||
}); | ||
expect(getAllByRole("option").length).toBe(3); | ||
}); | ||
|
||
test("should display a select input with 3 options after start typing and hitting down arrow key", async () => { | ||
const props = { | ||
formatOptions, | ||
}; | ||
|
||
const { getByRole, getAllByRole } = render(FormatSelector, { props }); | ||
|
||
const combobox = getByRole("combobox"); | ||
|
||
await fireEvent.input(combobox, { | ||
target: { | ||
value: "label", | ||
}, | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "ArrowDown", | ||
}); | ||
expect(getAllByRole("option").length).toBe(3); | ||
}); | ||
|
||
test("should display a select input with 3 options after start typing and hitting down arrow key", async () => { | ||
const props = { | ||
formatOptions, | ||
}; | ||
|
||
const { getByRole, queryByRole } = render(FormatSelector, { props }); | ||
|
||
const combobox = getByRole("combobox"); | ||
|
||
await fireEvent.input(combobox, { | ||
target: { | ||
value: "label", | ||
}, | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "ArrowDown", | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "Escape", | ||
}); | ||
expect(queryByRole("option")).toBe(null); | ||
}); | ||
|
||
test("should select an option after hitting Enter", async () => { | ||
const props = { | ||
formatOptions, | ||
}; | ||
|
||
const { getByRole, getAllByRole } = render(FormatSelector, { props }); | ||
|
||
const combobox = getByRole("combobox"); | ||
|
||
await fireEvent.input(combobox, { | ||
target: { | ||
value: "lab", | ||
}, | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "ArrowDown", | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "Enter", | ||
}); | ||
|
||
const tags = getAllByRole("listitem"); | ||
|
||
expect(tags).toHaveLength(1); | ||
|
||
expect(tags[0]).toHaveTextContent("label-1", { | ||
normalizeWhitespace: true, | ||
}); | ||
|
||
expect(combobox).toHaveValue(""); | ||
|
||
expect(combobox).toHaveValue(""); | ||
}); | ||
|
||
test("should select the second option after hitting down arrow twice and Enter", async () => { | ||
const props = { | ||
formatOptions, | ||
}; | ||
|
||
const { getByRole, getAllByRole } = render(FormatSelector, { props }); | ||
|
||
const combobox = getByRole("combobox"); | ||
|
||
await fireEvent.input(combobox, { | ||
target: { | ||
value: "lab", | ||
}, | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "ArrowDown", | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "ArrowDown", | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "Enter", | ||
}); | ||
const tags = getAllByRole("listitem"); | ||
|
||
expect(tags).toHaveLength(1); | ||
|
||
expect(tags[0]).toHaveTextContent("label-2", { | ||
normalizeWhitespace: true, | ||
}); | ||
|
||
expect(combobox).toHaveValue(""); | ||
}); | ||
|
||
test("should select the second option after hitting down arrow 3 times and Enter", async () => { | ||
const props = { | ||
formatOptions, | ||
}; | ||
|
||
const { getByRole, getAllByRole } = render(FormatSelector, { props }); | ||
|
||
const combobox = getByRole("combobox"); | ||
|
||
await fireEvent.input(combobox, { | ||
target: { | ||
value: "label-2", | ||
}, | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "ArrowDown", | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "ArrowDown", | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "ArrowDown", | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "ArrowDown", | ||
}); | ||
|
||
await fireEvent.keyDown(combobox, { | ||
key: "Enter", | ||
}); | ||
|
||
const tags = getAllByRole("listitem"); | ||
|
||
expect(tags).toHaveLength(1); | ||
|
||
expect(tags[0]).toHaveTextContent("label-2", { | ||
normalizeWhitespace: true, | ||
}); | ||
|
||
expect(combobox).toHaveValue(""); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.