-
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.
web-wallet: Add possibility to serve the web wallet from a sub folder
Resolves #1362
- Loading branch information
1 parent
871fb3c
commit fb8fe48
Showing
47 changed files
with
537 additions
and
77 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<svelte:options immutable={true}/> | ||
|
||
<script> | ||
import { Anchor } from "$lib/dusk/components"; | ||
import { addBasePath } from "$lib/navigation"; | ||
/** @type {string} */ | ||
export let href; | ||
</script> | ||
|
||
<Anchor | ||
{...$$restProps} | ||
href={addBasePath(href)} | ||
on:click | ||
> | ||
<slot/> | ||
</Anchor> |
15 changes: 15 additions & 0 deletions
15
web-wallet/src/lib/components/AppAnchorButton/AppAnchorButton.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,15 @@ | ||
<svelte:options immutable={true}/> | ||
|
||
<script> | ||
import { AnchorButton } from "$lib/dusk/components"; | ||
import { addBasePath } from "$lib/navigation"; | ||
/** @type {string} */ | ||
export let href; | ||
</script> | ||
|
||
<AnchorButton | ||
{...$$restProps} | ||
href={addBasePath(href)} | ||
on:click | ||
/> |
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
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
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,83 @@ | ||
import { | ||
afterEach, | ||
describe, | ||
expect, | ||
it, | ||
vi | ||
} from "vitest"; | ||
import { | ||
cleanup, | ||
fireEvent, | ||
render | ||
} from "@testing-library/svelte"; | ||
import { base } from "$app/paths"; | ||
|
||
import { renderWithSimpleContent } from "$lib/dusk/test-helpers"; | ||
|
||
import { AppAnchor } from ".."; | ||
|
||
describe("AppAnchor", () => { | ||
const baseProps = { | ||
className: "foo bar", | ||
href: "/setup", | ||
id: "some-id" | ||
}; | ||
const baseOptions = { | ||
props: baseProps, | ||
target: document.body | ||
}; | ||
|
||
afterEach(cleanup); | ||
|
||
it("should render an `Anchor` with the base path prepended to the `href` attribute, if the `href` represents an absolute URL", () => { | ||
const renderA = renderWithSimpleContent(AppAnchor, baseOptions); | ||
const anchorA = renderA.getByRole("link"); | ||
|
||
expect(renderA.container.firstChild).toMatchSnapshot(); | ||
expect(anchorA).toHaveAttribute("href", `${base}${baseProps.href}`); | ||
expect(anchorA).toHaveClass("foo bar"); | ||
expect(anchorA).toHaveAttribute("id", baseProps.id); | ||
|
||
cleanup(); | ||
|
||
const renderB = renderWithSimpleContent( | ||
AppAnchor, | ||
{ ...baseOptions, props: { ...baseProps, href: "/" } } | ||
); | ||
const anchorB = renderB.getByRole("link"); | ||
|
||
expect(anchorB).toHaveAttribute("href", `${base}/`); | ||
expect(anchorB).toHaveClass("foo bar"); | ||
expect(anchorB).toHaveAttribute("id", baseProps.id); | ||
}); | ||
|
||
it("should leave the `Anchor` as it is if the `href` points to a relative path", () => { | ||
const { getByRole } = renderWithSimpleContent( | ||
AppAnchor, | ||
{ ...baseOptions, props: { ...baseProps, href: "foo/bar" } } | ||
); | ||
|
||
expect(getByRole("link")).toHaveAttribute("href", "foo/bar"); | ||
}); | ||
|
||
it("should leave the `Anchor` as it is if the `href` points to an external URL", () => { | ||
const href = "http://example.com"; | ||
const { getByRole } = renderWithSimpleContent( | ||
AppAnchor, | ||
{ ...baseOptions, props: { ...baseProps, href } } | ||
); | ||
|
||
expect(getByRole("link")).toHaveAttribute("href", href); | ||
}); | ||
|
||
it("should forward the `onclick` event to the `Anchor`", async () => { | ||
const handler = vi.fn(); | ||
const { component, getByRole } = render(AppAnchor, { ...baseProps, href: "#" }); | ||
|
||
component.$on("click", handler); | ||
|
||
await fireEvent.click(getByRole("link")); | ||
|
||
expect(handler).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
67 changes: 67 additions & 0 deletions
67
web-wallet/src/lib/components/__tests__/AppAnchorButton.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,67 @@ | ||
import { | ||
afterEach, | ||
describe, | ||
expect, | ||
it, | ||
vi | ||
} from "vitest"; | ||
import { | ||
cleanup, | ||
fireEvent, | ||
render | ||
} from "@testing-library/svelte"; | ||
import { base } from "$app/paths"; | ||
|
||
import { AppAnchorButton } from ".."; | ||
|
||
describe("AppAnchorButton", () => { | ||
const baseProps = { | ||
className: "foo bar", | ||
href: "/setup", | ||
id: "some-id" | ||
}; | ||
|
||
afterEach(cleanup); | ||
|
||
it("should render an `AnchorButton` with the base path prepended to the `href` attribute, if the `href` represents an absolute URL", () => { | ||
const { container, getByRole, rerender } = render(AppAnchorButton, baseProps); | ||
const anchorA = getByRole("link"); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
expect(anchorA).toHaveAttribute("href", `${base}${baseProps.href}`); | ||
expect(anchorA).toHaveClass("foo bar"); | ||
expect(anchorA).toHaveAttribute("id", baseProps.id); | ||
|
||
rerender({ ...baseProps, href: "/" }); | ||
|
||
const anchorB = getByRole("link"); | ||
|
||
expect(anchorB).toHaveAttribute("href", `${base}/`); | ||
expect(anchorB).toHaveClass("foo bar"); | ||
expect(anchorB).toHaveAttribute("id", baseProps.id); | ||
}); | ||
|
||
it("should leave the `AnchorButton` as it is if the `href` points to a relative path", () => { | ||
const { getByRole } = render(AppAnchorButton, { ...baseProps, href: "foo/bar" }); | ||
|
||
expect(getByRole("link")).toHaveAttribute("href", "foo/bar"); | ||
}); | ||
|
||
it("should leave the `AnchorButton` as it is if the `href` points to an external URL", () => { | ||
const href = "http://example.com"; | ||
const { getByRole } = render(AppAnchorButton, { ...baseProps, href }); | ||
|
||
expect(getByRole("link")).toHaveAttribute("href", href); | ||
}); | ||
|
||
it("should forward the `onclick` event to the `AnchorButton`", async () => { | ||
const handler = vi.fn(); | ||
const { component, getByRole } = render(AppAnchorButton, { ...baseProps, href: "#" }); | ||
|
||
component.$on("click", handler); | ||
|
||
await fireEvent.click(getByRole("link")); | ||
|
||
expect(handler).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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
13 changes: 13 additions & 0 deletions
13
web-wallet/src/lib/components/__tests__/__snapshots__/AppAnchor.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,13 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`AppAnchor > should render an \`Anchor\` with the base path prepended to the \`href\` attribute, if the \`href\` represents an absolute URL 1`] = ` | ||
<a | ||
class="dusk-anchor foo bar" | ||
href="/some-base-path/setup" | ||
id="some-id" | ||
> | ||
<span> | ||
some text | ||
</span> | ||
</a> | ||
`; |
Oops, something went wrong.