All files / src/components/ranking LeaderboardCard.vue

100% Statements 102/102
62.96% Branches 17/27
100% Functions 3/3
100% Lines 102/102

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 1211x 1x     1x 1x 1x 1x 1x 1x   1x 1x 1x   1x 19x 19x 19x 19x   19x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 19x     19x 19x 19x 1x 19x 19x 19x 19x 1x 1x 116x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x   1x   1x       1x 1x 135x 135x 135x 135x 135x 135x 135x 135x   1x 1x 135x 135x 135x 19x 135x 1x 1x 1x 135x 19x 19x 135x 96x 96x 135x 135x    
<template>
  <!--
    One leaderboard (SB-1785). The coverage note is shown once above the
    boards by LeaderboardsPanel, not on every card (SB-1817).
  -->
  <!-- min-w-0: a grid item otherwise grows to its widest unwrapped line,
       which on a phone pushes the value column off screen (SB-1795). -->
  <section
    class="min-w-0 rounded-lg border border-line bg-card p-4 flex flex-col"
    :data-testid="`board-${board.key}`"
  >
    <h3 class="mb-2 text-base font-semibold text-fg" data-testid="board-title">
      {{ board.title }}
    </h3>
 
    <p
      v-if="!board.rows || board.rows.length === 0"
      class="py-6 text-center text-sm text-fg-muted"
      data-testid="board-no-rows"
    >
      No team qualifies yet
    </p>
    <ol v-else class="divide-y divide-line">
      <li v-for="(row, i) in board.rows" :key="row.team.id">
        <button
          type="button"
          class="w-full flex items-center gap-2 py-2 text-left hover:bg-surface-alt rounded focus:outline-none focus:bg-surface-alt"
          data-testid="board-row"
          @click="$emit('select-team', row)"
        >
          <span
            class="w-8 shrink-0 text-right text-sm tabular-nums text-fg-muted"
            data-testid="row-rank"
            >{{ rankLabel(i) }}</span
          >
          <ClubLogo
            :logo-url="row.club_logo_url || ''"
            :name="row.team.club_name || row.team.name"
            size="xs"
          />
          <span class="flex-1 min-w-0">
            <span
              class="line-clamp-2 break-words text-sm font-medium leading-snug text-brand-600 dark:text-brand-300"
              data-testid="row-team"
              >{{ row.team.name }}</span
            >
            <span class="block truncate text-xs text-fg-muted">
              <span
                v-if="
                  row.team.club_name && row.team.club_name !== row.team.name
                "
                data-testid="row-club"
                >{{ row.team.club_name }} ·
              </span>
              <span
                v-if="row.no_conference"
                class="inline-block rounded px-1.5 bg-surface-alt text-fg-muted"
                data-testid="row-no-conference"
                >No Homegrown conference</span
              >
              <span v-else data-testid="row-conference">{{
                row.conference || '—'
              }}</span>
              <!-- Matches played sits under the name, not in its own column,
                   so the board's value always has room (SB-1795). -->
              <span class="tabular-nums" data-testid="row-gp">
                · {{ row.gp ?? '—' }} MP</span
              >
            </span>
          </span>
          <span
            class="shrink-0 min-w-[3.5rem] text-right text-sm font-semibold tabular-nums text-fg"
            data-testid="row-value"
            >{{ formatValue(row) }}</span
          >
        </button>
      </li>
    </ol>
  </section>
</template>
 
<script setup>
import ClubLogo from '../shared/ClubLogo.vue';
 
const props = defineProps({
  board: { type: Object, required: true },
});
 
defineEmits(['select-team']);
 
// The API ranks; ties share a rank (1, 1, 3). "T" marks a shared one.
const rankLabel = i => {
  const rows = props.board.rows;
  const rank = rows[i].rank;
  if (rank == null) return '—';
  const tied =
    (i > 0 && rows[i - 1].rank === rank) ||
    (i < rows.length - 1 && rows[i + 1].rank === rank);
  return tied ? `T${rank}` : String(rank);
};
 
// Absent is "—", never 0: a team nobody measured has no value.
const formatValue = row => {
  const v = row.value;
  switch (props.board.key) {
    case 'unbeaten':
      return row.w == null ? '—' : `${row.w}-${row.d}-${row.l}`;
    case 'pro_wins':
      return v == null || row.pro_games == null
        ? '—'
        : `${v} of ${row.pro_games}`;
    case 'gd_pg':
      if (v == null) return '—';
      return v > 0 ? `+${v.toFixed(2)}` : v.toFixed(2);
    default:
      if (v == null) return '—';
      return props.board.variant === 'per_game' ? v.toFixed(2) : String(v);
  }
};
</script>