-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(navbar): implement navbar (#44)
-implement reusable navbar component [Delivers #21]
- Loading branch information
Showing
27 changed files
with
486 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { describe, it, expect } from 'vitest'; | ||
import BannerAd from '@/components/bannerAds/bannerAds'; | ||
import egg from '@/assets/egg.png' | ||
import snacks from '@/assets/snacks.png' | ||
import { MemoryRouter } from 'react-router-dom'; | ||
|
||
describe('banner Component', () => { | ||
it('renders BannerAd component with given props', () => { | ||
|
||
// const ads = [ | ||
// { | ||
// id: 1, | ||
// s_title: 'Only this week', | ||
// title: 'Quality eggs at an affordable price', | ||
// description: 'Eat one every day', | ||
// image: egg, | ||
// link: '/shop-eggs', | ||
// }, | ||
// { | ||
// id: 2, | ||
// s_title: 'Only this week', | ||
// title: 'Snacks that nourish our mind and body', | ||
// description: 'Shine the morning...', | ||
// image: snacks, | ||
// } | ||
// ] | ||
|
||
render( | ||
<MemoryRouter> | ||
<BannerAd | ||
key={1} | ||
s_title={"this week"} | ||
title={"eggs"} | ||
description={"snacks"} | ||
image={egg} | ||
/> | ||
</MemoryRouter> | ||
); | ||
|
||
expect(screen.getAllByRole('paragraph')[0]).toHaveTextContent( | ||
'this week' | ||
); | ||
|
||
expect(screen.getByText('eggs')).toBeInTheDocument() | ||
|
||
expect(screen.getAllByRole('paragraph')[1]).toHaveTextContent( | ||
'snacks' | ||
); | ||
|
||
|
||
const button = screen.getByText('Shop now') | ||
expect(button).toBeInTheDocument(); | ||
expect(screen.getByTitle('icon')).toBeInTheDocument() | ||
|
||
const image = screen.getByAltText(/eggs/i); | ||
expect(image).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { describe, it, expect } from 'vitest'; | ||
import Navbar from '@/components/Navbar'; | ||
|
||
describe('Navbar Component', () => { | ||
it('renders Navbar component', () => { | ||
render( | ||
<MemoryRouter> | ||
<Navbar /> | ||
</MemoryRouter> | ||
); | ||
|
||
const logo = screen.getByAltText(/logo/i); | ||
expect(logo).toBeInTheDocument(); | ||
|
||
const title = screen.getByText(/dynamites/i); | ||
expect(title).toBeInTheDocument(); | ||
|
||
const homeLink = screen.getByText(/Home/i); | ||
expect(homeLink).toBeInTheDocument(); | ||
|
||
const shopLink = screen.getByText(/Shop/i); | ||
expect(shopLink).toBeInTheDocument(); | ||
|
||
const aboutLink = screen.getByText(/About us/i); | ||
expect(aboutLink).toBeInTheDocument(); | ||
|
||
const contactLink = screen.getAllByText(/Contact/i)[0]; | ||
expect(contactLink).toBeInTheDocument(); | ||
|
||
const cartIcon = screen.getByTitle('cart'); | ||
expect(cartIcon).toBeInTheDocument(); | ||
|
||
const avatar = screen.getByAltText(/profile/i); | ||
expect(avatar).toBeInTheDocument(); | ||
|
||
const username = screen.getByText(/amanda green/i); | ||
expect(username).toBeInTheDocument(); | ||
}); | ||
|
||
it('highlights the correct navigation link based on the current route', () => { | ||
render( | ||
<MemoryRouter initialEntries={['/shop']}> | ||
<Navbar /> | ||
</MemoryRouter> | ||
); | ||
|
||
expect(screen.getByText('Shop')).toHaveClass( | ||
'border-b-[2px] border-primary text-primary' | ||
); | ||
}); | ||
|
||
it('toggles menu on hamburger icon click', () => { | ||
render( | ||
<MemoryRouter> | ||
<Navbar /> | ||
</MemoryRouter> | ||
); | ||
|
||
const hamburgerIcon = screen.getByTitle('hamburger'); | ||
fireEvent.click(hamburgerIcon); | ||
|
||
expect(screen.getAllByText(/home/i)[0]).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders links with correct paths', () => { | ||
render( | ||
<MemoryRouter> | ||
<Navbar /> | ||
</MemoryRouter> | ||
); | ||
|
||
const homeLink = screen.getByText(/home/i); | ||
expect(homeLink.closest('a')).toHaveAttribute('href', '/'); | ||
|
||
const shopLink = screen.getByText(/shop/i); | ||
expect(shopLink.closest('a')).toHaveAttribute('href', '/shop'); | ||
|
||
const aboutLink = screen.getByText(/about us/i); | ||
expect(aboutLink.closest('a')).toHaveAttribute('href', '/about'); | ||
|
||
const contactLink = screen.getAllByText(/contact/i)[0]; | ||
expect(contactLink.closest('a')).toHaveAttribute('href', '/contact'); | ||
}); | ||
|
||
it('displays cart item count', () => { | ||
render( | ||
<MemoryRouter> | ||
<Navbar /> | ||
</MemoryRouter> | ||
); | ||
|
||
const cartCount = screen.getByText(/5/i); | ||
expect(cartCount).toBeInTheDocument(); | ||
}); | ||
|
||
it('renders profile options on avatar click', () => { | ||
render( | ||
<MemoryRouter> | ||
<Navbar /> | ||
</MemoryRouter> | ||
); | ||
|
||
const profileIcon = screen.getByTitle('toggleProfile'); | ||
fireEvent.click(profileIcon); | ||
|
||
const editProfileOption = screen.getByText(/edit profile/i); | ||
expect(editProfileOption).toBeInTheDocument(); | ||
|
||
const preferencesOption = screen.getByText(/preferences/i); | ||
expect(preferencesOption).toBeInTheDocument(); | ||
|
||
const nightModeOption = screen.getByText(/night mode/i); | ||
expect(nightModeOption).toBeInTheDocument(); | ||
|
||
const helpCenterOption = screen.getByText(/help center/i); | ||
expect(helpCenterOption).toBeInTheDocument(); | ||
|
||
const signOutOption = screen.getByText(/sign out/i); | ||
expect(signOutOption).toBeInTheDocument(); | ||
}); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.