diff --git a/src/app/__tests__/cadastrarIdoso.spec.tsx b/src/app/__tests__/cadastrarIdoso.spec.tsx index 0764b755..97997741 100644 --- a/src/app/__tests__/cadastrarIdoso.spec.tsx +++ b/src/app/__tests__/cadastrarIdoso.spec.tsx @@ -159,7 +159,7 @@ describe("CadastrarIdoso component", () => { expect(router.push).toHaveBeenCalledWith("/private/pages/listarIdosos"); }); }); - + it("Cadastra um idoso com sucesso quando todos os dados estão válidos", async () => { const { getByText, getByPlaceholderText } = render(); @@ -175,4 +175,43 @@ describe("CadastrarIdoso component", () => { expect(replace).toHaveBeenCalledWith("/private/pages/listarIdosos"); }); }); + + it("Navega para a tela anterior ao clicar no botão de voltar quando canGoBack é falso", async () => { + (router.canGoBack as jest.Mock).mockReturnValue(false); + + const { getByTestId } = render(); + + const backButton = getByTestId("back-button-pressable"); + fireEvent.press(backButton); + + await waitFor(() => { + expect(router.push).toHaveBeenCalledWith("/private/pages/listarIdosos"); + }); + }); + + it("Exibe mensagem de erro ao deixar campos obrigatórios em branco", async () => { + const { getByText, getByTestId, getByPlaceholderText } = render(); + + const nome = getByPlaceholderText("Nome"); + const dataNascimento = getByPlaceholderText("Data de Nascimento"); + const telefone = getByPlaceholderText("Telefone Responsável"); + const cadastrar = getByText("Cadastrar"); + + act(() => { + fireEvent.changeText(nome, ""); + fireEvent.changeText(dataNascimento, ""); + fireEvent.changeText(telefone, ""); + fireEvent.press(cadastrar); + }); + + await waitFor(() => { + const erroNome = getByTestId("Erro-nome"); + const erroData = getByTestId("Erro-data"); + const erroTelefone = getByTestId("Erro-telefone"); + + expect(erroNome.props.children.props.text).toBe("Campo obrigatório!"); + expect(erroData.props.children.props.text).toBe("Campo obrigatório!"); + expect(erroTelefone.props.children.props.text).toBe("Campo obrigatório!"); + }); + }); }); diff --git a/src/app/private/pages/cadastrarIdoso.tsx b/src/app/private/pages/cadastrarIdoso.tsx index df5cb1e7..2584cc16 100644 --- a/src/app/private/pages/cadastrarIdoso.tsx +++ b/src/app/private/pages/cadastrarIdoso.tsx @@ -94,7 +94,7 @@ export default function CadastrarIdoso() { if (!dataNascimento) { - erros.dataNascimento = "Campo obrigatório"; + erros.dataNascimento = "Campo obrigatório!"; } else if (!/^\d{2}\/\d{2}\/\d{4}$/.test(dataNascimento)) { erros.dataNascimento = "Data deve ser no formato dd/mm/yyyy!"; }