Files
hermes-web-ui/tests/client/session-settings.test.ts
ekko 5df8734495 fix: resolve test failures related to v0.5.12 changes (#491)
* fix: update tests for new batch delete and update mechanism changes

**sessions-routes.test.ts:**
- Add missing batchRemove mock to controller mock
- Fix "No batchRemove export defined" error

**update-controller.test.ts:**
- Update test to expect direct npm/npm.cmd calls instead of dirname(process.execPath)
- Update timeout from 120000 to 10 * 60 * 1000 (10 minutes)
- Update spawn path check to use dynamic global prefix (expect.any)

Tests now match the refactored update mechanism that uses npm prefix -g
for reliable path resolution.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

* test: add speechSynthesis mock to message-item-highlight tests

* test: fix all failing tests

- Add approvals mock to session-settings test
- Fix NSwitch stub to properly emit events
- Update usage stats test expectations for new field structure
- Mock getDb in model-context tests to avoid database lock errors
- Add speechSynthesis API mock to message-item-highlight tests

Related to v0.5.12 feature changes

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-06 21:37:13 +08:00

91 lines
2.4 KiB
TypeScript

// @vitest-environment jsdom
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { mount } from '@vue/test-utils'
const mockSettingsStore = vi.hoisted(() => ({
sessionReset: { mode: 'both', idle_minutes: 60, at_hour: 0 },
approvals: { mode: 'manual' },
saveSection: vi.fn(),
}))
const mockPrefsStore = vi.hoisted(() => ({
humanOnly: true,
setHumanOnly: vi.fn((value: boolean) => {
mockPrefsStore.humanOnly = value
}),
}))
vi.mock('@/stores/hermes/settings', () => ({
useSettingsStore: () => mockSettingsStore,
}))
vi.mock('@/stores/hermes/session-browser-prefs', () => ({
useSessionBrowserPrefsStore: () => mockPrefsStore,
}))
vi.mock('vue-i18n', () => ({
useI18n: () => ({
t: (key: string) => key,
}),
}))
vi.mock('naive-ui', async () => {
const actual = await vi.importActual<any>('naive-ui')
return {
...actual,
useMessage: () => ({
success: vi.fn(),
error: vi.fn(),
}),
}
})
import SessionSettings from '@/components/hermes/settings/SessionSettings.vue'
describe('SessionSettings', () => {
beforeEach(() => {
vi.clearAllMocks()
mockPrefsStore.humanOnly = true
})
it('surfaces the human-only preference in the Session tab', async () => {
let emittedValue: boolean | undefined
const wrapper = mount(SessionSettings, {
global: {
stubs: {
SettingRow: {
props: ['label', 'hint'],
template: '<div class="setting-row"><div class="setting-row-label">{{ label }}</div><slot /></div>',
},
NSelect: true,
NInputNumber: true,
NSwitch: {
props: ['value'],
emits: ['update:value'],
template: '<div class="n-switch" @click="$emit(\'update:value\', !value)"></div>',
setup(props: any, { emit }: any) {
return {
onClick: () => {
emittedValue = !props.value
emit('update:value', emittedValue)
},
}
},
},
},
},
})
expect(wrapper.text()).toContain('settings.session.liveMonitorHumanOnly')
const toggles = wrapper.findAll('.n-switch')
expect(toggles.length).toBe(2)
const humanOnlyToggle = toggles[1]
await humanOnlyToggle.trigger('click')
await Promise.resolve()
expect(mockPrefsStore.setHumanOnly).toHaveBeenCalledWith(false)
})
})