-
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.
Showing
7 changed files
with
783 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
web-wallet/src/lib/components/DashboardNav/DashboardNav.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,76 @@ | ||
<svelte:options immutable={true} /> | ||
|
||
<script> | ||
import { mdiChevronLeft, mdiChevronRight } from "@mdi/js"; | ||
Check failure on line 4 in web-wallet/src/lib/components/DashboardNav/DashboardNav.svelte GitHub Actions / Node 20.x
|
||
import { createEventDispatcher, onMount } from "svelte"; | ||
Check failure on line 5 in web-wallet/src/lib/components/DashboardNav/DashboardNav.svelte GitHub Actions / Node 20.x
|
||
import { AppAnchor } from "$lib/components"; | ||
import { Card, Icon } from "$lib/dusk/components"; | ||
import { makeClassName } from "$lib/dusk/string"; | ||
/** @type {String | Undefined} */ | ||
export let className = undefined; | ||
/** @type {DashboardNavItem[]} */ | ||
export let items; | ||
</script> | ||
|
||
{#if items && items.length} | ||
<nav {...$$restProps} class={makeClassName(["dashboard-nav", className])}> | ||
<ul class="dashboard-nav-list"> | ||
{#each items as item (item.id)} | ||
{@const { icons, id, label, href } = item} | ||
<li role="menuitem"> | ||
<AppAnchor {href} className="dashboard-nav-list__item"> | ||
<span class="dashboard-nav-item-label">{label}</span> | ||
{#if icons && icons.length} | ||
<span class="dashboard-nav-item-icons"> | ||
{#each icons as icon (icon.path)} | ||
<Icon path={icon.path} /> | ||
{/each} | ||
</span> | ||
{/if} | ||
</AppAnchor> | ||
</li> | ||
{/each} | ||
</ul> | ||
</nav> | ||
{/if} | ||
|
||
<style lang="postcss"> | ||
.dashboard-nav { | ||
background-color: var(--surface-color); | ||
border-radius: var(--control-border-radius-size); | ||
padding: 0.5rem 1.375rem; | ||
width: 100%; | ||
} | ||
.dashboard-nav-list { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
list-style: none; | ||
:global(&__item) { | ||
display: flex; | ||
flex-direction: row; | ||
align-items: center; | ||
justify-content: space-between; | ||
gap: 0.625rem; | ||
} | ||
.dashboard-nav-item-label { | ||
color: var(--on-surface-color); | ||
font-size: 1.125rem; | ||
font-style: normal; | ||
font-weight: 500; | ||
line-height: 1.6875rem; | ||
} | ||
.dashboard-nav-item-icons { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 0.625rem; | ||
} | ||
} | ||
</style> |
124 changes: 124 additions & 0 deletions
124
web-wallet/src/lib/components/__tests__/DashboardNav.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,124 @@ | ||
import { afterEach, describe, expect, it } from "vitest"; | ||
import { cleanup, render } from "@testing-library/svelte"; | ||
import { DashboardNav } from ".."; | ||
import { mdiPlusBoxOutline, mdiSwapHorizontal, mdiTimerSand } from "@mdi/js"; | ||
|
||
describe("DashboardNav", () => { | ||
const baseProps = { | ||
items: [ | ||
{ | ||
href: "#", | ||
id: "item-1", | ||
label: "Something", | ||
}, | ||
{ | ||
href: "#", | ||
icons: [], | ||
id: "item-2", | ||
label: "Send", | ||
}, | ||
{ | ||
href: "#", | ||
icons: [{ path: mdiTimerSand }], | ||
id: "item-3", | ||
label: "Receive", | ||
}, | ||
{ | ||
href: "#", | ||
icons: [ | ||
{ path: mdiTimerSand }, | ||
{ path: mdiSwapHorizontal }, | ||
{ path: mdiPlusBoxOutline }, | ||
], | ||
id: "item-4", | ||
label: "Stake", | ||
}, | ||
], | ||
}; | ||
const baseOptions = { | ||
props: baseProps, | ||
target: document.body, | ||
}; | ||
|
||
afterEach(cleanup); | ||
|
||
it("renders the DashboardNav component", () => { | ||
const { container } = render(DashboardNav, baseOptions); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should pass additional class names and attributes to the rendered element", async () => { | ||
const props = { | ||
...baseProps, | ||
className: "foo bar", | ||
}; | ||
const { container, rerender } = render(DashboardNav, { | ||
...baseOptions, | ||
props, | ||
}); | ||
|
||
expect(container.firstChild).toHaveClass("foo bar"); | ||
|
||
await rerender({ | ||
...props, | ||
className: "qux", | ||
}); | ||
|
||
expect(container.firstChild).toHaveClass("qux"); | ||
}); | ||
|
||
it("should not display if the items array is undefined", () => { | ||
const props = { ...baseProps, items: undefined }; | ||
const { container } = render(DashboardNav, { ...baseOptions, props }); | ||
|
||
expect(container.querySelector(".dashboard-nav")).toBeNull(); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should not display if the items array is empty", () => { | ||
const props = { ...baseProps, items: [] }; | ||
const { container } = render(DashboardNav, { ...baseOptions, props }); | ||
|
||
expect(container.querySelector(".dashboard-nav")).toBeNull(); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should not display icons if the item's icons array is undefined", () => { | ||
const { container } = render(DashboardNav, baseProps); | ||
|
||
expect( | ||
container.querySelector( | ||
".dashboard-nav-list > li:nth-child(1) > .dashboard-nav-list__item > .dashboard-nav-item-icons" | ||
) | ||
).toBeNull(); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should not display icons if the item's icon array is empty", () => { | ||
const { container } = render(DashboardNav, baseProps); | ||
|
||
expect( | ||
container.querySelector( | ||
".dashboard-nav-list > li:nth-child(2) > .dashboard-nav-list__item > .dashboard-nav-item-icons" | ||
) | ||
).toBeNull(); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
|
||
it("should display icons if the item's icon array is present", () => { | ||
const { container } = render(DashboardNav, baseProps); | ||
|
||
expect( | ||
container.querySelector( | ||
".dashboard-nav-list > li:nth-child(3) > .dashboard-nav-list__item > .dashboard-nav-item-icons" | ||
) | ||
).toBeTruthy(); | ||
|
||
expect(container.firstChild).toMatchSnapshot(); | ||
}); | ||
}); |
Oops, something went wrong.