Skip to content

Commit

Permalink
Add more cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fosterfarrell9 committed Aug 21, 2024
1 parent 215b46b commit e33db99
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 13 deletions.
10 changes: 7 additions & 3 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 Down
68 changes: 58 additions & 10 deletions spec/cypress/e2e/vouchers_spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,55 @@ function createLectureScenario(context, type = "lecture") {
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.then(() => {
cy.contains(this.vouchers).should("be.visible");
ROLES.filter(role => role !== "speaker").forEach((role) => {
cy.getBySelector(`create-${role}-voucher-btn`).should("be.visible");
});
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);
});
});
});
Expand All @@ -41,11 +78,22 @@ describe("If the lecture is a seminar", () => {

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

0 comments on commit e33db99

Please sign in to comment.