-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
9d13a84
commit 04ecec8
Showing
8 changed files
with
133 additions
and
30 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
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,33 @@ | ||
import {render, screen, fireEvent} from "@testing-library/react"; | ||
import React from "react"; | ||
import ItemList from "@app/[locale]/components/general/ItemsList"; | ||
|
||
jest.mock("react-i18next", () => ({ | ||
useTranslation: () => ({ | ||
t: (key) => key | ||
}), | ||
})); | ||
|
||
const mockCourse = | ||
{ | ||
course_id: 1, | ||
name: "Course 1", | ||
description: "Description for Course 1", | ||
year: 2023, | ||
open_course: true, | ||
banner: null, | ||
}; | ||
|
||
|
||
|
||
describe("ItemList", () => { | ||
|
||
it("renders correctly", async () => { | ||
const mockSetItems = jest.fn(); | ||
render(<ItemList items={['test']} | ||
setItems={mockSetItems} | ||
empty_list_placeholder={"Test"} | ||
input_placeholder={"Input"} | ||
button_text={"Button"}/>); | ||
}); | ||
}); |
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,25 @@ | ||
import {render} from "@testing-library/react"; | ||
import React from "react"; | ||
import RequiredFilesList from "@app/[locale]/components/general/RequiredFilesList"; | ||
|
||
jest.mock("react-i18next", () => ({ | ||
useTranslation: () => ({ | ||
t: (key) => key | ||
}), | ||
})); | ||
|
||
|
||
describe("RequiredFilesList", () => { | ||
|
||
it("renders correctly", async () => { | ||
const mockSetItems = jest.fn(); | ||
render(<RequiredFilesList items={['test']} | ||
setItems={mockSetItems} | ||
empty_list_placeholder={"Test"} | ||
input_placeholder={"Input"} | ||
button_text={"Button"} | ||
items_status={["+", "-"]} | ||
setItemsStatus={jest.fn()} | ||
/>); | ||
}); | ||
}); |
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,11 @@ | ||
import {fireEvent, render, screen} from "@testing-library/react"; | ||
import React from "react"; | ||
import BackButton from "@app/[locale]/components/project_components/BackButton"; | ||
|
||
describe("BackButton", () => { | ||
it("render", async () => { | ||
render(<BackButton text={"back"} destination={"/home"}/>); | ||
const backButton = screen.getByRole("button", {name: /back/i}); | ||
fireEvent.click(backButton); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,40 +1,30 @@ | ||
import { render, screen, fireEvent } from "@testing-library/react"; | ||
import {render, screen, fireEvent} from "@testing-library/react"; | ||
import React from "react"; | ||
import RequiredFiles from "@app/[locale]/components/project_components/requiredFiles"; | ||
import { useTranslation } from "react-i18next"; // Import directly (optional) | ||
|
||
// Mock translations with actual translation logic (consider using a mocking library) | ||
jest.mock("react-i18next", () => ({ | ||
useTranslation: () => ({ | ||
t: (key) => { | ||
const translations = getTranslations(); // Replace with your translation retrieval logic | ||
return translations[key] || key; | ||
}, | ||
}), | ||
useTranslation: () => ({ | ||
t: (key) => key | ||
}), | ||
})); | ||
|
||
describe("RequiredFiles", () => { | ||
it("renders required files title and list with translations", async () => { | ||
const translations = await getTranslations(); | ||
render( | ||
<RequiredFiles | ||
files={["First", "Second"]} | ||
setFiles={jest.fn()} | ||
file_status={["+", "-"]} | ||
setFileStatus={jest.fn()} | ||
translations={translations.en} // Pass specific translations (optional) | ||
/> | ||
); | ||
it("renders required files title and list with translations", async () => { | ||
render( | ||
<RequiredFiles | ||
files={["First", "Second"]} | ||
setFiles={jest.fn()} | ||
file_status={["+", "-"]} | ||
setFileStatus={jest.fn()} | ||
/> | ||
); | ||
|
||
const title = screen.getByText(/required_files/i); // Match translated title partially | ||
const fileList = screen.getByRole("list"); | ||
const title = screen.getByText(/required_files/i); | ||
const fileList = screen.getByRole("list"); | ||
|
||
expect(title).toBeInTheDocument(); | ||
expect(fileList).toBeInTheDocument(); | ||
expect(title).toBeInTheDocument(); | ||
expect(fileList).toBeInTheDocument(); | ||
|
||
// Verify list items using translated data (consider data-testid or custom assertions) | ||
}); | ||
|
||
// Consider adding tests for RequiredFilesList behavior (adding/removing files, updating status) | ||
// Consider testing tooltip behavior if applicable | ||
}); | ||
}); |
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,10 @@ | ||
import {render, screen} from "@testing-library/react"; | ||
import React from "react"; | ||
import CancelButton from "@app/[locale]/components/user_components/CancelButton"; | ||
|
||
describe("CancelButton", () => { | ||
it("renders cancel button and click", async () => { | ||
render(<CancelButton/>); | ||
screen.getByText(/cancel/i).click(); | ||
}); | ||
}); |
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,34 @@ | ||
import {render, screen, fireEvent} from "@testing-library/react"; | ||
import React from "react"; | ||
import DeleteButton from "@app/[locale]/components/user_components/DeleteButton"; | ||
|
||
jest.mock("react-i18next", () => ({ | ||
useTranslation: () => ({ | ||
t: (key) => key | ||
}), | ||
})); | ||
|
||
|
||
jest.mock("../../lib/api", () => ({ | ||
deleteUser: jest.fn(() => Promise.resolve()), | ||
})); | ||
|
||
describe("DeleteButton", () => { | ||
it("render and delete", async () => { | ||
render(<DeleteButton userId={1}/>); | ||
|
||
const deleteButton = screen.getByRole("button", {name: /delete user/i}); | ||
expect(deleteButton).toBeInTheDocument(); | ||
|
||
fireEvent.click(deleteButton); | ||
|
||
const dialogTitle = screen.getByText("Are you sure you want to delete this user?"); | ||
const cancelButton = screen.getByRole("button", {name: /cancel/i}); | ||
const deleteButtonInDialog = screen.getByRole("button", {name: /delete/i}); | ||
|
||
fireEvent.click(cancelButton); | ||
|
||
fireEvent.click(deleteButton); | ||
fireEvent.click(deleteButtonInDialog); | ||
}); | ||
}); |