Skip to content

Commit e34e8b8

Browse files
committed
Added tests for user profile page and inserted newline in new story test
1 parent d08d80f commit e34e8b8

File tree

6 files changed

+135
-10
lines changed

6 files changed

+135
-10
lines changed

cypress.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@
88
"testStoryProduct": "EOS Icons",
99
"testCategory": "Documentation"
1010
},
11-
"testFiles": ["user_story.spec.js", "test_filters.spec.js"]
11+
"testFiles": ["auth.spec.js","new_story.spec.js","user_story.spec.js","dashboard.spec.js", "user_account.spec.js"]
1212
}

cypress/integration/new_story.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,4 @@ describe("Tests for creating a new story", () => {
102102

103103
cy.contains(testUser.username)
104104
})
105-
})
105+
})
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+

src/components/EditableLabel.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const EditableLabel = ({
5656
{children}
5757
{allowEditing && (
5858
<button
59+
data-cy={`edit-${name}-btn`}
5960
className='editable-label-edit-btn'
6061
onClick={() => setEditMode(!editMode)}
6162
>
@@ -68,6 +69,7 @@ export const EditableLabel = ({
6869
<>
6970
{ComponentToRender(type)}
7071
<button
72+
data-cy='save-changes-btn'
7173
onClick={() => {
7274
setEditMode(!editMode)
7375
updateProfile()

src/components/Navigation.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const Navigation = (props) => {
106106
</li>
107107
<li
108108
className='dropdown-element'
109+
data-cy='user-profile-btn'
109110
onClick={() => navigate('/myProfile')}
110111
>
111112
<EOS_SETTINGS className='eos-icons eos-18' />

src/components/UserProfile.jsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ export const UserSettings = ({ user }) => {
6767
<Skeleton width={200} />
6868
) : (
6969
<ul>
70-
<li>
70+
<li data-cy='user-email'>
7171
Email address:
7272
<span>{user?.email}</span>
7373
</li>
74-
<li>
74+
<li data-cy='user-username'>
7575
Username:
7676
<span>{user?.username}</span>
7777
</li>
@@ -107,8 +107,9 @@ export const UserDetails = ({
107107
allowEditing={allowEditing}
108108
updateProfile={updateProfile}
109109
placeholder='Your name'
110+
data-cy='edit-Name'
110111
>
111-
<h2 className='user-profile-name'>
112+
<h2 className='user-profile-name' data-cy='user-Name'>
112113
{user.Name ? user.Name : user.username}
113114
</h2>
114115
</EditableLabel>
@@ -120,8 +121,9 @@ export const UserDetails = ({
120121
allowEditing={allowEditing}
121122
updateProfile={updateProfile}
122123
placeholder='Say something about yourself'
124+
data-cy='edit-Bio'
123125
>
124-
<p>
126+
<p data-cy='user-Bio'>
125127
{user.Bio ||
126128
(allowEditing ? 'Say something about yourself' : 'Hi There!')}
127129
</p>
@@ -145,8 +147,9 @@ export const UserDetails = ({
145147
allowEditing={allowEditing}
146148
updateProfile={updateProfile}
147149
placeholder='Your job title'
150+
data-cy='edit-Profession'
148151
>
149-
<span>
152+
<span data-cy='user-Profession'>
150153
{!user.Profession ? 'Your job title' : user.Profession}
151154
</span>
152155
</EditableLabel>
@@ -163,8 +166,9 @@ export const UserDetails = ({
163166
allowEditing={allowEditing}
164167
updateProfile={updateProfile}
165168
placeholder='Your company name'
169+
data-cy='edit-Company'
166170
>
167-
<span>
171+
<span data-cy='user-Company'>
168172
{!user.Company ? 'Your company name' : user.Company}
169173
</span>
170174
</EditableLabel>
@@ -181,8 +185,9 @@ export const UserDetails = ({
181185
allowEditing={allowEditing}
182186
updateProfile={updateProfile}
183187
placeholder='Your LinkedIn username'
188+
data-cy='edit-LinkedIn'
184189
>
185-
<span>
190+
<span data-cy='user-LinkedIn'>
186191
{user.LinkedIn ? (
187192
<a
188193
className='link link-default'
@@ -210,8 +215,9 @@ export const UserDetails = ({
210215
allowEditing={allowEditing}
211216
updateProfile={updateProfile}
212217
placeholder='Your Twitter handle'
218+
data-cy='edit-Twitter'
213219
>
214-
<span>
220+
<span data-cy='user-Twitter'>
215221
{user.Twitter ? (
216222
<a
217223
className='link link-default'

0 commit comments

Comments
 (0)