-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap-settings.test.tsx
More file actions
131 lines (103 loc) · 3.83 KB
/
map-settings.test.tsx
File metadata and controls
131 lines (103 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import React from "react";
import { render, fireEvent } from "@testing-library/react-native";
import MapSettings from "@/components/map/indoor-map/indoor-map-settings";
jest.mock("@expo/vector-icons", () => {
const { Text } = require("react-native");
return {
Ionicons: ({ name }: { name: string }) => <Text>{name}</Text>,
};
});
jest.mock("@/hooks/use-color-scheme", () => ({
useColorScheme: () => "light",
}));
jest.mock("@/constants/theme", () => ({
Colors: {
light: {
mapSettings: {
fabBackground: "#fff",
fabIcon: "#000",
panelBackground: "#fff",
title: "#000",
icon: "#000",
text: "#000",
divider: "#eee",
toggleTrue: "#00f",
toggleFalse: "#ccc",
checkbox: "#00f",
},
},
},
}));
describe("MapSettings Component", () => {
const defaultProps = {
wheelchairOnly: false,
setWheelchairOnly: jest.fn(),
poiFilters: {
bathrooms: true,
elevators: false,
waterFountains: true,
stairs: false,
escalators: false,
},
setPoiFilters: jest.fn(),
};
beforeEach(() => {
jest.clearAllMocks();
});
it("should render only the FAB initially", () => {
const { queryByText } = render(<MapSettings {...defaultProps} />);
expect(queryByText("Settings")).toBeNull();
});
it("should open the settings panel when the FAB is pressed", () => {
const { getByText } = render(<MapSettings {...defaultProps} />);
const icon = getByText("settings-outline");
if (!icon.parent) throw new Error("FAB icon parent (TouchableOpacity) not found");
fireEvent.press(icon.parent);
expect(getByText("Settings")).toBeTruthy();
expect(getByText("Highlight Points of Interest")).toBeTruthy();
});
it("should toggle the wheelchair accessibility switch", () => {
const { getByText, getByRole } = render(<MapSettings {...defaultProps} />);
const fabIcon = getByText("settings-outline");
if (fabIcon.parent) fireEvent.press(fabIcon.parent);
const switchComponent = getByRole("switch");
fireEvent(switchComponent, "onValueChange", true);
expect(defaultProps.setWheelchairOnly).toHaveBeenCalledWith(true);
});
it("should call setPoiFilters when a POI item is pressed", () => {
const { getByText } = render(<MapSettings {...defaultProps} />);
const fabIcon = getByText("settings-outline");
if (fabIcon.parent) fireEvent.press(fabIcon.parent);
const elevatorLabel = getByText("Elevators");
if (!elevatorLabel.parent) throw new Error("Elevator row parent not found");
fireEvent.press(elevatorLabel.parent);
expect(defaultProps.setPoiFilters).toHaveBeenCalledWith({
...defaultProps.poiFilters,
elevators: true,
});
});
it("should toggle the panel closed when FAB is pressed twice", () => {
const { getByText, queryByText } = render(<MapSettings {...defaultProps} />);
const icon = getByText("settings-outline");
if (!icon.parent) throw new Error("FAB icon parent not found");
// Open
fireEvent.press(icon.parent);
expect(queryByText("Settings")).toBeTruthy();
// Close
fireEvent.press(icon.parent);
expect(queryByText("Settings")).toBeNull();
});
it("should display the correct checkbox icon based on POI filter state", () => {
const { getByText, getAllByText } = render(<MapSettings {...defaultProps} />);
const icon = getByText("settings-outline");
if (!icon.parent) throw new Error("FAB icon parent not found");
fireEvent.press(icon.parent);
const checkboxes = getAllByText("checkbox");
const uncheckedBoxes = getAllByText("square-outline");
expect(checkboxes.length).toBe(2);
expect(uncheckedBoxes.length).toBe(3);
expect(getByText("Water Fountains")).toBeTruthy();
expect(getByText("Stairs")).toBeTruthy();
expect(getByText("Escalators")).toBeTruthy();
});
});