From 9906c5059862801cad48540f54d5f0ba24787f62 Mon Sep 17 00:00:00 2001 From: Grisha Lavrov Date: Fri, 4 Dec 2026 16:34:46 +0100 Subject: [PATCH] interview: numbered question steps colored by outcome, with a legend and tooltips The unlabeled dots under the progress bar were unclear. Each question is now a numbered step: color is its outcome (passed/partial/failed, answered without a grade, not started), the current one is ringed, the tooltip says the outcome and its source (AI score, peeked reference, self-assessment). A legend explains the colors; a single question keeps the bar. --- .../interview/QuestionSteps.test.tsx | 44 ++++++ .../components/interview/QuestionSteps.tsx | 139 ++++++++++++++++++ frontend/src/pages/InterviewModePage.test.tsx | 2 +- frontend/src/pages/InterviewModePage.tsx | 56 +------ 4 files changed, 187 insertions(+), 54 deletions(-) create mode 100644 frontend/src/components/interview/QuestionSteps.test.tsx create mode 100644 frontend/src/components/interview/QuestionSteps.tsx diff --git a/frontend/src/components/interview/QuestionSteps.test.tsx b/frontend/src/components/interview/QuestionSteps.test.tsx new file mode 100644 index 0000000..0fb1a4b --- /dev/null +++ b/frontend/src/components/interview/QuestionSteps.test.tsx @@ -0,0 +1,44 @@ +import { fireEvent, render, screen } from '@testing-library/react'; +import { ThemeProvider as MuiThemeProvider } from '@mui/material'; +import { describe, expect, it, vi } from 'vitest'; +import { ThemeProvider } from '../../context/ThemeContext'; +import { darkTheme } from '../../theme/muiTheme'; +import type { AIReview } from '../../types'; +import { QuestionSteps } from './QuestionSteps'; +import { DEFAULT_OPTIONS, newSession } from './session'; + +const renderSteps = (ui: React.ReactNode) => + render( + + {ui} + , + ); + +describe('QuestionSteps', () => { + it('numbers every question, says its outcome and opens it on click', () => { + const session = newSession(['a', 'b', 'c', 'd'], DEFAULT_OPTIONS, 0); + session.results = { + a: { answer: 'x', review: { score: 9 } as AIReview, self: 'knew' }, + b: { answer: '', revealed: true, self: 'missed' }, + c: { answer: 'черновик' }, + }; + const onOpen = vi.fn(); + renderSteps(); + + expect(screen.getByText('Вопрос 3 из 4')).toBeInTheDocument(); + expect(screen.getByText('Отвечено: 3 из 4')).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Вопрос 1: прошёл (ИИ 9/10)' })).toHaveTextContent('1'); + expect(screen.getByRole('button', { name: 'Вопрос 2: не прошёл (подсмотрен эталон)' })).toBeInTheDocument(); + expect(screen.getByRole('button', { name: 'Вопрос 3: есть ответ, не оценён' })).toHaveAttribute('aria-current', 'step'); + fireEvent.click(screen.getByRole('button', { name: 'Вопрос 4: ещё без ответа' })); + expect(onOpen).toHaveBeenCalledWith(3); + // легенда объясняет цвета + for (const label of ['Прошёл', 'Частично', 'Не прошёл', 'Без оценки', 'Не начат']) expect(screen.getByText(label)).toBeInTheDocument(); + }); + + it('falls back to a progress bar for a single question', () => { + renderSteps( {}} />); + expect(screen.getByRole('progressbar', { name: 'Вопрос 1 из 1' })).toBeInTheDocument(); + expect(screen.queryByRole('button')).not.toBeInTheDocument(); + }); +}); diff --git a/frontend/src/components/interview/QuestionSteps.tsx b/frontend/src/components/interview/QuestionSteps.tsx new file mode 100644 index 0000000..cc723e2 --- /dev/null +++ b/frontend/src/components/interview/QuestionSteps.tsx @@ -0,0 +1,139 @@ +import { Box, LinearProgress, Stack, Tooltip, Typography } from '@mui/material'; +import { MASTERY_LABEL, useMasteryColor } from '../ui/masteryLevels'; +import { radius, useTokens } from '../../theme/tokens'; +import type { MasteryLevel } from '../../types'; +import { SELF_TO_LEVEL, type InterviewSession, type QuestionResult } from './session'; + +/** Больше шагов в ряд не помещается осмысленно: дальше только полоса прогресса. */ +const MAX_STEPS = 30; + +type StepState = MasteryLevel | 'answered' | 'empty'; + +const stateOf = (r: QuestionResult | undefined): StepState => + r?.self ? SELF_TO_LEVEL[r.self] : r?.answer?.trim() ? 'answered' : 'empty'; + +const stepLabel = (r: QuestionResult | undefined, state: StepState) => { + if (state === 'empty') return 'ещё без ответа'; + if (state === 'answered') return 'есть ответ, не оценён'; + const how = r?.review ? `ИИ ${r.review.score}/10` : r?.revealed ? 'подсмотрен эталон' : 'своя оценка'; + return `${MASTERY_LABEL[state].toLowerCase()} (${how})`; +}; + +interface QuestionStepsProps { + plan: string[]; + session: InterviewSession | null; + currentIndex: number; + onOpen: (index: number) => void; +} + +/** + * Шаги собеседования: номер каждого вопроса, цвет — итог по нему, клик — перейти. + * Под рядом — легенда, чтобы цвета не приходилось угадывать. + */ +export const QuestionSteps = ({ plan, session, currentIndex, onOpen }: QuestionStepsProps) => { + const { c } = useTokens(); + const masteryColor = useMasteryColor(); + const total = plan.length; + const states = plan.map((id) => stateOf(session?.results[id])); + const touched = states.filter((s) => s !== 'empty').length; + const showSteps = Boolean(session) && total > 1 && total <= MAX_STEPS; + + const look = (state: StepState) => + state === 'empty' + ? { fg: c.textMuted, bg: 'transparent', border: c.borderStrong } + : state === 'answered' + ? { fg: c.accent, bg: c.accentSoft, border: c.accent } + : { ...masteryColor(state), border: masteryColor(state).fg }; + + const legend: { state: StepState; label: string }[] = [ + { state: 'passed', label: MASTERY_LABEL.passed }, + { state: 'partial', label: MASTERY_LABEL.partial }, + { state: 'failed', label: MASTERY_LABEL.failed }, + { state: 'answered', label: 'Без оценки' }, + { state: 'empty', label: 'Не начат' }, + ]; + + return ( + + + + Вопрос {currentIndex + 1} из {total} + + {session && ( + + Отвечено: {touched} из {total} + + )} + + + {!showSteps ? ( + + ) : ( + <> + + {plan.map((id, i) => { + const state = states[i]; + const current = i === currentIndex; + const { fg, bg, border } = look(state); + const text = `Вопрос ${i + 1}: ${stepLabel(session?.results[id], state)}`; + return ( +
  • + + onOpen(i)} + sx={{ + all: 'unset', + boxSizing: 'border-box', + cursor: 'pointer', + minWidth: 32, + height: 32, + px: 0.75, + display: 'grid', + placeItems: 'center', + borderRadius: `${radius.md}px`, + border: `1px ${state === 'empty' ? 'dashed' : 'solid'} ${border}`, + bgcolor: bg, + color: fg, + fontSize: '.8125rem', + fontWeight: current ? 750 : 550, + fontVariantNumeric: 'tabular-nums', + boxShadow: current ? `0 0 0 2px ${c.bg}, 0 0 0 4px ${c.text}` : 'none', + transition: 'transform .15s, box-shadow .15s', + '&:hover': { transform: 'translateY(-1px)' }, + '&:focus-visible': { outline: `2px solid ${c.accent}`, outlineOffset: 3 }, + }} + > + {i + 1} + + +
  • + ); + })} +
    + + {legend.map(({ state, label }) => { + const { bg, border } = look(state); + return ( + + + + {label} + + + ); + })} + + + )} +
    + ); +}; diff --git a/frontend/src/pages/InterviewModePage.test.tsx b/frontend/src/pages/InterviewModePage.test.tsx index b4d6cea..cf8c430 100644 --- a/frontend/src/pages/InterviewModePage.test.tsx +++ b/frontend/src/pages/InterviewModePage.test.tsx @@ -113,7 +113,7 @@ describe('InterviewModePage', () => { expect(screen.getByText('2 вопроса из 2 подходящих')).toBeInTheDocument(); fireEvent.click(screen.getByRole('button', { name: 'Начать' })); expect(await screen.findByText('Question body 2')).toBeInTheDocument(); - expect(screen.getByText('1 / 2')).toBeInTheDocument(); + expect(screen.getByText('Вопрос 1 из 2')).toBeInTheDocument(); // без ИИ кнопки проверки нет, самооценка доступна expect(screen.queryByRole('button', { name: 'Сдать ответ' })).not.toBeInTheDocument(); fireEvent.click(screen.getByRole('button', { name: 'Не прошёл' })); diff --git a/frontend/src/pages/InterviewModePage.tsx b/frontend/src/pages/InterviewModePage.tsx index 3c483e1..d7fb2b1 100644 --- a/frontend/src/pages/InterviewModePage.tsx +++ b/frontend/src/pages/InterviewModePage.tsx @@ -1,5 +1,5 @@ import { type ReactNode, useCallback, useEffect, useMemo, useRef, useState } from 'react'; -import { Box, Button, Chip, CircularProgress, Container, Divider, LinearProgress, Stack, Typography } from '@mui/material'; +import { Box, Button, Chip, CircularProgress, Container, Divider, Stack, Typography } from '@mui/material'; import { ArrowBack as ArrowBackIcon, ArrowForward as ArrowForwardIcon, @@ -17,12 +17,11 @@ import { AnswerPanel } from '../components/interview/AnswerPanel'; import { InterviewResults } from '../components/interview/InterviewResults'; import { InterviewSetup } from '../components/interview/InterviewSetup'; import { GradeScale } from '../components/interview/GradeScale'; +import { QuestionSteps } from '../components/interview/QuestionSteps'; import { ScoreBadge } from '../components/interview/ScoreBadge'; -import { MASTERY_LABEL, useMasteryColor } from '../components/ui/masteryLevels'; import { buildPlan, DEFAULT_OPTIONS, - SELF_TO_LEVEL, type InterviewOptions, type InterviewSession, loadSession, @@ -145,8 +144,6 @@ const Frame = ({ children, wide }: { children: ReactNode; wide?: boolean }) => ( export const InterviewModePage = () => { const navigate = useNavigate(); const { companyId, questionIndex } = useParams<{ companyId: string; questionIndex: string }>(); - const { c } = useTokens(); - const masteryColor = useMasteryColor(); const questionsQuery = useCompanyQuestionsWithContent(companyId); const { completed } = useProgress(); @@ -303,7 +300,6 @@ export const InterviewModePage = () => { } const isLast = currentIndex === plan.length - 1; - const progress = ((currentIndex + 1) / plan.length) * 100; const currentResult = session?.results[currentQuestion.id]; const aiAvailable = Boolean(ai.data?.enabled) && ai.data!.used_today < ai.data!.daily_limit; @@ -322,53 +318,7 @@ export const InterviewModePage = () => { {session && } - - - - Вопрос - - - {currentIndex + 1} / {plan.length} - - - - {session && plan.length <= 30 && ( - - {plan.map((id, i) => { - const r = session.results[id]; - const done = Boolean(r?.answer?.trim() || r?.self); - // точка окрашена уровнем, который поставил ИИ (или сам кандидат, когда ИИ недоступен) - const fill = r?.self ? masteryColor(SELF_TO_LEVEL[r.self]).fg : done ? c.accent : 'transparent'; - return ( - navigate(`${base}/${i}`)} - sx={{ - all: 'unset', - cursor: 'pointer', - width: 10, - height: 10, - borderRadius: '50%', - border: `1px solid ${i === currentIndex ? c.text : fill === 'transparent' ? c.borderStrong : fill}`, - boxShadow: i === currentIndex ? `0 0 0 2px ${c.bg}, 0 0 0 3px ${c.accent}` : 'none', - backgroundColor: fill, - '&:focus-visible': { outline: `2px solid ${c.accent}`, outlineOffset: 2 }, - }} - /> - ); - })} - - )} - + navigate(`${base}/${i}`)} />