|
| 1 | +<template> |
| 2 | + <div |
| 3 | + class="border-t-4px min-w-200px w-full max-w-400px grid p-4 gap-4 grid-cols-1 justify-items-center" |
| 4 | + :class="severity.accentClass" |
| 5 | + data-cy="flaky-spec-summary" |
| 6 | + > |
| 7 | + <SpecNameDisplay |
| 8 | + :spec-file-name="specName" |
| 9 | + :spec-file-extension="specExtension" |
| 10 | + /> |
| 11 | + <div class="flex flex-row w-full text-size-14px justify-center items-center"> |
| 12 | + <component :is="severity.icon" /> |
| 13 | + <span |
| 14 | + class="font-medium ml-2" |
| 15 | + :class="severity.textClass" |
| 16 | + >{{ severity?.label }}</span> |
| 17 | + <span |
| 18 | + class="ml-4" |
| 19 | + data-cy="flaky-rate" |
| 20 | + >{{ t('specPage.flaky.flakyRate', [flakyRate]) }}</span> |
| 21 | + </div> |
| 22 | + |
| 23 | + <div class="w-full grid text-gray-700 text-size-14px gap-2 grid-cols-2 justify-items-center"> |
| 24 | + <span data-cy="flaky-runs">{{ t('specPage.flaky.flakyRuns', { count: totalFlakyRuns, flakyRuns: totalFlakyRuns, totalRuns }) }}</span> |
| 25 | + <span data-cy="last-flaky">{{ t('specPage.flaky.lastFlaky', { count: runsSinceLastFlake, runsSinceLastFlake }) }}</span> |
| 26 | + </div> |
| 27 | + </div> |
| 28 | +</template> |
| 29 | + |
| 30 | +<script setup lang="ts"> |
| 31 | +
|
| 32 | +import { computed } from 'vue' |
| 33 | +import { useI18n } from '@cy/i18n' |
| 34 | +import SpecNameDisplay from '../SpecNameDisplay.vue' |
| 35 | +import LowRateIcon from '~icons/cy/rate-low_x16' |
| 36 | +import MediumRateIcon from '~icons/cy/rate-medium_x16' |
| 37 | +import HighRateIcon from '~icons/cy/rate-high_x16' |
| 38 | +
|
| 39 | +const { t } = useI18n() |
| 40 | +
|
| 41 | +const SEVERITIES = { |
| 42 | + 'default': { |
| 43 | + accentClass: 'border-t-orange-400', |
| 44 | + textClass: null, |
| 45 | + label: null, |
| 46 | + icon: null, |
| 47 | + }, |
| 48 | + 'low': { |
| 49 | + accentClass: 'border-t-orange-400', |
| 50 | + textClass: 'text-orange-400', |
| 51 | + label: t('specPage.flaky.severityLow'), |
| 52 | + icon: LowRateIcon, |
| 53 | + }, |
| 54 | + 'medium': { |
| 55 | + accentClass: 'border-t-orange-500', |
| 56 | + textClass: 'text-orange-500', |
| 57 | + label: t('specPage.flaky.severityMedium'), |
| 58 | + icon: MediumRateIcon, |
| 59 | + }, |
| 60 | + 'high': { |
| 61 | + accentClass: 'border-t-orange-600', |
| 62 | + textClass: 'text-orange-600', |
| 63 | + label: t('specPage.flaky.severityHigh'), |
| 64 | + icon: HighRateIcon, |
| 65 | + }, |
| 66 | +} |
| 67 | +
|
| 68 | +const props = defineProps<{ |
| 69 | + specName: string |
| 70 | + specExtension: string |
| 71 | + severity: 'low' | 'medium' | 'high' |
| 72 | + totalFlakyRuns: number |
| 73 | + totalRuns: number |
| 74 | + runsSinceLastFlake: number |
| 75 | + dashboardUrl: string |
| 76 | +}>() |
| 77 | +
|
| 78 | +const flakyRate = computed(() => { |
| 79 | + if (props.totalFlakyRuns <= 0 || props.totalRuns <= 0) { |
| 80 | + return 0 |
| 81 | + } |
| 82 | +
|
| 83 | + const rawRate = (props.totalFlakyRuns / props.totalRuns) * 100 |
| 84 | +
|
| 85 | + // Only display 100 if rawRate is actually 100 (do not round to 100) |
| 86 | + if (rawRate > 99 && rawRate < 100) { |
| 87 | + return 99 |
| 88 | + } |
| 89 | +
|
| 90 | + return Math.ceil(rawRate) |
| 91 | +}) |
| 92 | +
|
| 93 | +const severity = computed(() => SEVERITIES[props.severity] || SEVERITIES.default) |
| 94 | +
|
| 95 | +</script> |
0 commit comments