-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy pathall.cy.ts
More file actions
130 lines (114 loc) · 3.9 KB
/
Copy pathall.cy.ts
File metadata and controls
130 lines (114 loc) · 3.9 KB
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
/// <reference types="cypress" />
/// <reference types="../../cypress/support" />
describe("auth-chakra-ui", () => {
const submitAuthForm = () => {
return cy.get("button[type=submit]").click();
};
const login = () => {
cy.fixture("demo-auth-credentials").then((auth) => {
cy.get("#email").clear();
cy.get("#email").type(auth.email);
cy.get("#password").clear();
cy.get("#password").type(auth.password);
});
submitAuthForm();
};
beforeEach(() => {
cy.clearAllCookies();
cy.clearAllLocalStorage();
cy.clearAllSessionStorage();
cy.visit("/");
});
describe("login", () => {
it("should login", () => {
login();
cy.location("pathname").should("eq", "/posts");
cy.getAllLocalStorage().then((ls) => {
expect(ls[Cypress.config("baseUrl")!]).to.have.property("email");
});
});
it("should throw error if login email is wrong", () => {
cy.get("#email").clear().type("test@test.com");
cy.get("#password").clear().type("test");
submitAuthForm();
cy.getChakraUINotification().contains(/login failed/i);
cy.location("pathname").should("eq", "/login");
});
it("should has 'to' param on URL after redirected to /login", () => {
login();
cy.location("pathname").should("eq", "/posts");
cy.visit("/test");
cy.location("pathname").should("eq", "/test");
cy.clearAllLocalStorage();
cy.reload();
cy.location("search").should("contains", "to=%2Ftest");
cy.location("pathname").should("eq", "/login");
login();
cy.location("pathname").should("eq", "/test");
});
it("should redirect to /login?to= if user not authenticated", () => {
cy.visit("/test-route");
cy.get(".chakra-heading").contains(/sign in to your account/i);
cy.location("search").should("contains", "to=%2Ftest");
cy.location("pathname").should("eq", "/login");
});
});
describe("register", () => {
it("should register", () => {
cy.get("a")
.contains(/sign up/i)
.click();
cy.location("pathname").should("eq", "/register");
login();
cy.location("pathname").should("eq", "/posts");
cy.getAllLocalStorage().then((ls) => {
expect(ls[Cypress.config("baseUrl")!]).to.have.property("email");
});
});
it("should throw error if register email is wrong", () => {
cy.get("a")
.contains(/sign up/i)
.click();
cy.get("#email").clear().type("test@test.com");
cy.get("#password").clear().type("test");
submitAuthForm();
cy.getChakraUINotification().contains(/invalid email/i);
cy.location("pathname").should("eq", "/register");
});
});
describe("forgot password", () => {
it("should throw error if forgot password email is wrong", () => {
cy.visit("/forgot-password");
cy.get("#email").clear().type("test@test.com");
submitAuthForm();
cy.getChakraUINotification().contains(/invalid email/i);
cy.location("pathname").should("eq", "/forgot-password");
});
});
describe("update password", () => {
it("should throw error if update password is wrong", () => {
cy.visit("/update-password");
cy.get("#password").clear().type("123456");
cy.get("#confirmPassword").clear().type("123456");
submitAuthForm();
cy.getChakraUINotification().contains(/invalid password/i);
cy.location("pathname").should("eq", "/update-password");
});
});
describe("logout", () => {
it("should logout", () => {
login();
cy.get(".chakra-button")
.contains(/logout/i)
.click();
cy.location("pathname").should("eq", "/login");
});
});
describe("get identity", () => {
it("should render getIdentity response on header", () => {
login();
cy.get(".chakra-text").contains(/jane doe/i);
cy.get(".chakra-avatar").should("be.visible");
});
});
});