Skip to content
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
27 changes: 20 additions & 7 deletions src/pages/TestListPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
import { DragDropContext, Droppable, Draggable, type DropResult } from '@hello-pangea/dnd';
import { useTranslation } from 'react-i18next';
import Topbar from '../components/Layout/Topbar';
import { useAssessment, useAuthoring, useClasses, useSettings, useStudents } from '../context/AppContext';
import { useStoreActions, useStoreSelector } from '../context/useStore';
import { useToast } from '../hooks/useToast';
import { logAuditEvent } from '../services/database/AuditLogger';
import { nanoid } from '../utils/nanoid';
Expand All @@ -40,12 +40,25 @@ import { calcClassAveragePercentage } from '../utils/testCalc';
export default function TestListPage() {
const { t } = useTranslation();
const navigate = useNavigate();
const { students } = useStudents();
const { classes } = useClasses();

const { exportTemplates } = useAuthoring();
const { tests, addTest, updateTest, deleteTest, studentTests, saveStudentTest } = useAssessment();
const { settings } = useSettings();
const {
students: allStudents,
classes,
exportTemplates,
tests,
studentTests,
settings,
} = useStoreSelector((s) => ({
students: s.students,
classes: s.classes,
exportTemplates: s.exportTemplates,
tests: s.tests,
studentTests: s.studentTests,
settings: s.settings,
}));
// The roster domain hooks filtered soft-deleted rows; archived students must not
// appear in cohort filters or per-student statistics.
const students = React.useMemo(() => allStudents.filter((s) => !s.archivedAt), [allStudents]);
const { addTest, updateTest, deleteTest, saveStudentTest } = useStoreActions();

const activeStyleTemplate = exportTemplates.find((t) => t.kind === 'style' && t.id === settings.styleTemplateId);
const [cohortFilter, setCohortFilter] = useState<CohortFilterValue>(ALL_COHORTS);
Expand Down
6 changes: 6 additions & 0 deletions src/pages/__tests__/TestListPage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { describe, it, expect, vi, beforeEach } from 'vitest';
import { MemoryRouter } from 'react-router-dom';
import { DEFAULT_FORMAT } from '../../types';
import type { AppSettings, Class, GradeScale, Student, Test as RmTest, StudentTest } from '../../types';
import type { StoreData } from '../../store/storage';

const mockSettings: AppSettings = {
defaultGradeScaleId: 'gs1',
Expand Down Expand Up @@ -92,6 +93,11 @@ vi.mock('../../context/AppContext', () => ({
usePlatform: () => mockUseApp,
}));

vi.mock('../../context/useStore', () => ({
useStoreSelector: <T,>(selector: (state: StoreData) => T): T => selector(mockUseApp as unknown as StoreData),
useStoreActions: () => mockUseApp,
}));

Comment thread
NesiciCoding marked this conversation as resolved.
vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string, params?: Record<string, unknown>) => {
Expand Down
Loading