Added test for renewing image when any button is clicked

This commit is contained in:
Sugui 2024-03-03 12:33:28 +01:00
parent 5aa75bc12d
commit cb266e1704
2 changed files with 24 additions and 8 deletions

View File

@ -1,8 +0,0 @@
import React from "react";
import { render } from "@testing-library/react";
import { describe, it } from "bun:test";
import ImageModerator from '../src/components/ImageModerator/ImageModerator';
it("should render without crashing", () => {
render(<ImageModerator apiEndpoint='"https://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=1&json=1"' imageUrlProperty='post[0]' />);
});

View File

@ -0,0 +1,24 @@
import React from "react";
import { render, screen } from "@testing-library/react";
import { describe, expect, it } from "bun:test";
import ImageModerator from '../../src/components/ImageModerator/ImageModerator';
it("should render into the document", () => {
render(<ImageModerator apiEndpoint='"https://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=1&json=1"' imageUrlProperty='post[0]' />);
});
it("should show a new image when accept button is clicked", () => {
const acceptButton = screen.getByText("Accept");
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("Discard");
const imgElement = screen.getByRole("img");
const imgElementSrcBefore = imgElement.getAttribute("src");
discardButton.click()
expect(imgElement.getAttribute("src")).not.toEqual(imgElementSrcBefore);
});