diff --git a/frontend/src/components/ui/PracticeMascot.test.tsx b/frontend/src/components/ui/PracticeMascot.test.tsx
new file mode 100644
index 0000000..16a7882
--- /dev/null
+++ b/frontend/src/components/ui/PracticeMascot.test.tsx
@@ -0,0 +1,48 @@
+import { http, HttpResponse } from 'msw';
+import { setupServer } from 'msw/node';
+import { MemoryRouter } from 'react-router-dom';
+import { QueryClient } from '@tanstack/react-query';
+import { act, fireEvent, render, screen } from '@testing-library/react';
+import { ThemeProvider as MuiThemeProvider } from '@mui/material';
+import { afterAll, afterEach, beforeAll, describe, expect, it } from 'vitest';
+import { AuthProvider } from '../../context/AuthContext';
+import { ThemeProvider } from '../../context/ThemeContext';
+import { darkTheme } from '../../theme/muiTheme';
+import { TestQueryProvider } from '../../test/TestQueryProvider';
+import { PracticeMascot } from './PracticeMascot';
+import { bitSay } from './bitVoice';
+
+const server = setupServer(http.get('*/auth/me', () => new HttpResponse(null, { status: 401 })));
+beforeAll(() => server.listen());
+afterEach(() => server.resetHandlers());
+afterAll(() => server.close());
+
+const renderMascot = () =>
+ render(
+
+
+
+
+
+
+
+
+
+
+ ,
+ );
+
+describe('PracticeMascot speech', () => {
+ it('does not repeat a line said before it mounted, shows new lines and hides on click', async () => {
+ bitSay('старая реплика');
+ renderMascot();
+ expect(screen.queryByText('старая реплика')).not.toBeInTheDocument();
+
+ act(() => bitSay('Хардкор-режим включён!', 'fire'));
+ expect(screen.getByRole('status')).toHaveTextContent('Бит: Хардкор-режим включён!');
+ const bubble = await screen.findByText('Хардкор-режим включён!', { selector: 'p' });
+
+ fireEvent.click(bubble);
+ expect(screen.getByRole('status')).toHaveTextContent('');
+ });
+});
diff --git a/frontend/src/components/ui/PracticeMascot.tsx b/frontend/src/components/ui/PracticeMascot.tsx
index da835db..1f25f52 100644
--- a/frontend/src/components/ui/PracticeMascot.tsx
+++ b/frontend/src/components/ui/PracticeMascot.tsx
@@ -1,10 +1,12 @@
import { useEffect, useId, useState } from 'react';
-import { Box, Button, Dialog, DialogContent, DialogTitle, IconButton, Stack, Typography } from '@mui/material';
+import { Box, Button, ClickAwayListener, Dialog, DialogContent, DialogTitle, Grow, IconButton, Popper, Stack, Typography } from '@mui/material';
import { ArrowForward, Close, Loop } from '@mui/icons-material';
import { Link as RouterLink, useLocation } from 'react-router-dom';
import { useAuth } from '../../context/auth-context';
import { useTokens } from '../../theme/tokens';
import bit from '../../assets/mascot/bit.webp';
+import { useBitVoice } from './bitVoice';
+import type { BitTone } from './bitVoice';
type TipSet = [string, string];
@@ -61,14 +63,22 @@ const comments = [
'Код сам себя не прочтёт',
];
-const BitAvatar = () => (
+const BitAvatar = ({ talking = false }: { talking?: boolean }) => (
{
const [alternate, setAlternate] = useState(false);
const [commentIndex, setCommentIndex] = useState(0);
const section = getSection(pathname);
+ // Реплики (bitSay) показываются облачком под Битом; сказанное до перехода на страницу не повторяем.
+ const voice = useBitVoice();
+ const [seenId] = useState(() => voice?.id ?? 0);
+ const [hiddenId, setHiddenId] = useState(0);
+ const [anchor, setAnchor] = useState(null);
+ const [arrow, setArrow] = useState(null);
+ const said = voice && voice.id > seenId && voice.id > hiddenId && !open ? voice : null;
+ useEffect(() => {
+ if (!voice) return;
+ const timer = window.setTimeout(() => setHiddenId(voice.id), 6500);
+ return () => window.clearTimeout(timer);
+ }, [voice]);
+ const toneColor: Record = { calm: c.accent, cheer: c.success, fire: c.danger, focus: c.warning };
useEffect(() => {
const timer = window.setInterval(() => {
@@ -119,6 +142,7 @@ const MascotPanel = ({ pathname }: { pathname: string }) => {
return (
<>
+
+ {said ? `Бит: ${said.text}` : ''}
+
+ t.zIndex.appBar + 1 }}
+ modifiers={[
+ { name: 'offset', options: { offset: [0, 10] } },
+ { name: 'preventOverflow', options: { padding: 8 } },
+ // хвостик всегда указывает на Бита, даже если облачко прижато к краю экрана
+ { name: 'arrow', enabled: Boolean(arrow), options: { element: arrow, padding: 14 } },
+ ]}
+ >
+ {({ TransitionProps }) => (
+
+
+ voice && setHiddenId(voice.id)}>
+ voice && setHiddenId(voice.id)}
+ sx={{
+ position: 'relative',
+ maxWidth: { xs: 'calc(100vw - 24px)', sm: 300 },
+ px: 1.75,
+ py: 1.25,
+ borderRadius: '14px',
+ border: `1px solid ${c.borderStrong}`,
+ borderTop: `3px solid ${said ? toneColor[said.tone] : c.accent}`,
+ bgcolor: c.surface,
+ boxShadow: shadow.lg,
+ cursor: 'pointer',
+ }}
+ >
+
+ Бит
+ {said?.text}
+
+
+
+
+ )}
+