Fix profile store mocks in usage tests
This commit is contained in:
@@ -3,11 +3,20 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { mount, flushPromises } from '@vue/test-utils'
|
||||
|
||||
const fetchSkillUsageStatsMock = vi.hoisted(() => vi.fn())
|
||||
const mockProfilesStore = vi.hoisted(() => ({
|
||||
activeProfileName: 'default',
|
||||
profiles: [{ name: 'default' }],
|
||||
fetchProfiles: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/api/hermes/skills', () => ({
|
||||
fetchSkillUsageStats: fetchSkillUsageStatsMock,
|
||||
}))
|
||||
|
||||
vi.mock('@/stores/hermes/profiles', () => ({
|
||||
useProfilesStore: () => mockProfilesStore,
|
||||
}))
|
||||
|
||||
vi.mock('vue-i18n', () => ({
|
||||
useI18n: () => ({
|
||||
t: (key: string, params?: Record<string, unknown>) => {
|
||||
@@ -70,6 +79,9 @@ describe('SkillsUsageView', () => {
|
||||
beforeEach(() => {
|
||||
fetchSkillUsageStatsMock.mockReset()
|
||||
fetchSkillUsageStatsMock.mockResolvedValue(sevenDayStats)
|
||||
mockProfilesStore.activeProfileName = 'default'
|
||||
mockProfilesStore.profiles = [{ name: 'default' }]
|
||||
mockProfilesStore.fetchProfiles.mockReset()
|
||||
})
|
||||
|
||||
it('loads rolling 7 day skill usage and renders statistics beside a skill-colored visual trend', async () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @vitest-environment jsdom
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { defineComponent } from 'vue'
|
||||
import { mount } from '@vue/test-utils'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
|
||||
const mockUsageStore = vi.hoisted(() => ({
|
||||
isLoading: false,
|
||||
@@ -9,10 +9,20 @@ const mockUsageStore = vi.hoisted(() => ({
|
||||
loadSessions: vi.fn(),
|
||||
}))
|
||||
|
||||
const mockProfilesStore = vi.hoisted(() => ({
|
||||
activeProfileName: 'default',
|
||||
profiles: [{ name: 'default' }],
|
||||
fetchProfiles: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/stores/hermes/usage', () => ({
|
||||
useUsageStore: () => mockUsageStore,
|
||||
}))
|
||||
|
||||
vi.mock('@/stores/hermes/profiles', () => ({
|
||||
useProfilesStore: () => mockProfilesStore,
|
||||
}))
|
||||
|
||||
vi.mock('vue-i18n', () => ({
|
||||
useI18n: () => ({
|
||||
t: (key: string) => key,
|
||||
@@ -54,10 +64,14 @@ describe('UsageView period selector', () => {
|
||||
mockUsageStore.isLoading = false
|
||||
mockUsageStore.hasData = true
|
||||
mockUsageStore.loadSessions.mockReset()
|
||||
mockProfilesStore.activeProfileName = 'default'
|
||||
mockProfilesStore.profiles = [{ name: 'default' }]
|
||||
mockProfilesStore.fetchProfiles.mockReset()
|
||||
})
|
||||
|
||||
it('loads the default 30-day period on mount', () => {
|
||||
it('loads the default 30-day period on mount', async () => {
|
||||
mount(UsageView)
|
||||
await flushPromises()
|
||||
|
||||
expect(mockUsageStore.loadSessions).toHaveBeenCalledWith(30)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user