Skip to content

Commit 3e437fb

Browse files
committed
refactor: structured reorganization of car and irrigation components, import path alias update, and dead code removal
1 parent e1e3809 commit 3e437fb

File tree

25 files changed

+162
-288
lines changed

25 files changed

+162
-288
lines changed
Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
import { describe, it, expect, vi } from "vitest";
2+
import { render, screen, fireEvent } from "@testing-library/react";
3+
import { JostickController } from "./jostick-controller";
4+
import "@testing-library/jest-dom";
5+
6+
describe("JostickController", () => {
7+
const defaultMessage = {
8+
joystickDirection: "IDLE",
9+
buttonJostick: "off",
10+
remoteGyroscope: "LEVEL",
11+
};
12+
13+
const mockOnDirection = vi.fn();
14+
15+
it("renders all control buttons", () => {
16+
render(
17+
<JostickController
18+
recibedMessage={defaultMessage}
19+
onDirection={mockOnDirection}
20+
/>
21+
);
22+
23+
expect(screen.getByTestId("joystick-arriba")).toBeInTheDocument();
24+
expect(screen.getByTestId("joystick-abajo")).toBeInTheDocument();
25+
expect(screen.getByTestId("joystick-izquierda")).toBeInTheDocument();
26+
expect(screen.getByTestId("joystick-derecha")).toBeInTheDocument();
27+
expect(screen.getByTestId("joystick-center")).toBeInTheDocument();
28+
});
29+
30+
it("calls onDirection with 'Arriba' when the top button is clicked", () => {
31+
render(
32+
<JostickController
33+
recibedMessage={defaultMessage}
34+
onDirection={mockOnDirection}
35+
/>
36+
);
37+
38+
fireEvent.click(screen.getByTestId("joystick-arriba"));
39+
expect(mockOnDirection).toHaveBeenCalledWith("Arriba");
40+
});
41+
42+
it("calls onDirection with 'Abajo' when the bottom button is clicked", () => {
43+
render(
44+
<JostickController
45+
recibedMessage={defaultMessage}
46+
onDirection={mockOnDirection}
47+
/>
48+
);
49+
50+
fireEvent.click(screen.getByTestId("joystick-abajo"));
51+
expect(mockOnDirection).toHaveBeenCalledWith("Abajo");
52+
});
53+
54+
it("calls onDirection with 'Izquierda' when the left button is clicked", () => {
55+
render(
56+
<JostickController
57+
recibedMessage={defaultMessage}
58+
onDirection={mockOnDirection}
59+
/>
60+
);
61+
62+
fireEvent.click(screen.getByTestId("joystick-izquierda"));
63+
expect(mockOnDirection).toHaveBeenCalledWith("Izquierda");
64+
});
65+
66+
it("calls onDirection with 'Derecha' when the right button is clicked", () => {
67+
render(
68+
<JostickController
69+
recibedMessage={defaultMessage}
70+
onDirection={mockOnDirection}
71+
/>
72+
);
73+
74+
fireEvent.click(screen.getByTestId("joystick-derecha"));
75+
expect(mockOnDirection).toHaveBeenCalledWith("Derecha");
76+
});
77+
78+
it("calls onDirection with 'CENTER' when the center button is clicked", () => {
79+
render(
80+
<JostickController
81+
recibedMessage={defaultMessage}
82+
onDirection={mockOnDirection}
83+
/>
84+
);
85+
86+
fireEvent.click(screen.getByTestId("joystick-center"));
87+
expect(mockOnDirection).toHaveBeenCalledWith("CENTER");
88+
});
89+
90+
it("highlights the 'Arriba' button when joystickDirection is 'Arriba'", () => {
91+
const activeMessage = { ...defaultMessage, joystickDirection: "Arriba" };
92+
render(
93+
<JostickController
94+
recibedMessage={activeMessage}
95+
onDirection={mockOnDirection}
96+
/>
97+
);
98+
99+
expect(screen.getByTestId("joystick-arriba")).toHaveClass("active");
100+
});
101+
102+
it("highlights the 'Izquierda' button when remoteGyroscope is 'Izquierda'", () => {
103+
const activeMessage = { ...defaultMessage, remoteGyroscope: "Izquierda" };
104+
render(
105+
<JostickController
106+
recibedMessage={activeMessage}
107+
onDirection={mockOnDirection}
108+
/>
109+
);
110+
111+
expect(screen.getByTestId("joystick-izquierda")).toHaveClass("active");
112+
});
113+
114+
it("highlights the center button when buttonJostick is 'on'", () => {
115+
const activeMessage = { ...defaultMessage, buttonJostick: "on" };
116+
render(
117+
<JostickController
118+
recibedMessage={activeMessage}
119+
onDirection={mockOnDirection}
120+
/>
121+
);
122+
123+
expect(screen.getByTestId("joystick-center")).toHaveClass("active");
124+
});
125+
126+
it("applies the provided id to the container", () => {
127+
render(
128+
<JostickController
129+
id="custom-joystick-id"
130+
recibedMessage={defaultMessage}
131+
onDirection={mockOnDirection}
132+
/>
133+
);
134+
135+
const container = screen.getByTestId("jostick-container");
136+
expect(container).toHaveAttribute("id", "custom-joystick-id");
137+
});
138+
});

client/src/components/jostick-controller/jostick-controller.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const JostickController: React.FC<JostickControllerProps> = ({ recibedMes
4040
);
4141

4242
return (
43-
<Box id={id} className="jostick-container">
43+
<Box id={id} className="jostick-container" data-testid="jostick-container">
4444
{/* Connection Lines Decor */}
4545
<Box className="connection-lines" />
4646

client/src/pages/car/car-page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import { SimulationAlert } from "@/components/simulation-alert/simulation-alert"
66
import { robotService } from "@/pages/car/services/robot.service";
77

88
// Atomic Components
9-
import { CarHeader } from "./components/car-header";
10-
import { TelemetryCard } from "./components/kpi-cards/telemetry-card";
11-
import { ActuatorsCard } from "./components/kpi-cards/actuators-card";
9+
import { CarHeader } from "@/pages/car/components/car-header/car-header";
10+
import { TelemetryCard } from "@/pages/car/components/kpi-cards/telemetry-card";
11+
import { ActuatorsCard } from "@/pages/car/components/kpi-cards/actuators-card/actuators-card";
1212
import { RgbCard } from "@/pages/car/components/rgb-card/rgb-card";
13-
import { KineticCard } from "./components/kpi-cards/kinetic-card";
13+
import { KineticCard } from "@/pages/car/components/kpi-cards/kinetic-card";
1414

1515
export const CarPage: React.FC = () => {
1616
const {

client/src/pages/car/components/card-image/components/car-controller/car-controller.tsx renamed to client/src/pages/car/components/car-controller/car-controller.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Box, Typography } from "@mui/material";
22
import { IRemoteControlReceiveStatus } from "@/pages/car/models/model";
3-
import { SliderLineComponent } from "@/pages/car/components/sub-components/slider";
4-
import { InputNumber } from "@/pages/car/components/sub-components/input-number";
3+
import { SliderLineComponent } from "./components/slider";
4+
import { InputNumber } from "./components/input-number";
55

66
// Icons
77
import SpeedIcon from '@mui/icons-material/Speed';

client/src/pages/car/components/sub-components/input-number.tsx renamed to client/src/pages/car/components/car-controller/components/input-number.tsx

File renamed without changes.

client/src/pages/car/components/sub-components/slider.tsx renamed to client/src/pages/car/components/car-controller/components/slider.tsx

File renamed without changes.

client/src/pages/car/components/car-header.tsx renamed to client/src/pages/car/components/car-header/car-header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Box, Typography, Button, IconButton } from "@mui/material";
22
import PowerSettingsNewIcon from '@mui/icons-material/PowerSettingsNew';
3-
import { ConnectInfo } from "./connect-info";
3+
import { ConnectInfo } from "./components/connect-info";
44
import { useTranslation } from "react-i18next";
55

66
interface HeaderProps {

client/src/pages/car/components/connect-info.tsx renamed to client/src/pages/car/components/car-header/components/connect-info.tsx

File renamed without changes.

client/src/pages/car/components/card-image/components/arrow-control.tsx

Lines changed: 0 additions & 30 deletions
This file was deleted.

client/src/pages/car/components/card-image/components/button-image.tsx

Lines changed: 0 additions & 26 deletions
This file was deleted.

0 commit comments

Comments
 (0)