# All files / src/lib/quality-validator/reporters/html HtmlScoreSection.ts

0% Statements 0/201
0% Branches 0/1
0% Functions 0/1
0% Lines 0/201

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
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202

     /**
     * HTML Report Score Section Module
     * Generates the overall score display, grade visualization, and scoring details
     */

    import { OverallScore, ComponentScores } from '../../types/index.js';
    import { formatScore } from '../../utils/formatters.js';

    /**
     * Generate the overall score section
     *
     * @param {OverallScore} overall - Overall score information
     * @returns {string} HTML section with grade circle and score details
     *
     * @description
     * Creates a prominent display containing:
     * - Large circular grade indicator (A-F)
     * - Numeric score
     * - Status badge
     * - Summary text
     */
    export function generateOverallSection(overall: OverallScore): string {
      const gradeClass = getGradeClass(overall.grade);

      return `<section class="section">
      <div class="card overall-card">
        <div class="overall-score">
          <div class="grade ${gradeClass}">
            <span class="grade-letter">${overall.grade}</span>
          </div>
          <div class="grade-info">
            <h2>${formatScore(overall.score)}</h2>
            <p>${overall.summary}</p>
            <p class="status ${overall.status}">${overall.status.toUpperCase()}</p>
          </div>
        </div>
      </div>
    </section>`;
    }

    /**
     * Generate component scores grid
     *
     * @param {ComponentScores} componentScores - Component scores with weights
     * @returns {string} HTML section with score cards
     *
     * @description
     * Creates a grid of cards showing:
     * - Code Quality score and weight
     * - Test Coverage score and weight
     * - Architecture score and weight
     * - Security score and weight
     * Each with visual progress bar
     */
    export function generateComponentScoresSection(componentScores: ComponentScores): string {
      const components = [
        {
          name: 'Code Quality',
          score: componentScores.codeQuality.score,
          weight: componentScores.codeQuality.weight,
        },
        {
          name: 'Test Coverage',
          score: componentScores.testCoverage.score,
          weight: componentScores.testCoverage.weight,
        },
        {
          name: 'Architecture',
          score: componentScores.architecture.score,
          weight: componentScores.architecture.weight,
        },
        {
          name: 'Security',
          score: componentScores.security.score,
          weight: componentScores.security.weight,
        },
      ];

      let scoresHtml = '<section class="section"><h2>Component Scores</h2><div class="scores-grid">';

      for (const component of components) {
        scoresHtml += generateScoreCard(component.name, component.score, component.weight);
      }

      scoresHtml += '</div></section>';
      return scoresHtml;
    }

    /**
     * Generate a single score card
     *
     * @param {string} name - Component name
     * @param {number} score - Score value (0-100)
     * @param {number} weight - Weight as decimal (0-1)
     * @returns {string} HTML score card
     *
     * @description
     * Creates a card with:
     * - Component name as title
     * - Visual progress bar
     * - Numeric score and weight
     * - Color coding based on score level
     */
    export function generateScoreCard(name: string, score: number, weight: number): string {
      const scoreClass = getScoreClass(score);

      return `
        <div class="card score-card ${scoreClass}">
          <h3>${name}</h3>
          <div class="score-bar">
            <div class="score-fill" style="width: ${score}%"></div>
          </div>
          <p class="score-value">${formatScore(score)} <span>(${(weight * 100).toFixed(0)}%)</span></p>
        </div>`;
    }

    /**
     * Generate summary statistics section
     *
     * @param {OverallScore} overall - Overall score data
     * @param {ComponentScores} componentScores - Component scores
     * @returns {string} HTML section with statistics
     *
     * @description
     * Displays summary metrics including:
     * - Highest scoring component
     * - Lowest scoring component
     * - Pass/fail status
     * - Grade summary
     */
    export function generateSummaryStatistics(
      overall: OverallScore,
      componentScores: ComponentScores
    ): string {
      const components = [
        { name: 'Code Quality', score: componentScores.codeQuality.score },
        { name: 'Test Coverage', score: componentScores.testCoverage.score },
        { name: 'Architecture', score: componentScores.architecture.score },
        { name: 'Security', score: componentScores.security.score },
      ];

      const highest = components.reduce((a, b) => (a.score > b.score ? a : b));
      const lowest = components.reduce((a, b) => (a.score < b.score ? a : b));

      return `<section class="section">
      <h2>Summary</h2>
      <div class="metrics-grid">
        <div class="metric">
          <div class="metric-label">Highest Component</div>
          <div class="metric-value">${highest.name}</div>
          <small>${formatScore(highest.score)}</small>
        </div>
        <div class="metric">
          <div class="metric-label">Lowest Component</div>
          <div class="metric-value">${lowest.name}</div>
          <small>${formatScore(lowest.score)}</small>
        </div>
        <div class="metric">
          <div class="metric-label">Overall Grade</div>
          <div class="metric-value">${overall.grade}</div>
          <small>Status: ${overall.status.toUpperCase()}</small>
        </div>
      </div>
    </section>`;
    }

    /**
     * Get CSS class for grade styling
     *
     * @param {string} grade - Letter grade (A-F)
     * @returns {string} CSS class name
     *
     * @description
     * Maps grades to styling classes:
     * - A, B → 'grade-pass' (blue)
     * - C, D → 'grade-warning' (orange)
     * - F → 'grade-fail' (red)
     */
    function getGradeClass(grade: string): string {
      if (grade === 'A' || grade === 'B') return 'grade-pass';
      if (grade === 'C' || grade === 'D') return 'grade-warning';
      return 'grade-fail';
    }

    /**
     * Get CSS class for score styling
     *
     * @param {number} score - Score value
     * @returns {string} CSS class name
     *
     * @description
     * Maps score ranges to styling classes:
     * - 80+ → 'score-pass' (green)
     * - 60-79 → 'score-warning' (yellow)
     * - <60 → 'score-fail' (red)
     */
    function getScoreClass(score: number): string {
      if (score >= 80) return 'score-pass';
      if (score >= 60) return 'score-warning';
      return 'score-fail';
    }