Hide documents link conditionally

This commit is contained in:
Ramon Wenger 2024-11-12 16:02:50 +01:00
parent 55515dd10f
commit 93660cf421
2 changed files with 27 additions and 4 deletions

View File

@ -1,9 +1,11 @@
<script setup lang="ts"> <script setup lang="ts">
import SubNavigation from "@/components/header/SubNavigation.vue"; import SubNavigation from "@/components/header/SubNavigation.vue";
import { useCurrentCourseSession } from "@/composables";
import { useExpertCockpitPageData } from "@/pages/cockpit/cockpitPage/composables"; import { useExpertCockpitPageData } from "@/pages/cockpit/cockpitPage/composables";
import { ATTENDANCE_ROUTE, COCKPIT_ROUTE, DOCUMENTS_ROUTE } from "@/router/names"; import { ATTENDANCE_ROUTE, COCKPIT_ROUTE, DOCUMENTS_ROUTE } from "@/router/names";
import { useTranslation } from "i18next-vue"; import { useTranslation } from "i18next-vue";
import log from "loglevel"; import log from "loglevel";
import { computed } from "vue";
const props = defineProps<{ const props = defineProps<{
courseSlug: string; courseSlug: string;
@ -25,10 +27,25 @@ const documentsRoute = {
const { t } = useTranslation(); const { t } = useTranslation();
const items = [ const courseSession = useCurrentCourseSession();
const enableDocuments = computed(() => {
return !!courseSession.value.course.configuration.enable_circle_documents;
});
const items = computed(() => [
{ id: 1, name: t("a.Übersicht"), route: defaultRoute }, { id: 1, name: t("a.Übersicht"), route: defaultRoute },
{ id: 2, name: t("a.Teilnehmer"), route: attendanceRoute }, { id: 2, name: t("a.Teilnehmer"), route: attendanceRoute },
{ id: 3, name: t("a.Unterlagen"), route: documentsRoute }, ...(enableDocuments.value
? [
{
id: 3,
name: t("a.Unterlagen"),
route: documentsRoute,
dataCy: "circle-documents",
},
]
: []),
{ {
id: 4, id: 4,
@ -40,7 +57,7 @@ const items = [
name: "MS Teams", name: "MS Teams",
route: "https://vbvbern.sharepoint.com/sites/myVBV-AFA_K-CI", route: "https://vbvbern.sharepoint.com/sites/myVBV-AFA_K-CI",
}, },
]; ]);
</script> </script>
<template> <template>

View File

@ -1,20 +1,24 @@
import {EXPERT_COCKPIT_URL, login} from "./helpers"; import { EXPERT_COCKPIT_URL, login } from "./helpers";
describe("settings.cy.js", () => { describe("settings.cy.js", () => {
beforeEach(() => { beforeEach(() => {
cy.manageCommand("cypress_reset"); cy.manageCommand("cypress_reset");
cy.intercept("/server/graphql").as("graphql");
}); });
describe("with circle documents enabled", () => { describe("with circle documents enabled", () => {
it("student can see circle documents", () => { it("student can see circle documents", () => {
login("test-student1@example.com", "test"); login("test-student1@example.com", "test");
cy.visit("/course/test-lehrgang/learn/fahrzeug"); cy.visit("/course/test-lehrgang/learn/fahrzeug");
cy.wait(["@graphql", "@graphql"]);
cy.get('[data-cy="circle-document-section"]').should("exist"); cy.get('[data-cy="circle-document-section"]').should("exist");
}); });
it("trainer can see circle documents", () => { it("trainer can see circle documents", () => {
login("test-trainer1@example.com", "test"); login("test-trainer1@example.com", "test");
cy.visit(EXPERT_COCKPIT_URL); cy.visit(EXPERT_COCKPIT_URL);
cy.wait(["@graphql", "@graphql"]);
cy.get('[data-cy="circle-documents"]').should("exist"); cy.get('[data-cy="circle-documents"]').should("exist");
}); });
}); });
@ -27,6 +31,7 @@ describe("settings.cy.js", () => {
it("student cannot see circle documents", () => { it("student cannot see circle documents", () => {
login("test-student1@example.com", "test"); login("test-student1@example.com", "test");
cy.visit("/course/test-lehrgang/learn/fahrzeug"); cy.visit("/course/test-lehrgang/learn/fahrzeug");
cy.wait(["@graphql", "@graphql"]);
cy.get('[data-cy="circle-title"]').should("contain", "Fahrzeug"); cy.get('[data-cy="circle-title"]').should("contain", "Fahrzeug");
cy.get('[data-cy="circle-document-section"]').should("not.exist"); cy.get('[data-cy="circle-document-section"]').should("not.exist");
}); });
@ -34,6 +39,7 @@ describe("settings.cy.js", () => {
it("trainer cannot see circle documents", () => { it("trainer cannot see circle documents", () => {
login("test-trainer1@example.com", "test"); login("test-trainer1@example.com", "test");
cy.visit(EXPERT_COCKPIT_URL); cy.visit(EXPERT_COCKPIT_URL);
cy.wait(["@graphql", "@graphql"]);
cy.get('[data-cy="circle-documents"]').should("not.exist"); cy.get('[data-cy="circle-documents"]').should("not.exist");
}); });
}); });