Skip to content
Snippets Groups Projects
Commit 5f0256e7 authored by Trygve Jørgensen's avatar Trygve Jørgensen
Browse files

chore: test cleanup

parent 1a3263fb
No related branches found
No related tags found
3 merge requests!66Final merge,!44Configuration validation,!4Pipeline fix
......@@ -10,7 +10,7 @@
</router-link>
<div class="flex flex-row justify-center">
<ButtonDisplayStreak></ButtonDisplayStreak>
<ButtonDisplayStreak />
</div>
</div>
<div v-if="!isHamburger" class="flex flex-row gap-10">
......
import { mount, VueWrapper } from '@vue/test-utils'
import NavBar from '@/components/NavBarComponent.vue'
import router from '@/router'
import { createPinia, setActivePinia } from 'pinia'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { nextTick } from 'vue'
vi.stubGlobal('scrollTo', vi.fn())
// Mocking Axios correctly using `importOriginal`
const mocks = vi.hoisted(() => ({
get: vi.fn(),
post: vi.fn()
}))
vi.mock('axios', async (importActual) => {
const actual = await importActual<typeof import('axios')>()
return {
default: {
...actual.default,
create: vi.fn(() => ({
...actual.default.create(),
get: mocks.get,
post: mocks.post
}))
}
}
})
describe('NavBar Routing', () => {
let wrapper: VueWrapper<any>
beforeEach(async () => {
const pinia = createPinia()
setActivePinia(pinia)
wrapper = mount(NavBar, {
global: {
plugins: [router, pinia]
}
})
await router.push({ name: 'start' })
await router.isReady()
await nextTick()
})
it('renders without errors', () => {
expect(wrapper.exists()).toBe(true)
})
it('displays correct active route for home link on full screen', async () => {
global.innerWidth = 1200
await router.push('/hjem')
await router.isReady()
expect(wrapper.find('.router-link-exact-active').exists()).toBe(true)
})
it('displays correct active route for goals link on full screen', async () => {
global.innerWidth = 1200
await router.push('/sparemaal')
await router.isReady()
expect(wrapper.find('.router-link-exact-active').exists()).toBe(true)
})
it('displays correct active route for challenges link on full screen', async () => {
global.innerWidth = 1200
await router.push('/spareutfordringer')
await router.isReady()
expect(wrapper.find('.router-link-exact-active').exists()).toBe(true)
})
it('displays correct active route for profile link on full screen', async () => {
global.innerWidth = 1200
await router.push('/profil')
await router.isReady()
expect(wrapper.find('.router-link-exact-active').exists()).toBe(true)
})
it('displays correct active route for home link when the hamburger menu is open', async () => {
global.innerWidth = 1000
wrapper.vm.hamburgerOpen = true
await wrapper.vm.$nextTick()
await router.push('/hjem')
await router.isReady()
expect(wrapper.find('.router-link-exact-active').exists()).toBe(true)
})
it('displays correct active route for goals link when the hamburger menu is open', async () => {
global.innerWidth = 1000
wrapper.vm.hamburgerOpen = true
await wrapper.vm.$nextTick()
await router.push('/sparemaal')
await router.isReady()
expect(wrapper.find('.router-link-exact-active').exists()).toBe(true)
})
it('displays correct active route for challenges link when the hamburger menu is open', async () => {
global.innerWidth = 1000
wrapper.vm.hamburgerOpen = true
await wrapper.vm.$nextTick()
await router.push('/spareutfordringer')
await router.isReady()
expect(wrapper.find('.router-link-exact-active').exists()).toBe(true)
})
it('displays correct active route for profile link when the hamburger menu is open', async () => {
global.innerWidth = 1000
wrapper.vm.hamburgerOpen = true
await wrapper.vm.$nextTick()
await router.push('/profil')
await router.isReady()
expect(wrapper.find('.router-link-exact-active').exists()).toBe(true)
})
})
......@@ -179,6 +179,10 @@ router.beforeEach(async (to, from, next) => {
return next({ name: 'home' })
}
if (!authRequired) {
await router.replace({ name: 'home' })
return next({ name: 'home' })
}
return next()
})
......
......@@ -84,22 +84,19 @@ export const useUserStore = defineStore('user', () => {
sessionStorage.removeItem('accessToken')
localStorage.removeItem('refreshToken')
user.value = defaultUser
console.log(user.value)
router.push({ name: 'login' })
}
const getUserStreak = async () => {
try {
const response = await authInterceptor('/profile/streak')
if (response.data) {
const getUserStreak = () => {
authInterceptor('/profile/streak')
.then((response) => {
streak.value = response.data
console.log('Fetched Challenges:', streak.value)
} else {
})
.catch((error) => {
console.error('Error fetching challenges:', error)
streak.value = undefined
console.error('No challenge content found:', response.data)
}
} catch (error) {
console.error('Error fetching challenges:', error)
streak.value = undefined // Ensure challenges is always an array
}
})
}
const bioRegister = async () => {
......
......@@ -17,7 +17,6 @@
</div>
<savings-path :challenges="challenges" :goal="goal"></savings-path>
</div>
<GeneratedChallengesModal v-if="showModal" />
</template>
<script setup lang="ts">
......@@ -29,7 +28,6 @@ import type { Goal } from '@/types/goal'
import { useGoalStore } from '@/stores/goalStore'
import { useChallengeStore } from '@/stores/challengeStore'
import SavingsPath from '@/components/SavingsPath.vue'
import GeneratedChallengesModal from '@/components/GeneratedChallengesModal.vue'
const showModal = ref(true)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment