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