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

32 lines
1.1 KiB
TypeScript
Raw Permalink Normal View History

import React from "react";
import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "bun:test";
2024-04-27 16:17:56 +00:00
import ImageModerator, {
ImageModeratorProps,
} from "../../src/components/ImageModerator/ImageModerator";
const properties: ImageModeratorProps = {
2024-04-27 16:17:56 +00:00
acceptLabel: "Accept",
discardLabel: "Discard",
};
it("should render into the document", () => {
2024-04-27 16:17:56 +00:00
render(<ImageModerator {...properties} />);
});
it("should show a new image when accept button is clicked", () => {
2024-04-27 16:17:56 +00:00
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", () => {
2024-04-27 16:17:56 +00:00
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);
});