Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 16 additions & 12 deletions app/components/Compare/FacetBarChart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -283,23 +283,27 @@ const config = computed<VueUiHorizontalBarConfig>(() => {
</VueUiHorizontalBar>

<template #fallback>
<div class="flex flex-col gap-2 justify-center items-center mb-2">
<SkeletonInline class="h-4 w-16" />
<SkeletonInline class="h-4 w-28" />
</div>
<div class="flex flex-col gap-1">
<SkeletonInline class="h-7 w-full" v-for="pkg in packages" :key="pkg" />
<div class="flex flex-col gap-3" data-test="facet-bar-chart-skeleton">
<div class="flex flex-col items-center gap-2 mb-3">
<SkeletonInline class="h-5 w-36 max-w-full" />
<SkeletonInline class="h-4 w-52 max-w-full" />
</div>
<div class="flex flex-col gap-2">
<SkeletonInline class="h-8 w-full" v-for="pkg in packages" :key="pkg" />
</div>
</div>
</template>
</ClientOnly>

<template v-else>
<div class="flex flex-col gap-2 justify-center items-center mb-2">
<SkeletonInline class="h-4 w-16" />
<SkeletonInline class="h-4 w-28" />
</div>
<div class="flex flex-col gap-1">
<SkeletonInline class="h-7 w-full" v-for="pkg in packages" :key="pkg" />
<div class="flex flex-col gap-3" data-test="facet-bar-chart-skeleton">

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we're repeating the same element twice. could we extract this into its own separate component and reuse in multiple places?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repeating just twice, especially when only localised to this file only, is ok.

<div class="flex flex-col items-center gap-2 mb-3">
<SkeletonInline class="h-5 w-36 max-w-full" />
<SkeletonInline class="h-4 w-52 max-w-full" />
</div>
<div class="flex flex-col gap-2">
<SkeletonInline class="h-8 w-full" v-for="pkg in packages" :key="pkg" />
</div>
</div>
</template>
</div>
Expand Down
27 changes: 27 additions & 0 deletions test/nuxt/components/compare/FacetBarChart.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expect, it } from 'vitest'
import { mountSuspended } from '@nuxt/test-utils/runtime'
import FacetBarChart from '~/components/Compare/FacetBarChart.vue'

describe('FacetBarChart', () => {
it('renders a taller loading skeleton with title and subtitle placeholders', async () => {
const component = await mountSuspended(FacetBarChart, {
props: {
values: [null, null],
packages: ['react', 'vue'],
label: 'Bundle size',
description: 'Compare install footprint',
facetLoading: true,
},
})

const skeleton = component.find('[data-test="facet-bar-chart-skeleton"]')
expect(skeleton.exists()).toBe(true)

const lines = skeleton.findAllComponents({ name: 'SkeletonInline' })

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checks for individual heights of placeholder items is not very useful. if we changed the height of the title to 8px for example, we'd have to update all of the unit tests for this. let's instead focus on the input instead and making sure that it exists. (eg:

testPackages = ['react', 'vue']

props: { ..... etc etc
...packages: testPackages
const lines = skeleton.findAllComponents({ name: 'SkeletonInline' })
expect(lines).toHaveLength(2 + testPackages.length)

expect(lines).toHaveLength(4)
expect(lines[0]?.attributes('class')).toContain('h-5')
expect(lines[1]?.attributes('class')).toContain('h-4')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a blocker for this PR, but this spec file could benefit from more comprehensive unit tests. success state, empty state, testing dynamic updates like the watch on props.packages etc

Copy link
Contributor

@graphieros graphieros Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is indeed not really in the scope of this issue, but can be part of an iteration pertaining to test coverage improvements.

expect(lines[2]?.attributes('class')).toContain('h-8')
expect(lines[3]?.attributes('class')).toContain('h-8')
})
})
Loading