Updated tests
This commit is contained in:
@@ -16,11 +16,26 @@ public class ApplicationDbContext : IdentityDbContext<IdentityUser>
|
|||||||
{
|
{
|
||||||
base.OnModelCreating(modelBuilder);
|
base.OnModelCreating(modelBuilder);
|
||||||
|
|
||||||
modelBuilder.HasPostgresExtension("vector");
|
if (Database.IsNpgsql())
|
||||||
|
{
|
||||||
|
modelBuilder.HasPostgresExtension("vector");
|
||||||
|
}
|
||||||
|
|
||||||
modelBuilder.Entity<Recipe>()
|
modelBuilder.Entity<Recipe>(entity =>
|
||||||
.HasOne<IdentityUser>()
|
{
|
||||||
.WithMany()
|
entity.HasOne<IdentityUser>()
|
||||||
.HasForeignKey(r => r.UserId);
|
.WithMany()
|
||||||
|
.HasForeignKey(r => r.UserId);
|
||||||
|
|
||||||
|
if (Database.ProviderName == "Microsoft.EntityFrameworkCore.InMemory")
|
||||||
|
{
|
||||||
|
entity.Ignore(r => r.Embedding);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
entity.Property(r => r.Embedding)
|
||||||
|
.HasColumnType("vector(1536)");
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,7 +233,7 @@
|
|||||||
|
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, onMounted, computed } from 'vue'
|
import { ref, onMounted, computed, watch } from 'vue'
|
||||||
import '@/assets/css/gallery.css'
|
import '@/assets/css/gallery.css'
|
||||||
import '@/assets/css/app-theme.css'
|
import '@/assets/css/app-theme.css'
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
import { mount } from '@vue/test-utils'
|
import { mount } from '@vue/test-utils'
|
||||||
|
import { nextTick } from 'vue'
|
||||||
import { createVuetify } from 'vuetify'
|
import { createVuetify } from 'vuetify'
|
||||||
|
import { flushPromises } from '@vue/test-utils'
|
||||||
import * as components from 'vuetify/components'
|
import * as components from 'vuetify/components'
|
||||||
import * as directives from 'vuetify/directives'
|
import * as directives from 'vuetify/directives'
|
||||||
import GalleryPage from "@/pages/gallery.vue"
|
import GalleryPage from "@/pages/gallery.vue"
|
||||||
@@ -37,6 +39,7 @@ vi.stubGlobal('navigateTo', mockNavigate)
|
|||||||
describe('GalleryPage.vue', () => {
|
describe('GalleryPage.vue', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
|
mockFetch.mockResolvedValue([])
|
||||||
})
|
})
|
||||||
|
|
||||||
const mountOptions = {
|
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 () => {
|
it('enters editing mode and formats arrays into strings', async () => {
|
||||||
mockFetch.mockResolvedValueOnce([
|
mockFetch.mockResolvedValueOnce([
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||||
import { mount } from '@vue/test-utils'
|
import { mount } from '@vue/test-utils'
|
||||||
import { createVuetify } from 'vuetify'
|
import { createVuetify } from 'vuetify'
|
||||||
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
import * as components from 'vuetify/components'
|
import * as components from 'vuetify/components'
|
||||||
import * as directives from 'vuetify/directives'
|
import * as directives from 'vuetify/directives'
|
||||||
import Uploader from "@/pages/uploader.vue"
|
import Uploader from "@/pages/uploader.vue"
|
||||||
@@ -21,6 +22,11 @@ vi.stubGlobal('useRouter', () => mockRouter)
|
|||||||
const mockFetch = vi.fn()
|
const mockFetch = vi.fn()
|
||||||
vi.stubGlobal('$fetch', mockFetch)
|
vi.stubGlobal('$fetch', mockFetch)
|
||||||
|
|
||||||
|
const router = createRouter({
|
||||||
|
history: createWebHistory(),
|
||||||
|
routes: [],
|
||||||
|
})
|
||||||
|
|
||||||
describe('Uploader.vue', () => {
|
describe('Uploader.vue', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks()
|
vi.clearAllMocks()
|
||||||
@@ -28,7 +34,7 @@ describe('Uploader.vue', () => {
|
|||||||
|
|
||||||
const mountOptions = {
|
const mountOptions = {
|
||||||
global: {
|
global: {
|
||||||
plugins: [vuetify],
|
plugins: [vuetify, router],
|
||||||
stubs: { RecipeDisplay: true },
|
stubs: { RecipeDisplay: true },
|
||||||
provide: { 'router': mockRouter }
|
provide: { 'router': mockRouter }
|
||||||
}
|
}
|
||||||
@@ -71,4 +77,5 @@ describe('Uploader.vue', () => {
|
|||||||
expect(vm.recipe.title).toBe('Restored Cake')
|
expect(vm.recipe.title).toBe('Restored Cake')
|
||||||
expect(localStorage.getItem('pending_recipe')).toBeNull()
|
expect(localStorage.getItem('pending_recipe')).toBeNull()
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user