All files / src/components/ui ScorePill.vue

100% Statements 35/35
100% Branches 9/9
100% Functions 0/0
100% Lines 35/35

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 601x 1x 1x           1x   1x 1x 1x 2x 2x 2x 2x 2x 2x 1x 1x 1x 1x       1x   1x                     1x   1x 1x 1x 1x   1x 19x 19x 7x 1x   1x 1x 12x 12x 1x 1x    
<template>
  <span
    :class="[
      'px-2 sm:px-2.5 py-0.5 rounded-md shrink-0 tabular-nums text-sm sm:text-base',
      played
        ? 'bg-surface-alt text-fg border border-line font-bold'
        : 'text-fg-muted font-medium',
    ]"
    data-testid="score-pill"
  >
    <template v-if="played">
      {{ homeScore }}&thinsp;–&thinsp;{{ awayScore
      }}<span
        v-if="hasPenalties"
        class="ml-1 text-xs font-semibold opacity-80"
        data-testid="score-pill-penalties"
        >({{ homePenaltyScore }}&thinsp;–&thinsp;{{
          awayPenaltyScore
        }}&nbsp;pk)</span
      >
    </template>
    <template v-else>vs</template>
  </span>
</template>
 
<script setup>
import { computed } from 'vue';
 
const props = defineProps({
  homeScore: { type: Number, default: null },
  awayScore: { type: Number, default: null },
  homePenaltyScore: { type: Number, default: null },
  awayPenaltyScore: { type: Number, default: null },
  // Optional: when given, a result is only rendered for a status that can have
  // one. Guards against stored placeholder zeros on unplayed matches (SB-886) —
  // prod carried `DEFAULT 0` on the score columns, so a fixture kicking off
  // tomorrow arrived here as a 0-0 draw. Omitted (null) keeps the old
  // score-presence-only behaviour for callers that have no status to hand.
  status: { type: String, default: null },
});
 
// Statuses under which a scoreline is real. A live match at 0-0 is a genuine
// scoreline, so it belongs here alongside completed and forfeit. `live` is the
// stored value; `in_progress` is kept as an alias (SB-910).
const SCORABLE = ['completed', 'live', 'in_progress', 'forfeit'];
 
const played = computed(() => {
  if (props.homeScore == null || props.awayScore == null) return false;
  if (props.status == null) return true;
  return SCORABLE.includes(props.status);
});
 
const hasPenalties = computed(
  () =>
    played.value &&
    props.homePenaltyScore != null &&
    props.awayPenaltyScore != null
);
</script>