-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathupdate-expense.spec.js
99 lines (78 loc) · 3.22 KB
/
update-expense.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/// <reference types="cypress" />
const { Expense } = require("../../support/utils");
const fieldsToUpdate = ["amount", "content", "category", "source", "date"];
const expenseData = require("../../fixtures/expense.json");
const newExpenseData = require("../../fixtures/new-expense.json");
describe("Update expense Tests", () => {
const ctx = {};
beforeEach(() => {
// Delete expense to start clean.
cy.loginAndCleanUp(ctx);
ctx.expense = new Expense(expenseData);
cy.createExpenseWithAPI(ctx.expense, ctx);
ctx.newExpense = new Expense(newExpenseData);
cy.visit("/");
cy.get("[data-test^=update-expense]").first().click();
cy.url().then((url) => {
ctx.updateExpensePageUrl = url;
});
});
fieldsToUpdate.forEach((fieldToUpdate) => {
it(`should update the ${fieldToUpdate} of an expense`, () => {
let textToCheck;
if (fieldToUpdate === "date") {
textToCheck = ctx.newExpense.date;
} else if (fieldsToUpdate === "amount") {
textToCheck = `€ ${ctx.newExpense[fieldToUpdate]}`;
} else {
textToCheck = ctx.newExpense[fieldToUpdate];
}
cy.updateExpenseField(fieldToUpdate, ctx.newExpense[fieldToUpdate]);
cy.url().should("eq", Cypress.config().baseUrl);
cy.get("#expense-table > table > tbody > tr:nth-child(1)")
.should("be.visible")
.and("contain", textToCheck);
});
});
it("should NOT allow to update an expense while leaving 'amount' field at 0", () => {
cy.updateExpenseField("amount", 0);
cy.url().should("eq", ctx.updateExpensePageUrl);
cy.get("[data-test=container]")
.should("be.visible")
.and("contain", "Ensure this value is greater than or equal to 0.01.");
});
fieldsToUpdate.forEach((fieldToUpdate) => {
it(`should NOT allow to update an expense while leaving ${fieldToUpdate} field empty`, () => {
fieldToUpdate === "category"
? cy.updateExpenseField(fieldToUpdate, "---------")
: cy.updateExpenseField(fieldToUpdate, " ");
cy.url().should("eq", ctx.updateExpensePageUrl);
cy.get("[data-test=update-expense-form]").should("be.visible");
});
});
it("should NOT allow to update an expense with amount bigger than 9,999,999,999", () => {
cy.updateExpenseField("amount", 99999999999);
cy.url().should("eq", ctx.updateExpensePageUrl);
cy.get("[data-test=container]")
.should("be.visible")
.and(
"contain",
"Ensure that expense amount is not bigger than 9,999,999,999."
);
});
it("should NOT allow to update an expense with an incorrect format date", () => {
cy.updateExpenseField("date", "2020/12/12 1230pm");
cy.url().should("eq", ctx.updateExpensePageUrl);
cy.get("[data-test=container]")
.should("be.visible")
.and("contain", "Enter a valid date/time.");
});
it("should display the old expense amount when user clicks the cancel button on the form", () => {
cy.updateExpenseField("amount", 10000, false);
cy.get("[data-test=update-expense-cancel]").click();
cy.url().should("eq", Cypress.config().baseUrl);
cy.get("#expense-table > table > tbody > tr:nth-child(1)")
.should("be.visible")
.and("contain", ctx.expense.amount);
});
});