feat: SEO SPA Sites, Articles and Integration (4/4)
This commit is contained in:
1 parent
cb737b7ae3
commit
02fb8751fd
47 files changed
+3218
-227
No files matched your search
@@ -0,0 +1,73 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { ref } from 'vue'
|
||||
import type { Article } from '@/composables/useArticles'
|
||||
import { DEFAULT_ARTICLE_SORT } from '@/lib/articleListQuery'
|
||||
import { useArticleRowActions } from '../useArticleRowActions'
|
||||
|
||||
const confirmDelete = vi.fn()
|
||||
|
||||
vi.mock('@/composables/useArticleActions', () => ({
|
||||
useArticleActions: () => ({
|
||||
confirmDelete: (...args: unknown[]) => confirmDelete(...args),
|
||||
publish: vi.fn(),
|
||||
deleteArticle: vi.fn(),
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock('@/i18n/presentation', () => ({
|
||||
useLocalizedToast: () => ({ add: vi.fn() }),
|
||||
}))
|
||||
|
||||
const article = {
|
||||
id: 4,
|
||||
title: 'Winter checklist',
|
||||
body: '',
|
||||
is_online: false,
|
||||
created_at: '2026-09-02T09:00:00Z',
|
||||
updated_at: '2026-09-05T09:00:00Z',
|
||||
} as Article
|
||||
|
||||
function setup() {
|
||||
return useArticleRowActions({
|
||||
items: ref([article]),
|
||||
total: ref(1),
|
||||
counts: ref({ all: 1, online: 0, draft: 1 }),
|
||||
shown: ref({
|
||||
page: 1,
|
||||
size: 25,
|
||||
q: '',
|
||||
status: '',
|
||||
sort: DEFAULT_ARTICLE_SORT,
|
||||
site: '',
|
||||
seo: '',
|
||||
}),
|
||||
reload: vi.fn(),
|
||||
})
|
||||
}
|
||||
|
||||
describe('handleDelete', () => {
|
||||
it('opens one confirm dialog when asked twice in a row', async () => {
|
||||
confirmDelete.mockReset()
|
||||
let settle: (value: boolean) => void = () => undefined
|
||||
confirmDelete.mockReturnValue(new Promise<boolean>((resolve) => (settle = resolve)))
|
||||
const { handleDelete } = setup()
|
||||
|
||||
const first = handleDelete(article)
|
||||
const second = handleDelete(article)
|
||||
expect(confirmDelete).toHaveBeenCalledTimes(1)
|
||||
|
||||
settle(false)
|
||||
await Promise.all([first, second])
|
||||
})
|
||||
|
||||
it('allows another dialog once the first one is settled', async () => {
|
||||
confirmDelete.mockReset()
|
||||
confirmDelete.mockResolvedValue(false)
|
||||
const { handleDelete } = setup()
|
||||
|
||||
await handleDelete(article)
|
||||
await handleDelete(article)
|
||||
|
||||
expect(confirmDelete).toHaveBeenCalledTimes(2)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user