{"size": 3131, "ext": "js", "max_stars_repo_path": "test/e2e/cypress/integration/profiles/mobile/settings/success.spec.js", "max_stars_repo_name": "radekg/kratos", "max_stars_repo_stars_event_min_datetime": "2019-11-06T15:13:30.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T21:07:46.000Z", "max_issues_repo_path": "test/e2e/cypress/integration/profiles/mobile/settings/success.spec.js", "max_issues_repo_name": "radekg/kratos", "max_issues_repo_issues_event_min_datetime": "2019-11-06T11:36:50.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-31T18:49:03.000Z", "max_forks_repo_path": "test/e2e/cypress/integration/profiles/mobile/settings/success.spec.js", "max_forks_repo_name": "radekg/kratos", "max_forks_repo_forks_event_min_datetime": "2019-11-14T13:05:05.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T21:04:17.000Z"}
{"max_stars_count": 5207, "max_issues_count": 1248, "max_forks_count": 641, "avg_line_length": 28.7247706422, "max_line_length": 81, "alphanum_fraction": 0.513573938}
import { gen, MOBILE_URL, website } from '../../../../helpers'

context('Mobile Profile', () => {
  describe('Login Flow Success', () => {
    before(() => {
      cy.useConfigProfile('mobile')
    })

    const up = (value) => `not-${value}`

    describe('password', () => {
      const email = gen.email()
      const password = gen.password()

      before(() => {
        cy.registerApi({
          email,
          password,
          fields: { 'traits.website': website }
        })
      })

      beforeEach(() => {
        cy.loginMobile({ email, password })
        cy.visit(MOBILE_URL + '/Settings')
      })

      it('modifies the password', () => {
        const newPassword = up(password)
        cy.get(
          '*[data-testid="settings-password"] input[data-testid="password"]'
        )
          .clear()
          .type(newPassword)
        cy.get(
          '*[data-testid="settings-password"] div[data-testid="submit-form"]'
        ).click()

        cy.get(
          '*[data-testid="settings-password"] div[data-testid="submit-form"]'
        ).should('have.attr', 'data-focusable', 'true')
        cy.get('*[data-testid="logout"]').click()

        cy.visit(MOBILE_URL + '/Home')
        cy.loginMobile({ email, password })
        cy.get('[data-testid="session-token"]').should('not.exist')
        cy.loginMobile({ email, password: newPassword })
        cy.get('[data-testid="session-token"]').should('not.be.empty')
      })
    })

    describe('profile', () => {
      const email = gen.email()
      const password = gen.password()

      before(() => {
        cy.registerApi({
          email,
          password,
          fields: { 'traits.website': website }
        })
      })

      beforeEach(() => {
        cy.loginMobile({ email, password })
        cy.visit(MOBILE_URL + '/Settings')
      })

      it('modifies an unprotected trait', () => {
        cy.get(
          '*[data-testid="settings-profile"] input[data-testid="traits.website"]'
        )
          .clear()
          .type('https://github.com/ory')
        cy.get(
          '*[data-testid="settings-profile"] div[data-testid="submit-form"]'
        ).click()
        cy.get(
          '*[data-testid="settings-profile"] div[data-testid="submit-form"]'
        ).should('have.attr', 'data-focusable', 'true')

        cy.visit(MOBILE_URL + '/Home')
        cy.get('[data-testid="session-content"]').should(
          'contain',
          'https://github.com/ory'
        )
      })

      it('modifies a protected trait', () => {
        const newEmail = up(email)
        cy.get(
          '*[data-testid="settings-profile"] input[data-testid="traits.email"]'
        )
          .clear()
          .type(newEmail)
        cy.get(
          '*[data-testid="settings-profile"] div[data-testid="submit-form"]'
        ).click()
        cy.get(
          '*[data-testid="settings-profile"] div[data-testid="submit-form"]'
        ).should('have.attr', 'data-focusable', 'true')

        cy.visit(MOBILE_URL + '/Home')
        cy.get('[data-testid="session-content"]').should('contain', newEmail)
      })
    })
  })
})
