-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1742bd6
commit a54ad65
Showing
2 changed files
with
79 additions
and
86 deletions.
There are no files selected for viewing
86 changes: 0 additions & 86 deletions
86
src/web/components/structure/__tests__/__snapshots__/header.jsx.snap
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,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(); | ||
}); | ||
}); | ||
}); |