Skip to content

Commit

Permalink
test(front): config vitest and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasWerey committed Jan 12, 2024
1 parent 1449034 commit 36ff80f
Show file tree
Hide file tree
Showing 9 changed files with 104 additions and 21 deletions.
1 change: 1 addition & 0 deletions Front/auto-import.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = {
'vue-router',
'@vueuse/core',
'vitest',
'pinia',
{
axios: [['default', 'axios']]
}
Expand Down
38 changes: 36 additions & 2 deletions Front/src/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ declare global {
const AuthenticationUtils: typeof import('./utils/authenticationUtils')['AuthenticationUtils']
const DateUtils: typeof import('./utils/dateUtils')['DateUtils']
const EffectScope: typeof import('vue')['EffectScope']
const acceptHMRUpdate: typeof import('pinia')['acceptHMRUpdate']
const afterAll: typeof import('vitest')['afterAll']
const afterEach: typeof import('vitest')['afterEach']
const assert: typeof import('vitest')['assert']
Expand All @@ -31,6 +32,7 @@ declare global {
const createEventHook: typeof import('@vueuse/core')['createEventHook']
const createGlobalState: typeof import('@vueuse/core')['createGlobalState']
const createInjectionState: typeof import('@vueuse/core')['createInjectionState']
const createPinia: typeof import('pinia')['createPinia']
const createReactiveFn: typeof import('@vueuse/core')['createReactiveFn']
const createReusableTemplate: typeof import('@vueuse/core')['createReusableTemplate']
const createSharedComposable: typeof import('@vueuse/core')['createSharedComposable']
Expand All @@ -42,6 +44,7 @@ declare global {
const debouncedWatch: typeof import('@vueuse/core')['debouncedWatch']
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
const defineComponent: typeof import('vue')['defineComponent']
const defineStore: typeof import('pinia')['defineStore']
const deleteUser: typeof import('./utils/userApiUtils')['deleteUser']
const describe: typeof import('vitest')['describe']
const difference: typeof import('./utils/arrayUtils')['difference']
Expand All @@ -50,6 +53,7 @@ declare global {
const effectScope: typeof import('vue')['effectScope']
const expect: typeof import('vitest')['expect']
const extendRef: typeof import('@vueuse/core')['extendRef']
const getActivePinia: typeof import('pinia')['getActivePinia']
const getAllUsers: typeof import('./utils/userApiUtils')['getAllUsers']
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
const getCurrentScope: typeof import('vue')['getCurrentScope']
Expand Down Expand Up @@ -77,6 +81,11 @@ declare global {
const loginUser: typeof import('./utils/userApiUtils')['loginUser']
const loginWords: typeof import('./data/wording')['loginWords']
const makeDestructurable: typeof import('@vueuse/core')['makeDestructurable']
const mapActions: typeof import('pinia')['mapActions']
const mapGetters: typeof import('pinia')['mapGetters']
const mapState: typeof import('pinia')['mapState']
const mapStores: typeof import('pinia')['mapStores']
const mapWritableState: typeof import('pinia')['mapWritableState']
const markRaw: typeof import('vue')['markRaw']
const nextTick: typeof import('vue')['nextTick']
const onActivated: typeof import('vue')['onActivated']
Expand Down Expand Up @@ -120,11 +129,14 @@ declare global {
const resolveComponent: typeof import('vue')['resolveComponent']
const resolveRef: typeof import('@vueuse/core')['resolveRef']
const resolveUnref: typeof import('@vueuse/core')['resolveUnref']
const setActivePinia: typeof import('pinia')['setActivePinia']
const setLocalStorage: typeof import('./utils/storageUtils')['setLocalStorage']
const setMapStoreSuffix: typeof import('pinia')['setMapStoreSuffix']
const setSessionStorage: typeof import('./utils/storageUtils')['setSessionStorage']
const shallowReactive: typeof import('vue')['shallowReactive']
const shallowReadonly: typeof import('vue')['shallowReadonly']
const shallowRef: typeof import('vue')['shallowRef']
const storeToRefs: typeof import('pinia')['storeToRefs']
const suite: typeof import('vitest')['suite']
const syncRef: typeof import('@vueuse/core')['syncRef']
const syncRefs: typeof import('@vueuse/core')['syncRefs']
Expand Down Expand Up @@ -344,6 +356,7 @@ declare module 'vue' {
readonly AuthenticationUtils: UnwrapRef<typeof import('./utils/authenticationUtils')['AuthenticationUtils']>
readonly DateUtils: UnwrapRef<typeof import('./utils/dateUtils')['DateUtils']>
readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
readonly afterAll: UnwrapRef<typeof import('vitest')['afterAll']>
readonly afterEach: UnwrapRef<typeof import('vitest')['afterEach']>
readonly assert: UnwrapRef<typeof import('vitest')['assert']>
Expand All @@ -366,6 +379,7 @@ declare module 'vue' {
readonly createEventHook: UnwrapRef<typeof import('@vueuse/core')['createEventHook']>
readonly createGlobalState: UnwrapRef<typeof import('@vueuse/core')['createGlobalState']>
readonly createInjectionState: UnwrapRef<typeof import('@vueuse/core')['createInjectionState']>
readonly createPinia: UnwrapRef<typeof import('pinia')['createPinia']>
readonly createReactiveFn: UnwrapRef<typeof import('@vueuse/core')['createReactiveFn']>
readonly createReusableTemplate: UnwrapRef<typeof import('@vueuse/core')['createReusableTemplate']>
readonly createSharedComposable: UnwrapRef<typeof import('@vueuse/core')['createSharedComposable']>
Expand All @@ -377,6 +391,7 @@ declare module 'vue' {
readonly debouncedWatch: UnwrapRef<typeof import('@vueuse/core')['debouncedWatch']>
readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>
readonly defineComponent: UnwrapRef<typeof import('vue')['defineComponent']>
readonly defineStore: UnwrapRef<typeof import('pinia')['defineStore']>
readonly deleteUser: UnwrapRef<typeof import('./utils/userApiUtils')['deleteUser']>
readonly describe: UnwrapRef<typeof import('vitest')['describe']>
readonly difference: UnwrapRef<typeof import('./utils/arrayUtils')['difference']>
Expand All @@ -385,6 +400,7 @@ declare module 'vue' {
readonly effectScope: UnwrapRef<typeof import('vue')['effectScope']>
readonly expect: UnwrapRef<typeof import('vitest')['expect']>
readonly extendRef: UnwrapRef<typeof import('@vueuse/core')['extendRef']>
readonly getActivePinia: UnwrapRef<typeof import('pinia')['getActivePinia']>
readonly getAllUsers: UnwrapRef<typeof import('./utils/userApiUtils')['getAllUsers']>
readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
Expand Down Expand Up @@ -412,6 +428,11 @@ declare module 'vue' {
readonly loginUser: UnwrapRef<typeof import('./utils/userApiUtils')['loginUser']>
readonly loginWords: UnwrapRef<typeof import('./data/wording')['loginWords']>
readonly makeDestructurable: UnwrapRef<typeof import('@vueuse/core')['makeDestructurable']>
readonly mapActions: UnwrapRef<typeof import('pinia')['mapActions']>
readonly mapGetters: UnwrapRef<typeof import('pinia')['mapGetters']>
readonly mapState: UnwrapRef<typeof import('pinia')['mapState']>
readonly mapStores: UnwrapRef<typeof import('pinia')['mapStores']>
readonly mapWritableState: UnwrapRef<typeof import('pinia')['mapWritableState']>
readonly markRaw: UnwrapRef<typeof import('vue')['markRaw']>
readonly nextTick: UnwrapRef<typeof import('vue')['nextTick']>
readonly onActivated: UnwrapRef<typeof import('vue')['onActivated']>
Expand Down Expand Up @@ -455,11 +476,14 @@ declare module 'vue' {
readonly resolveComponent: UnwrapRef<typeof import('vue')['resolveComponent']>
readonly resolveRef: UnwrapRef<typeof import('@vueuse/core')['resolveRef']>
readonly resolveUnref: UnwrapRef<typeof import('@vueuse/core')['resolveUnref']>
readonly setActivePinia: UnwrapRef<typeof import('pinia')['setActivePinia']>
readonly setLocalStorage: UnwrapRef<typeof import('./utils/storageUtils')['setLocalStorage']>
readonly setMapStoreSuffix: UnwrapRef<typeof import('pinia')['setMapStoreSuffix']>
readonly setSessionStorage: UnwrapRef<typeof import('./utils/storageUtils')['setSessionStorage']>
readonly shallowReactive: UnwrapRef<typeof import('vue')['shallowReactive']>
readonly shallowReadonly: UnwrapRef<typeof import('vue')['shallowReadonly']>
readonly shallowRef: UnwrapRef<typeof import('vue')['shallowRef']>
readonly storeToRefs: UnwrapRef<typeof import('pinia')['storeToRefs']>
readonly suite: UnwrapRef<typeof import('vitest')['suite']>
readonly syncRef: UnwrapRef<typeof import('@vueuse/core')['syncRef']>
readonly syncRefs: UnwrapRef<typeof import('@vueuse/core')['syncRefs']>
Expand Down Expand Up @@ -512,7 +536,6 @@ declare module 'vue' {
readonly useColorMode: UnwrapRef<typeof import('@vueuse/core')['useColorMode']>
readonly useConfirmDialog: UnwrapRef<typeof import('@vueuse/core')['useConfirmDialog']>
readonly useCounter: UnwrapRef<typeof import('@vueuse/core')['useCounter']>
readonly useCounterStore: UnwrapRef<typeof import('./stores/counter')['useCounterStore']>
readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']>
readonly useCssVar: UnwrapRef<typeof import('@vueuse/core')['useCssVar']>
readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
Expand Down Expand Up @@ -672,6 +695,7 @@ declare module '@vue/runtime-core' {
readonly AuthenticationUtils: UnwrapRef<typeof import('./utils/authenticationUtils')['AuthenticationUtils']>
readonly DateUtils: UnwrapRef<typeof import('./utils/dateUtils')['DateUtils']>
readonly EffectScope: UnwrapRef<typeof import('vue')['EffectScope']>
readonly acceptHMRUpdate: UnwrapRef<typeof import('pinia')['acceptHMRUpdate']>
readonly afterAll: UnwrapRef<typeof import('vitest')['afterAll']>
readonly afterEach: UnwrapRef<typeof import('vitest')['afterEach']>
readonly assert: UnwrapRef<typeof import('vitest')['assert']>
Expand All @@ -694,6 +718,7 @@ declare module '@vue/runtime-core' {
readonly createEventHook: UnwrapRef<typeof import('@vueuse/core')['createEventHook']>
readonly createGlobalState: UnwrapRef<typeof import('@vueuse/core')['createGlobalState']>
readonly createInjectionState: UnwrapRef<typeof import('@vueuse/core')['createInjectionState']>
readonly createPinia: UnwrapRef<typeof import('pinia')['createPinia']>
readonly createReactiveFn: UnwrapRef<typeof import('@vueuse/core')['createReactiveFn']>
readonly createReusableTemplate: UnwrapRef<typeof import('@vueuse/core')['createReusableTemplate']>
readonly createSharedComposable: UnwrapRef<typeof import('@vueuse/core')['createSharedComposable']>
Expand All @@ -705,6 +730,7 @@ declare module '@vue/runtime-core' {
readonly debouncedWatch: UnwrapRef<typeof import('@vueuse/core')['debouncedWatch']>
readonly defineAsyncComponent: UnwrapRef<typeof import('vue')['defineAsyncComponent']>
readonly defineComponent: UnwrapRef<typeof import('vue')['defineComponent']>
readonly defineStore: UnwrapRef<typeof import('pinia')['defineStore']>
readonly deleteUser: UnwrapRef<typeof import('./utils/userApiUtils')['deleteUser']>
readonly describe: UnwrapRef<typeof import('vitest')['describe']>
readonly difference: UnwrapRef<typeof import('./utils/arrayUtils')['difference']>
Expand All @@ -713,6 +739,7 @@ declare module '@vue/runtime-core' {
readonly effectScope: UnwrapRef<typeof import('vue')['effectScope']>
readonly expect: UnwrapRef<typeof import('vitest')['expect']>
readonly extendRef: UnwrapRef<typeof import('@vueuse/core')['extendRef']>
readonly getActivePinia: UnwrapRef<typeof import('pinia')['getActivePinia']>
readonly getAllUsers: UnwrapRef<typeof import('./utils/userApiUtils')['getAllUsers']>
readonly getCurrentInstance: UnwrapRef<typeof import('vue')['getCurrentInstance']>
readonly getCurrentScope: UnwrapRef<typeof import('vue')['getCurrentScope']>
Expand Down Expand Up @@ -740,6 +767,11 @@ declare module '@vue/runtime-core' {
readonly loginUser: UnwrapRef<typeof import('./utils/userApiUtils')['loginUser']>
readonly loginWords: UnwrapRef<typeof import('./data/wording')['loginWords']>
readonly makeDestructurable: UnwrapRef<typeof import('@vueuse/core')['makeDestructurable']>
readonly mapActions: UnwrapRef<typeof import('pinia')['mapActions']>
readonly mapGetters: UnwrapRef<typeof import('pinia')['mapGetters']>
readonly mapState: UnwrapRef<typeof import('pinia')['mapState']>
readonly mapStores: UnwrapRef<typeof import('pinia')['mapStores']>
readonly mapWritableState: UnwrapRef<typeof import('pinia')['mapWritableState']>
readonly markRaw: UnwrapRef<typeof import('vue')['markRaw']>
readonly nextTick: UnwrapRef<typeof import('vue')['nextTick']>
readonly onActivated: UnwrapRef<typeof import('vue')['onActivated']>
Expand Down Expand Up @@ -783,11 +815,14 @@ declare module '@vue/runtime-core' {
readonly resolveComponent: UnwrapRef<typeof import('vue')['resolveComponent']>
readonly resolveRef: UnwrapRef<typeof import('@vueuse/core')['resolveRef']>
readonly resolveUnref: UnwrapRef<typeof import('@vueuse/core')['resolveUnref']>
readonly setActivePinia: UnwrapRef<typeof import('pinia')['setActivePinia']>
readonly setLocalStorage: UnwrapRef<typeof import('./utils/storageUtils')['setLocalStorage']>
readonly setMapStoreSuffix: UnwrapRef<typeof import('pinia')['setMapStoreSuffix']>
readonly setSessionStorage: UnwrapRef<typeof import('./utils/storageUtils')['setSessionStorage']>
readonly shallowReactive: UnwrapRef<typeof import('vue')['shallowReactive']>
readonly shallowReadonly: UnwrapRef<typeof import('vue')['shallowReadonly']>
readonly shallowRef: UnwrapRef<typeof import('vue')['shallowRef']>
readonly storeToRefs: UnwrapRef<typeof import('pinia')['storeToRefs']>
readonly suite: UnwrapRef<typeof import('vitest')['suite']>
readonly syncRef: UnwrapRef<typeof import('@vueuse/core')['syncRef']>
readonly syncRefs: UnwrapRef<typeof import('@vueuse/core')['syncRefs']>
Expand Down Expand Up @@ -840,7 +875,6 @@ declare module '@vue/runtime-core' {
readonly useColorMode: UnwrapRef<typeof import('@vueuse/core')['useColorMode']>
readonly useConfirmDialog: UnwrapRef<typeof import('@vueuse/core')['useConfirmDialog']>
readonly useCounter: UnwrapRef<typeof import('@vueuse/core')['useCounter']>
readonly useCounterStore: UnwrapRef<typeof import('./stores/counter')['useCounterStore']>
readonly useCssModule: UnwrapRef<typeof import('vue')['useCssModule']>
readonly useCssVar: UnwrapRef<typeof import('@vueuse/core')['useCssVar']>
readonly useCssVars: UnwrapRef<typeof import('vue')['useCssVars']>
Expand Down
12 changes: 7 additions & 5 deletions Front/src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import { RouteLocationNormalized, NavigationGuardNext } from 'vue-router'
import {
createRouter,
createWebHistory,
RouteLocationNormalized,
NavigationGuardNext
} from 'vue-router'

const routes = [
{
path: '/',
name: 'home',
component: HomeView,
component: () => import('../views/HomeView.vue'),
beforeEnter: redirectToAboutIfUserExists,
meta: { requiresAuth: false }
},
Expand All @@ -28,7 +31,6 @@ const routes = [
component: () => import('../views/SignupView.vue'),
meta: { requiresAuth: false }
}
// Add meta: { requiresAuth: true } to all other routes
]

const router = createRouter({
Expand Down
12 changes: 0 additions & 12 deletions Front/src/stores/counter.ts

This file was deleted.

2 changes: 0 additions & 2 deletions Front/src/stores/userTypeStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { defineStore } from 'pinia'

export const useUserTypeStore = defineStore('userType', {
state: () => ({
userType: ''
Expand Down
34 changes: 34 additions & 0 deletions Front/tests/router/index.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @ts-nocheck
import router from '../../src/router/index'

test('home route should be correctly defined', () => {
const homeRoute = router.getRoutes().find(route => route.name === 'home')

expect(homeRoute).toBeDefined()
expect(homeRoute.path).toBe('/')
expect(homeRoute.meta.requiresAuth).toBe(false)
})

test('about route should be correctly defined', () => {
const aboutRoute = router.getRoutes().find(route => route.name === 'about')

expect(aboutRoute).toBeDefined()
expect(aboutRoute.path).toBe('/about')
expect(aboutRoute.meta.requiresAuth).toBe(true)
})

test('login route should be correctly defined', () => {
const loginRoute = router.getRoutes().find(route => route.name === 'login')

expect(loginRoute).toBeDefined()
expect(loginRoute.path).toBe('/login')
expect(loginRoute.meta.requiresAuth).toBe(false)
})

test('signup route should be correctly defined', () => {
const signupRoute = router.getRoutes().find(route => route.name === 'recruiterSignup')

expect(signupRoute).toBeDefined()
expect(signupRoute.path).toBe('/signup')
expect(signupRoute.meta.requiresAuth).toBe(false)
})
11 changes: 11 additions & 0 deletions Front/tests/stores/userTypeStore.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// @ts-nocheck
describe('userTypeStore', () => {
it('sets the user type', () => {
const pinia = createPinia()
const store = useUserTypeStore(pinia)

expect(store.userType).toBe('')
store.setUserType('admin')
expect(store.userType).toBe('admin')
})
})
1 change: 1 addition & 0 deletions Front/tests/utils/getQueryRouteUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ test('getQueryParameter returns undefined for a non-existent query parameter', (
const result = getQueryParameter(route, 'param')
expect(result).toBeUndefined()
})

14 changes: 14 additions & 0 deletions Front/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,20 @@ export default mergeConfig(
viteConfig,
defineConfig({
test: {
coverage: {
exclude: [
'*.js',
'*.cjs',
'*.d.ts',
'src/*.d.ts',
'src/data/*.ts',
'src/assets/*.vue',
'src/App.vue',
'src/main.ts',
'src/utils/screenSizeUtils.ts',
'src/utils/userApiUtils.ts'
]
},
environment: 'jsdom',
include: ['./tests/**/*.ts'],
exclude: [...configDefaults.exclude, 'e2e/*', './tests/setup.ts'],
Expand Down

0 comments on commit 36ff80f

Please sign in to comment.