@@ -37,4 +28,3 @@ const CopyToClipboardButton = ({ content }) => {
);
};
-export default CopyToClipboardButton;
diff --git a/frontend/src/pages/Lobby.jsx b/frontend/src/pages/Lobby.jsx
index fc9eb65..4dfc380 100644
--- a/frontend/src/pages/Lobby.jsx
+++ b/frontend/src/pages/Lobby.jsx
@@ -7,12 +7,13 @@ import { ListPlayers } from "../components/ListPlayers";
import { Card } from "../components/Card";
import { Header } from "../components/Header";
import { Footer } from "../components/Footer";
-import CopyToClipboardButton from "../components/CopyToClipboardButton";
+import { CopyToClipboardButton } from "../components/CopyToClipboardButton";
import { H1 } from "../components/H1";
-import { useEffect } from "react";
+import { useEffect, useState } from "react";
export function Lobby({ gameState, isHost, redirect, setRedirect}) {
const navigate = useNavigate();
+ const [isCopied, setIsCopied] = useState(false)
const handleClick = () => {
socket.emit("start_game");
@@ -38,6 +39,8 @@ export function Lobby({ gameState, isHost, redirect, setRedirect}) {
Share your game link:
diff --git a/frontend/tests/components/copyToClipboardButton.test.jsx b/frontend/tests/components/copyToClipboardButton.test.jsx
new file mode 100644
index 0000000..9ae6327
--- /dev/null
+++ b/frontend/tests/components/copyToClipboardButton.test.jsx
@@ -0,0 +1,51 @@
+//imports needed
+import { render, screen } from "@testing-library/react";
+import { describe, expect, test, vi } from "vitest";
+import { CopyToClipboardButton } from "../../src/components/CopyToClipboardButton";
+import userEvent from "@testing-library/user-event";
+
+vi.mock("../../src/socket.js", () => {
+ return { socket: { emit: vi.fn() } };
+});
+const setIsCopied = vi.fn();
+
+describe("Avatar dropdown", () => {
+ test("if is copied is true show copied svg", async () => {
+ render(
+
+ );
+ const imgEl = screen.getByTestId("copied-svg");
+ expect(imgEl).toBeDefined();
+ });
+ test("if is copied is false show clipbaord svg", async () => {
+ render(
+
+ );
+ const imgEl = screen.getByTestId("clipboard-svg");
+ expect(imgEl).toBeDefined();
+ });
+ test("when user clicks on copied", async () => {
+ const user = userEvent.setup();
+ render(
+
+ );
+ await user.click(screen.getByRole("button"));
+
+ const clipboardText = await navigator.clipboard.readText();
+
+ expect(clipboardText).toBe("test content");
+ expect(setIsCopied).toHaveBeenCalledWith(true)
+ });
+});
diff --git a/frontend/vite.config.js b/frontend/vite.config.js
index 10e8d12..9e9ecee 100644
--- a/frontend/vite.config.js
+++ b/frontend/vite.config.js
@@ -28,7 +28,8 @@ export default defineConfig({
"**/.{eslint,mocha,prettier}rc.{?(c|m)js,yml}",
"**/*.config.*",
"**/socket.js",
- "**/main.jsx"
+ "**/main.jsx",
+ "**/assets/**"
],
},
},