Skip to content

Commit

Permalink
n70: test: Authorization page JEST -> CYPRESS
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksandr-kiliushin committed Oct 23, 2022
1 parent 2711418 commit 4cb7b9d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 74 deletions.
53 changes: 53 additions & 0 deletions cypress/e2e/authorization.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { testUsers } from "#utils/testing/test-users"

describe("Authorization", () => {
it("logs in successfully", () => {
cy.visit("/auth")

expect(localStorage.authToken).to.be.equal(undefined)
cy.contains("Welcome").should("be.visible")
cy.contains("Log in").should("be.disabled")
cy.get('input[name="username"]').type("john-doe")
cy.get('input[name="password"]').type("john-doe-password")
cy.contains("Log in").should("be.enabled").click()
cy.contains("Welcome").should("not.exist")
expect(localStorage.authToken).to.match(/.+/)
cy.contains("Log in").should("not.exist")
cy.contains("Log out").should("be.visible")
cy.contains("You are logged in as john-doe.").should("be.visible")
})

it("case: user enters unexisting username", () => {
cy.visit("/auth")

cy.get('input[name="username"]').type("john-doe-WITH-A-TYPO")
cy.get('input[name="password"]').type("john-doe-password")
cy.contains("Log in").click()
cy.contains("User not found.").should("be.visible")
cy.get('input[name="username"]').clear().type("john-doe")
cy.contains("Log in").click()
cy.contains("You are logged in as john-doe.").should("be.visible")
})

it("case: user enters invalid password", () => {
cy.visit("/auth")

cy.get('input[name="username"]').type("john-doe")
cy.get('input[name="password"]').type("john-doe-password-WITH-A-TYPO")
cy.contains("Log in").click()
cy.contains("Invalid password.").should("be.visible")
cy.get('input[name="password"]').clear().type("john-doe-password")
cy.contains("Log in").click()
cy.contains("You are logged in as john-doe.").should("be.visible")
})

it("logs out successfully", () => {
cy.authorize(testUsers.johnDoe.id)
cy.visit("/auth")

expect(localStorage.authToken).to.match(/.+/)
cy.contains("Log out").click()
cy.contains("Log in").should("be.visible")
expect(localStorage.authToken).to.be.equal(undefined)
})
})
74 changes: 0 additions & 74 deletions src/views/auth/index.test.tsx

This file was deleted.

0 comments on commit 4cb7b9d

Please sign in to comment.