Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 33 additions & 6 deletions src/components/helpers/jsonforms/components/DataBox.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { render, screen } from "@testing-library/react";

import { DataBox } from "./DataBox";
import {DataBox, DataOrEmpty} from "./DataBox";

Check failure on line 3 in src/components/helpers/jsonforms/components/DataBox.test.tsx

View workflow job for this annotation

GitHub Actions / build (22.20.0)

'DataOrEmpty' is defined but never used

Check failure on line 3 in src/components/helpers/jsonforms/components/DataBox.test.tsx

View workflow job for this annotation

GitHub Actions / build (22.20.0)

Replace `DataBox,·DataOrEmpty` with `·DataBox,·DataOrEmpty·`

const props = {
label: "A Label",
Expand All @@ -15,17 +15,44 @@
expect(screen.getByText(props.data)).toBeInTheDocument();
expect(container.querySelector("dd span.empty")).not.toBeInTheDocument();
});


Check failure on line 18 in src/components/helpers/jsonforms/components/DataBox.test.tsx

View workflow job for this annotation

GitHub Actions / build (22.20.0)

Delete `··`
test("Should render data if zero and label", () => {
const data = "0"

Check failure on line 20 in src/components/helpers/jsonforms/components/DataBox.test.tsx

View workflow job for this annotation

GitHub Actions / build (22.20.0)

Insert `;`
const { container } = render(<DataBox {...props} data={data} />);

Check failure on line 22 in src/components/helpers/jsonforms/components/DataBox.test.tsx

View workflow job for this annotation

GitHub Actions / build (22.20.0)

Delete `····`
expect(screen.getByText(props.label)).toBeInTheDocument();
expect(screen.getByText(data)).toBeInTheDocument();
expect(container.querySelector("dd span.empty")).not.toBeInTheDocument();
});

Check failure on line 27 in src/components/helpers/jsonforms/components/DataBox.test.tsx

View workflow job for this annotation

GitHub Actions / build (22.20.0)

Delete `··`
test("Should render data if zero number and label", () => {
const data = 0

Check failure on line 29 in src/components/helpers/jsonforms/components/DataBox.test.tsx

View workflow job for this annotation

GitHub Actions / build (22.20.0)

Insert `;`
const { container } = render(<DataBox {...props} data={data} />);

Check failure on line 31 in src/components/helpers/jsonforms/components/DataBox.test.tsx

View workflow job for this annotation

GitHub Actions / build (22.20.0)

Delete `····`
expect(screen.getByText(props.label)).toBeInTheDocument();
expect(screen.getByText(data)).toBeInTheDocument();
expect(container.querySelector("dd span.empty")).not.toBeInTheDocument();
});

Check failure on line 36 in src/components/helpers/jsonforms/components/DataBox.test.tsx

View workflow job for this annotation

GitHub Actions / build (22.20.0)

Delete `··`
test("Should render data if zero number and label", () => {
const data = 0.0

Check failure on line 38 in src/components/helpers/jsonforms/components/DataBox.test.tsx

View workflow job for this annotation

GitHub Actions / build (22.20.0)

Insert `;`
const { container } = render(<DataBox {...props} data={data} />);

expect(screen.getByText(props.label)).toBeInTheDocument();
expect(screen.getByText(data)).toBeInTheDocument();
expect(container.querySelector("dd span.empty")).not.toBeInTheDocument();
});

test("Should render '-' with empty data", () => {
const { container } = render(<DataBox {...props} data="" />);

expect(screen.getByText(props.label)).toBeInTheDocument();
expect(container.querySelector("dd span.empty")).toBeInTheDocument();
});

test("Should render '-' with null data", () => {
const { container } = render(<DataBox {...props} data={null} />);

test("Should render '-' with whitespace data", () => {
const { container } = render(<DataBox {...props} data=" " />);
expect(screen.getByText(props.label)).toBeInTheDocument();
expect(container.querySelector("dd span.empty")).toBeInTheDocument();
});
Expand Down
6 changes: 3 additions & 3 deletions src/components/helpers/jsonforms/components/DataBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { Box, Stack, Typography } from "@mui/material";

interface DataBoxProps {
label: string;
data?: string | null;
data?: string | number | null;
}

export const DataOrEmpty = ({ data }: { data?: string | null }) =>
data ? (
export const DataOrEmpty = ({ data }: { data?: string | number | null }) =>
(data !== undefined && data !== null && (typeof data !== "string" || data.trim() !== "")) ? (
data
) : (
<Typography
Expand Down
41 changes: 32 additions & 9 deletions src/components/helpers/jsonforms/components/DataCell.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,45 @@ import { render, screen } from "@testing-library/react";

import { DataCell } from "./DataCell";

const props = {
data: "Data 1234",
};

describe("DataCell", () => {
test("Should render data and label", () => {
const { container } = render(<DataCell {...props} />);
expect(screen.getByText(props.data)).toBeInTheDocument();
test("Should render data string", () => {
const data = "Data 1234"
const { container } = render(<DataCell data={data} />);
expect(screen.getByText(data)).toBeInTheDocument();
expect(container.querySelector("span.empty")).not.toBeInTheDocument();
});


test("Should render data with 0", () => {
const data = "0"
const { container } = render(<DataCell data={data} />);
expect(screen.getByText(data)).toBeInTheDocument();
expect(container.querySelector("span.empty")).not.toBeInTheDocument();
});

test("Should render data with 0 number", () => {
const data = 0
const { container } = render(<DataCell data={data} />);
expect(screen.getByText(data)).toBeInTheDocument();
expect(container.querySelector("span.empty")).not.toBeInTheDocument();
});

test("Should render data with 0.0 number", () => {
const data = 0.0
const { container } = render(<DataCell data={data} />);
expect(screen.getByText(data)).toBeInTheDocument();
expect(container.querySelector("span.empty")).not.toBeInTheDocument();
});

test("Should render '-' with empty data", () => {
const { container } = render(<DataCell data="" />);
expect(container.querySelector("span.empty")).toBeInTheDocument();
});


test("Should render '-' with whitespace data", () => {
const { container } = render(<DataCell data=" " />);
expect(container.querySelector("span.empty")).toBeInTheDocument();
});

test("Should render '-' with null data", () => {
const { container } = render(<DataCell data={null} />);
expect(container.querySelector("span.empty")).toBeInTheDocument();
Expand Down
2 changes: 1 addition & 1 deletion src/components/helpers/jsonforms/components/DataCell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Box, Typography } from "@mui/material";
import { DataOrEmpty } from "./DataBox";

interface DataCellProps {
data?: string | null;
data?: string | number | null;
}

const DataCell = ({ data }: DataCellProps) => (
Expand Down
Loading