-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathall.cy.ts
122 lines (97 loc) · 3.58 KB
/
all.cy.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
/// <reference types="cypress" />
/// <reference types="../../cypress/support" />
describe("form-mantine-use-drawer-form", () => {
const mockPost = {
title:
"Lorem Ipsum is simply dummy text of the printing and typesetting industry",
content: `Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.`,
status: "Draft",
};
const isDrawerVisible = () => {
return cy.get(".mantine-Drawer-overlay").should("be.visible");
};
const fillForm = () => {
cy.get("#title").clear().type(mockPost.title);
cy.get("#content textarea").clear({ force: true }).type(mockPost.content);
cy.fillMantineStatus("Draft");
cy.get("#categoryId").click().type("{downArrow}{enter}", { force: true });
};
const assertSuccessResponse = (response: any) => {
const body = response?.body;
expect(response?.statusCode).to.eq(200);
expect(body).to.have.property("id");
expect(body).to.have.property("category");
expect(body?.title).to.eq(mockPost.title);
expect(body?.status?.toLowerCase()).to.eq(mockPost?.status?.toLowerCase());
cy.getMantineNotification().contains(/success/gi);
};
const submitForm = () => {
return cy.getSaveButton().click();
};
beforeEach(() => {
cy.interceptGETPost();
cy.interceptPOSTPost();
cy.interceptPATCHPost();
cy.interceptDELETEPost();
cy.interceptGETPosts();
cy.interceptGETCategories();
cy.clearAllCookies();
cy.clearAllLocalStorage();
cy.clearAllSessionStorage();
cy.visit("/");
});
it("should create record", () => {
cy.getCreateButton().click();
fillForm();
submitForm();
cy.wait("@postPost").then((interception) => {
const response = interception?.response;
assertSuccessResponse(response);
});
});
it("should edit record", () => {
cy.getEditButton().first().click();
isDrawerVisible();
// assert response values are equal to the form values
cy.wait("@getPost").then((interception) => {
const response = interception?.response;
const body = response?.body;
// wait loading state and render to be finished
cy.getSaveButton().should("not.be.disabled");
cy.getMantineLoadingOverlay().should("not.exist");
cy.get("#title").should("have.value", body?.title);
cy.get("#content textarea").should("have.value", body?.content);
cy.get("#status").should(
"have.value",
body?.status?.charAt(0).toUpperCase() + body?.status?.slice(1),
);
});
fillForm();
submitForm();
cy.wait("@patchPost").then((interception) => {
const response = interception?.response;
assertSuccessResponse(response);
});
});
it("should create form sync with location", () => {
cy.wait("@getPosts");
cy.getCreateButton().click();
isDrawerVisible();
cy.location("search").should("include", "modal-posts-create[open]=true");
cy.reload();
isDrawerVisible();
cy.location("search").should("include", "modal-posts-create[open]=true");
});
it("should edit form sync with location", () => {
cy.wait("@getPosts");
cy.getEditButton().first().click();
cy.wait("@getPost");
isDrawerVisible();
cy.location("search").should("include", "modal-posts-edit[open]=true");
cy.location("search").should("include", "modal-posts-edit[id]");
cy.reload();
isDrawerVisible();
cy.location("search").should("include", "modal-posts-edit[open]=true");
cy.location("search").should("include", "modal-posts-edit[id]");
});
});