Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Configurei corretamente os testes da pesquisa e app.js #108

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions front_end/babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
module.exports = {
presets: [
'@babel/preset-env',
'@babel/preset-react'
]
};
presets: ['@babel/preset-env', '@babel/preset-react'],
};
23 changes: 12 additions & 11 deletions front_end/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module.exports = {
transform: {
"^.+\\.jsx?$": "babel-jest"
},
moduleNameMapper: {
"\\.(css|less|scss|sass)$": "identity-obj-proxy"
},
moduleFileExtensions: ["js", "jsx"],
testMatch: ["**/__tests__/**/*.js?(x)", "**/?(*.)+(spec|test).js?(x)"],
setupFilesAfterEnv: ["<rootDir>/jest.setup.js"]
};

testEnvironment: 'jsdom',
transform: {
'^.+\\.[tj]sx?$': 'babel-jest',
},
transformIgnorePatterns: [
'/node_modules/(?!(axios|react-dnd|dnd-core)|@react-dnd/)',
],
moduleNameMapper: {
'\\.(css|less|sass|scss)$': 'identity-obj-proxy'
},
setupFilesAfterEnv: ['<rootDir>/src/setupTests.js'],
};
11 changes: 10 additions & 1 deletion front_end/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,14 @@
"identity-obj-proxy": "^3.0.0",
"jest": "^27.5.1",
"tailwindcss": "^3.4.6"
},
"jest": {
"testEnvironment": "jsdom",
"transform": {
"^.+\\.[tj]sx?$": "babel-jest"
},
"moduleNameMapper": {
"\\.(css|less|sass|scss)$": "identity-obj-proxy"
}
}
}
}
3 changes: 2 additions & 1 deletion front_end/src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
render(<App />);
const linkElement = screen.getByText(/learn react/i);
const linkElement = screen.getByText(/Pesquisar/i);
expect(linkElement).toBeInTheDocument();
});
1 change: 1 addition & 0 deletions front_end/src/components/ListaRoteiros.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from "react";
import "../styles/style.listaRoteiros.css"
import { useState, useEffect } from 'react';
import { useParams } from 'react-router-dom';
Expand Down
2 changes: 1 addition & 1 deletion front_end/src/components/Pesquisar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const Pesquisar = () => {
};

return (
<form onSubmit={handleSubmit} className="flex items-center relative w-full max-w-[24rem] rounded-lg shadow">
<form data-testid="pesquisar-form" onSubmit={handleSubmit} className="flex items-center relative w-full max-w-[24rem] rounded-lg shadow">
<svg className="w-6 h-6 text-black absolute left-3" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24">
<path stroke="currentColor" stroke-linecap="round" stroke-width="2" d="m21 21-3.5-3.5M17 10a7 7 0 1 1-14 0 7 7 0 0 1 14 0Z" />
</svg>
Expand Down
1 change: 1 addition & 0 deletions front_end/src/pages/Home.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import React from "react";
import ListaRoteiros from "../components/ListaRoteiros";
import NavBar from "../components/NavBar";

Expand Down
7 changes: 2 additions & 5 deletions front_end/src/setupTests.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
// jest-dom adds custom jest matchers for asserting on DOM nodes.
// allows you to do things like:
// expect(element).toHaveTextContent(/react/i)
// learn more: https://github.com/testing-library/jest-dom
import '@testing-library/jest-dom';
// src/setupTests.js
import '@testing-library/jest-dom';
44 changes: 0 additions & 44 deletions front_end/src/tests/Pesquisar.test.js

This file was deleted.

27 changes: 27 additions & 0 deletions front_end/src/tests/Pesquisar.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React from "react";
import { render, screen, fireEvent } from '@testing-library/react';
import '@testing-library/jest-dom';
import Pesquisar from "../components/Pesquisar";

describe('Pesquisar Roteiro', () => {
test('renders input element', () => {
render(<Pesquisar />);
const inputElement = screen.getByPlaceholderText(/pesquisar roteiros/i);
expect(inputElement).toBeInTheDocument();
});

test('updates input value on change', () => {
render(<Pesquisar />);
const inputElement = screen.getByPlaceholderText(/pesquisar roteiros/i);
fireEvent.change(inputElement, { target: { value: 'Novo Título' } });
expect(inputElement.value).toBe('Novo Título');
});

test('shows alert when form is submitted with empty title', () => {
render(<Pesquisar />);
window.alert = jest.fn();
const formElement = screen.getByTestId('pesquisar-form');
fireEvent.submit(formElement);
expect(window.alert).toHaveBeenCalledWith('É obrigatório o preenchimento do título');
});
});