T: Add logout test
This commit is contained in:
parent
28b147ed28
commit
ad1d1a47d6
|
@ -5,6 +5,7 @@ export default defineConfig({
|
|||
forbidOnly: !!process.env.CI,
|
||||
retries: process.env.CI ? 2 : 0,
|
||||
reporter: 'list',
|
||||
fullyParallel: true,
|
||||
projects: [
|
||||
{
|
||||
name: 'Desktop Chrome',
|
||||
|
|
|
@ -1,32 +1,23 @@
|
|||
import clsx from 'clsx';
|
||||
|
||||
import { type Styling, type Titled } from '@/components/props';
|
||||
import { type Styling } from '@/components/props';
|
||||
import { globalIDs } from '@/utils/constants';
|
||||
|
||||
interface NavigationButtonProps extends Titled, Styling {
|
||||
interface NavigationButtonProps extends Styling {
|
||||
text?: string;
|
||||
title?: string;
|
||||
icon: React.ReactNode;
|
||||
onClick?: (event: React.MouseEvent<Element>) => void;
|
||||
}
|
||||
|
||||
export function NavigationButton({
|
||||
icon,
|
||||
title,
|
||||
className,
|
||||
style,
|
||||
titleHtml,
|
||||
hideTitle,
|
||||
onClick,
|
||||
text
|
||||
}: NavigationButtonProps) {
|
||||
export function NavigationButton({ icon, title, className, style, onClick, text }: NavigationButtonProps) {
|
||||
return (
|
||||
<button
|
||||
type='button'
|
||||
tabIndex={-1}
|
||||
data-tooltip-id={!!title || !!titleHtml ? globalIDs.tooltip : undefined}
|
||||
data-tooltip-html={titleHtml}
|
||||
aria-label={title}
|
||||
data-tooltip-id={!!title ? globalIDs.tooltip : undefined}
|
||||
data-tooltip-content={title}
|
||||
data-tooltip-hidden={hideTitle}
|
||||
onClick={onClick}
|
||||
className={clsx(
|
||||
'mr-1 h-full',
|
||||
|
|
|
@ -8,9 +8,10 @@ import { NavigationButton } from './NavigationButton';
|
|||
interface UserButtonProps {
|
||||
onLogin: () => void;
|
||||
onClickUser: () => void;
|
||||
isOpen: boolean;
|
||||
}
|
||||
|
||||
export function UserButton({ onLogin, onClickUser }: UserButtonProps) {
|
||||
export function UserButton({ onLogin, onClickUser, isOpen }: UserButtonProps) {
|
||||
const { user, isAnonymous } = useAuthSuspense();
|
||||
const adminMode = usePreferencesStore(state => state.adminMode);
|
||||
if (isAnonymous) {
|
||||
|
@ -26,6 +27,9 @@ export function UserButton({ onLogin, onClickUser }: UserButtonProps) {
|
|||
return (
|
||||
<NavigationButton
|
||||
className='cc-fade-in'
|
||||
title='Пользователь'
|
||||
aria-haspopup='true'
|
||||
aria-expanded={isOpen}
|
||||
icon={<IconUser2 size='1.5rem' className={adminMode && user.is_staff ? 'icon-primary' : ''} />}
|
||||
onClick={onClickUser}
|
||||
/>
|
||||
|
|
|
@ -15,7 +15,11 @@ export function UserMenu() {
|
|||
return (
|
||||
<div ref={menu.ref} className='h-full w-[4rem] flex items-center justify-center'>
|
||||
<Suspense fallback={<Loader circular scale={1.5} />}>
|
||||
<UserButton onLogin={() => router.push({ path: urls.login, force: true })} onClickUser={menu.toggle} />
|
||||
<UserButton
|
||||
onLogin={() => router.push({ path: urls.login, force: true })}
|
||||
onClickUser={menu.toggle}
|
||||
isOpen={menu.isOpen}
|
||||
/>
|
||||
</Suspense>
|
||||
<UserDropdown isOpen={menu.isOpen} hideDropdown={() => menu.hide()} />
|
||||
</div>
|
||||
|
|
|
@ -54,6 +54,7 @@ export function Dropdown({
|
|||
clipPath: isOpen ? 'inset(0% 0% 0% 0%)' : 'inset(10% 0% 90% 0%)',
|
||||
...style
|
||||
}}
|
||||
aria-hidden={!isOpen}
|
||||
{...restProps}
|
||||
>
|
||||
{children}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import { setupLogin } from './mocks/auth';
|
||||
import { authAdmin, setupLogin, setupLogout } from './mocks/auth';
|
||||
import { expect, test } from './setup';
|
||||
|
||||
test('should display error message when login with wrong credentials', async ({ page }) => {
|
||||
|
@ -23,3 +23,16 @@ test('should login as admin successfully', async ({ page }) => {
|
|||
await expect(page.getByText('Вы вошли в систему как admin')).toBeVisible();
|
||||
await expect(page.getByRole('button', { name: 'Войти' })).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('logout procedure and consequence', async ({ page }) => {
|
||||
authAdmin();
|
||||
await setupLogout(page);
|
||||
|
||||
await page.goto('/');
|
||||
|
||||
await page.getByRole('button', { name: 'Пользователь' }).click();
|
||||
await page.getByRole('button', { name: 'Выйти' }).click();
|
||||
|
||||
await page.getByRole('button', { name: 'Перейти на страницу логина' }).click();
|
||||
await expect(page.getByRole('button', { name: 'Войти' })).toBeVisible();
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user