Skip to content

Commit

Permalink
tests: Add E2E tests for feedback + print button
Browse files Browse the repository at this point in the history
  • Loading branch information
jimwashbrook committed Aug 27, 2024
1 parent 9482914 commit 5faafc3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Dfe.ContentSupport.Web/Views/Shared/_Feedback.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

@if (track)
{
<div class="dfe-feedback-banner govuk-!-margin-top-9 govuk-visually-hidden" aria-hidden="true">
<div class="dfe-feedback-banner govuk-!-margin-top-9 govuk-visually-hidden" aria-hidden="true" id="feedback-banner">
<div class="dfe-feedback-banner--content">
<form id="feedbackForm">
<div class="dfe-feedback-banner--content-questions">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
describe('Feedback banner', () => {
it("should be visible when tracking consented", () => {
cy.visit('content/hello-world',
{
headers: {
'Cookie': '.AspNet.Consent=yes'
}
}
);

cy.get("div#feedback-banner")
.should('exist')
.not("govuk-visually-hidden")
.should('not.have.attr', 'aria-hidden');
});

it("should not exist when tracking consent not given", () => {
cy.visit('content/hello-world',
{
headers: {
'Cookie': '.AspNet.Consent=no'
}
}
);

cy.get("div#feedback-banner")
.should('not.exist');
});

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
describe('Print button', () => {
beforeEach(() => {
cy.visit('content/hello-world', {
onBeforeLoad(win) {
//Stub the print functionality so we can see if it was called
//Note: could spy instead, but I don't want the print dialog to actually show.
cy.stub(win, 'print', () => { });
},
});
});

it("should be visible", () => {
cy.get("div.print-button")
.should('exist')
.not("govuk-visually-hidden")
.should('not.have.attr', 'aria-hidden');

cy.get("button#print-link").should("exist");
});

it("should print on click", () => {
cy.get("button#print-link").click();
cy.window().its("print").should('be.called');
});
});

0 comments on commit 5faafc3

Please sign in to comment.