Skip to content

Commit 5407dab

Browse files
authored
fix(deploy): resolve production routing and asset paths for GitHub Pages
## 🐞 Bug Fix This MR addresses critical issues preventing the application from rendering correcty on GitHub Pages (subdirectory deployment). ## πŸ“ Changes ### 1. πŸ›£οΈ Routing (Subdirectory Support) - **Vite:** Updated `base` configuration to `/test-abb/` to serve assets from the correct subdirectory. - **React Router:** Added `basename="/test-abb"` to ensure client-side routing works within the hosted folder. - **Cypress:** Updated `baseUrl` and navigation assertions in E2E tests to match the new subdirectory structure. ### 2. πŸ–ΌοΈ Asset Management - **Broken Images:** Moved `public` images ([banner.jpg](cci:7://file:///home/lupy/Documentos/CV/tech_test_ABB/test-abb/public/banner.jpg:0:0-0:0), [hero.png](cci:7://file:///home/lupy/Documentos/CV/tech_test_ABB/test-abb/public/hero.png:0:0-0:0), etc.) to `src/assets`. - **Import Strategy:** Refactored components to import images directly. This forces Vite to hash and bundle them correctly, resolving 404 errors in production. ## βœ… Verification - **Local:** Verified via `yarn build` + `yarn preview`. - **CI/CD:** Pipeline passing (all E2E tests updated and green).
2 parents 3ee347f + 6c279d4 commit 5407dab

12 files changed

Lines changed: 20 additions & 13 deletions

File tree

β€Žcypress.config.tsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { defineConfig } from "cypress";
22

33
export default defineConfig({
44
e2e: {
5-
baseUrl: "http://localhost:5173",
5+
baseUrl: "http://localhost:5173/test-abb",
66
// SOLUCIΓ“N: ResoluciΓ³n Full HD para que el banner no tape nada
77
viewportWidth: 1920,
88
viewportHeight: 1080,

β€Žcypress/e2e/navbar.cy.tsβ€Ž

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@ describe("testing navbar functions", () => {
55

66
it("clicking on products works properly", () => {
77
cy.get('[data-test="main-products"]').click({ force: true });
8-
cy.location("pathname").should("equal", "/products");
8+
cy.location("pathname").should("contain", "/products");
99
});
1010

1111
it("clicking on products works properly", () => {
1212
cy.get('[data-test="main-logo"]').click({ force: true });
13-
cy.location("pathname").should("equal", "/");
13+
// Verify it goes back to root (which is /test-abb/)
14+
cy.location("pathname").should("match", /\/test-abb\/?$/);
1415
});
1516

1617
it.skip("clicking on a product works properly", () => {
1718
cy.get('[data-test="product-card"]').first().click({ force: true });
18-
cy.location("pathname").should("equal", "/product/1");
19+
cy.location("pathname").should("contain", "/product/1");
1920
});
2021

2122
it("login & logout works properly", () => {

β€Žsrc/components/Banner.tsxβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { FC } from "react";
22
import { Link } from "react-router-dom";
33

4+
import banner from "../assets/banner.jpg";
5+
46
const Banner: FC = () => (
57
<div className="container mt-8 mx-auto px-4 md:flex font-lora">
6-
<img src="/banner.jpg" alt="banner" className="md:w-1/2" />
8+
<img src={banner} alt="banner" className="md:w-1/2" />
79
<div className="bg-[#e3edf6] dark:bg-slate-600 dark:text-white md:w-1/2 flex flex-col items-center text-center justify-center p-4">
810
<h1 className="text-4xl font-bold mb-1">Don't miss the offer</h1>
911
<h2 className="text-3xl font-semibold mb-4">Grab it now</h2>

β€Žsrc/components/BannerPopup.tsxβ€Ž

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { FC } from "react";
22
import { useAppDispatch, useAppSelector } from "../redux/hooks";
33
import { updateBanner } from "../redux/features/homeSlice";
4+
import banner from "../assets/banner.jpg";
45

56
const BannerPopup: FC = () => {
67
const show = useAppSelector((state) => state.homeReducer.isBannerVisible);
@@ -10,13 +11,12 @@ const BannerPopup: FC = () => {
1011

1112
return (
1213
<div
13-
className={`fixed inset-0 flex items-center justify-center z-50 bg-black bg-opacity-50 transition-opacity duration-300 ${
14-
show ? "opacity-100" : "opacity-0 pointer-events-none"
15-
}`}
14+
className={`fixed inset-0 flex items-center justify-center z-50 bg-black bg-opacity-50 transition-opacity duration-300 ${show ? "opacity-100" : "opacity-0 pointer-events-none"
15+
}`}
1616
>
1717
<div className="relative">
1818
<img
19-
src="/banner.jpg"
19+
src={banner}
2020
alt="banner"
2121
className="w-[50vw] min-w-[300px] m-auto"
2222
/>

β€Žsrc/components/Cart.tsxβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { useAppDispatch, useAppSelector } from "../redux/hooks";
44
import { emptyCart, setCartState } from "../redux/features/cartSlice";
55
import CartRow from "./CartRow";
66
import toast from "react-hot-toast";
7+
import emptyCartImg from "../assets/emptyCart.jpg";
78

89
const Cart: FC = () => {
910
const dispatch = useAppDispatch();
@@ -78,7 +79,7 @@ const Cart: FC = () => {
7879
items.map((item) => <CartRow key={item.id} {...item} />)
7980
) : (
8081
<div className="flex flex-col justify-center items-center p-4">
81-
<img src="/emptyCart.jpg" alt="empty" className="w-40" />
82+
<img src={emptyCartImg} alt="empty" className="w-40" />
8283
<p className="text-center text-xl my-2">Your cart is empty</p>
8384
</div>
8485
)}

β€Žsrc/components/HeroSection.tsxβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { FC } from "react";
22
import { Link } from "react-router-dom";
3+
import hero from "../assets/hero.png";
34

45
const HeroSection: FC = () => {
56
return (
@@ -27,7 +28,7 @@ const HeroSection: FC = () => {
2728
</div>
2829
</div>
2930
<div>
30-
<img src="/hero.png" alt="hero" className="ml-auto" />
31+
<img src={hero} alt="hero" className="ml-auto" />
3132
</div>
3233
</div>
3334
</div>

β€Žsrc/main.tsxβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { BrowserRouter } from "react-router-dom";
66

77
ReactDOM.createRoot(document.getElementById("root")!).render(
88
<React.StrictMode>
9-
<BrowserRouter>
9+
<BrowserRouter basename="/test-abb">
1010
<App />
1111
</BrowserRouter>
1212
</React.StrictMode>

0 commit comments

Comments
Β (0)