-
-
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.
test: add tests do validators, mynetwork, informations and generators
- Loading branch information
1 parent
249894e
commit b547eef
Showing
16 changed files
with
723 additions
and
36 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { fireEvent, render, screen } from "@testing-library/react-native"; | ||
|
||
import GeneralInfoPage from ".."; | ||
|
||
describe("Informations", () => { | ||
it("should render correctly", () => { | ||
render(<GeneralInfoPage />); | ||
|
||
const title = screen.getByText(/Informações Gerais/i); | ||
|
||
expect(title).toBeDefined(); | ||
}); | ||
|
||
it("should show contributors", () => { | ||
render(<GeneralInfoPage />); | ||
|
||
const contributors = screen.getByText(/Contribuidores/i); | ||
|
||
expect(contributors).toBeDefined(); | ||
}); | ||
|
||
describe("Links buttons", () => { | ||
it("should show and open github link", () => { | ||
render(<GeneralInfoPage />); | ||
|
||
const githubButton = screen.getByText(/Ir para o repositório github/i); | ||
|
||
expect(githubButton).toBeDefined(); | ||
|
||
fireEvent.press(githubButton); | ||
}); | ||
|
||
it("should show and open buy me a coffee link", () => { | ||
render(<GeneralInfoPage />); | ||
|
||
const coffeeButton = screen.getByText(/Buy me a coffee/i); | ||
|
||
expect(coffeeButton).toBeDefined(); | ||
|
||
fireEvent.press(coffeeButton); | ||
}); | ||
|
||
it("should show and open Privacy Policy link", () => { | ||
render(<GeneralInfoPage />); | ||
|
||
const privacyPolicyButton = screen.getByText(/Políticas de Privacidade/i); | ||
|
||
expect(privacyPolicyButton).toBeDefined(); | ||
|
||
fireEvent.press(privacyPolicyButton); | ||
}); | ||
|
||
it("should show and open Terms of Use link", () => { | ||
render(<GeneralInfoPage />); | ||
|
||
const termsButton = screen.getByText(/Termos de Uso/i); | ||
|
||
expect(termsButton).toBeDefined(); | ||
|
||
fireEvent.press(termsButton); | ||
}); | ||
}); | ||
}); |
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,73 @@ | ||
import { NavigationContainer } from "@react-navigation/native"; | ||
import { fireEvent, render, screen } from "@testing-library/react-native"; | ||
import axios from "axios"; | ||
|
||
import MyNetwork from ".."; | ||
|
||
describe("MyNetwork", () => { | ||
it("should render correctly", async () => { | ||
jest | ||
.spyOn(axios, "get") | ||
.mockResolvedValue({ data: { ip: "201.8.168.176" } }); | ||
|
||
render( | ||
<NavigationContainer> | ||
<MyNetwork /> | ||
</NavigationContainer> | ||
); | ||
|
||
const title = await screen.findByText(/Informações de Rede/i); | ||
|
||
expect(title).toBeDefined(); | ||
}); | ||
|
||
it("should copy especific text to clipboard", async () => { | ||
render( | ||
<NavigationContainer> | ||
<MyNetwork /> | ||
</NavigationContainer> | ||
); | ||
|
||
const buttons = await screen.findAllByLabelText(/buttonCopy/i); | ||
|
||
expect(buttons).toHaveLength(4); | ||
|
||
buttons.forEach((button) => { | ||
fireEvent.press(button); | ||
}); | ||
}); | ||
|
||
it("should show error message when get external ip fails", async () => { | ||
jest.spyOn(axios, "get").mockResolvedValue({ data: undefined }); | ||
|
||
render( | ||
<NavigationContainer> | ||
<MyNetwork /> | ||
</NavigationContainer> | ||
); | ||
|
||
const error = await screen.findByText( | ||
/Houve um problema não identificado na solicitação, tente novamente mais tarde/i | ||
); | ||
|
||
expect(error).toBeDefined(); | ||
}); | ||
|
||
it("should console.error when get external ip fails", async () => { | ||
const consoleErrorSpy = jest | ||
.spyOn(console, "error") | ||
.mockImplementation(() => {}); | ||
|
||
jest.spyOn(axios, "get").mockRejectedValue(new Error("error")); | ||
|
||
render( | ||
<NavigationContainer> | ||
<MyNetwork /> | ||
</NavigationContainer> | ||
); | ||
|
||
await new Promise((resolve) => setTimeout(resolve, 10)); | ||
|
||
consoleErrorSpy.mockRestore(); | ||
}); | ||
}); |
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,99 @@ | ||
import AsyncStorage from "@react-native-async-storage/async-storage"; | ||
import { fireEvent, render, screen } from "@testing-library/react-native"; | ||
|
||
import CpfGeneratorPage from ".."; | ||
|
||
describe("Cpf Generator", () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
AsyncStorage.clear(); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it("should render correctly", () => { | ||
render(<CpfGeneratorPage />); | ||
|
||
const title = screen.getByText("Gerador de CPF"); | ||
|
||
expect(title).toBeDefined(); | ||
}); | ||
|
||
it("should generate a random CPF without punctuation", async () => { | ||
render(<CpfGeneratorPage />); | ||
|
||
const input = screen.getByPlaceholderText("Clique no botão abaixo"); | ||
|
||
expect(input).toBeDefined(); | ||
|
||
const button = screen.getByText("Gerar CPF"); | ||
|
||
expect(button).toBeDefined(); | ||
|
||
fireEvent.press(button); | ||
|
||
expect(input.props.value).toMatch(/^\d{11}$/); | ||
}); | ||
|
||
it("should change checkbox value", async () => { | ||
render(<CpfGeneratorPage />); | ||
|
||
const checkbox = screen.getByRole("checkbox"); | ||
|
||
fireEvent(checkbox, "onValueChange", true); | ||
|
||
expect(checkbox.props.accessibilityState.checked).toBe(true); | ||
|
||
fireEvent(checkbox, "onValueChange", false); | ||
|
||
expect(checkbox.props.accessibilityState.checked).toBe(false); | ||
}); | ||
|
||
it("should generate a random CPF with punctuation", async () => { | ||
render(<CpfGeneratorPage />); | ||
|
||
const input = screen.getByPlaceholderText("Clique no botão abaixo"); | ||
|
||
const checkbox = screen.getByRole("checkbox"); | ||
|
||
const button = screen.getByText("Gerar CPF"); | ||
|
||
fireEvent(checkbox, "onValueChange", true); | ||
|
||
fireEvent.press(button); | ||
|
||
expect(input.props.value).toMatch(/^\d{3}\.\d{3}\.\d{3}-\d{2}$/); | ||
}); | ||
|
||
it("should copy generated CPF to clipboard", async () => { | ||
render(<CpfGeneratorPage />); | ||
|
||
const buttonCopy = screen.getByTestId("buttonCopy"); | ||
|
||
const button = screen.getByText("Gerar CPF"); | ||
|
||
fireEvent.press(button); | ||
|
||
fireEvent.press(buttonCopy); | ||
}); | ||
|
||
it("should not copy if there is no generated CPF", async () => { | ||
render(<CpfGeneratorPage />); | ||
|
||
const buttonCopy = screen.getByTestId("buttonCopy"); | ||
|
||
fireEvent.press(buttonCopy); | ||
}); | ||
|
||
it("should load checkbox value from AsyncStorage", async () => { | ||
(AsyncStorage.getItem as jest.Mock).mockResolvedValueOnce("true"); | ||
|
||
render(<CpfGeneratorPage />); | ||
|
||
const checkbox = await screen.findByRole("checkbox"); | ||
|
||
expect(checkbox.props.accessibilityState.checked).toBe(true); | ||
}); | ||
}); |
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
Oops, something went wrong.