Skip to content

Commit f15381e

Browse files
Merge pull request #47 from SundeepChand/fix-test
Fixed Failing Cypress Test
2 parents 94637a1 + 5860c29 commit f15381e

File tree

4 files changed

+29
-26
lines changed

4 files changed

+29
-26
lines changed

.github/workflows/github-ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ jobs:
8888
run: npm install
8989

9090
- name: Create config.json
91-
run: echo "$TEST_CONFIG_JSON" > src/config.json
91+
run: echo $TEST_CONFIG_JSON > src/config.json
9292
env:
93-
TEST_CONFIG_JSON: ${{ secrets.TEST_CONFIG_JSON }}
93+
TEST_CONFIG_JSON: "{ \"apiURL\": \"http://localhost:1337\", \"APP_ENV\": \"prod\" }"
9494

9595
- name: Test Cypress
9696
uses: cypress-io/github-action@v2

cypress/integration/user_story.spec.js

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,27 @@ describe('Test new User Registration Workflow', () => {
2323

2424
cy
2525
.get('[data-cy=btn-signin]')
26-
.should('have.attr', 'href', '/login')
27-
.contains('Sign In')
2826
.click()
2927

30-
cy.url().should('equal', 'http://localhost:3000/login')
28+
cy.url().should('equal', `${Cypress.config().baseUrl}/login`)
3129

3230
cy
3331
.get('[data-cy=link-create-account]')
34-
.should('have.attr', 'href', '/register')
35-
.contains('Create an account')
3632
.click()
3733

38-
cy.url().should('equal', 'http://localhost:3000/register')
34+
cy.url().should('equal', `${Cypress.config().baseUrl}/register`)
3935

40-
cy.get('[data-cy=username]').should('have.attr', 'type', 'text').type(testUser.username)
36+
cy.get('[data-cy=username]').type(testUser.username)
4137

42-
cy.get('[data-cy=email]').should('have.attr', 'type', 'text').type(testUser.email)
38+
cy.get('[data-cy=email]').type(testUser.email)
4339

4440
cy.get('[data-cy=password]').should('have.attr', 'type', 'password').type(testUser.password)
4541

46-
cy.get('[data-cy=tc]').should('have.attr', 'type', 'checkbox').click()
42+
cy.get('[data-cy=tc]').click()
4743

48-
cy.get('[data-cy=btn-register]').contains('Register').click()
44+
cy.get('[data-cy=btn-register]').click()
4945

50-
cy.url().should('equal', 'http://localhost:3000/')
46+
cy.url().should('equal', `${Cypress.config().baseUrl}/`)
5147

5248
cy.saveLocalStorage()
5349
})
@@ -64,11 +60,9 @@ describe('Test new User Registration Workflow', () => {
6460
it('Allows user to create new story', () => {
6561
cy
6662
.get('[data-cy=btn-new-story]')
67-
.should('have.attr', 'href', '/newStory')
68-
.contains('+ New Story')
6963
.click()
7064

71-
cy.url().should('equal', 'http://localhost:3000/newStory')
65+
cy.url().should('equal', `${Cypress.config().baseUrl}/newStory`)
7266

7367
cy.get('[data-cy=title]').type(testStory.title)
7468

@@ -82,9 +76,9 @@ describe('Test new User Registration Workflow', () => {
8276
.get('[data-cy=description-editor]')
8377
.type(testStory.description)
8478

85-
cy.get('[data-cy=btn-submit]').contains('Submit').click()
79+
cy.get('[data-cy=btn-submit]').click()
8680

87-
cy.url().should('equal', 'http://localhost:3000/')
81+
cy.url().should('equal', `${Cypress.config().baseUrl}/`)
8882
})
8983

9084
it('Displays story in home page, once created', () => {
@@ -98,23 +92,25 @@ describe('Test new User Registration Workflow', () => {
9892
})
9993

10094
it('Allows user to edit the story created by them', () => {
101-
cy.get('[data-cy=btn-edit]').contains('Edit').click()
95+
cy.wait(1500)
96+
97+
cy.get('[data-cy=btn-edit]').click()
10298

10399
cy.get('[data-cy=edit-description]').type(editedDescription)
104100

105-
cy.get('[data-cy=story-buttons]').contains('Save').click()
101+
cy.get('[data-cy=btn-save]').click()
106102

107103
cy.get('[data-cy=story-description]').contains(editedDescription)
108104
})
109105

110106
it('Allows user to comment on a story', () => {
111-
cy.get('[data-cy=nav-eos-logo]').should('have.attr', 'href', '/').click()
107+
cy.get('[data-cy=nav-eos-logo]').click()
112108

113109
cy.get('[data-cy=stories]').contains(testStory.title).click()
114110

115-
cy.get('[data-cy=comment-input]').type(testComment)
111+
cy.get('[data-cy=comment-input-2]').type(testComment)
116112

117-
cy.get('[data-cy=btn-comment]').contains('Add Comment').click()
113+
cy.get('[data-cy=btn-comment-2]').click()
118114

119115
cy.get('[data-cy=comment-content]').contains(testComment)
120116

src/components/CommentForm.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const CommentForm = (props) => {
3939
cols='25'
4040
name='Comments'
4141
value={comment}
42+
data-cy={`comment-input-${id}`}
4243
ref={register({ required: true })}
4344
onChange={(e) => setComment(e.target.value)}
4445
></textarea>
@@ -57,7 +58,9 @@ const CommentForm = (props) => {
5758
</div>
5859
{errors.Comments && <FormError message='Reply cannot be empty' />}
5960
<MediaPreview attachments={attachments} setAttachments={setAttachments} />
60-
<Button className='btn btn-default'>{cta}</Button>
61+
<Button className='btn btn-default' data-cy={`btn-comment-${id}`}>
62+
{cta}
63+
</Button>
6164
</form>
6265
)
6366
}

src/pages/Story.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ const Story = (props) => {
152152
data-cy='story-description'
153153
/>
154154
)}
155-
<div className='story-buttons-container' data-cy='story-buttons'>
155+
<div className='story-buttons-container'>
156156
{editMode && !editor ? (
157157
<>
158158
<Button
@@ -179,7 +179,11 @@ const Story = (props) => {
179179
''
180180
)}
181181
{editor ? (
182-
<Button className='btn btn-default' onClick={save}>
182+
<Button
183+
className='btn btn-default'
184+
onClick={save}
185+
data-cy='btn-save'
186+
>
183187
Save
184188
</Button>
185189
) : (

0 commit comments

Comments
 (0)