From ecd16b9e9acbcb353aaff905e757ad969a844ecc Mon Sep 17 00:00:00 2001 From: alegarman2002 Date: Wed, 13 Mar 2024 15:47:29 +0100 Subject: [PATCH] Trying to fix error on how we call th context.js --- webapp/src/App.test.js | 6 ++--- webapp/src/components/Context.js | 2 +- webapp/src/components/Login.test.js | 35 +++++++++++++++-------------- 3 files changed, 22 insertions(+), 21 deletions(-) diff --git a/webapp/src/App.test.js b/webapp/src/App.test.js index 0319a782..c6c4561e 100644 --- a/webapp/src/App.test.js +++ b/webapp/src/App.test.js @@ -1,16 +1,16 @@ import { render, screen } from '@testing-library/react'; import App from './App'; -import { Context } from './components/Context'; +import { ContextFun } from './components/Context'; import { Router } from 'react-router-dom'; test('renders learn react link', () => { render( - + - + ); const linkElement = screen.getByText(/Welcome to wiq_0/i); expect(linkElement).toBeInTheDocument(); diff --git a/webapp/src/components/Context.js b/webapp/src/components/Context.js index 9e5bdcea..8a23041c 100644 --- a/webapp/src/components/Context.js +++ b/webapp/src/components/Context.js @@ -2,7 +2,7 @@ import React, { createContext, useContext, useState } from 'react'; const Context = createContext(); -export function UserProvider({ children }) { +export function ContextFun({ children }) { const [usernameGlobal, setUsernameGlobal] = useState(''); return ( diff --git a/webapp/src/components/Login.test.js b/webapp/src/components/Login.test.js index 5d83593b..3149be03 100644 --- a/webapp/src/components/Login.test.js +++ b/webapp/src/components/Login.test.js @@ -3,8 +3,8 @@ import { render, fireEvent, screen, waitFor, act } from '@testing-library/react' import axios from 'axios'; import MockAdapter from 'axios-mock-adapter'; import Login from './Login'; -import { Context } from './Context'; -import { BrowserRouter as Router } from 'react-router-dom'; +import { ContextFun } from './Context'; +import { BrowserRouter as Router } from 'react-router-dom'; @@ -17,11 +17,11 @@ describe('Login component', () => { it('should log in successfully', async () => { render( - - - - - ); + + + + + ); const usernameInput = screen.getByLabelText(/Username/i); const passwordInput = screen.getByLabelText(/Password/i); @@ -32,10 +32,10 @@ describe('Login component', () => { // Simulate user input await act(async () => { - fireEvent.change(usernameInput, { target: { value: 'testUser' } }); - fireEvent.change(passwordInput, { target: { value: 'testPassword' } }); - fireEvent.click(loginButton); - }); + fireEvent.change(usernameInput, { target: { value: 'testUser' } }); + fireEvent.change(passwordInput, { target: { value: 'testPassword' } }); + fireEvent.click(loginButton); + }); // Verify that the user information is displayed expect(screen.getByText(/Hello testUser!/i)).toBeInTheDocument(); @@ -43,12 +43,13 @@ describe('Login component', () => { }); it('should handle error when logging in', async () => { - - render( - - - - + + render( + + + + + ); const usernameInput = screen.getByLabelText(/Username/i);