diff --git a/TODO b/TODO index 883743c..7af26f3 100644 --- a/TODO +++ b/TODO @@ -5,9 +5,9 @@ //TODO about page //TODO contact page needs working mailer //TODO font size on mobile screen -//TODO scroll to top button positioning -//TODO add test for return to top button //TODO SEO - next headers etc +//TODO data fetching tests +//TODO redo layer groups tests ---------------------------------------------------------------- //TODO logo for navbar and favicon //TODO mobile map needs improving diff --git a/components/ScrollToTopButton.tsx b/components/ScrollToTopButton.tsx index 6bfd93c..528492a 100644 --- a/components/ScrollToTopButton.tsx +++ b/components/ScrollToTopButton.tsx @@ -2,12 +2,17 @@ import { FaArrowUp } from "react-icons/fa"; import { handleScrollToTop } from "@/handlers/scrollHandlers"; +import { useEffect, useRef } from "react"; const ScrollToTopButton = ({ isLgScreen }: { isLgScreen: boolean }) => { + const scrollToTopElementRef = useRef(null); // determine scrollable element based on screen size - window or div - const scrollToTopElement = isLgScreen - ? document.getElementById("tournament-table") - : window; + useEffect(() => { + if (isLgScreen) { + scrollToTopElementRef.current = + document.getElementById("tournament-table"); + } + }, [isLgScreen]); const scrollToTopButtonClass = isLgScreen ? "absolute bottom-0 right-3 p-10" @@ -16,8 +21,13 @@ const ScrollToTopButton = ({ isLgScreen }: { isLgScreen: boolean }) => { return ( ); }; diff --git a/components/TournamentTable.tsx b/components/TournamentTable.tsx index 20c6af8..4740b75 100644 --- a/components/TournamentTable.tsx +++ b/components/TournamentTable.tsx @@ -75,6 +75,7 @@ export default function TournamentTable({
{ + it("desktop scroll button clickable", () => { + cy.viewport("macbook-15"); + cy.mount(); + cy.get("[data-cy='scroll-to-top-button']").should("exist").click(); + }); + + it("mobile scroll button clickable", () => { + cy.viewport(600, 600); + cy.mount(); + cy.get("[data-cy='scroll-to-top-button']").should("exist").click(); + }); +}); diff --git a/cypress/component/themeToggle.cy.tsx b/cypress/component/themeToggle.cy.tsx index 6475314..920e4f9 100644 --- a/cypress/component/themeToggle.cy.tsx +++ b/cypress/component/themeToggle.cy.tsx @@ -1,13 +1,10 @@ import React from "react"; import ThemeSwitcher from "../../components/ThemeSwitcher"; -import Home from "@/app/page"; import "@/css/theme-toggle.css"; describe("ThemeSwitcher component", () => { it("should toggle between light and dark mode", () => { - cy.mount(); cy.mount(); - cy.wait(100); // checking that the toggle is there and light mode is active cy.get("[data-cy='toggle']").should("exist"); diff --git a/cypress/e2e/scroll.cy.tsx b/cypress/e2e/scroll.cy.tsx new file mode 100644 index 0000000..81d9155 --- /dev/null +++ b/cypress/e2e/scroll.cy.tsx @@ -0,0 +1,26 @@ +describe("Scroll to top button", () => { + beforeEach(() => { + cy.visit("/tournois"); + }); + + it("desktop scroll to top", () => { + cy.viewport(1024, 800); + cy.get("[data-cy='tournament-table-div']").scrollTo("bottom"); + cy.get("[data-cy='scroll-to-top-button']").click(); + // cy.get("[data-cy='tournament-table-div']") + // .invoke("scrollTop") + // .should("equal", 0); + // cy.get("[data-cy='tournament-table-div']") + // .its("scrollY") + // .should("not.equal", 0); + // TODO need to test element scrolls back to 0 + }); + + it("mobile scroll to top", () => { + cy.viewport(600, 600); + cy.scrollTo("bottom"); + cy.window().its("scrollY").should("not.equal", 0); + cy.get("[data-cy='scroll-to-top-button']").click(); + cy.window().its("scrollY").should("equal", 0); + }); +}); diff --git a/cypress/videos/data.cy.tsx.mp4 b/cypress/videos/data.cy.tsx.mp4 index 32ea032..da8a0bd 100644 Binary files a/cypress/videos/data.cy.tsx.mp4 and b/cypress/videos/data.cy.tsx.mp4 differ diff --git a/cypress/videos/links.cy.ts.mp4 b/cypress/videos/links.cy.ts.mp4 index 922b010..6702f32 100644 Binary files a/cypress/videos/links.cy.ts.mp4 and b/cypress/videos/links.cy.ts.mp4 differ diff --git a/cypress/videos/navbar.cy.tsx.mp4 b/cypress/videos/navbar.cy.tsx.mp4 index 2b370c7..9c8c0e7 100644 Binary files a/cypress/videos/navbar.cy.tsx.mp4 and b/cypress/videos/navbar.cy.tsx.mp4 differ diff --git a/cypress/videos/scroll.cy.tsx.mp4 b/cypress/videos/scroll.cy.tsx.mp4 new file mode 100644 index 0000000..84b62b8 Binary files /dev/null and b/cypress/videos/scroll.cy.tsx.mp4 differ