Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
anjula-sack committed Aug 27, 2024
1 parent 45786ea commit 92e785b
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Screens/DemoUserLogin.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { render } from "@testing-library/react";
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
import DemoUserLogin from "./DemoUserLogin";

jest.mock("../config/Common", () => ({
doConnect: jest.fn(),
doFileConnect: jest.fn(),
}));

describe("Demo User Login component", () => {
const initialState = {};
const mockStore = configureStore();
let store;

beforeEach(() => {
store = mockStore(initialState);
});

it.skip("renders without crashing", () => {
render(
<Provider store={store}>
<DemoUserLogin />
</Provider>
);
});
});
73 changes: 73 additions & 0 deletions src/Screens/ImageManager.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import React from "react";
import { render, fireEvent } from "@testing-library/react";
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
import ImageManager from "./ImageManager";
import { doConnect, doFileConnect } from "../config/Common";

jest.mock("../config/Common", () => ({
doConnect: jest.fn(),
doFileConnect: jest.fn(),
}));

describe("ImageManager component", () => {
const initialState = {};
const mockStore = configureStore();
let store;

beforeEach(() => {
store = mockStore(initialState);
});

it.skip("renders without crashing", () => {
render(
<Provider store={store}>
<ImageManager />
</Provider>
);
});

it.skip("adds a new file successfully", async () => {
const { getByPlaceholderText, getByText, findByText } = render(
<Provider store={store}>
<ImageManager />
</Provider>
);

// Fill out the form fields
fireEvent.change(getByPlaceholderText("Enter Title"), {
target: { value: "Test Image" },
});
fireEvent.change(getByText("Level"), { target: { value: "image" } });

// Simulate a file upload
const fileInput =
getByText("Image").parentElement.querySelector('input[type="file"]');
fireEvent.change(fileInput, {
target: {
files: [new File(["Hello, World!"], "test.png", { type: "image/png" })],
},
});

// Click the submit button
fireEvent.click(getByText("Submit"));

// Wait for the successful toast notification
await findByText("Added data !");

// Expect the doConnect and doFileConnect functions to have been called
expect(doConnect).toHaveBeenCalledWith("addGameFile", "POST", {
title: "Test Image",
fileName: expect.any(String),
fileType: "image",
sessionId: "1223",
});
expect(doFileConnect).toHaveBeenCalledWith(
expect.objectContaining({
file: expect.any(File),
fileName: expect.any(String),
fileType: "image",
})
);
});
});
27 changes: 27 additions & 0 deletions src/Screens/QrCode.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { render } from "@testing-library/react";
import { Provider } from "react-redux";
import configureStore from "redux-mock-store";
import QrCode from "./QrCode";

jest.mock("../config/Common", () => ({
doConnect: jest.fn(),
doFileConnect: jest.fn(),
}));

describe("QR Code component", () => {
const initialState = {};
const mockStore = configureStore();
let store;

beforeEach(() => {
store = mockStore(initialState);
});

it.skip("renders without crashing", () => {
render(
<Provider store={store}>
<QrCode />
</Provider>
);
});
});

0 comments on commit 92e785b

Please sign in to comment.