Skip to content

Commit

Permalink
Merge branch 'feature/vouchers-user-promotion' into feature/voucher-r…
Browse files Browse the repository at this point in the history
…edemption
  • Loading branch information
fosterfarrell9 committed Aug 21, 2024
2 parents e5f471e + e33db99 commit 2eda386
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/views/lectures/edit/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
id="lecture-nav-people" type="button" role="tab"
href="#people"
data-bs-toggle="pill" data-bs-target="#lecture-pane-people"
data-cy="people-tab-btn"
aria-controls="lecture-pane-people" aria-selected="false">
<%= t('basics.people') %>/<%= t('basics.tutorials') %>
</button>
Expand Down
13 changes: 9 additions & 4 deletions app/views/vouchers/_voucher.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<% voucher = lecture.active_voucher_of_role(role) %>
<% if voucher %>
<div>
<span>
<span data-cy='<%= "#{role}-voucher-data" %>'>
<%= t('admin.voucher.secure_hash') %>:
<%= voucher.secure_hash %>
<span data-cy='<%= "#{role}-voucher-secure-hash" %>'>
<%= voucher.secure_hash %>
</span>
</span>
<i class="clipboardpopup far fa-copy clickable text-secondary clipboard-btn
ms-3 clipboard-button"
data-clipboard-text="<%= voucher.secure_hash %>"
data-bs-toggle="tooltip"
data-id="<%= voucher.secure_hash %>"
data-cy="copy-<%= role %>-voucher-btn"
title="<%= t('buttons.copy_to_clipboard') %>">
<span class="clipboardpopuptext token-clipboard-popup"
data-id="<%= voucher.secure_hash %>">
Expand All @@ -20,7 +23,8 @@
class: 'text-dark ms-2',
data: { toggle: 'tooltip',
placement: 'bottom',
confirm: t('confirmation.generic') },
confirm: t('confirmation.generic'),
cy: "invalidate-#{role}-voucher-btn" },
style: 'text-decoration: none;',
title: t('buttons.invalidate'),
method: :post,
Expand All @@ -43,7 +47,8 @@
role: role }),
class: 'text-dark ms-2',
data: { toggle: 'tooltip',
placement: 'bottom' },
placement: 'bottom',
cy: "create-#{role}-voucher-btn" },
title: t('buttons.create_voucher'),
method: :post,
remote: true do %>
Expand Down
100 changes: 100 additions & 0 deletions spec/cypress/e2e/vouchers_spec.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import FactoryBot from "../support/factorybot";

const ROLES = ["tutor", "editor", "teacher", "speaker"];

function createLectureScenario(context, type = "lecture") {
cy.createUserAndLogin("teacher").as("teacher");

cy.then(() => {
FactoryBot.create(type, "with_teacher_by_id", { teacher_id: context.teacher.id }).as("lecture");
});

cy.then(() => {
cy.visit(`/lectures/${context.lecture.id}/edit`);
cy.getBySelector("people-tab-btn").click();
});

cy.i18n("basics.vouchers").as("vouchers");
}

function testCreateVoucher(role) {
cy.getBySelector(`create-${role}-voucher-btn`).click();

cy.then(() => {
cy.getBySelector(`${role}-voucher-data`).should("be.visible");
cy.getBySelector(`${role}-voucher-secure-hash`).should("not.be.empty");
cy.getBySelector(`invalidate-${role}-voucher-btn`).should("be.visible");
});
}

function testInvalidateVoucher(role) {
cy.getBySelector(`invalidate-${role}-voucher-btn`).click();

// Confirm popup
cy.on("window:confirm", () => true);

cy.then(() => {
cy.getBySelector(`${role}-voucher-data`).should("not.exist");
cy.getBySelector(`invalidate-${role}-voucher-btn`).should("not.exist");
cy.getBySelector(`create-${role}-voucher-btn`).should("be.visible");
});
}

describe("If the lecture is not a seminar", () => {
beforeEach(function () {
createLectureScenario(this);
});

describe("People tab in lecture edit page", () => {
it("shows buttons for creating tutor, editor and teacher vouchers", function () {
cy.contains(this.vouchers).should("be.visible");

ROLES.filter(role => role !== "speaker").forEach((role) => {
cy.getBySelector(`create-${role}-voucher-btn`).should("be.visible");
});

cy.getBySelector("create-speaker-voucher-btn").should("not.exist");
});

it("displays the voucher and invalidate button after the create button is clicked", function () {
ROLES.filter(role => role !== "speaker").forEach((role) => {
testCreateVoucher(role);
});
});

it("displays that there is no active voucher after the invalidate button is clicked", function () {
ROLES.filter(role => role !== "speaker").forEach((role) => {
testCreateVoucher(role);
testInvalidateVoucher(role);
});
});
});
});

describe("If the lecture is a seminar", () => {
beforeEach(function () {
createLectureScenario(this, "seminar");
});

describe("People tab in lecture edit page", () => {
it("shows buttons for creating tutor, editor, teacher, and speaker vouchers", function () {
cy.contains(this.vouchers).should("be.visible");
ROLES.forEach((role) => {
cy.getBySelector(`create-${role}-voucher-btn`).should("be.visible");
});
});

it("displays the voucher and invalidate button after the create button is clicked", function () {
ROLES.forEach((role) => {
testCreateVoucher(role);
});
});

it("displays that there is no active voucher after the invalidate button is clicked", function () {
ROLES.forEach((role) => {
testCreateVoucher(role);
testInvalidateVoucher(role);
});
});
});
});

0 comments on commit 2eda386

Please sign in to comment.