Skip to content

Commit

Permalink
Signup tests (TonyMckes#4)
Browse files Browse the repository at this point in the history
* Add logout test

* Add signup tests
  • Loading branch information
hugoguillin authored Mar 24, 2024
1 parent 64d9b7c commit 6cdeb91
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cypress/e2e/logout-test.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import UserSettingsPage from "../page-objects/user-settings-page";

describe("Check logout feature", { tags: "@user" }, () => {
before(() => {
cy.loginWithSession(Cypress.env("email"), Cypress.env("password"));
UserSettingsPage.visit();
});

it("Should navigate to home page after logout", () => {
UserSettingsPage.userPic().click();
cy.getByTestId("logout").click();
cy.url().should("eq", Cypress.config().baseUrl + "/");
UserSettingsPage.userPic().should("not.exist");
});
});
33 changes: 33 additions & 0 deletions cypress/e2e/signup-test.cy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import SignUpPage from "../page-objects/signup-page";
import Utils from "../utils/utils";
import UserSettingsPage from "../page-objects/user-settings-page";

describe("Sign up feature", () => {
beforeEach(() => {
SignUpPage.visit();
});

it("Should register valid new user", () => {
const newUser = Utils.generateNewUserData();
cy.intercept("GET", "**/api/user").as("getUser");
SignUpPage.fillForm(newUser);
UserSettingsPage.userPic().parent().should("have.text", newUser.username);
cy.wait("@getUser").then((user) => {
expect(user.response.body.user.email, "User email").to.eq(newUser.email);
});
});

it("Should display error message for email already in use", () => {
cy.intercept("POST", "**/api/users").as("getUser");
SignUpPage.fillForm({
username: "testuser",
email: Cypress.env("email"),
password: "password",
});
cy.wait("@getUser").its("response.statusCode").should("eq", 422);
SignUpPage.errorMessages().should(
"have.text",
"Email already exists.. try logging in"
);
});
});
15 changes: 15 additions & 0 deletions cypress/page-objects/signup-page.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export default class SignUpPage {
static visit() {
cy.visit("/register");
}

static fillForm({ username, email, password }) {
cy.getByTestId("username").type(username);
cy.getByTestId("email").type(email);
cy.getByTestId("password").type(password + "{enter}");
}

static errorMessages() {
return cy.getByTestId("signup-error");
}
}

0 comments on commit 6cdeb91

Please sign in to comment.