Fix cypress test for due dates page

This commit is contained in:
Daniel Egger 2024-04-25 18:48:13 +02:00
parent d15eb70792
commit 1693adce39
8 changed files with 117 additions and 54 deletions

View File

@ -29,7 +29,8 @@ const displayDueDates = computed(() => {
</router-link>
</div>
</section>
<section class="p-8">
<section v-if="dashboardDueDates.length > 0" class="p-8">
<h3>{{ $t("a.Termine") }}</h3>
<div v-for="dueDate in displayDueDates" :key="dueDate.id">

View File

@ -198,6 +198,7 @@ const selectedType = ref<DropboxItem>(dueDateTypes.value[0]);
watch(selectedCourse, async () => {
selectedSession.value = courseSessions.value[0];
selectedCircle.value = circles.value[0];
selectedType.value = dueDateTypes.value[0];
});
</script>
@ -225,37 +226,40 @@ watch(selectedCourse, async () => {
>
<ItDropdownSelect
v-model="selectedCourse"
data-cy="session-select"
data-cy="select-course"
:items="courses"
borderless
></ItDropdownSelect>
<ItDropdownSelect
v-model="selectedSession"
data-cy="session-select"
data-cy="select-session"
:items="courseSessions"
borderless
></ItDropdownSelect>
<ItDropdownSelect
v-model="selectedCircle"
data-cy="appointments-circle-select"
data-cy="select-circle"
:items="circles"
borderless
></ItDropdownSelect>
<ItDropdownSelect
v-model="selectedType"
data-cy="appointments-type-select"
data-cy="select-type"
:items="dueDateTypes"
borderless
></ItDropdownSelect>
</section>
<section>
<section data-cy="due-date-list">
<div v-for="dueDate in filteredDueDates" :key="dueDate.id" class="border-b">
<DueDateSingle :single-line="true" :due-date="dueDate"></DueDateSingle>
</div>
<div v-if="!filteredDueDates.length" class="mt-4">
<p>{{ $t("dueDates.noDueDatesAvailable") }}</p>
</div>
</section>
</div>
</div>

View File

@ -269,7 +269,7 @@ watch(selectedRegion, () => {
<ItDropdownSelect
v-if="courseSessions.length > 2"
v-model="selectedSession"
data-cy="select-session"
data-cy="select-course"
:items="courseSessions"
borderless
></ItDropdownSelect>

View File

@ -1,41 +0,0 @@
import { login } from "./helpers";
// constants
const COURSE_SELECT = "[data-cy=appointments-course-select]";
const SESSION_SELECT = "[data-cy=appointments-session-select]";
const CIRCLE_SELECT = "[data-cy=appointments-circle-select]";
const APPOINTMENTS = "[data-cy=appointments-list]";
describe("appointments.cy.js", () => {
beforeEach(() => {
cy.manageCommand("cypress_reset");
login("test-student2@example.com", "test");
cy.visit("/course/test-lehrgang/appointments");
});
it("preselects first course (Test Lehrgang)", () => {
cy.visit("/course/test-lehrgang/appointments");
cy.get(COURSE_SELECT).should("contain", "Test Lehrgang");
cy.get(SESSION_SELECT).should("contain", "Bern");
cy.get(CIRCLE_SELECT).should("contain", "Alle");
cy.get(".cy-single-due-date").should("have.length", 5);
});
it("can filter by circle", () => {
cy.get(CIRCLE_SELECT).click();
cy.get(CIRCLE_SELECT).contains("Fahrzeug").click();
// THEN
cy.get(APPOINTMENTS).should("not.contain", "Keine Termine");
});
it("can switch course session", () => {
cy.get(SESSION_SELECT).click();
cy.get(SESSION_SELECT).contains("Zürich").click();
cy.get(SESSION_SELECT).should("contain", "Zürich");
// THEN
cy.get(APPOINTMENTS).should("contain", "Keine Termine");
});
});

View File

@ -0,0 +1,50 @@
import { login } from "./helpers";
function selectDropboxItem(dropboxSelector, item) {
cy.get(dropboxSelector).click();
cy.get(dropboxSelector).contains(item).click();
}
describe("appointments.cy.js", () => {
beforeEach(() => {
cy.manageCommand("cypress_reset");
login("test-student2@example.com", "test");
cy.visit("/dashboard/due-dates");
});
it("can filter due dates by dropbox selects", () => {
cy.get('[data-cy="due-date-list"]').children().should("have.length", 7);
// can filter by session
cy.get('[data-cy="select-session"]').click();
selectDropboxItem('[data-cy="select-session"]', "Zürich");
cy.get('[data-cy="due-date-list"]').children().should("have.length", 1);
selectDropboxItem('[data-cy="select-session"]', "Bern");
cy.get('[data-cy="due-date-list"]').children().should("have.length", 6);
selectDropboxItem('[data-cy="select-session"]', "Alle");
cy.get('[data-cy="due-date-list"]').children().should("have.length", 7);
// can filter by circle
selectDropboxItem('[data-cy="select-circle"]', "Fahrzeug");
cy.get('[data-cy="due-date-list"]').children().should("have.length", 6);
selectDropboxItem('[data-cy="select-circle"]', "Reisen");
cy.get('[data-cy="due-date-list"]').children().should("have.length", 1);
selectDropboxItem('[data-cy="select-circle"]', "Alle");
cy.get('[data-cy="due-date-list"]').children().should("have.length", 7);
// can filter by types
selectDropboxItem('[data-cy="select-type"]', "Präsenzkurs");
cy.get('[data-cy="due-date-list"]').children().should("have.length", 3);
selectDropboxItem('[data-cy="select-type"]', "Bewertung");
cy.get('[data-cy="due-date-list"]').children().should("have.length", 1);
// combination
selectDropboxItem('[data-cy="select-session"]', "Bern");
selectDropboxItem('[data-cy="select-type"]', "Präsenzkurs");
cy.get('[data-cy="due-date-list"]').children().should("have.length", 2);
selectDropboxItem('[data-cy="select-session"]', "Zürich");
cy.get('[data-cy="due-date-list"]').children().should("have.length", 1);
selectDropboxItem('[data-cy="select-type"]', "Bewertung");
cy.get('[data-cy="due-date-list"]').should("contain", "Keine Termine");
});
});

View File

@ -28,7 +28,7 @@ describe("login.cy.js", () => {
login("test-student1@example.com", "test");
cy.visit("/");
cy.request("/api/core/me").its("status").should("eq", 200);
cy.get('[data-cy="dashboard-title"]').should("contain", "Dashboard");
cy.get('[data-cy="db-course-title"]').should("contain", "Test Lehrgang");
});
it("login will redirect to requested page", () => {

View File

@ -1,5 +1,6 @@
# pylint: disable=unused-wildcard-import,wildcard-import,wrong-import-position
import os
from environs import Env
script_path = os.path.abspath(__file__)

View File

@ -1,6 +1,6 @@
from datetime import datetime
from dateutil.relativedelta import MO, relativedelta, TH, TU
from dateutil.relativedelta import MO, relativedelta, TH, TU, WE
from django.utils import timezone
from slugify import slugify
from wagtail.rich_text import RichText
@ -164,14 +164,33 @@ def create_test_course(
location="Handelsschule KV Bern, Zimmer 123, Eigerstrasse 16, 3012 Bern",
trainer="Roland Grossenbacher, roland.grossenbacher@helvetia.ch",
)
tuesday_in_one_week = (
wednesday_in_four_weeks = (
datetime.now() + relativedelta(weekday=TU) + relativedelta(weeks=1)
)
csac.due_date.start = timezone.make_aware(
tuesday_in_one_week.replace(hour=8, minute=30, second=0, microsecond=0)
wednesday_in_four_weeks.replace(hour=8, minute=30, second=0, microsecond=0)
)
csac.due_date.end = timezone.make_aware(
tuesday_in_one_week.replace(hour=17, minute=0, second=0, microsecond=0)
wednesday_in_four_weeks.replace(hour=17, minute=0, second=0, microsecond=0)
)
csac.due_date.save()
csac = CourseSessionAttendanceCourse.objects.create(
course_session=cs_bern,
learning_content=LearningContentAttendanceCourse.objects.get(
slug="test-lehrgang-lp-circle-reisen-lc-präsenzkurs-reisen"
),
location="Handelsschule KV Bern, Zimmer 123, Eigerstrasse 16, 3012 Bern",
trainer="Roland Grossenbacher, roland.grossenbacher@helvetia.ch",
)
wednesday_in_four_weeks = (
datetime.now() + relativedelta(weekday=TU) + relativedelta(weeks=4)
)
csac.due_date.start = timezone.make_aware(
wednesday_in_four_weeks.replace(hour=8, minute=15, second=0, microsecond=0)
)
csac.due_date.end = timezone.make_aware(
wednesday_in_four_weeks.replace(hour=17, minute=30, second=0, microsecond=0)
)
csac.due_date.save()
@ -237,6 +256,24 @@ def create_test_course(
id=TEST_COURSE_SESSION_ZURICH_ID,
start_date=now,
)
csac = CourseSessionAttendanceCourse.objects.create(
course_session=cs_zurich,
learning_content=LearningContentAttendanceCourse.objects.get(
slug="test-lehrgang-lp-circle-fahrzeug-lc-präsenzkurs-fahrzeug"
),
location="siehe Anzeigetafel, Bildungszentrum Jungholz, Jungholzstrasse 43, 8050 Zürich-Oerlikon",
trainer="Catia Logarzo",
)
wednesday_in_four_weeks = (
datetime.now() + relativedelta(weekday=WE) + relativedelta(weeks=1)
)
csac.due_date.start = timezone.make_aware(
wednesday_in_four_weeks.replace(hour=8, minute=30, second=0, microsecond=0)
)
csac.due_date.end = timezone.make_aware(
wednesday_in_four_weeks.replace(hour=17, minute=0, second=0, microsecond=0)
)
csac.due_date.save()
region1 = CourseSessionGroup.objects.create(
name="Region 1",
@ -603,8 +640,19 @@ def create_test_circle_reisen(lp):
content_url="/course/test-lehrgang/media/handlungsfelder/reisen",
)
LearningSequenceFactory(title="Analyse", parent=circle)
LearningSequenceFactory(title="Training", parent=circle)
LearningUnitFactory(title="Präsenzkurs", parent=circle)
LearningContentAttendanceCourseFactory(
title="Präsenzkurs Reisen",
parent=circle,
)
LearningUnitFactory(title="Unterlagen", parent=circle)
LearningContentPlaceholderFactory(
title="Unterlagen für den Unterricht",
parent=circle,
)
LearningSequenceFactory(title="Analyse", parent=circle)
# analyse
lu = LearningUnitFactory(
title="Bedarfsanalyse, Ist- und Soll-Situation",