All files / src/utils/helpers testIds.js

88.88% Statements 16/18
62.5% Branches 10/16
75% Functions 6/8
93.33% Lines 14/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84        23x 1775x 1326x                   23x 1751x 3502x 3502x       23x                                           23x 1270x   481x     23x                                   23x                         23x  
/**
 * Convention: `{role}-{area}-{element}` e.g. `teacher-tests-search`
 */
 
export const slugifyTestId = (value, fallback = "item") => {
    if (value == null || value === "") return fallback;
    return (
        String(value)
            .trim()
            .toLowerCase()
            .replace(/[^a-z0-9]+/g, "-")
            .replace(/^-+|-+$/g, "")
            .slice(0, 80) || fallback
    );
};
 
export const testId = (...parts) =>
    parts
        .flatMap((part) => (Array.isArray(part) ? part : [part]))
        .filter((part) => part != null && part !== "")
        .join("-");
 
/** Teacher — Tests catalog */
export const TEACHER_TESTS_IDS = {
    page: "teacher-tests-page",
    header: "teacher-tests-header",
    title: "teacher-tests-title",
    helpButton: "teacher-tests-button-help",
    planBadge: "teacher-tests-plan-badge",
    errorAlert: "teacher-tests-alert-error",
    statsBar: "teacher-tests-stats-bar",
    statCatalog: "teacher-tests-stat-catalog",
    statEruditionLibrary: "teacher-tests-stat-erudition-library",
    statAvailable: "teacher-tests-stat-available",
    statLocked: "teacher-tests-stat-locked",
    table: "teacher-tests-table",
    search: "teacher-tests-search",
    filterType: "teacher-tests-filter-type",
    filterAccess: "teacher-tests-filter-access",
    filterCatalog: "teacher-tests-filter-catalog",
    filterSlot: "teacher-tests-filter-slot",
    filterReset: "teacher-tests-button-reset-filters",
    countLabel: "teacher-tests-count-label",
};
 
export const teacherTestsRowId = (row) =>
    testId("teacher-tests-row", slugifyTestId(row?.title, `index-${row?._rowIndex ?? 0}`));
 
export const teacherTestsRowActionViewId = (row) => testId(teacherTestsRowId(row), "action-view");
 
/** Teacher — View test (global assignment) */
export const TEACHER_TEST_VIEW_IDS = {
    page: "teacher-test-view-page",
    appBar: "teacher-test-view-appbar",
    title: "teacher-test-view-title",
    lockedState: "teacher-test-view-locked-state",
    backButton: "teacher-test-view-button-back",
    headerCard: "teacher-test-view-header-card",
    chipType: "teacher-test-view-chip-type",
    chipAvailable: "teacher-test-view-chip-available",
    chipLocked: "teacher-test-view-chip-locked",
    chipQuestions: "teacher-test-view-chip-questions",
    panelDetails: "teacher-test-view-panel-details",
    panelQuestions: "teacher-test-view-panel-questions",
    panelActions: "teacher-test-view-panel-actions",
    questionCard: (index) => testId("teacher-test-view-question", index),
};
 
/** Shared dialogs & feature access */
export const SHARED_IDS = {
    upgradeDialog: "upgrade-dialog",
    upgradeDialogClose: "upgrade-dialog-button-close",
    upgradeDialogConfirm: "upgrade-dialog-button-got-it",
    viewProfileDialog: "view-profile-dialog",
    viewProfileClose: "view-profile-button-close",
    viewProfilePlanChip: "view-profile-chip-plan",
    viewProfileRoleChip: "view-profile-chip-role",
    copyright: "app-footer",
    copyrightText: "app-footer-copyright-text",
    copyrightVersion: "app-footer-version",
};
 
export const rowIndexFromMrtRow = (row) => row?.index ?? row?.id ?? 0;