-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee1f961
commit 5363e27
Showing
9 changed files
with
204 additions
and
14 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
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = "SvgMock"; |
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
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
9 changes: 9 additions & 0 deletions
9
src/components/DrawerContent/__tests__/DrawerContent.test.tsx
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { render } from "@testing-library/react-native"; | ||
|
||
import CustomDrawerContent from ".."; | ||
|
||
describe("DrawerContent", () => { | ||
it("should render correctly", () => { | ||
render(<CustomDrawerContent />); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import drawerMenu from "../drawerMenu"; | ||
|
||
describe("drawerMenu", () => { | ||
it("should have the correct number of items", () => { | ||
expect(drawerMenu).toHaveLength(7); | ||
}); | ||
|
||
it("should have the correct structure for each item", () => { | ||
drawerMenu.forEach((item) => { | ||
expect(item).toHaveProperty("title"); | ||
if ("route" in item) { | ||
expect(item).toHaveProperty("route"); | ||
expect(item).not.toHaveProperty("menuList"); | ||
} else { | ||
expect(item).toHaveProperty("menuList"); | ||
expect(item).not.toHaveProperty("route"); | ||
item.menuList.forEach((subItem) => { | ||
expect(subItem).toHaveProperty("title"); | ||
expect(subItem).toHaveProperty("route"); | ||
}); | ||
} | ||
}); | ||
}); | ||
}); |
132 changes: 132 additions & 0 deletions
132
src/components/ThemeContext/__tests__/ThemeContext.test.tsx
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 |
---|---|---|
@@ -0,0 +1,132 @@ | ||
import AsyncStorage from "@react-native-async-storage/async-storage"; | ||
import { | ||
render, | ||
fireEvent, | ||
screen, | ||
waitFor, | ||
} from "@testing-library/react-native"; | ||
import { Text, TouchableOpacity } from "react-native"; | ||
|
||
import ThemeProvider, { useTheme } from ".."; | ||
|
||
describe("ThemeContext", () => { | ||
describe("ThemeProvider", () => { | ||
test("renders children correctly", () => { | ||
render( | ||
<ThemeProvider> | ||
<Text>Test</Text> | ||
</ThemeProvider> | ||
); | ||
|
||
expect(screen.getByText("Test")).toBeDefined(); | ||
}); | ||
|
||
test("toggles theme correctly", () => { | ||
const TestComponent = () => { | ||
const { theme, toggleTheme } = useTheme(); | ||
|
||
return ( | ||
<TouchableOpacity | ||
onPress={() => toggleTheme(theme === "light" ? "dark" : "light")} | ||
> | ||
<Text>{theme}</Text> | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
render( | ||
<ThemeProvider> | ||
<TestComponent /> | ||
</ThemeProvider> | ||
); | ||
|
||
const toggleButton = screen.getByText("light"); | ||
|
||
fireEvent.press(toggleButton); | ||
|
||
expect(screen.getByText("dark")).toBeDefined(); | ||
}); | ||
|
||
describe("useEffect", () => { | ||
test("themeSelected from AsyncStorage is system", async () => { | ||
const valueStoraged = "system"; | ||
|
||
(AsyncStorage.getItem as jest.Mock).mockResolvedValueOnce( | ||
valueStoraged | ||
); | ||
|
||
render( | ||
<ThemeProvider> | ||
<Text>Test</Text> | ||
</ThemeProvider> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText("Test")).toBeDefined(); | ||
}); | ||
}); | ||
|
||
test("themeSelected from AsyncStorage is not system", async () => { | ||
const valueStoraged = "dark"; | ||
|
||
(AsyncStorage.getItem as jest.Mock).mockResolvedValueOnce( | ||
valueStoraged | ||
); | ||
|
||
render( | ||
<ThemeProvider> | ||
<Text>Test</Text> | ||
</ThemeProvider> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText("Test")).toBeDefined(); | ||
}); | ||
}); | ||
|
||
test("error on AsyncStorage.getItem", async () => { | ||
(AsyncStorage.getItem as jest.Mock).mockRejectedValueOnce( | ||
new Error("AsyncStorage error") | ||
); | ||
|
||
render( | ||
<ThemeProvider> | ||
<Text>Test</Text> | ||
</ThemeProvider> | ||
); | ||
|
||
await waitFor(() => { | ||
expect(screen.getByText("Test")).toBeDefined(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("useTheme", () => { | ||
test("returns theme and toggleTheme function", () => { | ||
const TestComponent = () => { | ||
const { theme, toggleTheme } = useTheme(); | ||
|
||
return ( | ||
<TouchableOpacity | ||
onPress={() => toggleTheme(theme === "light" ? "dark" : "light")} | ||
> | ||
<Text>{theme}</Text> | ||
</TouchableOpacity> | ||
); | ||
}; | ||
|
||
render( | ||
<ThemeProvider> | ||
<TestComponent /> | ||
</ThemeProvider> | ||
); | ||
|
||
const toggleButton = screen.getByText("light"); | ||
|
||
fireEvent.press(toggleButton); | ||
|
||
expect(screen.getByText("dark")).toBeDefined(); | ||
}); | ||
}); | ||
}); |
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