bot-image-moderation-fe/test/unit/ImageModerator.test.tsx

32 lines
1.1 KiB
TypeScript

import { render, screen } from "@testing-library/react";
import { expect, it } from "bun:test";
import React from "react";
import ImageModerator, {
ImageModeratorProps,
} from "../../src/components/ImageModerator/ImageModerator";
const properties: ImageModeratorProps = {
acceptLabel: "Accept",
discardLabel: "Discard",
};
it("should render into the document", () => {
render(<ImageModerator {...properties} />);
});
it("should show a new image when accept button is clicked", () => {
const acceptButton = screen.getByText(properties.acceptLabel);
const imgElement = screen.getByRole("img");
const imgElementSrcBefore = imgElement.getAttribute("src");
acceptButton.click();
expect(imgElement.getAttribute("src")).not.toEqual(imgElementSrcBefore);
});
it("should show a new image when discard button is clicked", () => {
const discardButton = screen.getByText(properties.discardLabel);
const imgElement = screen.getByRole("img");
const imgElementSrcBefore = imgElement.getAttribute("src");
discardButton.click();
expect(imgElement.getAttribute("src")).not.toEqual(imgElementSrcBefore);
});