Skip to content

Commit

Permalink
Add DashboardMenu component
Browse files Browse the repository at this point in the history
Resolves #2074
  • Loading branch information
kieranhall committed Aug 14, 2024
1 parent dc0e3fc commit b6baead
Show file tree
Hide file tree
Showing 7 changed files with 783 additions and 0 deletions.
76 changes: 76 additions & 0 deletions web-wallet/src/lib/components/DashboardNav/DashboardNav.svelte
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

View workflow job for this annotation

GitHub Actions / Node 20.x

'mdiChevronLeft' is defined but never used

Check failure on line 4 in web-wallet/src/lib/components/DashboardNav/DashboardNav.svelte

View workflow job for this annotation

GitHub Actions / Node 20.x

'mdiChevronRight' is defined but never used
import { createEventDispatcher, onMount } from "svelte";

Check failure on line 5 in web-wallet/src/lib/components/DashboardNav/DashboardNav.svelte

View workflow job for this annotation

GitHub Actions / Node 20.x

'createEventDispatcher' is defined but never used

Check failure on line 5 in web-wallet/src/lib/components/DashboardNav/DashboardNav.svelte

View workflow job for this annotation

GitHub Actions / Node 20.x

'onMount' is defined but never used
import { AppAnchor } from "$lib/components";
import { Card, Icon } from "$lib/dusk/components";

Check failure on line 8 in web-wallet/src/lib/components/DashboardNav/DashboardNav.svelte

View workflow job for this annotation

GitHub Actions / Node 20.x

'Card' is defined but never used
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}

Check failure on line 22 in web-wallet/src/lib/components/DashboardNav/DashboardNav.svelte

View workflow job for this annotation

GitHub Actions / Node 20.x

'id' is assigned a value but never used
<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 web-wallet/src/lib/components/__tests__/DashboardNav.spec.js
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();
});
});
Loading

0 comments on commit b6baead

Please sign in to comment.