-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
user-settings.spec.ts
80 lines (62 loc) · 2.75 KB
/
user-settings.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
import { User } from "../../../src/models";
import { isMobile } from "../../support/utils";
describe("User Settings", function () {
beforeEach(function () {
cy.task("db:seed");
cy.intercept("PATCH", "/users/*").as("updateUser");
cy.intercept("GET", "/notifications*").as("getNotifications");
cy.database("find", "users").then((user: User) => {
cy.loginByXstate(user.username);
});
if (isMobile()) {
cy.getBySel("sidenav-toggle").click();
}
cy.getBySel("sidenav-user-settings").click();
});
it("renders the user settings form", function () {
cy.wait("@getNotifications");
cy.getBySel("user-settings-form").should("be.visible");
cy.location("pathname").should("include", "/user/settings");
cy.visualSnapshot("User Settings Form");
});
it("should display user setting form errors", function () {
["first", "last"].forEach((field) => {
cy.getBySelLike(`${field}Name-input`).type("Abc").clear().blur();
cy.get(`#user-settings-${field}Name-input-helper-text`)
.should("be.visible")
.and("contain", `Enter a ${field} name`);
});
cy.getBySelLike("email-input").type("abc").clear().blur();
cy.get("#user-settings-email-input-helper-text")
.should("be.visible")
.and("contain", "Enter an email address");
cy.getBySelLike("email-input").type("abc@bob.").blur();
cy.get("#user-settings-email-input-helper-text")
.should("be.visible")
.and("contain", "Must contain a valid email address");
cy.getBySelLike("phoneNumber-input").type("abc").clear().blur();
cy.get("#user-settings-phoneNumber-input-helper-text")
.should("be.visible")
.and("contain", "Enter a phone number");
cy.getBySelLike("phoneNumber-input").type("615-555-").blur();
cy.get("#user-settings-phoneNumber-input-helper-text")
.should("be.visible")
.and("contain", "Phone number is not valid");
cy.getBySelLike("submit").should("be.disabled");
cy.visualSnapshot("User Settings Form Errors and Submit Disabled");
});
it("updates first name, last name, email and phone number", function () {
cy.getBySelLike("firstName").clear().type("New First Name");
cy.getBySelLike("lastName").clear().type("New Last Name");
cy.getBySelLike("email").clear().type("[email protected]");
cy.getBySelLike("phoneNumber-input").clear().type("6155551212").blur();
cy.getBySelLike("submit").should("not.be.disabled");
cy.getBySelLike("submit").click();
cy.wait("@updateUser").its("response.statusCode").should("equal", 204);
if (isMobile()) {
cy.getBySel("sidenav-toggle").click();
}
cy.getBySel("sidenav-user-full-name").should("contain", "New First Name");
cy.visualSnapshot("User Settings Update Profile");
});
});