Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header user timezone #4280

Merged
merged 3 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 37 additions & 37 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
},
"dependencies": {
"@atlaskit/pragmatic-drag-and-drop-react-beautiful-dnd-migration": "^1.2.4",
"@greenbone/opensight-ui-components-mantinev7": "^0.0.7-alpha4",
"@greenbone/opensight-ui-components-mantinev7": "^0.0.7",
"@mantine/core": "^7.15.3",
"@reduxjs/toolkit": "^2.5.0",
"@sentry/react": "^8.39.0",
Expand Down

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();
});
});
});
12 changes: 8 additions & 4 deletions src/web/components/structure/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,28 @@
*/

import {AppHeader} from '@greenbone/opensight-ui-components-mantinev7';
import _ from 'gmp/locale';
import {useCallback} from 'react';
import {useSelector} from 'react-redux';
import {useNavigate} from 'react-router-dom';
import LogoutIcon from 'web/components/icon/logouticon';
import MySettingsIcon from 'web/components/icon/mysettingsicon';
import SessionTimer from 'web/components/sessionTimer/SessionTimer';
import getLogo from 'web/components/structure/getLogo';
import LanguageSwitch from 'web/components/structure/languageswitch';
import useGmp from 'web/hooks/useGmp';
import useTranslation from 'web/hooks/useTranslation';
import useUserIsLoggedIn from 'web/hooks/useUserIsLoggedIn';
import useUserName from 'web/hooks/useUserName';

import LanguageSwitch from './languageswitch';
import SessionTimer from '../sessionTimer/SessionTimer';

const Header = () => {
const [_] = useTranslation();

const gmp = useGmp();
const username = useUserName();
const loggedIn = useUserIsLoggedIn();
const navigate = useNavigate();
const logoComponent = getLogo(gmp.settings.vendorLabel);
const timezone = useSelector(state => state.userSettings.timezone);

const handleSettingsClick = useCallback(
event => {
Expand Down Expand Up @@ -58,6 +61,7 @@ const Header = () => {

return (
<AppHeader
ianaTimeZone={timezone}
isLoggedIn={loggedIn}
isThemeSwitchVisible={false}
languageSwitch={<LanguageSwitch />}
Expand Down
Loading