forked from cypress-io/cypress-realworld-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bankaccounts.spec.ts
163 lines (129 loc) · 5.93 KB
/
bankaccounts.spec.ts
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
import { User } from "../../../src/models";
import { isMobile } from "../../support/utils";
const apiGraphQL = `${Cypress.env("apiUrl")}/graphql`;
type BankAccountsTestCtx = {
user?: User;
};
describe("Bank Accounts", function () {
const ctx: BankAccountsTestCtx = {};
beforeEach(function () {
cy.task("db:seed");
cy.intercept("GET", "/notifications").as("getNotifications");
cy.intercept("POST", apiGraphQL, (req) => {
const { body } = req;
if (body.hasOwnProperty("operationName") && body.operationName === "ListBankAccount") {
req.alias = "gqlListBankAccountQuery";
}
if (body.hasOwnProperty("operationName") && body.operationName === "CreateBankAccount") {
req.alias = "gqlCreateBankAccountMutation";
}
if (body.hasOwnProperty("operationName") && body.operationName === "DeleteBankAccount") {
req.alias = "gqlDeleteBankAccountMutation";
}
});
cy.database("find", "users").then((user: User) => {
ctx.user = user;
return cy.loginByXstate(ctx.user.username);
});
});
it("creates a new bank account", function () {
cy.wait("@getNotifications");
if (isMobile()) {
cy.getBySel("sidenav-toggle").click();
}
cy.getBySel("sidenav-bankaccounts").click();
cy.getBySel("bankaccount-new").click();
cy.location("pathname").should("eq", "/bankaccounts/new");
cy.visualSnapshot("Display New Bank Account Form");
cy.getBySelLike("bankName-input").type("The Best Bank");
cy.getBySelLike("routingNumber-input").type("987654321");
cy.getBySelLike("accountNumber-input").type("123456789");
cy.visualSnapshot("Fill out New Bank Account Form");
cy.getBySelLike("submit").click();
cy.wait("@gqlCreateBankAccountMutation");
cy.getBySelLike("bankaccount-list-item")
.should("have.length", 2)
.eq(1)
.should("contain", "The Best Bank");
cy.visualSnapshot("Bank Account Created");
});
it("should display bank account form errors", function () {
cy.visit("/bankaccounts");
cy.getBySel("bankaccount-new").click();
cy.getBySelLike("bankName-input").type("The").find("input").clear().blur();
cy.get("#bankaccount-bankName-input-helper-text")
.should("be.visible")
.and("contain", "Enter a bank name");
cy.getBySelLike("bankName-input").type("The").find("input").blur();
cy.get("#bankaccount-bankName-input-helper-text")
.should("be.visible")
.and("contain", "Must contain at least 5 characters");
/** Routing number input validations **/
// Required field
cy.getBySelLike("routingNumber-input").find("input").focus().blur();
cy.get(`#bankaccount-routingNumber-input-helper-text`)
.should("be.visible")
.and("contain", "Enter a valid bank routing number");
// Min 9 digit
cy.getBySelLike("routingNumber-input").type("12345678").find("input").blur();
cy.get("#bankaccount-routingNumber-input-helper-text")
.should("be.visible")
.and("contain", "Must contain a valid routing number");
cy.getBySelLike("routingNumber-input").find("input").clear();
cy.getBySelLike("routingNumber-input").type("123456789").find("input").blur();
cy.get("#bankaccount-routingNumber-input-helper-text").should("not.exist");
/** Account number input validations **/
// Required field
cy.getBySelLike("accountNumber-input").find("input").focus().blur();
cy.get(`#bankaccount-accountNumber-input-helper-text`)
.should("be.visible")
.and("contain", "Enter a valid bank account number");
// Min 9 digit
cy.getBySelLike("accountNumber-input").type("12345678").find("input").blur();
cy.get("#bankaccount-accountNumber-input-helper-text")
.should("be.visible")
.and("contain", "Must contain at least 9 digits");
cy.getBySelLike("accountNumber-input").find("input").clear();
cy.getBySelLike("accountNumber-input").type("123456789").find("input").blur();
cy.get("#bankaccount-accountNumber-input-helper-text").should("not.exist");
cy.getBySelLike("accountNumber-input").find("input").clear();
// Max 12 gdigit
cy.getBySelLike("accountNumber-input").type("123456789111").find("input").blur();
cy.get("#bankaccount-accountNumber-input-helper-text").should("not.exist");
cy.getBySelLike("accountNumber-input").find("input").clear();
cy.getBySelLike("accountNumber-input").type("1234567891111").find("input").blur();
cy.get("#bankaccount-accountNumber-input-helper-text")
.should("be.visible")
.and("contain", "Must contain no more than 12 digits");
cy.getBySel("bankaccount-submit").should("be.disabled");
cy.visualSnapshot("Bank Account Form with Errors and Submit button disabled");
});
it("soft deletes a bank account", function () {
cy.visit("/bankaccounts");
cy.getBySelLike("delete").first().click();
cy.wait("@gqlDeleteBankAccountMutation");
cy.getBySelLike("list-item").children().contains("Deleted");
cy.visualSnapshot("Soft Delete Bank Account");
});
// TODO: [enhancement] the onboarding modal assertion can be removed after adding "onboarded" flag to user profile
it("renders an empty bank account list state with onboarding modal", function () {
cy.wait("@getNotifications");
cy.intercept("POST", apiGraphQL, (req) => {
const { body } = req;
if (body.hasOwnProperty("operationName") && body.operationName === "ListBankAccount") {
req.alias = "gqlListBankAccountQuery";
req.continue((res) => {
res.body.data.listBankAccount = [];
});
}
});
cy.visit("/bankaccounts");
cy.wait("@getNotifications");
cy.wait("@gqlListBankAccountQuery");
cy.getBySel("bankaccount-list").should("not.exist");
cy.getBySel("empty-list-header").should("contain", "No Bank Accounts");
cy.getBySel("user-onboarding-dialog").should("be.visible");
cy.getBySel("nav-top-notifications-count").should("exist");
cy.visualSnapshot("User Onboarding Dialog is Visible");
});
});