Skip to content

Commit

Permalink
add tests for the invoice page
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard-Pentecost committed Apr 26, 2024
1 parent 9a3dabe commit 33203d7
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/app/views/_includes/bank-transfer-instructions.njk
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<p data-test="transfer-heading">Please make your payment in sterling for <strong>{{ order.total_cost | formatCurrency }}</strong> to Department for Business & Trade’s bank account at National Westminster Bank.</p>
<p data-test="transfer-heading">Please make your payment in sterling for <strong data-test="order-total-cost">{{ order.total_cost | formatCurrency }}</strong> to Department for Business & Trade’s bank account at National Westminster Bank.</p>

<p>
<span data-test="account-name"><strong>Account Name:</strong> DBT OMIS Service<br></span>
Expand Down
2 changes: 1 addition & 1 deletion src/app/views/_includes/payment-instructions.njk
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p>
You will need to pay
<a href="/{{ publicToken }}/invoice">the invoice</a>
<a href="/{{ publicToken }}/invoice" data-test='invoice-link'>the invoice</a>
by {{ invoice.payment_due_date | formatDate }} ({{ invoice.payment_due_date | fromNow(invoice.overdue) }}{{ ' overdue' if invoice.overdue }}).
</p>

Expand Down
14 changes: 7 additions & 7 deletions src/app/views/invoice.njk
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
{% extends '_layouts/invoice.njk' %}

{% block invoice_payment_information %}
<h3>Payment terms</h3>
<h3 data-test="payment-terms">Payment terms</h3>

<p>Payable by {{ invoice.payment_due_date | formatDate }} ({{ invoice.payment_due_date | fromNow }}).</p>
<p data-test="due-date">Payable by {{ invoice.payment_due_date | formatDate }} ({{ invoice.payment_due_date | fromNow }}).</p>

<h3>How to pay by credit or debit card</h3>
<h3 data-test="pay-by-card">How to pay by credit or debit card</h3>

<p>You can pay online using the government’s secure payment service.</p>

<p>
<a href="/{{ publicToken }}/payment/card">Pay by credit or debit card</a>
<a href="/{{ publicToken }}/payment/card" data-test="pay-by-card-link">Pay by credit or debit card</a>
</p>

<h3>How to pay by bank transfer</h3>
<h3 data-test="pay-by-bank-transfer">How to pay by bank transfer</h3>

{% include '_includes/bank-transfer-instructions.njk' %}

<h3>In case of problems</h3>
<h3 data-test="if-problem">In case of problems</h3>

<p>Get in touch with your DBT contact or email <a href="mailto:[email protected]">[email protected]</a>.</p>
<p>Get in touch with your DBT contact or email <a href="mailto:[email protected]" data-test="email-link">[email protected]</a>.</p>
{% endblock %}
2 changes: 1 addition & 1 deletion src/app/views/order-summary.njk
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
<ul class="list-unstyled">
{% if invoice.invoice_company_name %}
<li>
<a href="/{{ publicToken }}/invoice">View your invoice</a>
<a href="/{{ publicToken }}/invoice" data-test='view-invoice-link'>View your invoice</a>
</li>
{% endif %}
{% if order.status in ['paid', 'complete'] %}
Expand Down
113 changes: 113 additions & 0 deletions test/end-to-end/cypress/invoice-spec.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
import { acceptedQuote } from "../test-data";

describe("Invoice spec", () => {
const order = acceptedQuote;

context("Link to invoice page", () => {
it("should take you to the invoice page when clicking 'the invoice' link", () => {
cy.visit(`http://localhost:4000/${order.public_token}`);
cy.get('[data-test="invoice-link"]').click();
cy.get('[data-test="heading"]')
.should("exist")
.and("have.text", "Invoice");
});

it("should take you to the invoice page when clicking 'View your invoice'", () => {
cy.visit(`http://localhost:4000/${order.public_token}`);
cy.get('[data-test="view-invoice-link"]').click();
cy.get('[data-test="heading"]')
.should("exist")
.and("have.text", "Invoice");
});
});

context("When on the invoice page", () => {
beforeEach(() => {
cy.visit(`http://localhost:4000/${order.public_token}/invoice`);
});

it("should show the address of the company the invoice is for", () => {
cy.contains("To")
.should("exist")
.parent()
.and("contain", order.billing_company_name)
.and("contain", order.billing_address_town)
.and("contain", order.billing_address_1)
.and("contain", order.billing_address_postcode)
.and("contain", order.billing_address_country);
});

it("should show the invoice number and an invoice date", () => {
cy.contains("Invoice number").should("exist");
cy.contains("Invoice date").should("exist");
});

it("should show the address that the invoice has been sent from and the vat number", () => {
cy.contains("From").should("exist");
cy.contains("VAT number").should("exist");
});

it("should show the table with the order number, the description and the amount", () => {
cy.get('[data-test="cost-table"]')
.should("exist")
.and("contain", order.reference)
.and("contain", `UK Government support in ${order.primary_market.name}`)
.and("contain", order.subtotal_cost);
});

it("should show payment terms with date invoice is due by", () => {
cy.get('[data-test="payment-terms"]').should(
"have.text",
"Payment terms"
);
cy.get('[data-test="due-date"]').should("exist");
});

it("should show how to pay by credit card with link to pay by this method", () => {
cy.get('[data-test="pay-by-card"]').should(
"have.text",
"How to pay by credit or debit card"
);
cy.get('[data-test="pay-by-card-link')
.should("have.text", "Pay by credit or debit card")
.and("have.attr", "href", `/${order.public_token}/payment/card`);
});

it("should show how to pay by bank transfer with the amount owed", () => {
cy.get('[data-test="pay-by-bank-transfer"]').should(
"have.text",
"How to pay by bank transfer"
);
cy.get('[data-test="order-total-cost"]')
.should("exist")
.and("contain", order.total_cost);
cy.get('[data-test="reference"]')
.should("exist")
.and("contain", order.reference);
});

it("should show in case of problem section with and email link", () => {
cy.get('[data-test="if-problem"]').should(
"have.text",
"In case of problems"
);
cy.get('[data-test="email-link"]')
.should("have.text", "[email protected]")
.and("have.attr", "href", "mailto:[email protected]");
});

it("should take you to the order history page when clicking 'View your order history' link", () => {
cy.get('[data-test="view-order-history-link"]')
.should("exist")
.click()
.location("pathname")
.should("eq", `/${order.public_token}`);

cy.contains("Your order").should("exist");
});

it("should have a 'Print this page' link", () => {
cy.contains("Print this page").should("exist");
});
});
});
4 changes: 2 additions & 2 deletions test/end-to-end/cypress/receipt-spec.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("Reciept spec", () => {
cy.contains("Receipt date").should("exist");
});

it("should show the invoice adderss and VAT number", () => {
it("should show the address that the receipt has been sent from and VAT number", () => {
cy.contains("From").should("exist");
cy.contains("VAT number").should("exist");
});
Expand All @@ -46,7 +46,7 @@ describe("Reciept spec", () => {
cy.get('[data-test="cost-table"]')
.should("exist")
.and("contain", order.reference)
.and("contain", `UK Government support in ${order.primaryMarket.name}`)
.and("contain", `UK Government support in ${order.primary_market.name}`)
.and("contain", order.subtotal_cost);
});

Expand Down
18 changes: 5 additions & 13 deletions test/end-to-end/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,13 @@ export const quoteAwaitingAcceptance = {

export const acceptedQuote = {
reference: "RYM547/24",
created_on: "2024-03-08T13:56:12.108209Z",
company: "fc3530bc-383c-4b18-94c8-8fbe918bee31",
contact: "9b1138ab-ec7b-497f-b8c3-27fed21694ef",
primary_market: "5daf72a6-5d95-e211-a939-e4115bead28a",
sector: "355f977b-8ac3-e211-a646-e4115bead28a",
service_types: ["22fc9edd-41a5-4182-ba4e-baacc681d5f7"],
description: "test order",
public_token: "XXMPH3b2185a7Vpe2f3RiI5HXT0Nshrck_6xGJuRp4UAsA6vkQ",
primary_market: { name: "Canada" },
delivery_date: "2030-05-07",
discount_value: 0,
vat_status: "outside_eu",
net_cost: 500000,
subtotal_cost: 500000,
vat_cost: 0,
total_cost: 500000,
subtotal_cost: "£1,000.00",
total_cost: "£1,000.00",
billing_company_name: "Motorleaf",
billing_address_1: "5000 Rue Saint-Patrick,",
billing_address_town: "Montréal",
Expand All @@ -48,13 +40,13 @@ export const acceptedQuote = {

export const paidQuote = {
reference: "CJC167/23",
status: "draft",
description: "test order paid",
public_token: "h93Dn7DKvMLbUB5Yz2h5z7dL1mXXGUa_UiPNBkVoyKLmBE29YQ",
primaryMarket: { name: "Canada" },
primary_market: { name: "Canada" },
delivery_date: "2030-05-07",
vat_status: "outside_eu",
subtotal_cost: "£1,000.00",
total_cost: "£1,000.00",
billing_company_name: "Motorleaf",
billing_address_1: "5000 Rue Saint-Patrick,",
billing_address_town: "Montréal",
Expand Down

0 comments on commit 33203d7

Please sign in to comment.