|
| 1 | +/// <reference types="cypress" /> |
| 2 | + |
| 3 | +describe("Tests for user's profile page", () => { |
| 4 | + const testUser = { |
| 5 | + username: Cypress.env('testUsername'), |
| 6 | + email: Cypress.env('testUserEmail'), |
| 7 | + password: Cypress.env('testUserPassword') |
| 8 | + } |
| 9 | + |
| 10 | + const updatedUser = { |
| 11 | + name: testUser.username + '-updated', |
| 12 | + bio: 'Hello, this is a updated bio for testing', |
| 13 | + profession: 'updated-profession', |
| 14 | + company: 'updated-company', |
| 15 | + linkedin: 'updated-linkedin', |
| 16 | + twitter: 'updated-twitter', |
| 17 | + } |
| 18 | + |
| 19 | + // Function to update the detaiil of a user with the given text |
| 20 | + const updateDetail = (field, value) => { |
| 21 | + cy.get(`[data-cy=edit-${field}-btn]`).click({ force: true }) |
| 22 | + |
| 23 | + cy.get(`[data-cy=edit-${field}]`).clear().type(value) |
| 24 | + |
| 25 | + // Save the edit |
| 26 | + cy.get('[data-cy=save-changes-btn]').click() |
| 27 | + |
| 28 | + cy.wait(1000) |
| 29 | + |
| 30 | + // check if the text has been updated |
| 31 | + cy.get(`[data-cy=user-${field}]`).contains(value) |
| 32 | + } |
| 33 | + |
| 34 | + before('Log in the user', () => { |
| 35 | + cy.visit('/') |
| 36 | + |
| 37 | + cy.get('[data-cy=btn-signin]').click() |
| 38 | + |
| 39 | + cy.url().should('equal', `${Cypress.config().baseUrl}/login`) |
| 40 | + |
| 41 | + cy.wait(500) |
| 42 | + |
| 43 | + cy.get('[data-cy=login-username]').type(testUser.username) |
| 44 | + |
| 45 | + cy.get('[data-cy=login-password]').type(testUser.password) |
| 46 | + |
| 47 | + cy.get('[data-cy=login-btn]').click() |
| 48 | + |
| 49 | + cy.url().should('equal', `${Cypress.config().baseUrl}/`) |
| 50 | + }) |
| 51 | + |
| 52 | + before('Navigate to user\'s account page', () => { |
| 53 | + |
| 54 | + // Open the context menu on top right of the screen |
| 55 | + cy.get('[data-cy=user-dropdown-menu-btn]').click() |
| 56 | + |
| 57 | + cy.get('[data-cy=user-profile-btn]').click() |
| 58 | + |
| 59 | + // Naviage to the user's stories page |
| 60 | + cy.url().should('equal', `${Cypress.config().baseUrl}/myProfile`) |
| 61 | + }) |
| 62 | + |
| 63 | + |
| 64 | + beforeEach(() => { |
| 65 | + Cypress.Cookies.preserveOnce('token') |
| 66 | + cy.restoreLocalStorage() |
| 67 | + }) |
| 68 | + |
| 69 | + afterEach(() => { |
| 70 | + cy.saveLocalStorage() |
| 71 | + }) |
| 72 | + |
| 73 | + it('Shows user details', () => { |
| 74 | + |
| 75 | + cy.get('[data-cy=user-username]').contains(testUser.username) |
| 76 | + |
| 77 | + cy.get('[data-cy=user-email]').contains(testUser.email) |
| 78 | + |
| 79 | + cy.get('[data-cy=user-Bio]').contains('Say something about yourself') |
| 80 | + |
| 81 | + cy.get('[data-cy=user-Profession]').contains('Your job title') |
| 82 | + |
| 83 | + cy.get('[data-cy=user-Company]').contains('Your company name') |
| 84 | + |
| 85 | + cy.get('[data-cy=user-LinkedIn]').contains('Your LinkedIn username') |
| 86 | + |
| 87 | + cy.get('[data-cy=user-Twitter]').contains('Your Twitter handle') |
| 88 | + |
| 89 | + }) |
| 90 | + |
| 91 | + it('Updates user\'s name', () => { |
| 92 | + |
| 93 | + updateDetail('Name', updatedUser.name) |
| 94 | + |
| 95 | + }) |
| 96 | + |
| 97 | + it('Updates user\'s bio', () => { |
| 98 | + |
| 99 | + updateDetail('Bio', updatedUser.bio) |
| 100 | + |
| 101 | + }) |
| 102 | + |
| 103 | + it('Updates user\'s details', () => { |
| 104 | + |
| 105 | + updateDetail('Profession', updatedUser.profession) |
| 106 | + |
| 107 | + updateDetail('Company', updatedUser.company) |
| 108 | + |
| 109 | + updateDetail('LinkedIn', updatedUser.linkedin) |
| 110 | + |
| 111 | + updateDetail('Twitter', updatedUser.twitter) |
| 112 | + |
| 113 | + }) |
| 114 | + |
| 115 | +}) |
| 116 | + |
0 commit comments