mirror of
https://github.com/ajurna/cbwebreader.git
synced 2026-11-02 10:36:55 +00:00
- Added Vitest configuration (`vitest.config.mjs`) for frontend unit testing with a `jsdom` environment. - Migrated and rewrote key frontend tests (`api.test.js`, `comiclist.test.js`, `comicreader.test.js`, `historytable.test.js`, `router.test.js`, `store.test.js`) to Vitest, improving maintainability. - Removed `tsconfig.json` and related TypeScript loaders from `webpack` configurations (`webpack.dev.js`, `webpack.prod.js`). - Adjusted `eslint.config.mjs` to support Vitest tests. - Updated `package-lock.json` to include Vitest, test utilities (`jsdom`, `@vue/test-utils`), and other associated packages. - Updated Nginx configuration for better compression on assets (`gzip` adjustments). - Enhanced `entrypoint.sh` to include first-run library indexing (`--if-empty` argument). - Simplified the `scan_comics` command with a dedicated test for empty database scans. This transition improves testing workflows and backend/frontend synergy while removing unused TypeScript dependencies.
51 lines
1.4 KiB
JavaScript
51 lines
1.4 KiB
JavaScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
vi.mock('@/api', () => ({ default: { get: vi.fn(), post: vi.fn() } }))
|
|
|
|
import store from '@/store'
|
|
import router from '@/router'
|
|
|
|
beforeEach(() => {
|
|
localStorage.clear()
|
|
store.commit('logOut')
|
|
})
|
|
|
|
describe('navigation guards', () => {
|
|
it('redirects an anonymous user to the login page', async () => {
|
|
await router.push('/account')
|
|
|
|
expect(router.currentRoute.value.name).toBe('login')
|
|
expect(router.currentRoute.value.query.error).toBe('Please log in to access this page')
|
|
})
|
|
|
|
it('keeps the requested path so the user returns there after logging in', async () => {
|
|
await router.push('/history')
|
|
|
|
expect(router.currentRoute.value.query.next).toBe('/history')
|
|
})
|
|
|
|
it('allows an authenticated non-admin to reach the history page', async () => {
|
|
store.commit('updateUser', { id: 1, is_superuser: false })
|
|
|
|
await router.push('/history')
|
|
|
|
expect(router.currentRoute.value.name).toBe('history')
|
|
})
|
|
|
|
it('still requires admin for the user page', async () => {
|
|
store.commit('updateUser', { id: 1, is_superuser: false })
|
|
|
|
await router.push('/user')
|
|
|
|
expect(router.currentRoute.value.name).toBe('login')
|
|
})
|
|
|
|
it('allows an admin on the user page', async () => {
|
|
store.commit('updateUser', { id: 1, is_superuser: true })
|
|
|
|
await router.push('/user')
|
|
|
|
expect(router.currentRoute.value.name).toBe('user')
|
|
})
|
|
})
|