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
24 changes: 17 additions & 7 deletions src/pages/RubricBuilder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from 'lucide-react';
import { DragDropContext, Droppable, DropResult } from '@hello-pangea/dnd';
import Topbar from '../components/Layout/Topbar';
import { useAssessment, useAuthoring, useGrading, useSettings } from '../context/AppContext';
import { useStoreActions, useStoreSelector } from '../context/useStore';
import { useTranslation, Trans } from 'react-i18next';
import type {
Rubric,
Expand Down Expand Up @@ -101,25 +101,35 @@ export default function RubricBuilder() {
const navigate = useNavigate();
const { id } = useParams();
const location = useLocation();
const { studentRubrics } = useGrading();

const {
studentRubrics: allStudentRubrics,
rubrics,
gradeScales,
peerReviews,
settings,
} = useStoreSelector((s) => ({
studentRubrics: s.studentRubrics,
rubrics: s.rubrics,
gradeScales: s.gradeScales,
peerReviews: s.peerReviews,
settings: s.settings,
}));
// The roster domain hooks filtered soft-deleted rows; keep that behavior here.
const studentRubrics = React.useMemo(() => allStudentRubrics.filter((sr) => !sr.deletedAt), [allStudentRubrics]);

const {
addRubric,
updateRubric,
syncRubricSnapshot,
fetchRubricVersions,
saveRubricVersion,
restoreRubricVersion,
gradeScales,
addVocabularyItem,
updateVocabularyItem,
deleteVocabularyItem,
deleteVocabularyItems,
saveUserTemplate,
} = useAuthoring();
const { peerReviews } = useAssessment();
const { settings } = useSettings();
} = useStoreActions();

const existing = id ? rubrics.find((r) => r.id === id) : undefined;
const template = location.state?.template as Partial<Rubric> | undefined;
Expand Down
12 changes: 12 additions & 0 deletions src/pages/__tests__/RubricBuilder.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ const mockShowToast = vi.fn();
const mockExportPdf = vi.fn();
const mockExportDocx = vi.fn();
const mockSyncRubricSnapshot = vi.fn();
const mockSaveUserTemplate = vi.fn();
const mockFetchRubricVersions = vi.fn(async () => [] as typeof mockVersions);
const mockSaveRubricVersion = vi.fn(async () => {});
const mockRestoreRubricVersion = vi.fn();
Expand All @@ -126,6 +127,7 @@ const makeAppContextMock = () => ({
fetchRubricVersions: mockFetchRubricVersions,
saveRubricVersion: mockSaveRubricVersion,
restoreRubricVersion: mockRestoreRubricVersion,
saveUserTemplate: mockSaveUserTemplate,
gradeScales: [mockGradeScale],
settings: mockSettings,
addVocabularyItem: vi.fn(),
Expand All @@ -149,6 +151,11 @@ vi.mock('../../context/AppContext', () => ({
usePlatform: () => makeAppContextMock(),
}));

vi.mock('../../context/useStore', () => ({
useStoreSelector: (selector: (state: any) => any) => selector(makeAppContextMock()),
useStoreActions: () => makeAppContextMock(),
}));
Comment thread
NesiciCoding marked this conversation as resolved.

vi.mock('react-i18next', () => ({
useTranslation: () => ({
t: (key: string, opts?: string | Record<string, unknown>) => {
Expand Down Expand Up @@ -514,9 +521,14 @@ describe('RubricBuilder', () => {
// ── Save-as-template, print, JSON export ──────────────────────────────────────

it('saves the rubric as a template from the export menu', () => {
mockSaveUserTemplate.mockClear();
mockShowToast.mockClear();
renderEdit();
fireEvent.click(screen.getByText('rubricBuilder.action_export'));
fireEvent.click(screen.getByText('rubricBuilder.action_save_as_template'));
expect(mockSaveUserTemplate).toHaveBeenCalledWith(
expect.objectContaining({ name: mockRubric.name, subject: mockRubric.subject })
);
expect(mockShowToast).toHaveBeenCalled();
});

Expand Down
Loading