Skip to content

Commit

Permalink
Test to check home on navbar and logs in
Browse files Browse the repository at this point in the history
Relates #80
  • Loading branch information
Feargh committed Jun 25, 2024
1 parent 6a19c72 commit 7a555bf
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions src/__tests__/App.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ jest.mock('../components/UserContextProvider', () => ({
}));

import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import { render, screen, fireEvent } from '@testing-library/react';
import App from '../App';
import UserContextProvider from '../components/UserContextProvider';

test('demo', () => {
test('demo test', () => {
expect(true).toBe(true);
});

Expand All @@ -25,12 +25,38 @@ test('Renders the main page', () => {
expect(true).toBeTruthy();
});

test('Renders main UI elements', () => {
test('Renders main page and navbar elements', () => {
render(
<UserContextProvider>
<App />
</UserContextProvider>,
);
expect(screen.getByRole('navigation')).toBeInTheDocument(); // Navbar
// expect(screen.getByRole('heading', { name: /welcome/i })).toBeInTheDocument(); // Assuming there's a welcome heading

// check for the navigation
expect(screen.getByRole('navigation')).toBeInTheDocument();

// Check for the Home link
const homeLink = screen.getByRole('link', { name: /home/i });
expect(homeLink).toBeInTheDocument();
expect(homeLink).toHaveAttribute('href', '#');
});

test('Login form submission', () => {
render(
<UserContextProvider>
<App />
</UserContextProvider>,
);
fireEvent.click(screen.getByRole('button', { name: /log in/i }));
fireEvent.change(screen.getByLabelText(/email/i), {
target: { value: 'testuser' },
});
fireEvent.change(screen.getByLabelText(/password/i), {
target: { value: 'password123' },
});
const loginButton = screen.getByText('Log In!');
expect(loginButton).toBeInTheDocument();
fireEvent.click(loginButton);

// Add expectations based on what should happen after login
});

0 comments on commit 7a555bf

Please sign in to comment.