Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
daniele-mng authored and bjoernricks committed Jan 14, 2025
1 parent 1742bd6 commit a54ad65
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 86 deletions.

This file was deleted.

79 changes: 79 additions & 0 deletions src/web/components/structure/__tests__/header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/* SPDX-FileCopyrightText: 2025 Greenbone AG
*
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import {describe, test, expect, testing} from '@gsa/testing';
import Header from 'web/components/structure/header';
import {setTimezone, setUsername} from 'web/store/usersettings/actions';
import {rendererWith, screen, userEvent, waitFor} from 'web/utils/testing';

const gmp = {
settings: {
vendorLabel: 'gsm-150_label.svg',
},
doLogout: testing.fn().mockResolvedValue(),
};

describe('Header', () => {
test('renders component', async () => {
const {render, store} = rendererWith({
gmp,
router: true,
store: true,
});
store.dispatch(setTimezone('UTC'));
store.dispatch(setUsername('testUser'));

render(<Header />);

expect(screen.getByText('UTC')).toBeVisible();

const langBtn = screen.getByRole('button', {
name: 'Switch language to German',
});
expect(langBtn).toBeVisible();

const renewBtn = screen.getByRole('button', {
name: 'Renew session timeout',
});
expect(renewBtn).toBeVisible();

const username = screen.getByText('testUser');
expect(username).toBeVisible();

const themeSwitch = screen.queryByRole('button', {
name: 'Switch color theme',
});

expect(themeSwitch).not.toBeInTheDocument();

const logo = screen.getByTestId('Enterprise150');
expect(logo).toBeVisible();
});

test('opens user menu, checks items and logs out user', async () => {
const {render, store} = rendererWith({
gmp,
router: true,
store: true,
});
store.dispatch(setUsername('testUser'));

render(<Header />);

const settingsBtn = screen.getByText('testUser');
userEvent.click(settingsBtn);

await waitFor(() => {
expect(screen.getByText('Settings')).toBeVisible();
});

const logoutBtn = screen.getByText('Logout');
userEvent.click(logoutBtn);

await waitFor(() => {
expect(gmp.doLogout).toHaveBeenCalled();
});
});
});

0 comments on commit a54ad65

Please sign in to comment.