Skip to content

Commit 216bbb8

Browse files
committed
Updated all dom selections to use data-cy
1 parent 02a6dd3 commit 216bbb8

File tree

6 files changed

+51
-19
lines changed

6 files changed

+51
-19
lines changed

cypress/integration/user_story.spec.js

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,29 @@ describe('Test new User Registration Workflow', () => {
1010
before('Register a new user', () => {
1111
cy.visit('/')
1212

13-
cy.get('[href="/login"]').contains('Sign In').click()
13+
cy
14+
.get('[data-cy=btn-signin]')
15+
.should('have.attr', 'href', '/login')
16+
.contains('Sign In')
17+
.click()
1418

1519
cy.url().should('equal', 'http://localhost:3000/login')
1620

17-
cy.get('[href="/register"]').contains('Create an account').click()
21+
cy
22+
.get('[data-cy=link-create-account]')
23+
.should('have.attr', 'href', '/register')
24+
.contains('Create an account')
25+
.click()
1826

1927
cy.url().should('equal', 'http://localhost:3000/register')
2028

21-
cy.get('[name=username]').should('have.attr', 'type', 'text').type(testUser.username)
29+
cy.get('[data-cy=username]').should('have.attr', 'type', 'text').type(testUser.username)
2230

23-
cy.get('[name=email]').should('have.attr', 'type', 'text').type(testUser.email)
31+
cy.get('[data-cy=email]').should('have.attr', 'type', 'text').type(testUser.email)
2432

25-
cy.get('[name=password]').should('have.attr', 'type', 'password').type(testUser.password)
33+
cy.get('[data-cy=password]').should('have.attr', 'type', 'password').type(testUser.password)
2634

27-
cy.get('[name=tc]').should('have.attr', 'type', 'checkbox').click()
35+
cy.get('[data-cy=tc]').should('have.attr', 'type', 'checkbox').click()
2836

2937
cy.get('[data-cy=btn-register]').contains('Register').click()
3038

@@ -43,17 +51,21 @@ describe('Test new User Registration Workflow', () => {
4351
})
4452

4553
it('Allows user to create new story', () => {
46-
cy.get('[href="/newStory"]').contains('+ New Story').click()
54+
cy
55+
.get('[data-cy=btn-new-story]')
56+
.should('have.attr', 'href', '/newStory')
57+
.contains('+ New Story')
58+
.click()
4759

4860
cy.url().should('equal', 'http://localhost:3000/newStory')
4961

50-
cy.get('[name=title]').type('This is a test story')
62+
cy.get('[data-cy=title]').type('This is a test story')
5163

52-
cy.get('[name=product]').select('EOS Icons')
64+
cy.get('[data-cy=product]').select('EOS Icons')
5365

54-
cy.get('[name=category]').select('Documentation')
66+
cy.get('[data-cy=category]').select('Documentation')
5567

56-
cy.get('[name=priority]').select('High')
68+
cy.get('[data-cy=priority]').select('High')
5769

5870
cy
5971
.get('[data-cy=description-editor]')
@@ -85,16 +97,18 @@ describe('Test new User Registration Workflow', () => {
8597
})
8698

8799
it('Allows user to comment on a story', () => {
88-
cy.get('[href="/"]').click()
100+
cy.get('[data-cy=nav-eos-logo]').should('have.attr', 'href', '/').click()
89101

90102
cy.get('[data-cy=stories]').contains('Testing my story').click()
91103

92-
cy.get('[name="addComment"]').type('Testing comments')
104+
cy.get('[data-cy=comment-input]').type('Testing comments')
93105

94106
cy.get('[data-cy=btn-comment]').contains('Add Comment').click()
95107

96-
cy.get('[data-cy=comment-content] > a').contains(testUser.username)
97-
98108
cy.get('[data-cy=comment-content]').contains('Testing comments')
109+
110+
cy.get('[data-cy=comment-username]').contains(testUser.username).click()
111+
112+
cy.url().should('contain', 'profile')
99113
})
100114
})

src/components/Comments.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ const Comments = (props) => {
168168
<div className='comment-content' data-cy='comment-content'>
169169
<Link
170170
className='link link-default'
171+
data-cy='comment-username'
171172
to={`/profile/${data.user.id}`}
172173
>
173174
{data.user.username}
@@ -293,6 +294,7 @@ const Comments = (props) => {
293294
<textarea
294295
rows='4'
295296
name='addComment'
297+
data-cy='comment-input'
296298
cols='16'
297299
ref={registerComment({ required: true })}
298300
value={comment}

src/components/Navigation.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,21 @@ const Navigation = (props) => {
4444

4545
return (
4646
<header className='nav-header'>
47-
<Link className='link' to='/'>
47+
<Link className='link' data-cy='nav-eos-logo' to='/'>
4848
<img className='logo' src={eosIcon} alt='' />
4949
</Link>
5050
<nav className='navbar-content'>
5151
{state.auth && (
52-
<Link className='btn btn-default' to='/newStory'>
52+
<Link
53+
className='btn btn-default'
54+
data-cy='btn-new-story'
55+
to='/newStory'
56+
>
5357
+ New Story
5458
</Link>
5559
)}
5660
{!state.auth && (
57-
<Link className='btn btn-default' to='/login'>
61+
<Link className='btn btn-default' data-cy='btn-signin' to='/login'>
5862
Sign In
5963
</Link>
6064
)}

src/pages/Login.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,11 @@ export const Login = (props) => {
109109
<Link className='link link-default' to='/forgotPassword'>
110110
{t('authentication:forgot-password')}
111111
</Link>
112-
<Link className='link link-default' to='/register'>
112+
<Link
113+
className='link link-default'
114+
data-cy='link-create-account'
115+
to='/register'
116+
>
113117
{t('authentication:create-account')}
114118
</Link>
115119
</div>

src/pages/NewStory.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ const NewStory = () => {
213213
className='input-default'
214214
type='text'
215215
name='title'
216+
data-cy='title'
216217
autoComplete='off'
217218
ref={register({ required: true })}
218219
/>
@@ -231,6 +232,7 @@ const NewStory = () => {
231232
<select
232233
className='select-default'
233234
name='product'
235+
data-cy='product'
234236
onChange={handleProductSelectChange}
235237
ref={register({ required: true })}
236238
>
@@ -253,6 +255,7 @@ const NewStory = () => {
253255
<select
254256
className='select-default'
255257
name='category'
258+
data-cy='category'
256259
ref={register({ required: true })}
257260
>
258261
<option defaultValue={true} value=''>
@@ -274,6 +277,7 @@ const NewStory = () => {
274277
<select
275278
className='select-default'
276279
name='priority'
280+
data-cy='priority'
277281
ref={register({ required: true })}
278282
>
279283
<option defaultValue={true} value=''>

src/pages/Register.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const Register = () => {
6767
className='input-default'
6868
type='text'
6969
name='username'
70+
data-cy='username'
7071
ref={register({ required: true })}
7172
/>
7273
{errors.username && <FormError type={errors.username.type} />}
@@ -77,6 +78,7 @@ export const Register = () => {
7778
className='input-default'
7879
type='text'
7980
name='email'
81+
data-cy='email'
8082
ref={register({ required: true })}
8183
/>
8284
{errors.email && <FormError type={errors.email.type} />}
@@ -89,6 +91,7 @@ export const Register = () => {
8991
className='input-default'
9092
type='password'
9193
name='password'
94+
data-cy='password'
9295
ref={register({
9396
required: 'This is required',
9497
minLength: {
@@ -106,6 +109,7 @@ export const Register = () => {
106109
<input
107110
type='checkbox'
108111
name='tc'
112+
data-cy='tc'
109113
ref={register({
110114
required: 'You must accept our Terms and Conditions'
111115
})}

0 commit comments

Comments
 (0)