-
-
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
5363e27
commit f0a423c
Showing
10 changed files
with
251 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
// __mocks__/react-native-localize.ts | ||
export * from "react-native-localize/mock"; // or "react-native-localize/mock/jest" |
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
53 changes: 52 additions & 1 deletion
53
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 |
---|---|---|
@@ -1,9 +1,60 @@ | ||
import { render } from "@testing-library/react-native"; | ||
import { fireEvent, render, screen } from "@testing-library/react-native"; | ||
|
||
import CustomDrawerContent from ".."; | ||
|
||
describe("DrawerContent", () => { | ||
it("should render correctly", () => { | ||
render(<CustomDrawerContent />); | ||
|
||
expect(screen.getByText(/Principal/i)).toBeTruthy(); | ||
}); | ||
|
||
describe("Main menu", () => { | ||
it("should navigate to the correct screen", async () => { | ||
render(<CustomDrawerContent />); | ||
|
||
const drawerItem = await screen.findAllByTestId("drawerItem"); | ||
|
||
drawerItem.forEach((item) => { | ||
fireEvent.press(item); | ||
}); | ||
|
||
expect(screen.getByText(/Principal/i)).toBeTruthy(); | ||
}); | ||
|
||
it("should open and close the sub menu", async () => { | ||
render(<CustomDrawerContent />); | ||
|
||
const drawerItem = await screen.findAllByTestId("drawerItem"); | ||
|
||
fireEvent.press(drawerItem[2]); | ||
|
||
const drawerItemSub = await screen.findAllByTestId("drawerItemSub"); | ||
|
||
expect(drawerItemSub).toHaveLength(4); | ||
|
||
fireEvent.press(drawerItem[2]); | ||
|
||
expect(screen.queryByTestId("drawerItemSub")).toBeNull(); | ||
}); | ||
}); | ||
|
||
describe("Sub menu", () => { | ||
it("should navigate to the correct screen", async () => { | ||
render(<CustomDrawerContent />); | ||
|
||
const drawerItem = await screen.findAllByTestId("drawerItem"); | ||
|
||
fireEvent.press(drawerItem[2]); | ||
fireEvent.press(drawerItem[3]); | ||
|
||
const drawerItemSub = await screen.findAllByTestId("drawerItemSub"); | ||
|
||
drawerItemSub.forEach((item) => { | ||
fireEvent.press(item); | ||
}); | ||
|
||
expect(screen.getByText(/Principal/i)).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
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
15 changes: 15 additions & 0 deletions
15
src/components/LogoComponent/__tests__/LogoComponent.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,15 @@ | ||
import { render } from "@testing-library/react-native"; | ||
|
||
import LogoComponent from ".."; | ||
|
||
describe("LogoComponent", () => { | ||
it("should render correctly", () => { | ||
render( | ||
<LogoComponent | ||
width={20} | ||
height={20} | ||
style={{ backgroundColor: "black" }} | ||
/> | ||
); | ||
}); | ||
}); |
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
115 changes: 115 additions & 0 deletions
115
src/components/PrivacyPolicesAndTerms/__tests__/PrivacyPolicesAndTerms.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,115 @@ | ||
import AsyncStorage from "@react-native-async-storage/async-storage"; | ||
import { | ||
fireEvent, | ||
render, | ||
screen, | ||
waitFor, | ||
} from "@testing-library/react-native"; | ||
import { Alert } from "react-native"; | ||
|
||
import PrivacyPolicesAndTerms from ".."; | ||
import type { NavigationType } from "../../../types/navigationProps"; | ||
|
||
const mockNavigation = { | ||
navigate: jest.fn(), | ||
dispatch: jest.fn(), | ||
reset: jest.fn(), | ||
goBack: jest.fn(), | ||
isFocused: jest.fn(), | ||
} as unknown as NavigationType; | ||
|
||
jest.mock("react-native-vector-icons/MaterialCommunityIcons", () => "Icon"); | ||
|
||
describe("PrivacyPolicesAndTerms", () => { | ||
it("should render correctly", () => { | ||
render(<PrivacyPolicesAndTerms navigation={mockNavigation} />); | ||
}); | ||
|
||
describe("open links", () => { | ||
it("should open the terms link", () => { | ||
render(<PrivacyPolicesAndTerms navigation={mockNavigation} />); | ||
|
||
const button = screen.getByText("Ler termos de uso"); | ||
|
||
fireEvent.press(button); | ||
}); | ||
|
||
it("should open the privacy link", () => { | ||
render(<PrivacyPolicesAndTerms navigation={mockNavigation} />); | ||
|
||
const button = screen.getByText("Ler politicas de privacidade"); | ||
|
||
fireEvent.press(button); | ||
}); | ||
}); | ||
|
||
describe("checkbox", () => { | ||
it("should apear activeSpan if checkbox is not checked", async () => { | ||
render(<PrivacyPolicesAndTerms navigation={mockNavigation} />); | ||
|
||
const button = screen.getByText("Continuar"); | ||
|
||
fireEvent.press(button); | ||
|
||
const textActiveSpan = await screen.findByText( | ||
"Para continuar você precisa aceitar os termos" | ||
); | ||
|
||
expect(textActiveSpan).toBeTruthy(); | ||
}); | ||
|
||
it("should not apear activeSpan if checkbox is checked", async () => { | ||
render(<PrivacyPolicesAndTerms navigation={mockNavigation} />); | ||
|
||
const checkbox = screen.getByTestId("checkbox"); | ||
|
||
fireEvent.press(checkbox); | ||
|
||
const button = screen.getByText("Continuar"); | ||
|
||
fireEvent.press(button); | ||
|
||
const textActiveSpan = screen.queryByText( | ||
"Para continuar você precisa aceitar os termos" | ||
); | ||
|
||
await waitFor(() => { | ||
expect(textActiveSpan).toBeNull(); | ||
}); | ||
}); | ||
|
||
it("should check the checkbox", () => { | ||
render(<PrivacyPolicesAndTerms navigation={mockNavigation} />); | ||
|
||
const checkbox = screen.getByTestId("checkbox"); | ||
|
||
fireEvent.press(checkbox); | ||
}); | ||
}); | ||
|
||
describe("error handling", () => { | ||
it("should show alert on AsyncStorage.setItem error", async () => { | ||
jest.spyOn(Alert, "alert"); | ||
|
||
(AsyncStorage.setItem as jest.Mock).mockRejectedValueOnce( | ||
new Error("AsyncStorage error") | ||
); | ||
|
||
render(<PrivacyPolicesAndTerms navigation={mockNavigation} />); | ||
|
||
const checkbox = screen.getByTestId("checkbox"); | ||
|
||
fireEvent.press(checkbox); | ||
|
||
const button = screen.getByText("Continuar"); | ||
|
||
fireEvent.press(button); | ||
|
||
await waitFor(() => { | ||
expect(Alert.alert).toHaveBeenCalledWith( | ||
"Alguma coisa errada aconteceu, contate o desenvolvedor" | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |
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,35 @@ | ||
import { | ||
height, | ||
RFPercentage, | ||
RFValue, | ||
RFValueWithFixedSecondParam, | ||
width, | ||
} from ".."; | ||
|
||
describe("Responsive", () => { | ||
it("should calculate width correctly", () => { | ||
const calculatedWidth = width("100%"); | ||
expect(calculatedWidth).toBeGreaterThan(0); | ||
}); | ||
|
||
it("should calculate height correctly", () => { | ||
const calculatedHeight = height(50); | ||
expect(calculatedHeight).toBeGreaterThan(0); | ||
}); | ||
|
||
it("should calculate RFPercentage correctly", () => { | ||
const calculatedRFPercentage = RFPercentage(50); | ||
expect(calculatedRFPercentage).toBeGreaterThan(0); | ||
}); | ||
|
||
it("should calculate RFValue correctly", () => { | ||
const calculatedRFValue = RFValue(16); | ||
expect(calculatedRFValue).toBeGreaterThan(0); | ||
}); | ||
|
||
it("should calculate RFValueWithFixedSecondParam correctly", () => { | ||
const calculatedRFValueWithFixedSecondParam = | ||
RFValueWithFixedSecondParam(16); | ||
expect(calculatedRFValueWithFixedSecondParam).toBeGreaterThan(0); | ||
}); | ||
}); |
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,19 @@ | ||
import { termsURL, privacyURL, buyMeACoffeeURL, repoGithubURL } from ".."; | ||
|
||
describe("Urls", () => { | ||
it("should have the correct terms URL", () => { | ||
expect(termsURL).toBe("https://2devs.tech/terms"); | ||
}); | ||
|
||
it("should have the correct privacy URL", () => { | ||
expect(privacyURL).toBe("https://2devs.tech/PrivacyPolicy"); | ||
}); | ||
|
||
it("should have the correct buy me a coffee URL", () => { | ||
expect(buyMeACoffeeURL).toBe("https://www.buymeacoffee.com/gabriellogan"); | ||
}); | ||
|
||
it("should have the correct GitHub repository URL", () => { | ||
expect(repoGithubURL).toBe("https://github.com/gabriel-logan/2Devs-Mobile"); | ||
}); | ||
}); |