mirror of
https://github.com/fleetdm/fleet
synced 2026-04-21 21:47:20 +00:00
relates to #19433 Makes the rendering of empty text cell values consistent. We also want to render the '0' value as a number instead of the default value `---` with greyed styles. **Before:**  **After:**  - [x] Changes file added for user-visible changes in `changes/`, `orbit/changes/` or `ee/fleetd-chrome/changes`. - [x] Added/updated tests - [x] Manual QA for all new/changed functionality --------- Co-authored-by: Sarah Gillespie <73313222+gillespi314@users.noreply.github.com>
41 lines
1.7 KiB
TypeScript
41 lines
1.7 KiB
TypeScript
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();
|
|
});
|
|
|
|
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="" />);
|
|
expect(screen.getByText(DEFAULT_EMPTY_CELL_VALUE)).toBeInTheDocument();
|
|
});
|
|
|
|
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={() => ""} />);
|
|
expect(screen.getByText(DEFAULT_EMPTY_CELL_VALUE)).toBeInTheDocument();
|
|
});
|
|
|
|
it("uses the provided formatter function", () => {
|
|
render(<TextCell value="foo" formatter={() => "bar"} />);
|
|
expect(screen.getByText("bar")).toBeInTheDocument();
|
|
});
|
|
|
|
it("renders the value '0' as a number", () => {
|
|
render(<TextCell value={0} />);
|
|
expect(screen.getByText("0")).toBeInTheDocument();
|
|
});
|
|
});
|