/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import React from "react";
import { render, screen } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import TableWidget from "../TableWidget";
import { library } from "@fortawesome/fontawesome-svg-core";
import { faCaretUp, faCaretDown } from "@fortawesome/free-solid-svg-icons";
library.add(faCaretUp, faCaretDown);
test("renders the table title", async () => {
render(
,
{ wrapper: MemoryRouter },
);
expect(screen.getByText("test title")).toBeInTheDocument();
const summary = screen.getByText("test summary");
expect(summary).toBeInTheDocument();
expect(summary.closest("div")).toHaveClass("tableSummaryAbove");
});
test("renders the summary below the chart", async () => {
render(
,
{ wrapper: MemoryRouter },
);
const summary = screen.getByText("test summary");
expect(summary).toBeInTheDocument();
expect(summary.closest("div")).toHaveClass("tableSummaryBelow");
});
test("table preview should match snapshot", async () => {
const wrapper = render(
,
{ wrapper: MemoryRouter },
);
expect(wrapper.container).toMatchSnapshot();
});
test("table should not crash when a column header is an empty string", async () => {
render(
,
{ wrapper: MemoryRouter },
);
expect(screen.getByRole("table")).toBeInTheDocument();
expect(screen.getByText("Banana")).toBeInTheDocument();
expect(screen.getByText("Chocolate")).toBeInTheDocument();
expect(screen.getByText("Vanilla")).toBeInTheDocument();
});