diff --git a/frontend/src/components/Dashboard.spec.ts b/frontend/src/components/Dashboard.spec.ts index d9c2e09..1ede917 100644 --- a/frontend/src/components/Dashboard.spec.ts +++ b/frontend/src/components/Dashboard.spec.ts @@ -17,7 +17,7 @@ describe('Dashboard.vue', () => { it('renders dashboard component', () => { const wrapper = mount(Dashboard) - expect(wrapper.find('h2').text()).toBe('Dashboard') + expect(wrapper.find('h1').text()).toBe('Dashboard') }) it('displays error message when error occurs', async () => { @@ -57,9 +57,9 @@ describe('Dashboard.vue', () => { } await wrapper.vm.$nextTick() - expect(wrapper.text()).toContain('Total Packages') - expect(wrapper.text()).toContain('Total Size') - expect(wrapper.text()).toContain('Total Downloads') + expect(wrapper.text()).toContain('Total packages') + expect(wrapper.text()).toContain('Total size') + expect(wrapper.text()).toContain('Total downloads') }) it('displays total packages from stats', async () => { @@ -141,7 +141,7 @@ describe('Dashboard.vue', () => { ] await wrapper.vm.$nextTick() - expect(wrapper.text()).toContain('Recent Packages') + expect(wrapper.text()).toContain('Recent packages') }) it('shows recent packages sorted by cached_at', async () => { @@ -173,7 +173,7 @@ describe('Dashboard.vue', () => { ] await wrapper.vm.$nextTick() - const recentPackagesSection = wrapper.text().split('Recent Packages')[1] + const recentPackagesSection = wrapper.text().split('Recent packages')[1] // new-package should appear before old-package since it's more recent expect(recentPackagesSection.indexOf('new-package')).toBeLessThan( @@ -198,7 +198,7 @@ describe('Dashboard.vue', () => { })) await wrapper.vm.$nextTick() - const recentSection = wrapper.text().split('Recent Packages')[1] + const recentSection = wrapper.text().split('Recent packages')[1] // Count how many "package" strings appear (each package has the word "package" in its name) const packageCount = (recentSection.match(/package\d+/g) || []).length expect(packageCount).toBeLessThanOrEqual(10) diff --git a/frontend/src/components/Dashboard.vue b/frontend/src/components/Dashboard.vue index c51e3ae..6efe9b6 100644 --- a/frontend/src/components/Dashboard.vue +++ b/frontend/src/components/Dashboard.vue @@ -1,243 +1,134 @@ diff --git a/frontend/src/components/SeveritySummary.vue b/frontend/src/components/SeveritySummary.vue new file mode 100644 index 0000000..bbb07bc --- /dev/null +++ b/frontend/src/components/SeveritySummary.vue @@ -0,0 +1,18 @@ + + + diff --git a/frontend/src/components/Stats.spec.ts b/frontend/src/components/Stats.spec.ts index d25b302..edb0780 100644 --- a/frontend/src/components/Stats.spec.ts +++ b/frontend/src/components/Stats.spec.ts @@ -1,17 +1,22 @@ import { describe, it, expect, beforeEach, vi } from 'vitest' -import { mount } from '@vue/test-utils' +import { mount as mountWith } from '@vue/test-utils' import { createPinia, setActivePinia } from 'pinia' import Stats from './Stats.vue' +import { createTestRouter } from '@/test/router' import { usePackageStore } from '../stores/packages' describe('Stats.vue', () => { - beforeEach(() => { + let router: Awaited> + const mount = (component: typeof Stats) => mountWith(component, { global: { plugins: [router] } }) + + beforeEach(async () => { setActivePinia(createPinia()) + router = await createTestRouter('/stats') }) it('renders stats component', () => { const wrapper = mount(Stats) - expect(wrapper.find('h2').text()).toBe('Statistics') + expect(wrapper.find('h1').text()).toBe('Statistics') }) it('displays loading state when loading', async () => { @@ -51,7 +56,7 @@ describe('Stats.vue', () => { } await wrapper.vm.$nextTick() - expect(wrapper.text()).toContain('Overall Statistics') + expect(wrapper.text()).toContain('Overall statistics') expect(wrapper.text()).toContain('100') expect(wrapper.text()).toContain('500') }) @@ -73,9 +78,9 @@ describe('Stats.vue', () => { } await wrapper.vm.$nextTick() - expect(wrapper.text()).toContain('Security Scanning') - expect(wrapper.text()).toContain('Scanned Packages') - expect(wrapper.text()).toContain('Vulnerable Packages') + expect(wrapper.text()).toContain('Security scanning') + expect(wrapper.text()).toContain('Scanned packages') + expect(wrapper.text()).toContain('Vulnerable packages') }) it('displays registry breakdown', async () => { @@ -112,13 +117,15 @@ describe('Stats.vue', () => { } await wrapper.vm.$nextTick() - expect(wrapper.text()).toContain('Registry Breakdown') - expect(wrapper.text()).toContain('NPM Registry') - expect(wrapper.text()).toContain('PyPI Registry') - expect(wrapper.text()).toContain('Go Modules') - expect(wrapper.text()).toContain('50 packages') - expect(wrapper.text()).toContain('30 packages') - expect(wrapper.text()).toContain('20 packages') + expect(wrapper.text()).toContain('Registry breakdown') + expect(wrapper.text()).toContain('npm') + expect(wrapper.text()).toContain('PyPI') + expect(wrapper.text()).toContain('Go modules') + // The cards layout prefixes each cell with its column label. + const packageCounts = wrapper + .findAll('tbody tr') + .map((row) => row.findAll('td')[0].text().replace(/^Packages/, '')) + expect(packageCounts).toEqual(['50', '30', '20']) }) it('formats bytes correctly in overall stats', async () => { @@ -150,7 +157,7 @@ describe('Stats.vue', () => { expect(fetchSpy).toHaveBeenCalled() }) - it('displays correct icon colors for different registries', async () => { + it('lists the registries in the order the API reports them', async () => { const wrapper = mount(Stats) const store = usePackageStore() @@ -172,13 +179,8 @@ describe('Stats.vue', () => { } await wrapper.vm.$nextTick() - // Scope to the registry icon containers (w-12 h-12 rounded-full), - // excluding the storage progress bar which also uses rounded-full. - const containers = wrapper.findAll('.w-12.h-12.rounded-full') - expect(containers).toHaveLength(3) - expect(containers[0].classes()).toContain('bg-red-100') // npm - expect(containers[1].classes()).toContain('bg-blue-100') // pypi - expect(containers[2].classes()).toContain('bg-cyan-100') // go + const labels = wrapper.findAll('tbody th').map((cell) => cell.text().replace(/^Registry/, '')) + expect(labels).toEqual(['npm', 'PyPI', 'Go modules']) }) it('handles empty registries data', async () => { @@ -199,9 +201,8 @@ describe('Stats.vue', () => { store.registries = {} await wrapper.vm.$nextTick() - expect(wrapper.text()).toContain('Registry Breakdown') - // Should have no registry items - const registryItems = wrapper.findAll('.bg-gray-50') - expect(registryItems.length).toBe(3) // Only the overall stats cards + expect(wrapper.text()).toContain('Registry breakdown') + expect(wrapper.findAll('tbody th')).toHaveLength(0) + expect(wrapper.text()).toContain('No registries reported') }) }) diff --git a/frontend/src/components/Stats.vue b/frontend/src/components/Stats.vue index d60acf8..e9a1cf3 100644 --- a/frontend/src/components/Stats.vue +++ b/frontend/src/components/Stats.vue @@ -1,150 +1,87 @@ @@ -153,8 +90,21 @@ import { computed, onMounted } from 'vue' import { storeToRefs } from 'pinia' import { useRouter } from 'vue-router' import { usePackageStore } from '../stores/packages' -import { Alert, AlertDescription } from '@/components/ui/alert' -import { Card, CardContent } from '@/components/ui/card' +import { + Card, + CardContent, + CardHeader, + CardTitle, + DataTable, + ErrorState, + KpiTile, + LoadingState, + PageHeader, + StatGroup, + type DataTableColumn, +} from '@perfect-design/ui' +import { formatBytes, formatNumber } from '@/lib/format' +import { faBan, faDownload, faHardDrive, faBoxesStacked, faCircleCheck, faTriangleExclamation } from '@/lib/icons' const store = usePackageStore() const { stats, loading, error } = storeToRefs(store) @@ -180,43 +130,36 @@ function showBlockedPackages() { router.push('/blocked-packages') } -// Registry configuration for icons and colors -const registryConfig: Record = { - npm: { - label: 'NPM Registry', - icon: 'fab fa-npm text-red-500', - color: 'bg-red-100' - }, - pypi: { - label: 'PyPI Registry', - icon: 'fab fa-python text-blue-500', - color: 'bg-blue-100' - }, - go: { - label: 'Go Modules', - icon: 'fas fa-code text-cyan-500', - color: 'bg-cyan-100' - } +const REGISTRY_LABELS: Record = { + npm: 'npm', + pypi: 'PyPI', + go: 'Go modules', } +interface RegistryRow { + name: string + label: string + packages: number + size: string + downloads: number +} + +const registryColumns: DataTableColumn[] = [ + { key: 'label', header: 'Registry', rowHeader: true }, + { key: 'packages', header: 'Packages', numeric: true, accessor: (r) => formatNumber(r.packages) }, + { key: 'size', header: 'Size', numeric: true }, + { key: 'downloads', header: 'Downloads', numeric: true, accessor: (r) => formatNumber(r.downloads) }, +] + const registries = computed(() => { const apiRegistries = store.registries || {} - return Object.entries(apiRegistries).map(([name, data]: [string, any]) => { - const config = registryConfig[name] || { - label: name.toUpperCase(), - icon: 'fas fa-box', - color: 'bg-gray-100' - } - return { - name, - label: config.label, - icon: config.icon, - color: config.color, - packages: data.count || 0, - size: formatBytes(data.size || 0), - downloads: data.downloads || 0 - } - }) + return Object.entries(apiRegistries).map(([name, data]: [string, any]): RegistryRow => ({ + name, + label: REGISTRY_LABELS[name] ?? name.toUpperCase(), + packages: data.count || 0, + size: formatBytes(data.size || 0), + downloads: data.downloads || 0, + })) }) const storagePercentage = computed(() => { @@ -225,15 +168,13 @@ const storagePercentage = computed(() => { return (totalSize / maxSize) * 100 }) -function formatNumber(num: number): string { - return new Intl.NumberFormat().format(num) -} +const storageTone = computed(() => { + if (storagePercentage.value >= 90) return 'danger' + if (storagePercentage.value >= 50) return 'warning' + return 'success' +}) -function formatBytes(bytes: number): string { - if (bytes === 0) return '0 B' - const k = 1024 - const sizes = ['B', 'KB', 'MB', 'GB', 'TB'] - const i = Math.floor(Math.log(bytes) / Math.log(k)) - return Math.round((bytes / Math.pow(k, i)) * 100) / 100 + ' ' + sizes[i] +function refresh() { + void store.fetchStats() } diff --git a/frontend/src/components/VulnerabilityBadge.vue b/frontend/src/components/VulnerabilityBadge.vue index 05201a5..c8480b3 100644 --- a/frontend/src/components/VulnerabilityBadge.vue +++ b/frontend/src/components/VulnerabilityBadge.vue @@ -1,97 +1,58 @@