From be6c96319359edf81e27a0a1ad454d812574af61 Mon Sep 17 00:00:00 2001 From: helenanull Date: Wed, 17 Mar 2021 22:56:35 +0200 Subject: [PATCH] added more tests and improvements --- cypress/integration/settings.spec.js | 41 ++++++++++++++++++++++++++++ cypress/selectors/profile.sel.js | 4 +++ cypress/selectors/settings.sel.js | 11 ++++++++ package.json | 2 +- 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 cypress/integration/settings.spec.js create mode 100644 cypress/selectors/profile.sel.js create mode 100644 cypress/selectors/settings.sel.js diff --git a/cypress/integration/settings.spec.js b/cypress/integration/settings.spec.js new file mode 100644 index 0000000..628b161 --- /dev/null +++ b/cypress/integration/settings.spec.js @@ -0,0 +1,41 @@ +import settings from '../selectors/settings.sel' +import profile from '../selectors/profile.sel' + +describe('Settings', () => { + beforeEach(() => { + cy.register().then((email) => { + cy.wrap(email).as('email') + cy.wrap() + cy.login(email) + }) + cy.visit('/settings') + }) + + it('can update settings', () => { + const logoLink = 'https://www.cypress.io/static/33498b5f95008093f5f94467c61d20ab/ac1e1/cypress-logo.webp' + const username = `updated_cy${Math.random().toString().slice(2, 8)}` + + cy.get(settings.title).should('be.visible') + .and('contain', 'Your Settings') + cy.get(settings.imageField).type(logoLink) + cy.get(settings.usernameField).clear().type(username) + cy.get(settings.bioField).type('update settings') + cy.get(settings.submitButton).click() + cy.url().should('eq', `${Cypress.config('baseUrl')}/@${username}`) + cy.get(profile.savedBio).should('be.visible') + .and('have.text', 'update settings') + cy.get(profile.image).should('be.visible') + .and('have.attr', 'src', logoLink) + }) + + it('can see error message when fields are empty', () => { + cy.get(settings.usernameField).clear() + cy.get(settings.emailField).clear() + cy.get(settings.submitButton).click() + cy.url().should('include', '/settings') + cy.get(settings.errorMessages).should('be.visible') + .and('contain', 'email can\'t be blank') + .and('contain', 'username can\'t be blank') + .and('contain', 'username is too short') + }) +}) diff --git a/cypress/selectors/profile.sel.js b/cypress/selectors/profile.sel.js new file mode 100644 index 0000000..b8840f3 --- /dev/null +++ b/cypress/selectors/profile.sel.js @@ -0,0 +1,4 @@ +module.exports = { + savedBio: '[ng-bind*="profile.bio"]', + image: '.user-info img' +} diff --git a/cypress/selectors/settings.sel.js b/cypress/selectors/settings.sel.js new file mode 100644 index 0000000..13754e5 --- /dev/null +++ b/cypress/selectors/settings.sel.js @@ -0,0 +1,11 @@ +module.exports = { + title: '.container h1', + imageField: '[ng-model="$ctrl.formData.image"]', + usernameField: '[ng-model="$ctrl.formData.username"]', + bioField: '[ng-model="$ctrl.formData.bio"]', + emailField: '[ng-model="$ctrl.formData.email"]', + passwordField: '[ng-model="$ctrl.formData.password"]', + submitButton: 'button[type="submit"]', + logoutButton: 'button[ng-click="$ctrl.logout()"]', + errorMessages: '.error-messages' +} diff --git a/package.json b/package.json index 02c09c5..e6e128e 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "cy:run:web": "cypress run --env device=web" }, "devDependencies": { - "cypress": "^6.6.0", + "cypress": "^6.7.1", "eslint": "^7.21.0" } }