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

@@ -233,7 +233,7 @@
<script setup>
import { ref, onMounted, computed } from 'vue'
import { ref, onMounted, computed, watch } from 'vue'
import '@/assets/css/gallery.css'
import '@/assets/css/app-theme.css'

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([
{

View File

@@ -1,6 +1,7 @@
import { describe, it, expect, vi, beforeEach } from 'vitest'
import { mount } from '@vue/test-utils'
import { createVuetify } from 'vuetify'
import { createRouter, createWebHistory } from 'vue-router'
import * as components from 'vuetify/components'
import * as directives from 'vuetify/directives'
import Uploader from "@/pages/uploader.vue"
@@ -21,6 +22,11 @@ vi.stubGlobal('useRouter', () => mockRouter)
const mockFetch = vi.fn()
vi.stubGlobal('$fetch', mockFetch)
const router = createRouter({
history: createWebHistory(),
routes: [],
})
describe('Uploader.vue', () => {
beforeEach(() => {
vi.clearAllMocks()
@@ -28,7 +34,7 @@ describe('Uploader.vue', () => {
const mountOptions = {
global: {
plugins: [vuetify],
plugins: [vuetify, router],
stubs: { RecipeDisplay: true },
provide: { 'router': mockRouter }
}
@@ -71,4 +77,5 @@ describe('Uploader.vue', () => {
expect(vm.recipe.title).toBe('Restored Cake')
expect(localStorage.getItem('pending_recipe')).toBeNull()
})
})