-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #457 from w3bdesign/develop
New loading spinner
- Loading branch information
Showing
3 changed files
with
57 additions
and
70 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 |
---|---|---|
@@ -1,42 +1,41 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import "@testing-library/jest-dom"; | ||
import RotatingLoader from "../../src/components/Animations/RotatingLoader.component"; | ||
|
||
// Mock framer-motion to avoid issues with animations in tests | ||
jest.mock("framer-motion", () => ({ | ||
motion: { | ||
div: ({ children, ...props }) => <div {...props}>{children}</div>, | ||
}, | ||
})); | ||
|
||
describe("RotatingLoader", () => { | ||
it("renders without crashing", () => { | ||
render(<RotatingLoader />); | ||
}); | ||
|
||
it("renders the correct number of motion divs", () => { | ||
const { container } = render(<RotatingLoader />); | ||
const motionDivs = container.querySelectorAll(".bg-green-500"); | ||
expect(motionDivs.length).toBe(4); | ||
}); | ||
|
||
it("has the correct structure", () => { | ||
const { container } = render(<RotatingLoader />); | ||
|
||
// Check for the main wrapper div | ||
const wrapperDiv = container.firstChild; | ||
expect(wrapperDiv).toHaveClass("flex items-center justify-center"); | ||
|
||
// Check for the rotating container | ||
const rotatingContainer = wrapperDiv.firstChild; | ||
expect(rotatingContainer).toHaveClass("relative h-12 w-12"); | ||
|
||
// Check for the individual motion divs | ||
const motionDivs = rotatingContainer.children; | ||
expect(motionDivs.length).toBe(4); | ||
expect(wrapperDiv).toHaveClass("grid min-h-[140px] w-full place-items-center"); | ||
|
||
// Check for the SVG element | ||
const svg = container.querySelector("svg"); | ||
expect(svg).toBeInTheDocument(); | ||
expect(svg).toHaveClass("animate-spin"); | ||
|
||
// Check for the paths with Matrix theme colors | ||
const paths = container.querySelectorAll("path"); | ||
expect(paths.length).toBe(2); | ||
expect(paths[0]).toHaveClass("stroke-matrix-dark"); | ||
expect(paths[1]).toHaveClass("stroke-matrix-light"); | ||
}); | ||
|
||
Array.from(motionDivs).forEach((div) => { | ||
expect(div).toHaveClass("absolute h-4 w-4 rounded-full bg-green-500"); | ||
}); | ||
it("has the correct animations", () => { | ||
const { container } = render(<RotatingLoader />); | ||
|
||
// Check for glow animation container | ||
const glowContainer = container.querySelector(".animate-matrix-glow"); | ||
expect(glowContainer).toBeInTheDocument(); | ||
|
||
// Check for spin animation on SVG | ||
const svg = container.querySelector("svg"); | ||
expect(svg).toHaveClass("animate-spin"); | ||
}); | ||
}); |
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,54 +1,37 @@ | ||
import { motion } from "framer-motion"; | ||
|
||
/** | ||
* RotatingLoader component | ||
* Renders a rotating loader animation with four circular elements | ||
* Renders a rotating loader animation with Matrix theme | ||
* @returns {JSX.Element} The rendered RotatingLoader component | ||
*/ | ||
export default function RotatingLoader() { | ||
const rotateVariants = { | ||
rotate: { | ||
rotate: 360, | ||
transition: { | ||
duration: 1.5, | ||
repeat: Infinity, | ||
ease: "linear", | ||
}, | ||
}, | ||
}; | ||
|
||
export default function RotatingLoader() { | ||
return ( | ||
<div className="flex items-center justify-center"> | ||
<motion.div | ||
className="relative h-12 w-12" | ||
variants={rotateVariants} | ||
animate="rotate" | ||
> | ||
<motion.div | ||
className="absolute left-0 top-0 h-4 w-4 rounded-full bg-green-500" | ||
initial="initial" | ||
animate="animate" | ||
transition={{ delay: 0 }} | ||
></motion.div> | ||
<motion.div | ||
className="absolute right-0 top-0 h-4 w-4 rounded-full bg-green-500" | ||
initial="initial" | ||
animate="animate" | ||
transition={{ delay: 0.2 }} | ||
></motion.div> | ||
<motion.div | ||
className="absolute bottom-0 left-0 h-4 w-4 rounded-full bg-green-500" | ||
initial="initial" | ||
animate="animate" | ||
transition={{ delay: 0.4 }} | ||
></motion.div> | ||
<motion.div | ||
className="absolute bottom-0 right-0 h-4 w-4 rounded-full bg-green-500" | ||
initial="initial" | ||
animate="animate" | ||
transition={{ delay: 0.6 }} | ||
></motion.div> | ||
</motion.div> | ||
<div className="grid min-h-[140px] w-full place-items-center overflow-x-scroll rounded-lg p-6 lg:overflow-visible"> | ||
<div className="animate-matrix-glow"> | ||
<svg | ||
className="animate-spin" | ||
viewBox="0 0 64 64" | ||
fill="none" | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="64" | ||
height="64" | ||
> | ||
<path | ||
d="M32 3C35.8083 3 39.5794 3.75011 43.0978 5.20749C46.6163 6.66488 49.8132 8.80101 52.5061 11.4939C55.199 14.1868 57.3351 17.3837 58.7925 20.9022C60.2499 24.4206 61 28.1917 61 32C61 35.8083 60.2499 39.5794 58.7925 43.0978C57.3351 46.6163 55.199 49.8132 52.5061 52.5061C49.8132 55.199 46.6163 57.3351 43.0978 58.7925C39.5794 60.2499 35.8083 61 32 61C28.1917 61 24.4206 60.2499 20.9022 58.7925C17.3837 57.3351 14.1868 55.199 11.4939 52.5061C8.801 49.8132 6.66487 46.6163 5.20749 43.0978C3.7501 39.5794 3 35.8083 3 32C3 28.1917 3.75011 24.4206 5.2075 20.9022C6.66489 17.3837 8.80101 14.1868 11.4939 11.4939C14.1868 8.80099 17.3838 6.66487 20.9022 5.20749C24.4206 3.7501 28.1917 3 32 3L32 3Z" | ||
className="stroke-matrix-dark" | ||
strokeWidth="5" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
></path> | ||
<path | ||
d="M32 3C36.5778 3 41.0906 4.08374 45.1692 6.16256C49.2477 8.24138 52.7762 11.2562 55.466 14.9605C58.1558 18.6647 59.9304 22.9531 60.6448 27.4748C61.3591 31.9965 60.9928 36.6232 59.5759 40.9762" | ||
className="stroke-matrix-light" | ||
strokeWidth="5" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
></path> | ||
</svg> | ||
</div> | ||
</div> | ||
); | ||
} |
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