-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
958dfd8
commit 86ab28e
Showing
27 changed files
with
530 additions
and
830 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
46 changes: 46 additions & 0 deletions
46
web-wallet/src/lib/dusk/components/FieldButtonGroup/FieldButtonGroup.svelte
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,46 @@ | ||
<script> | ||
import { makeClassName } from "$lib/dusk/string"; | ||
import { Button, Textbox } from ".."; | ||
/** @type {TextboxTypes} */ | ||
export let type = "text"; | ||
/** @type {string} */ | ||
export let name; | ||
export let autocomplete = "off"; | ||
export let placeholder = ""; | ||
export let value = ""; | ||
/** @type {string | undefined} */ | ||
export let className = undefined; | ||
/** @type {string} */ | ||
export let buttonText = "Submit"; | ||
/** @type {Textbox} */ | ||
let inputElement; | ||
export function focus() { | ||
inputElement?.focus(); | ||
} | ||
export function select() { | ||
inputElement?.select(); | ||
} | ||
$: classes = makeClassName(["dusk-field-button-group", className]); | ||
</script> | ||
<div class={classes}> | ||
<Textbox | ||
bind:this={inputElement} | ||
tabindex={0} | ||
{type} | ||
{autocomplete} | ||
{name} | ||
required | ||
bind:value | ||
{placeholder} | ||
/> | ||
<Button on:click type="submit" text={buttonText} variant="secondary" /> | ||
</div> |
76 changes: 76 additions & 0 deletions
76
web-wallet/src/lib/dusk/components/__tests__/FieldButtonGroup.spec.js
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,76 @@ | ||
import { render, fireEvent, cleanup } from "@testing-library/svelte"; | ||
|
||
import { FieldButtonGroup } from ".."; | ||
|
||
import { vi, describe, it, expect, afterEach } from "vitest"; | ||
|
||
describe("FieldButtonGroup", () => { | ||
const baseProps = { name: "test" }; | ||
const baseOptions = { | ||
props: baseProps, | ||
target: document.body, | ||
}; | ||
|
||
afterEach(cleanup); | ||
|
||
it("renders the component with default values", async () => { | ||
const { getByRole, container } = render(FieldButtonGroup, baseOptions); | ||
|
||
const input = getByRole("textbox"); | ||
const button = getByRole("button"); | ||
|
||
expect(input).toBeInTheDocument(); | ||
expect(button).toBeInTheDocument(); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("updates input value on change", async () => { | ||
const { getByRole, container } = render(FieldButtonGroup, baseOptions); | ||
const input = getByRole("textbox"); | ||
|
||
await fireEvent.input(input, { target: { value: "test value" } }); | ||
|
||
expect(input).toHaveValue("test value"); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("triggers click event on button click", async () => { | ||
const { getByRole, component } = render(FieldButtonGroup); | ||
const button = getByRole("button"); | ||
|
||
const mockClickHandler = vi.fn(); | ||
component.$on("click", mockClickHandler); | ||
|
||
await fireEvent.click(button); | ||
|
||
expect(mockClickHandler).toHaveBeenCalled(); | ||
}); | ||
|
||
it("focuses input on focus() call", async () => { | ||
const { getByRole, component } = render(FieldButtonGroup); | ||
const input = getByRole("textbox"); | ||
|
||
component.focus(); | ||
expect(input).toHaveFocus(); | ||
}); | ||
|
||
it("should expose a method to select the element's text", () => { | ||
const { component, getByRole } = render(FieldButtonGroup, { | ||
...baseProps, | ||
value: "some input text", | ||
}); | ||
|
||
const input = /** @type {HTMLInputElement} */ (getByRole("textbox")); | ||
|
||
component.select(); | ||
|
||
const selectedText = input.value.substring( | ||
Number(input.selectionStart), | ||
Number(input.selectionEnd) | ||
); | ||
|
||
expect(selectedText).toBe("some input text"); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
web-wallet/src/lib/dusk/components/__tests__/__snapshots__/FieldButtonGroup.spec.js.snap
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,61 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`FieldButtonGroup > renders the component with default values 1`] = ` | ||
<div | ||
class="dusk-field-button-group" | ||
> | ||
<input | ||
autocomplete="off" | ||
class="dusk-textbox dusk-textbox-text" | ||
name="test" | ||
placeholder="" | ||
required="" | ||
tabindex="0" | ||
type="text" | ||
/> | ||
<!--<Textbox>--> | ||
<button | ||
class="dusk-button dusk-button--type--submit dusk-button--variant--secondary dusk-button--size--normal" | ||
type="submit" | ||
> | ||
<span | ||
class="dusk-button__text" | ||
> | ||
Submit | ||
</span> | ||
</button> | ||
<!--<Button>--> | ||
</div> | ||
`; | ||
|
||
exports[`FieldButtonGroup > updates input value on change 1`] = ` | ||
<div | ||
class="dusk-field-button-group" | ||
> | ||
<input | ||
autocomplete="off" | ||
class="dusk-textbox dusk-textbox-text" | ||
name="test" | ||
placeholder="" | ||
required="" | ||
tabindex="0" | ||
type="text" | ||
/> | ||
<!--<Textbox>--> | ||
<button | ||
class="dusk-button dusk-button--type--submit dusk-button--variant--secondary dusk-button--size--normal" | ||
type="submit" | ||
> | ||
<span | ||
class="dusk-button__text" | ||
> | ||
Submit | ||
</span> | ||
</button> | ||
<!--<Button>--> | ||
</div> | ||
`; |
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.