Skip to content

Commit 183c42e

Browse files
committed
test: add a bunch of coverage for compare page
1 parent 2085eff commit 183c42e

8 files changed

Lines changed: 2048 additions & 0 deletions

File tree

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import { describe, expect, it } from 'vitest'
2+
import { mountSuspended } from '@nuxt/test-utils/runtime'
3+
import ComparisonGrid from '~/components/compare/ComparisonGrid.vue'
4+
5+
describe('ComparisonGrid', () => {
6+
describe('header rendering', () => {
7+
it('renders column headers', async () => {
8+
const component = await mountSuspended(ComparisonGrid, {
9+
props: {
10+
columns: 2,
11+
headers: ['lodash@4.17.21', 'underscore@1.13.6'],
12+
},
13+
})
14+
expect(component.text()).toContain('lodash@4.17.21')
15+
expect(component.text()).toContain('underscore@1.13.6')
16+
})
17+
18+
it('renders correct number of header cells', async () => {
19+
const component = await mountSuspended(ComparisonGrid, {
20+
props: {
21+
columns: 3,
22+
headers: ['pkg1', 'pkg2', 'pkg3'],
23+
},
24+
})
25+
const headerCells = component.findAll('.comparison-cell-header')
26+
expect(headerCells.length).toBe(3)
27+
})
28+
29+
it('truncates long header text with title attribute', async () => {
30+
const longName = 'very-long-package-name@1.0.0-beta.1'
31+
const component = await mountSuspended(ComparisonGrid, {
32+
props: {
33+
columns: 2,
34+
headers: [longName, 'short'],
35+
},
36+
})
37+
const spans = component.findAll('.truncate')
38+
const longSpan = spans.find(s => s.text() === longName)
39+
expect(longSpan?.attributes('title')).toBe(longName)
40+
})
41+
})
42+
43+
describe('column layout', () => {
44+
it('applies columns-2 class for 2 columns', async () => {
45+
const component = await mountSuspended(ComparisonGrid, {
46+
props: {
47+
columns: 2,
48+
headers: ['a', 'b'],
49+
},
50+
})
51+
expect(component.find('.columns-2').exists()).toBe(true)
52+
})
53+
54+
it('applies columns-3 class for 3 columns', async () => {
55+
const component = await mountSuspended(ComparisonGrid, {
56+
props: {
57+
columns: 3,
58+
headers: ['a', 'b', 'c'],
59+
},
60+
})
61+
expect(component.find('.columns-3').exists()).toBe(true)
62+
})
63+
64+
it('applies columns-4 class for 4 columns', async () => {
65+
const component = await mountSuspended(ComparisonGrid, {
66+
props: {
67+
columns: 4,
68+
headers: ['a', 'b', 'c', 'd'],
69+
},
70+
})
71+
expect(component.find('.columns-4').exists()).toBe(true)
72+
})
73+
74+
it('sets min-width for 4 columns to 800px', async () => {
75+
const component = await mountSuspended(ComparisonGrid, {
76+
props: {
77+
columns: 4,
78+
headers: ['a', 'b', 'c', 'd'],
79+
},
80+
})
81+
expect(component.find('.min-w-\\[800px\\]').exists()).toBe(true)
82+
})
83+
84+
it('sets min-width for 2-3 columns to 600px', async () => {
85+
const component = await mountSuspended(ComparisonGrid, {
86+
props: {
87+
columns: 2,
88+
headers: ['a', 'b'],
89+
},
90+
})
91+
expect(component.find('.min-w-\\[600px\\]').exists()).toBe(true)
92+
})
93+
94+
it('sets --columns CSS variable', async () => {
95+
const component = await mountSuspended(ComparisonGrid, {
96+
props: {
97+
columns: 3,
98+
headers: ['a', 'b', 'c'],
99+
},
100+
})
101+
const grid = component.find('.comparison-grid')
102+
expect(grid.attributes('style')).toContain('--columns: 3')
103+
})
104+
})
105+
106+
describe('slot content', () => {
107+
it('renders default slot content', async () => {
108+
const component = await mountSuspended(ComparisonGrid, {
109+
props: {
110+
columns: 2,
111+
headers: ['a', 'b'],
112+
},
113+
slots: {
114+
default: '<div class="test-row">Row content</div>',
115+
},
116+
})
117+
expect(component.find('.test-row').exists()).toBe(true)
118+
expect(component.text()).toContain('Row content')
119+
})
120+
})
121+
122+
describe('structure', () => {
123+
it('has overflow-x-auto wrapper for horizontal scrolling', async () => {
124+
const component = await mountSuspended(ComparisonGrid, {
125+
props: {
126+
columns: 2,
127+
headers: ['a', 'b'],
128+
},
129+
})
130+
expect(component.find('.overflow-x-auto').exists()).toBe(true)
131+
})
132+
133+
it('has comparison-grid class on main container', async () => {
134+
const component = await mountSuspended(ComparisonGrid, {
135+
props: {
136+
columns: 2,
137+
headers: ['a', 'b'],
138+
},
139+
})
140+
expect(component.find('.comparison-grid').exists()).toBe(true)
141+
})
142+
143+
it('has comparison-header using display:contents', async () => {
144+
const component = await mountSuspended(ComparisonGrid, {
145+
props: {
146+
columns: 2,
147+
headers: ['a', 'b'],
148+
},
149+
})
150+
expect(component.find('.comparison-header').exists()).toBe(true)
151+
})
152+
153+
it('has empty label cell in header row', async () => {
154+
const component = await mountSuspended(ComparisonGrid, {
155+
props: {
156+
columns: 2,
157+
headers: ['a', 'b'],
158+
},
159+
})
160+
expect(component.find('.comparison-label').exists()).toBe(true)
161+
})
162+
})
163+
164+
describe('styling', () => {
165+
it('applies header cell background', async () => {
166+
const component = await mountSuspended(ComparisonGrid, {
167+
props: {
168+
columns: 2,
169+
headers: ['a', 'b'],
170+
},
171+
})
172+
// Header cells have comparison-cell-header class which applies bg
173+
expect(component.findAll('.comparison-cell-header').length).toBe(2)
174+
})
175+
176+
it('header text is monospace and medium weight', async () => {
177+
const component = await mountSuspended(ComparisonGrid, {
178+
props: {
179+
columns: 2,
180+
headers: ['lodash'],
181+
},
182+
})
183+
const headerSpan = component.find('.comparison-cell-header span')
184+
expect(headerSpan.classes()).toContain('font-mono')
185+
expect(headerSpan.classes()).toContain('font-medium')
186+
})
187+
})
188+
})

0 commit comments

Comments
 (0)