-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Convert AppBar component to TypeScript
- Loading branch information
1 parent
865dd72
commit 18134ac
Showing
5 changed files
with
71 additions
and
71 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { render, fireEvent } from '@testing-library/react'; | ||
import AppBar from './AppBar'; | ||
import { BrowserRouter as Router } from 'react-router-dom'; | ||
import { vi, describe, beforeEach, it, expect } from 'vitest'; | ||
|
||
describe('AppBar', () => { | ||
|
||
const BASE_URL = 'https://www.amsterdammusiclab.nl'; | ||
|
||
beforeEach(() => { | ||
vi.resetModules(); | ||
import.meta.env.VITE_AML_HOME = BASE_URL; | ||
}); | ||
|
||
it('renders correctly', () => { | ||
const { getByText } = render(<AppBar title="Test Title" />, { wrapper: Router }); | ||
|
||
const titleElement = getByText('Test Title'); | ||
expect(document.body.contains(titleElement)).to.be.true; | ||
}); | ||
|
||
it('renders logo as Link for relative URL', () => { | ||
const { getByLabelText } = render(<AppBar title="Test Title" />, { wrapper: Router }); | ||
const logo = getByLabelText('Logo'); | ||
expect(logo.tagName).toBe('A'); | ||
expect(logo.getAttribute('href')).toBe(BASE_URL); | ||
}); | ||
|
||
it('renders logo as an a-element for absolute URL', () => { | ||
const { getByLabelText } = render(<AppBar title="Test Title" />, { wrapper: Router }); | ||
const logo = getByLabelText('Logo'); | ||
expect(logo.tagName).toBe('A'); | ||
expect(logo.getAttribute('href')).toBe(BASE_URL); | ||
}); | ||
|
||
it('prevents navigation when logoClickConfirm is provided and user cancels', () => { | ||
// Mock window.confirm | ||
window.confirm = vi.fn(() => false); | ||
|
||
const { getByLabelText } = render(<AppBar title="Test Title" logoClickConfirm="Confirm?" />, { wrapper: Router }); | ||
const logo = getByLabelText('Logo'); | ||
fireEvent.click(logo); | ||
|
||
expect(window.confirm).toHaveBeenCalledWith('Confirm?'); | ||
}); | ||
|
||
}); |
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,16 @@ | ||
import Logo from "@/components/Logo/Logo"; | ||
|
||
interface AppBarProps { | ||
title: string; | ||
logoClickConfirm?: string | null; | ||
} | ||
|
||
/** AppBar is a bar on top of the app, with navigation and title */ | ||
const AppBar = ({ title, logoClickConfirm = null }: AppBarProps) => ( | ||
<div className="aha__app-bar navbar bg-black"> | ||
<Logo logoClickConfirm={logoClickConfirm} /> | ||
<h4 className="title text-light">{title}</h4> | ||
<span className="action-right"></span> | ||
</div> | ||
); | ||
export default AppBar; |
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