Skip to content

Commit

Permalink
Add test for module settings (allow to subscribe to a lecture)
Browse files Browse the repository at this point in the history
  • Loading branch information
Splines committed Dec 3, 2024
1 parent 9904350 commit f7bcb3c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/views/profile/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@

<!-- 🌟 Courses -->
<div class="col">
<div class="card profile-card" id="courses-accordion">
<div class="card profile-card" id="courses-accordion" data-cy="courses-accordion">
<div class="card-header">
<h5 class="mb-0">
<%= t('profile.courses') %>
Expand Down
44 changes: 32 additions & 12 deletions spec/cypress/e2e/profile_spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
});
});
16 changes: 16 additions & 0 deletions spec/factories/courses.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit f7bcb3c

Please sign in to comment.