-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathall.cy.ts
142 lines (115 loc) · 4.14 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/// <reference types="cypress" />
/// <reference types="../../cypress/support" />
describe("auth-mantine", () => {
const submitAuthForm = () => {
return cy.get("button[type=submit]").click();
};
const login = () => {
cy.fixture("demo-auth-credentials").then((auth) => {
cy.get('input[name="email"]').clear().type(auth.email);
cy.get('input[name="password"]').clear().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('input[name="password"]').clear().type("test");
submitAuthForm();
cy.getMantineNotification().contains(/invalid email/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(".mantine-Title-root").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").as("registerPath");
cy.get("@registerPath").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('input[name="email"]').as("emailInput").clear();
cy.get('input[name="password"]').as("passwordInput").clear();
cy.get("@passwordInput").type("test");
submitAuthForm();
cy.getMantineNotification().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");
submitAuthForm();
cy.getMantineNotification().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('input[name="password"]').clear().type("123456");
cy.get('input[name="confirmPassword"]').clear().type("123456");
submitAuthForm();
cy.getMantineNotification().contains(/invalid password/i);
cy.location("pathname").should("eq", "/update-password");
});
});
describe("logout", () => {
it("should logout", () => {
login();
cy.get("a")
.contains(/logout/i)
.click();
cy.location("pathname").should("eq", "/login");
});
});
describe("get identity", () => {
it("should render getIdentity response on header", () => {
login();
cy.get("header .mantine-Title-root").contains(/jane doe/i);
cy.get("header .mantine-Avatar-image").should("have.attr", "src");
});
});
});