forked from cypress-io/cypress-realworld-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
transaction-view.spec.ts
114 lines (92 loc) · 4.09 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
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.server();
cy.route("GET", "/transactions").as("personalTransactions");
cy.route("GET", "/transactions/public").as("publicTransactions");
cy.route("GET", "/transactions/*").as("getTransaction");
cy.route("PATCH", "/transactions/*").as("updateTransaction");
cy.route("GET", "/checkAuth").as("userProfile");
cy.route("GET", "/notifications").as("getNotifications");
cy.route("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 () {
cy.getBySelLike("transaction-item").first().click();
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 () {
cy.getBySelLike("transaction-item").first().click();
cy.wait("@getTransaction");
cy.getBySelLike("like-button").click();
cy.getBySelLike("like-count").should("contain", 1);
cy.getBySelLike("like-button").should("be.disabled");
cy.visualSnapshot("Transaction after Liked");
});
it("comments on a transaction", function () {
cy.getBySelLike("transaction-item").first().click();
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").should("have.property", "status", 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").should("have.property", "status", 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("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)");
});
});
});