Skip to content

Commit

Permalink
[web] Simplify the change product link
Browse files Browse the repository at this point in the history
The logic for not rendering it when already on the product selection page is no
longer needed now that it's rendered on demand (when the user is on the
Overview page at this moment).
  • Loading branch information
dgdavid committed Mar 13, 2023
1 parent 2c71202 commit c6b2ccb
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 22 deletions.
8 changes: 2 additions & 6 deletions web/src/components/software/ChangeProductLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,14 @@
*/

import React from "react";
import { Link, useLocation } from "react-router-dom";
import { Link } from "react-router-dom";
import { useSoftware } from "~/context/software";
import { Icon } from "~/components/layout";

export default function ChangeProductLink() {
const { products } = useSoftware();
const { pathname } = useLocation();
const multiProduct = products?.length > 1;

if (!multiProduct || pathname === "/products") {
return null;
}
if (products?.length === 1) return null;

return (
<Link to="/products">
Expand Down
17 changes: 1 addition & 16 deletions web/src/components/software/ChangeProductLink.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import React from "react";
import { screen, waitFor } from "@testing-library/react";
import { installerRender, mockRoutes } from "~/test-utils";
import { installerRender } from "~/test-utils";
import { createClient } from "~/client";
import { ChangeProductLink } from "~/components/software";

Expand All @@ -48,21 +48,6 @@ beforeEach(() => {
});

describe("ChangeProductLink", () => {
describe("when it's already in the product selection path", () => {
beforeEach(() => {
mockRoutes("/products");
mockProducts = [
{ id: "openSUSE", name: "openSUSE Tumbleweed" },
{ id: "Leap Micro", name: "openSUSE Micro" }
];
});

it("renders nothing", async () => {
const { container } = installerRender(<ChangeProductLink />);
await waitFor(() => expect(container).toBeEmptyDOMElement());
});
});

describe("when there is only a single product", () => {
beforeEach(() => {
mockProducts = [
Expand Down

0 comments on commit c6b2ccb

Please sign in to comment.