Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Profile and username add tests #1834

Merged
merged 13 commits into from
Jan 5, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ export const settingsPage = {
firstNameInput: () => cy.get("[data-cy=input-profile-firstname]"),
lastNameInput: () => cy.get("[data-cy=input-profile-lastname]"),
saveChangesButton: () => cy.get("[data-cy=button-save-changes]"),
addUsernameButton: () => cy.get("[data-cy=button-add-username]"),
usernameInput: () => cy.get("[data-cy=input-profile-username]"),
usernameErrorLabel: () => cy.get("[data-cy=input-profile-username] span.error"),
setUsernameButton: () => cy.get("[data-cy=button-set-username]"),
usernamePresentInput: () => cy.get("[data-cy=input-profile-username-present]"),
securityTabButton: () => cy.get("[data-testid=tab-security]"),
securityTabHeader: () => cy.get("[data-cy=label-security-header]"),
subscriptionTabButton: () => cy.get("[data-testid=tab-subscription]")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const profileUpdateSuccessToast = {
body: () => cy.get("[data-testId=toast-profile-update-success]", { timeout: 10000 }),
closeButton: () => cy.get("[data-testid=button-close-toast-profile-update-success]")
}
59 changes: 46 additions & 13 deletions packages/files-ui/cypress/tests/settings-spec.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,58 @@
import { navigationMenu } from "../support/page-objects/navigationMenu"
import { settingsPage } from "../support/page-objects/settingsPage"
import { homePage } from "../support/page-objects/homePage"
import { profileUpdateSuccessToast } from "../support/page-objects/toasts/profileUpdateSuccessToast"

describe("Settings", () => {

context("desktop", () => {
beforeEach(() => {
cy.web3Login()
})

it("can navigate to the settings profile page", () => {
navigationMenu.settingsNavButton().click()
})
it("can navigate to settings profile page", () => {
settingsPage.profileTabHeader().should("be.visible")
cy.url().should("include", "/settings")
settingsPage.profileTabButton().click()
cy.url().should("include", "/settings/profile")
settingsPage.profileTabHeader().should("be.visible")
})

it("save changes button should be disabled without first and last name", () => {
settingsPage.firstNameInput().clear()
settingsPage.lastNameInput().clear()

settingsPage.saveChangesButton().should("be.disabled")
})

it("can add/edit firstname and lastname", () => {
const newFirstName = "test first name"
const newLastName = "test last name"

settingsPage.firstNameInput().type(newFirstName)
settingsPage.lastNameInput().type(`${newLastName}{enter}`)

profileUpdateSuccessToast.body().should("be.visible")
settingsPage.firstNameInput().should("have.value", newFirstName)
settingsPage.lastNameInput().should("have.value", newLastName)
})

// random username generation
const newUserName = Buffer.from(Math.random().toString()).toString("base64").substr(10, 12)
tanmoyAtb marked this conversation as resolved.
Show resolved Hide resolved

it("can add a username", () => {
settingsPage.addUsernameButton().should("be.visible")
settingsPage.addUsernameButton().click()
settingsPage.usernameInput().should("be.visible")
settingsPage.usernameInput().type(`${newUserName}`)
tanmoyAtb marked this conversation as resolved.
Show resolved Hide resolved
settingsPage.setUsernameButton().should("be.enabled")
settingsPage.setUsernameButton().safeClick()
settingsPage.usernamePresentInput().should("be.visible")
settingsPage.usernamePresentInput().should("be.disabled")
})

it("can navigate to settings security page", () => {
settingsPage.securityTabButton().click()
cy.url().should("include", "/settings")
settingsPage.securityTabButton().click()
cy.url().should("include", "/settings/security")
settingsPage.securityTabHeader().should("be.visible")
Expand All @@ -25,21 +62,17 @@ describe("Settings", () => {
context("mobile", () => {
beforeEach(() => {
cy.viewport("iphone-6")
})

beforeEach(() => {
cy.web3Login()
})

it("can navigate to the settings security page on a phone", () => {
homePage.hamburgerMenuButton().click()
navigationMenu.settingsNavButton().click()
settingsPage.profileTabHeader().should("not.exist")
cy.url().should("include", "/settings")
})
it("can navigate to the settings profile page on a phone", () => {
settingsPage.profileTabButton().click()
cy.url().should("include", "/settings/profile")
settingsPage.profileTabHeader().should("be.visible")
cy.go("back")
})

it("can navigate to settings security page", () => {
settingsPage.securityTabButton().click()
cy.url().should("include", "/settings/security")
settingsPage.securityTabHeader().should("be.visible")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ const ProfileView = () => {
try {
setUpdatingProfile(true)
await updateProfile(firstName, lastName)
addToast({ title: t`Profile updated`, type: "success" })
addToast({ title: t`Profile updated`, type: "success", testId: "profile-update-success" })
setUpdatingProfile(false)
} catch (error) {
error instanceof Error && addToast({ title: error.message, type: "error" })
Expand Down Expand Up @@ -410,6 +410,7 @@ const ProfileView = () => {
disabled={true}
value={profile.username}
className={classes.usernameInput}
data-cy="input-profile-username-present"
/>
</div>
</>
Expand Down Expand Up @@ -442,13 +443,14 @@ const ProfileView = () => {
onChange={onUsernameChange}
captionMessage={usernameData.error}
state={usernameData.error ? "error" : "normal"}
data-cy="profile-username-input"
data-cy="input-profile-username"
/>
<div>
<Button
type="submit"
disabled={usernameData.loading || !!usernameData.error || !username}
loading={usernameData.loading}
data-cy="button-set-username"
>
{usernameData.loading ? t`Setting Username` : t`Set Username`}
</Button>
Expand All @@ -467,6 +469,7 @@ const ProfileView = () => {
<span
className={classes.buttonLink}
onClick={() => setShowUsernameForm(true)}
data-cy="button-add-username"
>
<Trans>Add a username</Trans>
</span>
Expand Down
Loading