Skip to content

Commit 790c895

Browse files
committed
Added tests for new story
1 parent b94adcf commit 790c895

File tree

2 files changed

+107
-0
lines changed

2 files changed

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

src/components/Navigation.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ const Navigation = (props) => {
7272
{state.auth && (
7373
<div
7474
className='dropdown-container'
75+
data-cy='user-dropdown-menu-btn'
7576
onClick={() => {
7677
setUserDropdownState(!userDropdownState)
7778
}}
@@ -97,6 +98,7 @@ const Navigation = (props) => {
9798
<hr className='dropdown-separator' />
9899
<li
99100
className='dropdown-element'
101+
data-cy='user-stories-btn'
100102
onClick={() => navigate('/myStories')}
101103
>
102104
<EOS_MESSAGE className='eos-icons eos-18' />

0 commit comments

Comments
 (0)