Skip to content

Commit

Permalink
fix: route logo link to machine list page (#5211)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay-Topher committed Nov 23, 2023
1 parent 56c3913 commit f30ef33
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
4 changes: 2 additions & 2 deletions cypress/e2e/with-users/base/navigation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,12 @@ context("Navigation - admin", () => {
{ destinationUrl: "/zones", linkLabel: "AZs" },
];

it("navigates to /dashboard when clicking on the logo", () => {
it("navigates to machines when clicking on the logo", () => {
cy.waitForPageToLoad();
cy.getMainNavigation().within(() =>
cy.findByRole("link", { name: "Homepage" }).click()
);
cy.location("pathname").should("eq", generateMAASURL("/dashboard"));
cy.location("pathname").should("eq", generateMAASURL("/machines"));
});

expected.forEach(({ destinationUrl, linkLabel }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ describe("GlobalSideNav", () => {
state,
});

const currentMenuItem = screen.getAllByRole("link", { current: "page" })[0];
// Ensure that machine link is selected from within the nav
const sideNavigation = screen.getAllByRole("navigation")[0];
const currentMenuItem = within(sideNavigation).getAllByRole("link", {
current: "page",
})[0];
expect(currentMenuItem).toBeInTheDocument();
expect(currentMenuItem).toHaveTextContent("Machines");
});
Expand Down Expand Up @@ -265,7 +269,7 @@ describe("GlobalSideNav", () => {
).not.toBeInTheDocument();
});

it("links from the logo to the dashboard for admins", () => {
it("links from the logo to machine list page for admins", () => {
state.user.auth.user = userFactory({ is_superuser: true });
renderWithBrowserRouter(<AppSideNavigation />, {
route: "/machine/abc123",
Expand All @@ -278,15 +282,7 @@ describe("GlobalSideNav", () => {
name: "Homepage",
}
)
).toHaveAttribute("href", "/dashboard");
expect(
within(screen.getByRole("banner", { name: "main navigation" })).getByRole(
"link",
{
name: "Homepage",
}
)
).toHaveAttribute("href", "/dashboard");
).toHaveAttribute("href", "/machines");
});

it("links from the logo to the machine list for non admins", () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
import { Navigation } from "@canonical/maas-react-components";
import { useSelector } from "react-redux";
import { Link, useLocation } from "react-router-dom-v5-compat";

import { isSelected } from "../utils";

import urls from "app/base/urls";
import authSelectors from "app/store/auth/selectors";

const NavigationBanner = ({
children,
}: {
children?: React.ReactNode;
}): JSX.Element => {
const isAdmin = useSelector(authSelectors.isAdmin);
const location = useLocation();

const homepageLink = isAdmin
? { url: urls.dashboard.index, label: "Homepage" }
: { url: urls.machines.index, label: "Homepage" };
const homepageLink = { url: urls.machines.index, label: "Homepage" };
return (
<Navigation.Banner>
<Navigation.Logo
Expand Down

0 comments on commit f30ef33

Please sign in to comment.