Fix cypress tests by not loading unknown data

This commit is contained in:
Daniel Egger 2022-11-11 18:21:16 +01:00
parent f212df5d29
commit 05fa4ab3be
4 changed files with 19 additions and 11 deletions

View File

@ -63,7 +63,9 @@ function logout() {
onMounted(() => { onMounted(() => {
log.debug("MainNavigationBar mounted"); log.debug("MainNavigationBar mounted");
courseSessionsStore.loadCourseSessionsData(); if (userStore.loggedIn) {
courseSessionsStore.loadCourseSessionsData();
}
}); });
const profileDropdownData: DropdownListItem[] = [ const profileDropdownData: DropdownListItem[] = [

View File

@ -17,7 +17,7 @@ const learningPathData = ref<LearningPath | undefined>(undefined);
const learningPathStore = useLearningPathStore(); const learningPathStore = useLearningPathStore();
learningPathStore learningPathStore
.loadLearningPath(props.learningPathUrl.replace("/learn/", "")) .loadLearningPath(props.learningPathUrl.replace("/learn/", ""), false, false)
.then((data) => { .then((data) => {
learningPathData.value = data; learningPathData.value = data;
}); });

View File

@ -22,7 +22,7 @@ export const useLearningPathStore = defineStore({
}, },
getters: {}, getters: {},
actions: { actions: {
async loadLearningPath(slug: string, reload = false) { async loadLearningPath(slug: string, reload = false, fail = true) {
this.loading = true; this.loading = true;
const completionStore = useCompletionStore(); const completionStore = useCompletionStore();
if (this.learningPath && !reload && slug === lastSlug) { if (this.learningPath && !reload && slug === lastSlug) {
@ -30,18 +30,21 @@ export const useLearningPathStore = defineStore({
} }
this.learningPath = undefined; this.learningPath = undefined;
const learningPathData = await itGetCached(`/api/course/page/${slug}/`); const learningPathData = await itGetCached(`/api/course/page/${slug}/`);
lastSlug = slug;
const completionData = await completionStore.loadCompletionData(
learningPathData.course.id
);
if (!learningPathData) { if (!learningPathData && fail) {
throw `No learning path found with: ${slug}`; throw `No learning path found with: ${slug}`;
} }
this.learningPath = LearningPath.fromJson(learningPathData, completionData); if (learningPathData) {
this.loading = false; lastSlug = slug;
return this.learningPath; const completionData = await completionStore.loadCompletionData(
learningPathData.course.id
);
this.learningPath = LearningPath.fromJson(learningPathData, completionData);
this.loading = false;
return this.learningPath;
}
}, },
}, },
}); });

View File

@ -2,6 +2,7 @@ import * as log from "loglevel";
import { bustItGetCache, itGetCached, itPost } from "@/fetchHelpers"; import { bustItGetCache, itGetCached, itPost } from "@/fetchHelpers";
import { useAppStore } from "@/stores/app"; import { useAppStore } from "@/stores/app";
import { useCourseSessionsStore } from "@/stores/courseSessions";
import { defineStore } from "pinia"; import { defineStore } from "pinia";
const logoutRedirectUrl = import.meta.env.VITE_LOGOUT_REDIRECT; const logoutRedirectUrl = import.meta.env.VITE_LOGOUT_REDIRECT;
@ -75,6 +76,8 @@ export const useUserStore = defineStore({
this.$state = data; this.$state = data;
this.loggedIn = true; this.loggedIn = true;
appStore.userLoaded = true; appStore.userLoaded = true;
const courseSessionsStore = useCourseSessionsStore();
courseSessionsStore.loadCourseSessionsData();
}) })
.catch(() => { .catch(() => {
this.loggedIn = false; this.loggedIn = false;