From f7bcb3c433787317ba7d9044a073cc56c2ebdb99 Mon Sep 17 00:00:00 2001 From: Splines Date: Tue, 3 Dec 2024 18:07:48 +0100 Subject: [PATCH] Add test for module settings (allow to subscribe to a lecture) --- app/views/profile/edit.html.erb | 2 +- spec/cypress/e2e/profile_spec.cy.js | 44 +++++++++++++++++++++-------- spec/factories/courses.rb | 16 +++++++++++ 3 files changed, 49 insertions(+), 13 deletions(-) diff --git a/app/views/profile/edit.html.erb b/app/views/profile/edit.html.erb index 346789343..74f40c6ef 100644 --- a/app/views/profile/edit.html.erb +++ b/app/views/profile/edit.html.erb @@ -95,7 +95,7 @@
-
+
<%= t('profile.courses') %> diff --git a/spec/cypress/e2e/profile_spec.cy.js b/spec/cypress/e2e/profile_spec.cy.js index 428712006..19efcc2ad 100644 --- a/spec/cypress/e2e/profile_spec.cy.js +++ b/spec/cypress/e2e/profile_spec.cy.js @@ -115,28 +115,48 @@ describe("Account settings", () => { }); }); -describe("Module settings", () => { +describe.only("Module settings", () => { beforeEach(function () { - cy.createUserAndLogin("generic").as("user"); + cy.wrap("Happy course").as("courseName"); + cy.wrap("Happy division").as("divisionName"); - FactoryBot.create("course").as("course1"); - FactoryBot.create("course").as("course2"); + cy.then(() => { + FactoryBot.create("division", { name: this.divisionName }).as("division"); + }); + + cy.then(() => { + FactoryBot.create("course", "with_division", + { title: this.courseName, division_id: this.division.id }).as("course"); + }); cy.then(() => { FactoryBot.create("lecture", "released_for_all", - { course_id: this.course1.id }).as("lecture1"); - FactoryBot.create("lecture", "released_for_all", - { course_id: this.course2.id }).as("lecture2"); + { course_id: this.course.id }).as("lecture"); }); - // cy.createUser("teacher").as("teacher"); - // FactoryBot.create("lecture_with_sparse_toc", "released_for_all").as("lecture"); }); - it("todo", function () { - cy.visit(PROFILE_PAGE); + it("allows to subscribe to a lecture", function () { + this.lecture.call.teacher().as("teacher"); + this.lecture.call.term().as("term"); - cy.logout(); cy.createUserAndLogin("admin").as("admin"); cy.visit(PROFILE_PAGE); + + cy.getBySelector("courses-accordion").find("button:visible").first().click(); + cy.getBySelector("courses-accordion").should("contain", this.divisionName); + cy.contains(this.courseName).click(); + + this.lecture.call.term_teacher_info().as("lectureName"); + cy.then(() => { + cy.contains(this.lectureName).click(); + cy.contains(this.lectureName).parent().find("input").should("be.checked"); + cy.getBySelector("profile-change-submit").click(); + }); + + cy.then(() => { + cy.visit("/main/start"); + cy.getBySelector("subscribed-inactive-lectures-collapse").contains(this.courseName); + cy.getBySelector("subscribed-inactive-lectures-collapse").contains(this.teacher.name); + }); }); }); diff --git a/spec/factories/courses.rb b/spec/factories/courses.rb index 2a645fb12..27291a8ae 100644 --- a/spec/factories/courses.rb +++ b/spec/factories/courses.rb @@ -44,5 +44,21 @@ course.tags = FactoryBot.create_list(:tag, evaluator.tag_count) end end + + trait :with_division do + transient do + division_id { nil } + end + + after(:build) do |course, evaluator| + if evaluator.division_id + FactoryBot.create(:division_course_join, + course: course, division_id: evaluator.division_id) + else + division = FactoryBot.create(:division) + FactoryBot.create(:division_course_join, course: course, division: division) + end + end + end end end