Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(navigation): implement contextual back navigation for Neuron's page #6345

Merged
merged 2 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions frontend/src/routes/(app)/(u)/(list)/neurons/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import Content from "$lib/components/layout/Content.svelte";
import Layout from "$lib/components/layout/Layout.svelte";
import LayoutList from "$lib/components/layout/LayoutList.svelte";
import { AppPath } from "$lib/constants/routes.constants";
import { neuronsPageOrigin } from "$lib/derived/routes.derived";
import { i18n } from "$lib/stores/i18n";
const back = (): Promise<void> => goto(AppPath.Staking);
const back = (): Promise<void> => goto($neuronsPageOrigin);
</script>

<LayoutList title={$i18n.navigation.neurons}>
Expand Down
31 changes: 30 additions & 1 deletion frontend/src/tests/routes/app/neurons/layout.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { AppPath } from "$lib/constants/routes.constants";
import { pageStore } from "$lib/derived/page.derived";
import { layoutTitleStore } from "$lib/stores/layout.store";
import { referrerPathStore } from "$lib/stores/routes.store";
import { page } from "$mocks/$app/stores";
import NeuronsLayout from "$routes/(app)/(u)/(list)/neurons/+layout.svelte";
import { render } from "@testing-library/svelte";
import { get } from "svelte/store";
Expand All @@ -22,9 +24,36 @@ describe("Neurons layout", () => {
it("should have a back button", () => {
const { getByTestId } = render(NeuronsLayout);
const backButton = getByTestId("back");

expect(backButton).toBeInTheDocument();
expect(get(pageStore).path).not.toBe(AppPath.Staking);
});

it("should navigate back to Staking page", () => {
page.mock({
routeId: AppPath.Neurons,
});

const { getByTestId } = render(NeuronsLayout);
const backButton = getByTestId("back");

expect(get(pageStore).path).toEqual(AppPath.Neurons);
backButton.click();

expect(get(pageStore).path).toBe(AppPath.Staking);
});

it("should navigate back to Portfolio page if previous page was Portfolio page", async () => {
page.mock({
routeId: AppPath.Neurons,
});
referrerPathStore.pushPath(AppPath.Portfolio);

const { getByTestId } = render(NeuronsLayout);
const backButton = getByTestId("back");

expect(get(pageStore).path).toEqual(AppPath.Neurons);
backButton.click();

expect(get(pageStore).path).toBe(AppPath.Portfolio);
});
});