Skip to content

Commit

Permalink
Trying to fix error on how we call th context.js
Browse files Browse the repository at this point in the history
  • Loading branch information
alegarman2002 committed Mar 13, 2024
1 parent c5681f2 commit ecd16b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 21 deletions.
6 changes: 3 additions & 3 deletions webapp/src/App.test.js
Original file line number Diff line number Diff line change
@@ -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(
<Context>
<ContextFun>
<Router>
<App />
</Router>
</Context>
</ContextFun>
);
const linkElement = screen.getByText(/Welcome to wiq_0/i);
expect(linkElement).toBeInTheDocument();
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/Context.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
35 changes: 18 additions & 17 deletions webapp/src/components/Login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';



Expand All @@ -17,11 +17,11 @@ describe('Login component', () => {

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

const usernameInput = screen.getByLabelText(/Username/i);
const passwordInput = screen.getByLabelText(/Password/i);
Expand All @@ -32,23 +32,24 @@ 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();
expect(screen.getByText(/Your account was created on 1\/1\/2024/i)).toBeInTheDocument();
});

it('should handle error when logging in', async () => {

render(<Context>
<Router>
<Login />
</Router>
</Context>

render(
<ContextFun>
<Router>
<Login />
</Router>
</ContextFun>
);

const usernameInput = screen.getByLabelText(/Username/i);
Expand Down

0 comments on commit ecd16b9

Please sign in to comment.