-
-
Notifications
You must be signed in to change notification settings - Fork 424
Expand file tree
/
Copy pathPackageWeeklyDownloadStats.spec.ts
More file actions
67 lines (56 loc) · 2.04 KB
/
PackageWeeklyDownloadStats.spec.ts
File metadata and controls
67 lines (56 loc) · 2.04 KB
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
60
61
62
63
64
65
66
67
import { mockNuxtImport, mountSuspended } from '@nuxt/test-utils/runtime'
import { defineComponent, h } from 'vue'
import { describe, expect, it, vi } from 'vitest'
const { mockFetchPackageDownloadEvolution } = vi.hoisted(() => ({
mockFetchPackageDownloadEvolution: vi.fn(),
}))
mockNuxtImport('useCharts', () => {
return () => ({
fetchPackageDownloadEvolution: (...args: unknown[]) =>
mockFetchPackageDownloadEvolution(...args),
})
})
vi.mock('vue-data-ui/vue-ui-sparkline', () => ({
VueUiSparkline: defineComponent({
name: 'VueUiSparkline',
inheritAttrs: false,
setup(_, { attrs, slots }) {
return () => h('div', { class: attrs.class }, slots.default?.() ?? [])
},
}),
}))
import PackageWeeklyDownloadStats from '~/components/Package/WeeklyDownloadStats.vue'
describe('PackageWeeklyDownloadStats', () => {
const baseProps = {
packageName: 'test-package',
createdIso: '2026-02-05T00:00:00.000Z',
}
it('hides the section when weekly downloads are empty', async () => {
mockFetchPackageDownloadEvolution.mockReset()
mockFetchPackageDownloadEvolution.mockResolvedValue([])
const component = await mountSuspended(PackageWeeklyDownloadStats, {
props: baseProps,
})
expect(component.text()).toContain('Weekly Downloads')
expect(component.text()).toContain('Across all versions')
expect(component.text()).toContain('No data available')
})
it('shows the section when weekly downloads exist', async () => {
mockFetchPackageDownloadEvolution.mockReset()
mockFetchPackageDownloadEvolution.mockResolvedValue([
{
weekStart: '2026-01-01',
weekEnd: '2026-01-07',
timestampStart: 1767225600000,
timestampEnd: 1767744000000,
value: 42,
},
])
const component = await mountSuspended(PackageWeeklyDownloadStats, {
props: baseProps,
})
expect(component.text()).toContain('Weekly Downloads')
expect(component.text()).toContain('Across all versions')
expect(component.text()).not.toContain('No data available')
})
})