Skip to content

Commit

Permalink
test: Add AppBar component tests
Browse files Browse the repository at this point in the history
  • Loading branch information
drikusroor committed Dec 8, 2023
1 parent cc655f1 commit 1604ec1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
46 changes: 46 additions & 0 deletions frontend/src/components/AppBar/AppBar.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import AppBar from './AppBar';
import { BrowserRouter as Router } from 'react-router-dom';
import '@testing-library/jest-dom';

describe('AppBar', () => {

const BASE_URL = 'https://www.amsterdammusiclab.nl';

beforeEach(() => {
jest.resetModules();
process.env.REACT_APP_AML_HOME = BASE_URL;
});

it('renders correctly', () => {
const { getByText } = render(<AppBar title="Test Title" />, { wrapper: Router });
expect(getByText('Test Title')).toBeInTheDocument();
});

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 = jest.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?');
});

});
2 changes: 1 addition & 1 deletion frontend/src/hooks/useSingleToArray.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { renderHook } from '@testing-library/react-hooks';
import useSingleToArray from './useSingleToArray'; // Adjust the import path as necessary
import useSingleToArray from './useSingleToArray';

describe('useSingleToArray', () => {

Expand Down

0 comments on commit 1604ec1

Please sign in to comment.