Skip to content

Commit

Permalink
Merge pull request #141 from Arquisoft/test-authenticated-user
Browse files Browse the repository at this point in the history
Tests components render
  • Loading branch information
Koquda authored Apr 30, 2023
2 parents c5ed855 + 79dda0b commit 8c4d555
Showing 1 changed file with 87 additions and 9 deletions.
96 changes: 87 additions & 9 deletions webapp/src/App.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import React from 'react';
import { fireEvent, render, screen } from '@testing-library/react';
import App from './App';
import userEvent from '@testing-library/user-event';
import '@testing-library/jest-dom';
import RequestFriendship from './components/Solid/Friends/RequestFriendship';
import Footer from './components/Footer/Footer';
import About from './components/About/About';
import CommentsPage from './components/CommentsPage/CommentsPage';
import LoginForm from './components/Pages/LoginPage/LoginPage';
import UserLogin from './components/Solid/User/UserLogin';

/**
* TESTS PAGES
*/

/**
* Test that default web page shows correctly
Expand All @@ -18,6 +26,76 @@ test('aplication starts in correct page', () =>{
expect(about).toBeInTheDocument();
expect(profile).toBeInTheDocument();
});

test('about renders correctly', ()=>{
render(<About/>);
const title_txt = screen.getByRole('heading',{name:"Sobre Nosotros - LoMap_ES6C"});

expect(title_txt).toBeInTheDocument();
});

test('commentsPage renders correctly', ()=> {
render(<CommentsPage/>);
const cancel_button_img = screen.getByRole('img');
const title = screen.getByText("Crear marcador");
const name = screen.getByText("Titulo del marcador:");
const type = screen.getByText("Tipo de marcador");
const pub = screen.getByRole('option',{name:"Bar o restaurante"});
const monument = screen.getByRole('option',{name:"Monumento"});
const landscape = screen.getByRole('option',{name:"Paisaje / Mirador"});
const comment_area = screen.getByPlaceholderText("Escribe tu comentario aquí");
const rating = screen.getByText("Puntuación:");
const submit = screen.getByRole('button',{name:"Enviar"});

expect(cancel_button_img).toBeInTheDocument();
expect(title).toBeInTheDocument();
expect(name).toBeInTheDocument();
expect(type).toBeInTheDocument();
expect(pub).toBeInTheDocument();
expect(monument).toBeInTheDocument();
expect(landscape).toBeInTheDocument();
expect(comment_area).toBeInTheDocument();
expect(rating).toBeInTheDocument();
expect(submit).toBeInTheDocument();
});

test('loginForm renders correctly',()=>{
render(<LoginForm/> );
const img = screen.getByRole('img',{name:"Logo"});
const title = screen.getByRole('heading',{name:"Log in"});
const buttons = screen.getAllByRole('button',{name:"Login"});

expect(img).toBeInTheDocument();
expect(title).toBeInTheDocument();
expect(buttons[1]).toBeInTheDocument();
});

test('userLogin renders correctly', () => {
render(<UserLogin/>);
const txtbox = screen.getByRole('textbox',{name:""});
const btn_login = screen.getAllByRole('button',{name:"Login"})[1];

expect(txtbox).toBeInTheDocument();
expect(btn_login).toBeInTheDocument();
});

test('requestFriendship renders correctly without athentication', () => {
render(<RequestFriendship />);
const friend_text = screen.getByText("Vete al login que no tas autenticado");

expect(friend_text).toBeInTheDocument();
});

test('footer render property', () => {
render(<Footer/>);
const txt = screen.getByText("© Lomap 2023");
expect(txt).toBeInTheDocument();
});


/**
* TESTS LINKS
*/

/**
* Test that link to start page works correctly
Expand Down Expand Up @@ -57,10 +135,10 @@ test('profile link redirects correctly', () => {
expect(button).toBeInTheDocument();
});

/**
* Test that start button in start page works correctly
* Test too that u can click in LOGIN button and go to inrupt log in
*/
/**
* Test that start button in start page works correctly
* Test too that u can click in LOGIN button and go to inrupt log in
*/
test('start page start-button works correctly', () => {
render(<App />);
fireEvent.click(screen.getByRole("link",{name: "Inicio"}));
Expand All @@ -73,7 +151,6 @@ test('start page start-button works correctly', () => {

const login_button = screen.getByText("Login");
fireEvent.click(login_button);
//Completar: comprobar la url
});

/**
Expand Down Expand Up @@ -113,7 +190,6 @@ test('navbar link to about works correctly', () => {
expect(heading).toBeInTheDocument();
});


/**
* Test that a navbar link for profile works correctly
*/
Expand All @@ -133,4 +209,6 @@ test('navbar link to profile works correctly', () => {
expect(title).toBeInTheDocument();
expect(button).toBeInTheDocument();
expect(id_prov).toBeInTheDocument();
});
});


0 comments on commit 8c4d555

Please sign in to comment.