Updated tests

This commit is contained in:
2026-03-18 21:52:04 +00:00
parent 11a752a6b2
commit a7574d2a93
4 changed files with 72 additions and 7 deletions

View File

@@ -1,6 +1,8 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { mount } from '@vue/test-utils'
import { nextTick } from 'vue'
import { createVuetify } from 'vuetify'
import { flushPromises } from '@vue/test-utils'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
import GalleryPage from "@/pages/gallery.vue"
@@ -37,6 +39,7 @@ vi.stubGlobal('navigateTo', mockNavigate)
describe('GalleryPage.vue', () => {
beforeEach(() => {
vi.clearAllMocks()
mockFetch.mockResolvedValue([])
})
const mountOptions = {
@@ -58,6 +61,46 @@ describe('GalleryPage.vue', () => {
})
})
it('triggers semantic search when searchQuery changes', async () => {
vi.useFakeTimers()
mockFetch.mockResolvedValue([])
const wrapper = mount(GalleryPage, mountOptions)
const vm = wrapper.vm as any
vm.searchQuery = 'spicy pasta'
await nextTick()
vi.advanceTimersByTime(600)
mockFetch.mockResolvedValueOnce([{ id: 2, title: 'Spicy Pasta' }])
await flushPromises()
expect(mockFetch).toHaveBeenCalledWith(
expect.stringContaining('api/recipe/search'),
expect.objectContaining({
params: expect.objectContaining({ query: 'spicy pasta' })
})
)
vi.useRealTimers()
})
it('redirects to login if API returns 401', async () => {
mockFetch.mockReset()
mockFetch.mockRejectedValue({ status: 401 })
mount(GalleryPage, mountOptions)
await flushPromises()
await vi.waitFor(() => {
expect(mockNavigate).toHaveBeenCalledWith('/login')
}, { timeout: 1000 })
})
it('enters editing mode and formats arrays into strings', async () => {
mockFetch.mockResolvedValueOnce([
{