mirror of
https://github.com/gotson/komga.git
synced 2026-05-08 12:35:30 +02:00
add some pinia colada tests
This commit is contained in:
parent
66aac8f5ed
commit
1555bd55c8
11 changed files with 2112 additions and 11 deletions
1
next-ui/.env.test
Normal file
1
next-ui/.env.test
Normal file
|
|
@ -0,0 +1 @@
|
|||
VITE_KOMGA_API_URL=http://localhost:5555
|
||||
1927
next-ui/package-lock.json
generated
1927
next-ui/package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -36,6 +36,7 @@
|
|||
"@eslint/js": "^9.28.0",
|
||||
"@formatjs/cli": "^6.7.1",
|
||||
"@iconify-json/mdi": "^1.2.3",
|
||||
"@testing-library/vue": "^8.1.0",
|
||||
"@tsconfig/node22": "^22.0.2",
|
||||
"@types/node": "^22.15.29",
|
||||
"@vitejs/plugin-vue": "^5.1.4",
|
||||
|
|
@ -46,7 +47,8 @@
|
|||
"eslint-config-prettier": "^10.1.5",
|
||||
"eslint-plugin-formatjs": "^5.3.1",
|
||||
"eslint-plugin-vue": "^10.1.0",
|
||||
"jsdom": "^26.1.0",
|
||||
"happy-dom": "^18.0.1",
|
||||
"msw": "^2.10.2",
|
||||
"npm-run-all2": "^8.0.4",
|
||||
"openapi-typescript": "^7.8.0",
|
||||
"prettier": "^3.5.3",
|
||||
|
|
|
|||
19
next-ui/src/colada/queries/actuator-info.test.ts
Normal file
19
next-ui/src/colada/queries/actuator-info.test.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { afterAll, afterEach, beforeAll, expect, test } from 'vitest'
|
||||
import { server } from '@/mocks/api/node'
|
||||
import { useActuatorInfo } from '@/colada/queries/actuator-info'
|
||||
import { mockPiniaColada } from '@/mocks/pinia-colada'
|
||||
|
||||
beforeAll(() => server.listen())
|
||||
afterEach(() => server.resetHandlers())
|
||||
afterAll(() => {
|
||||
server.close()
|
||||
mockPiniaColada.unmount()
|
||||
})
|
||||
|
||||
test('when getting actuator-info then values are correct', async () => {
|
||||
const { buildVersion, commitId, refresh } = useActuatorInfo()
|
||||
|
||||
await refresh()
|
||||
expect(buildVersion.value).toBe('9.9.9')
|
||||
expect(commitId.value).toBe('ABC123')
|
||||
})
|
||||
18
next-ui/src/colada/queries/announcements.test.ts
Normal file
18
next-ui/src/colada/queries/announcements.test.ts
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
import { afterAll, afterEach, beforeAll, expect, test } from 'vitest'
|
||||
import { server } from '@/mocks/api/node'
|
||||
import { mockPiniaColada } from '@/mocks/pinia-colada'
|
||||
import { useAnnouncements } from '@/colada/queries/announcements'
|
||||
|
||||
beforeAll(() => server.listen())
|
||||
afterEach(() => server.resetHandlers())
|
||||
afterAll(() => {
|
||||
server.close()
|
||||
mockPiniaColada.unmount()
|
||||
})
|
||||
|
||||
test('when getting announcements then values are correct', async () => {
|
||||
const { unreadCount, refresh } = useAnnouncements()
|
||||
|
||||
await refresh()
|
||||
expect(unreadCount.value).toBe(1)
|
||||
})
|
||||
19
next-ui/src/colada/queries/app-releases.test.ts
Normal file
19
next-ui/src/colada/queries/app-releases.test.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { afterAll, afterEach, beforeAll, expect, test } from 'vitest'
|
||||
import { server } from '@/mocks/api/node'
|
||||
import { mockPiniaColada } from '@/mocks/pinia-colada'
|
||||
import { useAppReleases } from '@/colada/queries/app-releases'
|
||||
|
||||
beforeAll(() => server.listen())
|
||||
afterEach(() => server.resetHandlers())
|
||||
afterAll(() => {
|
||||
server.close()
|
||||
mockPiniaColada.unmount()
|
||||
})
|
||||
|
||||
test('when getting app releases then values are correct', async () => {
|
||||
const { latestRelease, isLatestVersion, refresh } = useAppReleases()
|
||||
|
||||
await refresh()
|
||||
expect(latestRelease.value!.version).toBe('9.9.9')
|
||||
expect(isLatestVersion.value).toBe(true)
|
||||
})
|
||||
114
next-ui/src/mocks/api/handlers.ts
Normal file
114
next-ui/src/mocks/api/handlers.ts
Normal file
|
|
@ -0,0 +1,114 @@
|
|||
import { http, HttpResponse } from 'msw'
|
||||
|
||||
export const baseUrl = import.meta.env.VITE_KOMGA_API_URL + '/'
|
||||
|
||||
export const handlers = [
|
||||
http.get(baseUrl + 'actuator/info', () => {
|
||||
return HttpResponse.json({
|
||||
git: {
|
||||
branch: 'master',
|
||||
commit: {
|
||||
id: 'ABC123',
|
||||
time: '2025-05-16T03:26:50Z',
|
||||
},
|
||||
},
|
||||
build: {
|
||||
artifact: 'komga',
|
||||
name: 'komga',
|
||||
version: '9.9.9',
|
||||
group: 'komga',
|
||||
},
|
||||
java: {
|
||||
version: '23.0.2',
|
||||
vendor: {
|
||||
name: 'Eclipse Adoptium',
|
||||
version: 'Temurin-23.0.2+7',
|
||||
},
|
||||
runtime: {
|
||||
name: 'OpenJDK Runtime Environment',
|
||||
version: '23.0.2+7',
|
||||
},
|
||||
jvm: {
|
||||
name: 'OpenJDK 64-Bit Server VM',
|
||||
vendor: 'Eclipse Adoptium',
|
||||
version: '23.0.2+7',
|
||||
},
|
||||
},
|
||||
os: {
|
||||
name: 'Linux',
|
||||
version: '6.8.0-57-generic',
|
||||
arch: 'amd64',
|
||||
},
|
||||
})
|
||||
}),
|
||||
http.get(baseUrl + 'api/v1/announcements', () => {
|
||||
return HttpResponse.json({
|
||||
version: 'https://jsonfeed.org/version/1',
|
||||
title: 'Announcements',
|
||||
home_page_url: 'https://komga.org/blog',
|
||||
description: 'Latest Komga announcements',
|
||||
items: [
|
||||
{
|
||||
id: 'https://komga.org/blog/ebook-drop2',
|
||||
url: 'https://komga.org/blog/ebook-drop2',
|
||||
title: 'eBook drop 2',
|
||||
summary: 'Version 1.9.0 contains the second feature drop for Ebooks support.',
|
||||
content_html: 'Truncated',
|
||||
date_modified: '2023-12-15T00:00:00Z',
|
||||
author: {
|
||||
name: 'gotson',
|
||||
url: 'https://github.com/gotson',
|
||||
},
|
||||
tags: ['upgrade', 'komga'],
|
||||
_komga: {
|
||||
read: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
id: 'https://komga.org/blog/ebook-support',
|
||||
url: 'https://komga.org/blog/ebook-support',
|
||||
title: 'eBook support',
|
||||
summary: 'Version 1.8.0 is bringing a long awaited feature: proper eBook support!',
|
||||
content_html: 'Truncated',
|
||||
date_modified: '2023-11-29T00:00:00Z',
|
||||
author: {
|
||||
name: 'gotson',
|
||||
url: 'https://github.com/gotson',
|
||||
},
|
||||
tags: ['upgrade', 'komga'],
|
||||
_komga: {
|
||||
read: true,
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
}),
|
||||
http.get(baseUrl + 'api/v1/releases', () => {
|
||||
return HttpResponse.json([
|
||||
{
|
||||
version: '9.9.9',
|
||||
releaseDate: '2025-05-16T04:31:05Z',
|
||||
url: 'https://github.com/gotson/komga/releases/tag/1.21.3',
|
||||
latest: true,
|
||||
preRelease: false,
|
||||
description: 'Truncated',
|
||||
},
|
||||
{
|
||||
version: '1.21.2',
|
||||
releaseDate: '2025-03-12T04:19:30Z',
|
||||
url: 'https://github.com/gotson/komga/releases/tag/1.21.2',
|
||||
latest: false,
|
||||
preRelease: false,
|
||||
description: 'Truncated',
|
||||
},
|
||||
{
|
||||
version: '1.21.1',
|
||||
releaseDate: '2025-03-06T07:31:00Z',
|
||||
url: 'https://github.com/gotson/komga/releases/tag/1.21.1',
|
||||
latest: false,
|
||||
preRelease: false,
|
||||
description: 'Truncated',
|
||||
},
|
||||
])
|
||||
}),
|
||||
]
|
||||
4
next-ui/src/mocks/api/node.ts
Normal file
4
next-ui/src/mocks/api/node.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import { setupServer } from 'msw/node'
|
||||
import { handlers } from './handlers'
|
||||
|
||||
export const server = setupServer(...handlers)
|
||||
14
next-ui/src/mocks/pinia-colada.ts
Normal file
14
next-ui/src/mocks/pinia-colada.ts
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
import { createPinia } from 'pinia'
|
||||
import { PiniaColada } from '@pinia/colada'
|
||||
import { mount } from '@vue/test-utils'
|
||||
|
||||
const DummyComponent = {
|
||||
template: '<p></p>',
|
||||
}
|
||||
|
||||
const pinia = createPinia()
|
||||
export const mockPiniaColada = mount(DummyComponent, {
|
||||
global: {
|
||||
plugins: [pinia, [PiniaColada, {}]],
|
||||
},
|
||||
})
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
// @vitest-environment jsdom
|
||||
|
||||
import { beforeAll, expect, test, vi } from 'vitest'
|
||||
import { loadLocale, defaultLocale, setLocale, getLocale, availableLocales } from './locale-helper'
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,7 @@ export default defineConfig({
|
|||
},
|
||||
},
|
||||
test: {
|
||||
environment: 'happy-dom',
|
||||
restoreMocks: true,
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in a new issue