-
-
Notifications
You must be signed in to change notification settings - Fork 365
fix: use varying widths for compare bar chart skeleton loaders #2209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,65 @@ | ||||||||||||||
| import { describe, expect, it, vi } from 'vitest' | ||||||||||||||
| import { mountSuspended } from '@nuxt/test-utils/runtime' | ||||||||||||||
| import FacetBarChart from '~/components/Compare/FacetBarChart.vue' | ||||||||||||||
|
|
||||||||||||||
| // Stub the heavy chart library | ||||||||||||||
| vi.mock('vue-data-ui/vue-ui-horizontal-bar', () => ({ | ||||||||||||||
| VueUiHorizontalBar: { template: '<div class="chart-stub"><slot name="fallback" /></div>' }, | ||||||||||||||
| })) | ||||||||||||||
| vi.mock('vue-data-ui/style.css', () => ({})) | ||||||||||||||
|
|
||||||||||||||
| describe('FacetBarChart skeleton loaders', () => { | ||||||||||||||
| const baseProps = { | ||||||||||||||
| values: [null, null, null], | ||||||||||||||
| packages: ['react', 'vue', 'svelte'], | ||||||||||||||
| label: 'Weekly Downloads', | ||||||||||||||
| description: 'Downloads per week', | ||||||||||||||
| facetLoading: true, | ||||||||||||||
| } | ||||||||||||||
|
|
||||||||||||||
| it('renders skeleton loaders when facetLoading is true', async () => { | ||||||||||||||
| const wrapper = await mountSuspended(FacetBarChart, { | ||||||||||||||
| props: baseProps, | ||||||||||||||
| }) | ||||||||||||||
|
|
||||||||||||||
| const html = wrapper.html() | ||||||||||||||
| // Should show skeleton elements | ||||||||||||||
| expect(html).toContain('h-7') | ||||||||||||||
| }) | ||||||||||||||
|
|
||||||||||||||
| it('skeleton bar label widths vary across packages (not all the same)', () => { | ||||||||||||||
| // The formula used is: width = `${40 + (i * 17) % 40}%` | ||||||||||||||
| // For 3 packages: i=0 -> 40%, i=1 -> 57%, i=2 -> 74% | ||||||||||||||
| const packages = ['react', 'vue', 'svelte'] | ||||||||||||||
| const widths = packages.map((_, i) => `${40 + ((i * 17) % 40)}%`) | ||||||||||||||
|
|
||||||||||||||
| // Verify they are not all the same (the bug was all bars had the same width) | ||||||||||||||
| const uniqueWidths = new Set(widths) | ||||||||||||||
| expect(uniqueWidths.size).toBeGreaterThan(1) | ||||||||||||||
| }) | ||||||||||||||
|
|
||||||||||||||
| it('skeleton width formula produces values within 40-80% range', () => { | ||||||||||||||
| const indices = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | ||||||||||||||
| for (const i of indices) { | ||||||||||||||
| const width = 40 + ((i * 17) % 40) | ||||||||||||||
| expect(width).toBeGreaterThanOrEqual(40) | ||||||||||||||
| expect(width).toBeLessThan(80) | ||||||||||||||
| } | ||||||||||||||
| }) | ||||||||||||||
|
|
||||||||||||||
| it('renders one row per package in the skeleton', async () => { | ||||||||||||||
| const wrapper = await mountSuspended(FacetBarChart, { | ||||||||||||||
| props: { | ||||||||||||||
| ...baseProps, | ||||||||||||||
| packages: ['pkg-a', 'pkg-b', 'pkg-c'], | ||||||||||||||
| facetLoading: true, | ||||||||||||||
| }, | ||||||||||||||
| }) | ||||||||||||||
|
|
||||||||||||||
| // The skeleton renders one flex row per package | ||||||||||||||
| const html = wrapper.html() | ||||||||||||||
| // flex items-center gap-3 = the skeleton row class | ||||||||||||||
| const rowMatches = html.match(/flex items-center gap-3/g) | ||||||||||||||
| expect(rowMatches).not.toBeNull() | ||||||||||||||
| }) | ||||||||||||||
|
Comment on lines
+62
to
+64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Assert exact row count, not only presence. Line 63 only checks that at least one match exists. To verify “one row per package”, assert the exact number of rendered rows. 🎯 Tightened assertion- const rowMatches = html.match(/flex items-center gap-3/g)
- expect(rowMatches).not.toBeNull()
+ const rowMatches = html.match(/flex items-center gap-3/g) ?? []
+ expect(rowMatches).toHaveLength(3)📝 Committable suggestion
Suggested change
|
||||||||||||||
| }) | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regression test is detached from the component output.
Line 30 to Line 48 currently re-tests arithmetic in the spec itself, so it can still pass if the template no longer applies those widths. Please assert widths from rendered skeleton DOM/styles instead.
✅ Proposed test rewrite (DOM-coupled)
As per coding guidelines, "Write unit tests for core functionality using
vitest."Also applies to: 41-48