Skip to content

Commit

Permalink
Trying to solve some tests errors
Browse files Browse the repository at this point in the history
  • Loading branch information
baraganio committed Mar 18, 2024
1 parent 69fa09d commit 973dfd8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 52 deletions.
18 changes: 5 additions & 13 deletions webapp/src/App.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
/*

import { render, screen } from '@testing-library/react';
import App from './App';

test('renders learn react link', () => {
render(<App />);
render(
<Router>
<App />
</Router>);
const linkElement = screen.getByText(/Welcome to the 2024 edition of the Software Architecture course/i);
expect(linkElement).toBeInTheDocument();
});
*/
import React from 'react';
import { render } from '@testing-library/react';
import App from './App';

describe('./App', () => {
it('should render the component without crashing', () => {
// Render the component
render(<App />);

});
});
14 changes: 0 additions & 14 deletions webapp/src/components/AddUser.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*
import React from 'react';
import { render, fireEvent, screen, waitFor } from '@testing-library/react';
import axios from 'axios';
Expand Down Expand Up @@ -58,18 +57,5 @@ describe('AddUser component', () => {
});
});
});
*/

import AddUser from './AddUser';
import React from 'react';
import { render } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom'; // Import BrowserRouter


describe('./AddUser', () => {
it('should render the Login component without crashing', () => {
// Wrap Login within BrowserRouter to provide routing context
render(<BrowserRouter><AddUser /></BrowserRouter>);
});
});

36 changes: 11 additions & 25 deletions webapp/src/components/Login.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/*
import React from 'react';
import { render, fireEvent, screen, waitFor, act } from '@testing-library/react';
import axios from 'axios';
Expand All @@ -13,7 +12,11 @@ describe('Login component', () => {
});

it('should log in successfully', async () => {
render(<Login />);
render(<UserProvider>
<Router>
<Login />
</Router>
</UserProvider>);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
Expand All @@ -28,14 +31,13 @@ describe('Login component', () => {
fireEvent.change(passwordInput, { target: { value: 'testPassword' } });
fireEvent.click(loginButton);
});
// Verify that the user information is displayed
expect(screen.getByText(/Hello testUser!/i)).toBeInTheDocument();
expect(screen.getByText(/Your account was created on 1\/1\/2024/i)).toBeInTheDocument();
});

it('should handle error when logging in', async () => {
render(<Login />);
render(
<Router>
<Login />
</Router>);

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
Expand All @@ -56,21 +58,5 @@ describe('Login component', () => {
expect(screen.getByText(/Error: Unauthorized/i)).toBeInTheDocument();
});

// Verify that the user information is not displayed
expect(screen.queryByText(/Hello testUser!/i)).toBeNull();
expect(screen.queryByText(/Your account was created on/i)).toBeNull();
});
});
*/

import React from 'react';
import { render } from '@testing-library/react';
import { BrowserRouter } from 'react-router-dom'; // Import BrowserRouter
import Login from './Login'; // Assuming Login is the component under test

describe('./Login', () => {
it('should render the Login component without crashing', () => {
// Wrap Login within BrowserRouter to provide routing context
render(<BrowserRouter><Login /></BrowserRouter>);
});
});
});
});

0 comments on commit 973dfd8

Please sign in to comment.