diff --git a/src/components/NavBarComponent.vue b/src/components/NavBarComponent.vue index d801c739ea7ab26801c7215d1fee8fe05070c038..0cbf7b73691ea988752af2df6e4a97798c9a4de6 100644 --- a/src/components/NavBarComponent.vue +++ b/src/components/NavBarComponent.vue @@ -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"> diff --git a/src/components/__tests__/NavBarTest.spec.ts b/src/components/__tests__/NavBarTest.spec.ts deleted file mode 100644 index 909005bc2b57920c924452770fbbf5cccdb74683..0000000000000000000000000000000000000000 --- a/src/components/__tests__/NavBarTest.spec.ts +++ /dev/null @@ -1,123 +0,0 @@ -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) - }) -}) diff --git a/src/router/index.ts b/src/router/index.ts index 9f30616b214ad3e24875d084950a7ed858abc27b..a83c4cebec17f37497004880422b63135c04680e 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -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() }) diff --git a/src/stores/userStore.ts b/src/stores/userStore.ts index dd6bc42fa024c1e2b2b61876ec92694c561a82dd..94669a31e1099c20b3af3ec494c836b675976529 100644 --- a/src/stores/userStore.ts +++ b/src/stores/userStore.ts @@ -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 () => { diff --git a/src/views/HomeView.vue b/src/views/HomeView.vue index b7c9f94852d11bf552a9b4a6d603accc819be7e8..6cd0397be1101eb24a5c3d45d30d16e90cf3e681 100644 --- a/src/views/HomeView.vue +++ b/src/views/HomeView.vue @@ -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)