| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- /*
- Copyright (C) 2021 Cloudbase Solutions SRL
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as
- published by the Free Software Foundation, either version 3 of the
- License, or (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- import React from "react";
- import { render } from "@testing-library/react";
- import TestUtils from "@tests/TestUtils";
- import { NotificationItemData } from "@src/@types/NotificationItem";
- import progressImage from "@src/components/ui/StatusComponents/StatusIcon/images/progress";
- import { ThemePalette } from "@src/components/Theme";
- import DashboardActivity from ".";
- const encodedProgressImage = encodeURIComponent(
- progressImage(ThemePalette.grayscale[3], ThemePalette.primary),
- );
- jest.mock("react-router", () => ({ Link: "a" }));
- const ITEMS: NotificationItemData[] = [
- {
- id: "1",
- type: "replica",
- status: "ERROR",
- name: "Replica 1",
- description: "Replica 1 description",
- },
- {
- id: "2",
- type: "migration",
- status: "RUNNING",
- name: "Migration 1",
- description: "Migration 1 description",
- },
- {
- id: "3",
- type: "migration",
- status: "COMPLETED",
- name: "Migration 2",
- description: "Migration 2 description",
- },
- ];
- describe("DashboardActivity", () => {
- it("renders no recent activity", () => {
- render(<DashboardActivity notificationItems={[]} />);
- expect(
- TestUtils.select("DashboardActivity__Message")!.textContent,
- ).toContain("There is no recent activity");
- });
- it("fires new click", () => {
- const onNewClick = jest.fn();
- render(
- <DashboardActivity notificationItems={[]} onNewClick={onNewClick} />,
- );
- TestUtils.select("Button__StyledButton")!.click();
- expect(onNewClick).toHaveBeenCalled();
- });
- it("renders loading", () => {
- const { rerender } = render(
- <DashboardActivity notificationItems={[]} loading />,
- );
- expect(TestUtils.select("DashboardActivity__LoadingWrapper")).toBeTruthy();
- rerender(<DashboardActivity notificationItems={[]} />);
- expect(TestUtils.select("DashboardActivity__LoadingWrapper")).toBeFalsy();
- });
- it("renders all items", () => {
- render(<DashboardActivity notificationItems={ITEMS} />);
- const listItemsEl = TestUtils.selectAll("DashboardActivity__ListItem");
- expect(listItemsEl.length).toBe(ITEMS.length);
- });
- it.each`
- idx | href | expectedStatusIcon
- ${0} | ${"/deployments/1"} | ${"error-hollow.svg"}
- ${1} | ${"/deployments/2"} | ${encodedProgressImage}
- ${2} | ${"/deployments/3"} | ${"success-hollow.svg"}
- `("renders item with href $href", ({ idx, href, expectedStatusIcon }) => {
- render(<DashboardActivity notificationItems={ITEMS} />);
- const itemElement = TestUtils.selectAll("DashboardActivity__ListItem")[idx];
- expect(itemElement.getAttribute("to")).toBe(href);
- const background = window.getComputedStyle(
- TestUtils.select("StatusIcon__Wrapper", itemElement)!,
- ).background;
- expect(background).toContain(expectedStatusIcon);
- expect(
- TestUtils.select("NotificationDropdown__ItemTransferBadge", itemElement)!
- .textContent,
- ).toContain(ITEMS[idx].type === "transfer" ? "TR" : "DE");
- expect(
- TestUtils.select("NotificationDropdown__ItemTitle", itemElement)!
- .textContent,
- ).toContain(ITEMS[idx].name);
- expect(
- TestUtils.select("NotificationDropdown__ItemDescription", itemElement)!
- .textContent,
- ).toContain(ITEMS[idx].description);
- });
- });
|