wip: e2e cypress tests

This commit is contained in:
Livio Bieri 2023-11-01 15:15:19 +01:00
parent d125e66c02
commit 2e0c8205ee
6 changed files with 164 additions and 12 deletions

View File

@ -12,7 +12,7 @@ defineProps<{
<slot name="content"></slot>
<div class="flex-grow"></div>
<div class="pt-8">
<router-link class="underline" :to="detailsLink">
<router-link class="underline" :to="detailsLink" data-cy="basebox.detailsLink">
{{ $t("a.Details anschauen") }}
</router-link>
</div>

View File

@ -9,14 +9,19 @@ defineProps<{
</script>
<template>
<BaseBox :details-link="detailsLink">
<BaseBox :details-link="detailsLink" data-cy="dashboard.stats.competence">
<template #title>{{ $t("a.Selbsteinschätzungen") }}</template>
<template #content>
<div class="flex items-center">
<it-icon-smiley-happy class="mr-4 h-12 w-12"></it-icon-smiley-happy>
<i18next :translation="$t('a.{NUMBER} Das kann ich')">
<template #NUMBER>
<span class="mr-3 text-4xl font-bold">{{ successCount }}</span>
<span
class="mr-3 text-4xl font-bold"
data-cy="dashboard.stats.competence.success"
>
{{ successCount }}
</span>
</template>
</i18next>
</div>
@ -24,7 +29,12 @@ defineProps<{
<it-icon-smiley-thinking class="mr-4 h-12 w-12"></it-icon-smiley-thinking>
<i18next :translation="$t('a.{NUMBER} Das will ich nochmals anschauen')">
<template #NUMBER>
<span class="mr-3 text-4xl font-bold">{{ failCount }}</span>
<span
class="mr-3 text-4xl font-bold"
data-cy="dashboard.stats.competence.fail"
>
{{ failCount }}
</span>
</template>
</i18next>
</div>

View File

@ -10,19 +10,19 @@ defineProps<{
<div class="flex items-center justify-between bg-white p-6">
<div class="flex space-x-6">
<div class="flex items-center space-x-2">
<span class="text-4xl font-bold">
<span class="text-4xl font-bold" data-cy="dashboard.stats.participant.count">
{{ participantCount }}
</span>
<span>{{ $t("a.Teilnehmer") }}</span>
</div>
<div class="flex items-center space-x-2">
<span class="text-4xl font-bold">
<span class="text-4xl font-bold" data-cy="dashboard.stats.expert.count">
{{ expertCount }}
</span>
<span>{{ $t("a.Trainer") }}</span>
</div>
<div class="flex items-center space-x-2">
<span class="text-4xl font-bold">
<span class="text-4xl font-bold" data-cy="dashboard.stats.session.count">
{{ sessionCount }}
</span>
<span>{{ $t("a.Durchführungen") }}</span>

View File

@ -15,7 +15,7 @@ const satisfactionColor = computed(() => {
</script>
<template>
<BaseBox :details-link="'/statistic/feedback'">
<BaseBox :details-link="'/statistic/feedback'" data-cy="dashboard.stats.feedback">
<template #title>{{ $t("a.Feedback Teilnehmer") }}</template>
<template #content>
<div class="flex items-center">
@ -26,7 +26,10 @@ const satisfactionColor = computed(() => {
>
<i18next :translation="$t('a.{AVG} von {MAX}')">
<template #AVG>
<span class="pr-2 text-4xl font-bold">
<span
class="pr-2 text-4xl font-bold"
data-cy="dashboard.stats.feedback.average"
>
{{ props.statisfactionAvg.toFixed(1) }}
</span>
</template>
@ -41,7 +44,9 @@ const satisfactionColor = computed(() => {
<div class="self-start">
<i18next :translation="$t('a.Total {NUMBER} Antworten')">
<template #NUMBER>
<span class="font-bold">{{ props.feedbackCount }}</span>
<span class="font-bold" data-cy="dashboard.stats.feedback.count">
{{ props.feedbackCount }}
</span>
</template>
</i18next>
</div>

View File

@ -0,0 +1,62 @@
import {login} from "../helpers";
const getDashboardStatistics = (what) => {
return cy.get(`[data-cy="dashboard.stats.${what}"]`);
};
const clickOnDetailsLink = (within) => {
cy.get(`[data-cy="dashboard.stats.${within}"]`).within(() => {
cy.get('[data-cy="basebox.detailsLink"]').click();
})
};
describe("dashboardSupervisor.cy.js", () => {
beforeEach(() => {
cy.manageCommand("cypress_reset --create-assignment-evaluation --create-feedback-responses --create-course-completion-performance-criteria --create-attendance-days");
login("test-supervisor1@example.com", "test");
cy.visit("/");
});
describe("overall summary box", () => {
it("contains correct numbers (members, experts etc.)", () => {
getDashboardStatistics("participant.count").should("have.text", "4");
getDashboardStatistics("expert.count").should("have.text", "1");
getDashboardStatistics("session.count").should("have.text", "2");
});
});
describe("feedback summary box", () => {
it("contains correct numbers", () => {
getDashboardStatistics("feedback.average").should("have.text", "3.3");
getDashboardStatistics("feedback.count").should("have.text", "3");
});
it("contains correct details link", () => {
clickOnDetailsLink("feedback");
cy.url().should("contain", "/statistic/feedback");
// might be improved: roughly check
// that the correct data is displayed
cy.contains("3.3 von 4");
cy.contains("Test Trainer1");
cy.contains("Durchführung «Test Bern 2022 a»")
cy.contains("Circle «Fahrzeug»")
});
});
describe("competence summary box", () => {
it("contains correct numbers", () => {
getDashboardStatistics("competence.success").should("have.text", "1");
getDashboardStatistics("competence.fail").should("have.text", "0");
});
it("contains correct details link", () => {
clickOnDetailsLink("competence");
cy.url().should("contain", "/statistic/competence");
// might be improved: roughly check
// that the correct data is displayed
cy.contains("Selbsteinschätzung: Learning Unit");
cy.contains("Durchführung «Test Bern 2022 a»");
});
});
});

View File

@ -1,4 +1,7 @@
from datetime import timedelta
import djclick as click
from django.utils import timezone
from vbv_lernwelt.assignment.models import Assignment, AssignmentCompletion
from vbv_lernwelt.core.constants import (
@ -15,9 +18,21 @@ from vbv_lernwelt.course.creators.test_course import (
create_test_assignment_evaluation_data,
create_test_assignment_submitted_data,
)
from vbv_lernwelt.course.models import CourseCompletion, CourseSession
from vbv_lernwelt.course.creators.test_utils import (
create_attendance_course,
create_performance_criteria_page,
)
from vbv_lernwelt.course.models import (
Course,
CourseCompletion,
CourseCompletionStatus,
CourseSession,
)
from vbv_lernwelt.course.services import mark_course_completion
from vbv_lernwelt.course_session.models import CourseSessionAttendanceCourse
from vbv_lernwelt.course_session.services.attendance import AttendanceUserStatus
from vbv_lernwelt.feedback.models import FeedbackResponse
from vbv_lernwelt.learnpath.models import LearningContentFeedback
from vbv_lernwelt.learnpath.models import Circle, LearningContentFeedback
from vbv_lernwelt.notify.models import Notification
@ -49,18 +64,31 @@ from vbv_lernwelt.notify.models import Notification
default=False,
help="will create feedback response data",
)
@click.option(
"--create-course-completion-performance-criteria/--no-create-course-completion-performance-criteria",
default=False,
help="will create course completion performance criteria data",
)
@click.option(
"--create-attendance-days/--no-create-attendance-days",
default=False,
help="will create attendance days data",
)
def command(
create_assignment_completion,
create_assignment_evaluation,
assignment_evaluation_scores,
create_edoniq_test_results,
create_feedback_responses,
create_course_completion_performance_criteria,
create_attendance_days,
):
print("cypress reset data")
CourseCompletion.objects.all().delete()
Notification.objects.all().delete()
AssignmentCompletion.objects.all().delete()
FeedbackResponse.objects.all().delete()
CourseSessionAttendanceCourse.objects.all().delete()
User.objects.all().update(language="de")
User.objects.all().update(additional_json_data={})
@ -171,3 +199,50 @@ def command(
"course_positive_feedback": "Die Präsentation war super",
},
)
if create_course_completion_performance_criteria:
member = User.objects.get(id=TEST_STUDENT1_USER_ID)
course = Course.objects.get(slug="test-lehrgang")
course_session = CourseSession.objects.get(id=TEST_COURSE_SESSION_BERN_ID)
# circle, _ = create_circle(
# title="How to circle like a pro!", course_page=course.coursepage
# )
circle = Circle.objects.get(slug="überbetriebliche-kurse-lp-circle-kickoff")
mark_course_completion(
page=create_performance_criteria_page(
course=course,
course_page=course.coursepage,
circle=circle,
),
user=member,
course_session=course_session,
completion_status=CourseCompletionStatus.SUCCESS.value,
)
if create_attendance_days:
course_session = CourseSession.objects.get(id=TEST_COURSE_SESSION_BERN_ID)
course = course_session.course
# circle, _ = create_circle(
# title="Circle to attend", course_page=course_session.course.coursepage
# )
circle = Circle.objects.get(slug="überbetriebliche-kurse-lp-circle-kickoff")
create_attendance_course(
course_session=course_session,
circle=circle,
due_date_end=timezone.now() - timedelta(hours=2),
attendance_user_list=[
{
"user_id": TEST_STUDENT1_USER_ID,
"status": AttendanceUserStatus.PRESENT.value,
},
{
"user_id": TEST_STUDENT2_USER_ID,
"status": AttendanceUserStatus.ABSENT.value,
},
],
)