-
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
12,428 additions
and
5,330 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const nextJest = require("next/jest"); | ||
|
||
const createJestConfig = nextJest({ | ||
// Provide the path to your Next.js app to load next.config.js and .env files in your test environment | ||
dir: "./", | ||
}); | ||
|
||
// Add any custom config to be passed to Jest | ||
const customJestConfig = { | ||
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"], | ||
testEnvironment: "jest-environment-jsdom", | ||
}; | ||
|
||
// createJestConfig is exported this way to ensure that next/jest can load the Next.js config which is async | ||
module.exports = createJestConfig(customJestConfig); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Optional: configure or set up a testing framework before each test. | ||
// If you delete this file, remove `setupFilesAfterEnv` from `jest.config.js` | ||
|
||
// Used for __tests__/testing-library.js | ||
// Learn more: https://github.com/testing-library/jest-dom | ||
import "@testing-library/jest-dom/extend-expect"; |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-argument */ | ||
/* eslint-disable @typescript-eslint/no-unsafe-call */ | ||
import React from "react"; | ||
import { render, fireEvent, screen } from "@testing-library/react"; | ||
import InputField from "~/components/elements/inputField"; | ||
|
||
describe("InputField", () => { | ||
// ...existing code... | ||
|
||
test("renderInputs: renders form with input elements and buttons", () => { | ||
const fields = [ | ||
{ | ||
name: "testField", | ||
initialValue: "Initial value", | ||
type: "text", | ||
placeholder: "Test placeholder", | ||
}, | ||
]; | ||
|
||
const submitHandler = jest.fn(); | ||
|
||
const { container } = render( | ||
<InputField | ||
label="Test Label" | ||
fields={fields} | ||
submitHandler={submitHandler} | ||
/> | ||
); | ||
|
||
// Click the edit icon to render the inputs | ||
fireEvent.click(screen.getByTestId("edit-icon")); | ||
|
||
// Check if the form is rendered | ||
const formElement = container.querySelector("form"); | ||
expect(formElement).toBeInTheDocument(); | ||
|
||
// Check if the input elements are rendered | ||
const inputElement = screen.getByPlaceholderText("Test placeholder"); | ||
expect(inputElement).toBeInTheDocument(); | ||
|
||
// Check if the submit button is rendered | ||
const submitButton = screen.getByRole("button", { name: /submit/i }); | ||
expect(submitButton).toBeInTheDocument(); | ||
|
||
// Check if the cancel button is rendered | ||
const cancelButton = screen.getByRole("button", { name: /cancel/i }); | ||
expect(cancelButton).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { render, fireEvent, screen } from "@testing-library/react"; | ||
import Modal from "~/components/elements/modal"; | ||
import { useModalStore } from "~/utils/store"; | ||
|
||
jest.mock("../../utils/store", () => ({ | ||
useModalStore: jest.fn(), | ||
})); | ||
|
||
describe("Modal", () => { | ||
const closeModal = jest.fn(); | ||
const toggleModal = jest.fn(); | ||
const yesAction = jest.fn(); | ||
|
||
beforeEach(() => { | ||
(useModalStore as unknown as jest.Mock).mockImplementation(() => ({ | ||
isOpen: true, | ||
description: "Test description", | ||
title: "Test title", | ||
yesAction, | ||
toggleModal, | ||
closeModal, | ||
})); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("renders modal with title and description", () => { | ||
render(<Modal />); | ||
expect(screen.getByText("Test title")).toBeInTheDocument(); | ||
expect(screen.getByText("Test description")).toBeInTheDocument(); | ||
}); | ||
|
||
test("handles yes and cancel actions", () => { | ||
render(<Modal />); | ||
fireEvent.click(screen.getByText("Yes")); | ||
expect(yesAction).toHaveBeenCalledTimes(1); | ||
expect(toggleModal).toHaveBeenCalledTimes(1); | ||
|
||
fireEvent.click(screen.getByText("Cancle")); | ||
expect(closeModal).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,8 @@ | |
"**/*.ts", | ||
"**/*.tsx", | ||
"**/*.cjs", | ||
"**/*.mjs" | ||
"**/*.mjs", | ||
"jest.config.js" | ||
], | ||
"exclude": ["node_modules"] | ||
} |