-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
transaction-view.spec.ts
117 lines (95 loc) · 4.51 KB
/
transaction-view.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
import { User, Transaction } from "../../../src/models";
type NewTransactionCtx = {
transactionRequest?: Transaction;
authenticatedUser?: User;
};
describe("Transaction View", function () {
const ctx: NewTransactionCtx = {};
beforeEach(function () {
cy.task("db:seed");
cy.intercept("GET", "/transactions*").as("personalTransactions");
cy.intercept("GET", "/transactions/public*").as("publicTransactions");
cy.intercept("GET", "/transactions/*").as("getTransaction");
cy.intercept("PATCH", "/transactions/*").as("updateTransaction");
cy.intercept("GET", "/checkAuth").as("userProfile");
cy.intercept("GET", "/notifications").as("getNotifications");
cy.intercept("GET", "/bankAccounts").as("getBankAccounts");
cy.database("find", "users").then((user: User) => {
ctx.authenticatedUser = user;
cy.loginByXstate(ctx.authenticatedUser.username);
cy.database("find", "transactions", {
receiverId: ctx.authenticatedUser.id,
status: "pending",
requestStatus: "pending",
requestResolvedAt: "",
}).then((transaction: Transaction) => {
ctx.transactionRequest = transaction;
});
});
cy.getBySel("nav-personal-tab").click();
cy.wait("@personalTransactions");
});
it("transactions navigation tabs are hidden on a transaction view page", function () {
// { force: true } is a workaround for https://github.com/cypress-io/cypress/issues/29776
cy.getBySelLike("transaction-item").first().click({ force: true });
cy.location("pathname").should("include", "/transaction");
cy.getBySel("nav-transaction-tabs").should("not.exist");
cy.getBySel("transaction-detail-header").should("be.visible");
cy.visualSnapshot("Transaction Navigation Tabs Hidden");
});
it("likes a transaction", function () {
// { force: true } is a workaround for https://github.com/cypress-io/cypress/issues/29776
cy.getBySelLike("transaction-item").first().click({ force: true });
cy.wait("@getTransaction");
cy.getBySelLike("like-button").click();
cy.getBySelLike("like-count").should("contain", 2);
cy.getBySelLike("like-button").should("be.disabled");
cy.visualSnapshot("Transaction after Liked");
});
it("comments on a transaction", function () {
// { force: true } is a workaround for https://github.com/cypress-io/cypress/issues/29776
cy.getBySelLike("transaction-item").first().click({ force: true });
cy.wait("@getTransaction");
const comments = ["Thank you!", "Appreciate it."];
comments.forEach((comment, index) => {
cy.getBySelLike("comment-input").type(`${comment}{enter}`);
cy.getBySelLike("comments-list").children().eq(index).contains(comment);
});
cy.getBySelLike("comments-list").children().should("have.length", comments.length);
cy.visualSnapshot("Comment on Transaction");
});
it("accepts a transaction request", function () {
cy.visit(`/transaction/${ctx.transactionRequest!.id}`);
cy.wait("@getTransaction");
cy.getBySelLike("accept-request").click();
cy.wait("@updateTransaction").its("response.statusCode").should("equal", 204);
cy.getBySelLike("accept-request").should("not.exist");
cy.getBySel("transaction-detail-header").should("be.visible");
cy.visualSnapshot("Transaction Accepted");
});
it("rejects a transaction request", function () {
cy.visit(`/transaction/${ctx.transactionRequest!.id}`);
cy.wait("@getTransaction");
cy.getBySelLike("reject-request").click();
cy.wait("@updateTransaction").its("response.statusCode").should("equal", 204);
cy.getBySelLike("reject-request").should("not.exist");
cy.getBySel("transaction-detail-header").should("be.visible");
cy.visualSnapshot("Transaction Rejected");
});
it("does not display accept/reject buttons on completed request", function () {
cy.database("find", "transactions", {
receiverId: ctx.authenticatedUser!.id,
status: "complete",
requestStatus: "accepted",
}).then((transactionRequest) => {
cy.visit(`/transaction/${transactionRequest!.id}`);
cy.wait("@getNotifications");
cy.getBySel("nav-top-notifications-count").should("be.visible");
cy.getBySel("transaction-detail-header").should("be.visible");
cy.getBySel("transaction-accept-request").should("not.exist");
cy.getBySel("transaction-reject-request").should("not.exist");
cy.getBySel("transaction-detail-header").should("be.visible");
cy.visualSnapshot("Transaction Completed (not able to accept or reject)");
});
});
});