2023-02-17 18:25:28 +00:00
|
|
|
import React from "react";
|
|
|
|
|
import { render, screen } from "@testing-library/react";
|
|
|
|
|
import { DEFAULT_EMPTY_CELL_VALUE } from "utilities/constants";
|
|
|
|
|
import TextCell from "./TextCell";
|
|
|
|
|
|
|
|
|
|
describe("TextCell", () => {
|
|
|
|
|
it("renders booleans as string", () => {
|
|
|
|
|
render(<TextCell value={false} />);
|
|
|
|
|
expect(screen.getByText("false")).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-11 11:54:24 +00:00
|
|
|
it("renders a default value when `value` is null, undefined, or an empty string", () => {
|
|
|
|
|
const { rerender } = render(<TextCell value={null} />);
|
|
|
|
|
expect(screen.getByText(DEFAULT_EMPTY_CELL_VALUE)).toBeInTheDocument();
|
|
|
|
|
rerender(<TextCell value={undefined} />);
|
|
|
|
|
expect(screen.getByText(DEFAULT_EMPTY_CELL_VALUE)).toBeInTheDocument();
|
|
|
|
|
rerender(<TextCell value="" />);
|
2023-02-17 18:25:28 +00:00
|
|
|
expect(screen.getByText(DEFAULT_EMPTY_CELL_VALUE)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
2024-06-11 11:54:24 +00:00
|
|
|
it("renders a default value when `value` is null, undefined, or an empty string after formatting", () => {
|
|
|
|
|
const { rerender } = render(
|
|
|
|
|
<TextCell value="foo" formatter={() => null} />
|
|
|
|
|
);
|
|
|
|
|
expect(screen.getByText(DEFAULT_EMPTY_CELL_VALUE)).toBeInTheDocument();
|
|
|
|
|
rerender(<TextCell value="foo" formatter={() => undefined} />);
|
|
|
|
|
expect(screen.getByText(DEFAULT_EMPTY_CELL_VALUE)).toBeInTheDocument();
|
|
|
|
|
rerender(<TextCell value="foo" formatter={() => ""} />);
|
2023-02-17 18:25:28 +00:00
|
|
|
expect(screen.getByText(DEFAULT_EMPTY_CELL_VALUE)).toBeInTheDocument();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("uses the provided formatter function", () => {
|
2024-02-23 14:57:18 +00:00
|
|
|
render(<TextCell value="foo" formatter={() => "bar"} />);
|
2023-02-17 18:25:28 +00:00
|
|
|
expect(screen.getByText("bar")).toBeInTheDocument();
|
|
|
|
|
});
|
2024-06-11 11:54:24 +00:00
|
|
|
|
|
|
|
|
it("renders the value '0' as a number", () => {
|
|
|
|
|
render(<TextCell value={0} />);
|
|
|
|
|
expect(screen.getByText("0")).toBeInTheDocument();
|
|
|
|
|
});
|
2023-02-17 18:25:28 +00:00
|
|
|
});
|