Skip to content

Commit

Permalink
fix navigation-bar spec errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Mairis Bērziņš committed Dec 28, 2023
1 parent 29b2bcc commit 627ebd5
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions packages/client/src/app/navigation-bar/navigation-bar.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
import '@testing-library/jest-dom';
import { screen } from '@testing-library/react';
import { AuthState } from '../../features/auth/auth.types';
import { renderWithProviders } from '../../utils/test.utils';
import { NavigationBar } from './navigation-bar';
import { RootStore } from '../../core/root.store';
import { UserDto } from '@tspark/common';

describe('NavigationBar', () => {
it('should render Login button when user is not logged in', () => {
renderWithProviders(<NavigationBar />, {
preloadedState: {
auth: { isLoggedIn: false } as AuthState,
},
});
const rootStore = new RootStore();
rootStore.authStore.isAuthenticated = false;

renderWithProviders(<NavigationBar />, { rootStore });

expect(screen.queryByTestId('login-btn')).toBeInTheDocument();
expect(screen.queryByTestId('user-dropdown')).toBeNull();
});

it('should render user dropdown button when user is logged in', () => {
renderWithProviders(<NavigationBar />, {
preloadedState: {
auth: {
isLoggedIn: true,
user: { username: 'johnsmith' },
} as AuthState,
},
});
const rootStore = new RootStore();
rootStore.authStore.isAuthenticated = true;
rootStore.authStore.user = { username: 'johnsmith' } as UserDto;

renderWithProviders(<NavigationBar />, { rootStore });

expect(screen.queryByTestId('login-btn')).toBeNull();
expect(screen.queryByTestId('user-dropdown')).toBeInTheDocument();
Expand Down

0 comments on commit 627ebd5

Please sign in to comment.