Skip to content

Commit 0c03f2c

Browse files
authored
Merge pull request #126 from kailash360/add-tests
Fix #119 : Added and modified Cypress tests
2 parents 488947b + cd86f94 commit 0c03f2c

File tree

14 files changed

+524
-89
lines changed

14 files changed

+524
-89
lines changed

cypress.json

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
{
22
"baseUrl": "http://localhost:3000",
33
"env": {
4-
"testUsername": "user1",
5-
"testUserEmail": "[email protected]",
6-
"testUserPassword": "password",
7-
"testStoryTitle": "This is a test story",
8-
"testStoryProduct": "EOS Icons",
9-
"testCategory": "Documentation"
4+
"testUser":{
5+
"username": "user1",
6+
"email": "[email protected]",
7+
"password": "password"
8+
},
9+
"updatedUser": {
10+
"name": "user1-updated",
11+
"bio": "Hello, this is a updated bio for testing",
12+
"profession": "updated-profession",
13+
"company": "updated-company",
14+
"linkedin": "updated-linkedin",
15+
"twitter": "updated-twitter"
16+
},
17+
"testStory": {
18+
"title": "This is a test story",
19+
"product": "EOS Icons",
20+
"category": "Documentation"
21+
}
1022
},
11-
"testFiles": ["user_story.spec.js", "test_filters.spec.js"]
23+
"testFiles": ["auth.spec.js","new_story.spec.js","user_story.spec.js","dashboard.spec.js", "user_account.spec.js"]
1224
}

cypress/integration/auth.spec.js

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/// <reference types="cypress" />
2+
3+
describe("Authentication Tests", () => {
4+
5+
const testUser = Cypress.env("testUser")
6+
7+
beforeEach('visit the page and wait it to load', () => {
8+
9+
cy.visit('/')
10+
11+
cy.wait(1000)
12+
})
13+
14+
/**
15+
* @success
16+
*/
17+
it("Registers new user", () => {
18+
19+
20+
cy.get('[data-cy=btn-signin]').click()
21+
22+
cy.url().should('equal', `${Cypress.config().baseUrl}/login`)
23+
24+
cy.get('[data-cy=link-create-account]').click()
25+
26+
cy.url().should('equal', `${Cypress.config().baseUrl}/register`)
27+
28+
cy.get('[data-cy=username]').type(testUser.username)
29+
30+
cy.get('[data-cy=email]').type(testUser.email)
31+
32+
cy.get('[data-cy=password]')
33+
.should('have.attr', 'type', 'password')
34+
.type(testUser.password)
35+
36+
cy.get('[data-cy=tc]').click()
37+
38+
cy.get('[data-cy=btn-register]').click()
39+
40+
cy.url().should('equal', `${Cypress.config().baseUrl}/`)
41+
})
42+
43+
44+
it("Signs in an existing user", () => {
45+
46+
cy.get('[data-cy=btn-signin]').click()
47+
48+
cy.url().should('equal', `${Cypress.config().baseUrl}/login`)
49+
50+
cy.wait(500)
51+
52+
cy.get('[data-cy=login-username]').type(testUser.username)
53+
54+
cy.get('[data-cy=login-password]').type(testUser.password)
55+
56+
cy.get('[data-cy=login-btn]').click()
57+
58+
cy.url().should('equal', `${Cypress.config().baseUrl}/`)
59+
60+
})
61+
62+
63+
/**
64+
* @failure
65+
*/
66+
it("Should not register using already registered credentials", () => {
67+
68+
cy.get('[data-cy=btn-signin]').click()
69+
70+
cy.url().should('equal', `${Cypress.config().baseUrl}/login`)
71+
72+
cy.get('[data-cy=link-create-account]').click()
73+
74+
cy.url().should('equal', `${Cypress.config().baseUrl}/register`)
75+
76+
cy.get('[data-cy=username]').type(testUser.username)
77+
78+
cy.get('[data-cy=email]').type(testUser.email) //Using already registered email address
79+
80+
cy.get('[data-cy=password]')
81+
.should('have.attr', 'type', 'password')
82+
.type(testUser.password)
83+
84+
cy.get('[data-cy=tc]').click()
85+
86+
cy.get('[data-cy=btn-register]').click()
87+
88+
cy.contains("Email is already taken")
89+
})
90+
91+
it("Should not register using invalid details", () => {
92+
93+
94+
cy.get('[data-cy=btn-signin]').click()
95+
96+
cy.url().should('equal', `${Cypress.config().baseUrl}/login`)
97+
98+
cy.get('[data-cy=link-create-account]').click()
99+
100+
cy.url().should('equal', `${Cypress.config().baseUrl}/register`)
101+
102+
cy.get('[data-cy=username]').type(testUser.username)
103+
104+
cy.get('[data-cy=email]').type(Math.random() * 1000) //Invalid email address
105+
106+
cy.get('[data-cy=password]')
107+
.should('have.attr', 'type', 'password') // Password not provided
108+
109+
cy.get('[data-cy=tc]').click()
110+
111+
cy.get('[data-cy=btn-register]').click()
112+
113+
cy.contains("This is required")
114+
})
115+
116+
117+
it("Should not register without agreeing to terms and conditions", () => {
118+
119+
cy.get('[data-cy=btn-signin]').click()
120+
121+
cy.url().should('equal', `${Cypress.config().baseUrl}/login`)
122+
123+
cy.get('[data-cy=link-create-account]').click()
124+
125+
cy.url().should('equal', `${Cypress.config().baseUrl}/register`)
126+
127+
cy.get('[data-cy=username]').type(testUser.username)
128+
129+
cy.get('[data-cy=email]').type(Math.random() * 1000)
130+
131+
cy.get('[data-cy=password]')
132+
.should('have.attr', 'type', 'password')
133+
.type(testUser.password)
134+
135+
// Do not click on the checkbox
136+
137+
cy.get('[data-cy=btn-register]').click()
138+
139+
cy.contains("You must accept our Terms and Conditions")
140+
})
141+
142+
143+
it("Should not login using invalid credentials", () => {
144+
145+
cy.get('[data-cy=btn-signin]').click()
146+
147+
cy.url().should('equal', `${Cypress.config().baseUrl}/login`)
148+
149+
cy.get('[data-cy=login-username]').type(testUser.username)
150+
151+
cy.get('[data-cy=login-password]').type(Math.random() * 1000) //Invalid password
152+
153+
cy.get('[data-cy=login-btn]').click()
154+
155+
cy.contains("Identifier or password invalid")
156+
})
157+
158+
})

cypress/integration/test_filters.spec.js renamed to cypress/integration/dashboard.spec.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
/// <reference types="cypress" />
22

3+
describe('Tests for dashboard',()=>{
4+
5+
before(()=>{
6+
cy.visit('/')
7+
})
8+
9+
it('Shows the dashboard',()=>{
10+
cy.get('[data-cy=dashboard-heading]').contains('TELL US YOUR STORY')
11+
})
12+
})
13+
14+
315
describe('Test the filters and search for stories in Home page', () => {
4-
const testStory = {
5-
title: Cypress.env('testStoryTitle'),
6-
product: Cypress.env('testStoryProduct'),
7-
category: Cypress.env('testCategory')
8-
}
16+
const testStory = Cypress.env("testStory")
17+
18+
const testUser = Cypress.env("testUser")
919

1020
const selectProduct = (productName) => {
1121
cy.get(`[data-cy=${productName.split(' ').join('-')}-card]`).click({
@@ -81,9 +91,9 @@ describe('Test the filters and search for stories in Home page', () => {
8191

8292
clearSearchInput()
8393

84-
typeOnSearch('us')
94+
typeOnSearch(testUser.username.slice(0,2))
8595
cy.get('[data-cy=search-input-div]')
86-
.contains('user1')
96+
.contains(testUser.username)
8797
.click({ force: true })
8898

8999
cy.contains(testStory.title)
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/// <reference types="cypress" />
2+
3+
describe("Tests for creating a new story", () => {
4+
5+
const testUser = Cypress.env("testUser")
6+
7+
const testStory = {
8+
...Cypress.env("testStory"),
9+
... {
10+
priority: 'High',
11+
description: '{enter}Testing User Story'
12+
}
13+
}
14+
15+
before('Log in the user', () => {
16+
cy.visit('/')
17+
18+
cy.get('[data-cy=btn-signin]').click()
19+
20+
cy.url().should('equal', `${Cypress.config().baseUrl}/login`)
21+
22+
cy.wait(1500)
23+
24+
cy.get('[data-cy=login-username]').type(testUser.username)
25+
26+
cy.get('[data-cy=login-password]').type(testUser.password)
27+
28+
cy.get('[data-cy=login-btn]').click()
29+
30+
cy.url().should('equal', `${Cypress.config().baseUrl}/`)
31+
})
32+
33+
beforeEach(() => {
34+
Cypress.Cookies.preserveOnce('token')
35+
cy.restoreLocalStorage()
36+
})
37+
38+
afterEach(() => {
39+
cy.saveLocalStorage()
40+
})
41+
42+
it('Allows user to create new story', () => {
43+
44+
// Naviage to new story page
45+
cy.get('[data-cy=btn-new-story]').click()
46+
47+
cy.url().should('equal', `${Cypress.config().baseUrl}/newStory`)
48+
49+
cy.wait(1000)
50+
51+
// Enter data of the new story
52+
cy.get('[data-cy=title]').type(testStory.title)
53+
54+
cy.get('[data-cy=product]').select(testStory.product)
55+
56+
cy.get('[data-cy=category]').select(testStory.category)
57+
58+
cy.get('[data-cy=priority]').select(testStory.priority)
59+
60+
cy.get('[data-cy=description-editor]').type(testStory.description)
61+
62+
// Click on submit button to add a new story
63+
cy.get('[data-cy=btn-submit]').click()
64+
65+
// Redirect to dashboard if story added successfully
66+
cy.url().should('equal', `${Cypress.config().baseUrl}/`)
67+
})
68+
69+
it('Shows the new story in dashboard, once created', () => {
70+
71+
// Enter story title in seacrh bar and click on search button
72+
cy.get('[data-cy=search-input]').type(testStory.title)
73+
74+
cy.get('[data-cy=btn-search]').click()
75+
76+
// Check if a story has same title and username
77+
cy.contains(testStory.title)
78+
79+
cy.contains(testUser.username)
80+
})
81+
82+
it('Shows the new story in user\'s stories , once created', () => {
83+
84+
// Open the context menu on top right of the screen
85+
cy.get('[data-cy=user-dropdown-menu-btn]').click()
86+
87+
cy.get('[data-cy=user-stories-btn]').click()
88+
89+
// Naviage to the user's stories page
90+
cy.url().should('equal', `${Cypress.config().baseUrl}/myStories`)
91+
92+
// Enter story title in search box and click on search button
93+
cy.get('[data-cy=search-input]').type(testStory.title)
94+
95+
cy.get('[data-cy=btn-search]').click()
96+
97+
// check if a story has same name and username
98+
cy.contains(testStory.title)
99+
100+
cy.contains(testUser.username)
101+
})
102+
})

0 commit comments

Comments
 (0)