-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added tests #286
base: main
Are you sure you want to change the base?
added tests #286
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,52 @@ | ||
/// <reference types='cypress' /> | ||
/// <reference types='../support' /> | ||
|
||
import SignInPageObject from "../support/pages/signIn.pageObject"; | ||
const signInPage = new SignInPageObject(); | ||
import ArticlePageObject from "../support/pages/article.pageObject"; | ||
const articlePage = new ArticlePageObject(); | ||
describe('Article', () => { | ||
before(() => { | ||
|
||
}); | ||
|
||
beforeEach(() => { | ||
cy.task('db:clear'); | ||
}); | ||
beforeEach(() => { | ||
let user; | ||
cy.task('db:clear'); | ||
cy.task('generateUser').then((generateUser) => { | ||
user = new Object(generateUser); | ||
cy.login(user.email, user.username, user.password); | ||
}); | ||
articlePage.visit(); | ||
}); | ||
|
||
it('should be created using New Article form', () => { | ||
|
||
cy.task('generateArticle').then((articleDataString) => { | ||
const article = new Object(articleDataString); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
articlePage.typeArticleTitle(article.title); | ||
articlePage.typeArticleDesc(article.description); | ||
articlePage.typeArticleBody(article.body); | ||
articlePage.publishArticle(); | ||
}); | ||
}); | ||
|
||
it('should be edited using Edit button', () => { | ||
|
||
cy.task('generateArticle').then((articleDataString) => { | ||
const article = new Object(articleDataString); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
cy.createArticle(article.title, article.description, article.body); | ||
}); | ||
articlePage.editArticle(); | ||
cy.task('generateArticle').then((articleDataString) => { | ||
const articleUpdated = new Object(articleDataString); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
articlePage.typeArticleTitle(articleUpdated.title); | ||
articlePage.typeArticleDesc(articleUpdated.description); | ||
articlePage.typeArticleBody(articleUpdated.body); | ||
}); | ||
|
||
articlePage.updateArticle(); | ||
}); | ||
|
||
it('should be deleted using Delete button', () => { | ||
|
||
cy.task('generateArticle').then((articleDataString) => { | ||
const article = new Object(articleDataString); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
cy.createArticle(article.title, article.description, article.body); | ||
}); | ||
articlePage.deleteArticle(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,47 @@ | ||
/// <reference types='cypress' /> | ||
/// <reference types='../support' /> | ||
import SettingsPageObject from '../support/pages/settings.pageObject'; | ||
const settingPage = new SettingsPageObject(); | ||
const { faker } = require('@faker-js/faker'); | ||
const testData = { | ||
updateName: faker.person.firstName().toLowerCase(), | ||
updateBio: faker.person.bio(), | ||
updateEmail: faker.internet.email(), | ||
updatePass: faker.internet.password({ length: 9 }) | ||
}; | ||
|
||
describe('Settings page', () => { | ||
before(() => { | ||
|
||
}); | ||
|
||
let user; | ||
beforeEach(() => { | ||
|
||
cy.task('db:clear'); | ||
cy.task('generateUser').then((generateUser) => { | ||
user = new Object(generateUser); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
cy.login(user.email, user.username, user.password); | ||
}); | ||
settingPage.visit(); | ||
}); | ||
|
||
it('should provide an ability to update username', () => { | ||
|
||
settingPage.typeUsernameField(testData.updateName); | ||
settingPage.updateSettings(); | ||
}); | ||
|
||
it('should provide an ability to update bio', () => { | ||
|
||
settingPage.typeBioField(testData.updateBio); | ||
settingPage.updateSettings(); | ||
}); | ||
|
||
it('should provide an ability to update an email', () => { | ||
|
||
settingPage.typeEmailField(testData.updateEmail); | ||
settingPage.updateSettings(); | ||
}); | ||
|
||
it('should provide an ability to update password', () => { | ||
|
||
settingPage.typePassField(testData.updatePass); | ||
settingPage.updateSettings(); | ||
}); | ||
|
||
it('should provide an ability to log out', () => { | ||
|
||
settingPage.logoutFromSettings(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,36 @@ | ||
/// <reference types='cypress' /> | ||
/// <reference types='../support' /> | ||
import SignUpPageObject from "../support/pages/signUp.pageObject"; | ||
const signUpPage = new SignUpPageObject(); | ||
import HomePageObject from '../support/pages/home.pageObject'; | ||
const homePage = new HomePageObject(); | ||
const wrongEmail = '[email protected]'; | ||
|
||
describe('Sign Up page', () => { | ||
before(() => { | ||
beforeEach(() => { | ||
let user; | ||
cy.task('db:clear'); | ||
cy.task('generateUser').then((generateUser) => { | ||
user = new Object(generateUser); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
}); | ||
signUpPage.visit(); | ||
}); | ||
|
||
it('should sign up with valid credentials', () => { | ||
signUpPage.typeEmail(user.email); | ||
signUpPage.typeUsername(user.username); | ||
signUpPage.typePassword(user.password); | ||
signUpPage.clickSignUpBtn(); | ||
|
||
homePage.assertHeaderContainUsername(user.username); | ||
}); | ||
|
||
it('should ...', () => { | ||
it('should not provide an ability to sign up in with wrong credentials', () => { | ||
signUpPage.typeEmail(wrongEmail); | ||
signUpPage.typeUsername(user.username); | ||
signUpPage.typePassword(user.password); | ||
signUpPage.clickSignUpBtn(); | ||
|
||
signUpPage.assertErrorMessage('This email is taken.'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,33 @@ | ||
/// <reference types='cypress' /> | ||
/// <reference types='../support' /> | ||
import SignUpPageObject from "../support/pages/signUp.pageObject"; | ||
import UserPageObject from "../support/pages/user.pageObject"; | ||
import HomePageObject from '../support/pages/home.pageObject'; | ||
const signUpPage = new SignUpPageObject(); | ||
const homePage = new HomePageObject(); | ||
const userPage = new UserPageObject(); | ||
|
||
describe('User', () => { | ||
before(() => { | ||
|
||
beforeEach(() => { | ||
let user; | ||
cy.task('db:clear'); | ||
cy.task('generateUser').then((generateUser) => { | ||
user = new Object(generateUser); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The use of |
||
}); | ||
homePage.visit(); | ||
}); | ||
|
||
it.skip('should be able to follow the another user', () => { | ||
it('should be able to follow the another user', () => { | ||
userPage.getGlobalFeed(); | ||
userPage.goToProfile(); | ||
userPage.followUser(); | ||
userPage.pageHasUnfollowBtn(); | ||
}); | ||
|
||
it('should be able to unfollow the another user', () => { | ||
userPage.getGlobalFeed(); | ||
userPage.goToProfile(); | ||
userPage.unfollowUser(); | ||
userPage.pageHasFollowBtn(); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,10 +32,59 @@ Cypress.Commands.add('getByDataCy', (selector) => { | |
cy.get(`[data-cy="${selector}"]`); | ||
}); | ||
|
||
Cypress.Commands.add('getByDataQa', (selector) => { | ||
cy.get(`[data-qa="${selector}"]`); | ||
}); | ||
|
||
Cypress.Commands.add('register', (email = '[email protected]', username = 'riot', password = '12345Qwert!') => { | ||
cy.request('POST', '/users', { | ||
email, | ||
username, | ||
password | ||
}); | ||
}); | ||
|
||
Cypress.Commands.add('login', (email = '[email protected]', username = 'riot', password = '12345Qwert!') => { | ||
cy.request('POST', '/users', { | ||
user: { | ||
email, | ||
username, | ||
password | ||
} | ||
}).then(response => { | ||
const user = { | ||
bio: response.body.user.bio, | ||
effectiveImage: "https://static.productionready.io/images/smiley-cyrus.jpg", | ||
email: response.body.user.email, | ||
image: response.body.user.image, | ||
token: response.body.user.token, | ||
username: response.body.user.username, | ||
}; | ||
window.localStorage.setItem('user', JSON.stringify(user)); | ||
cy.setCookie('auth', response.body.user.token); | ||
}); | ||
}); | ||
Comment on lines
+47
to
+66
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the |
||
|
||
Cypress.Commands.add('createArticle', (title, description, body) => { | ||
cy.getCookie('auth').then((token) => { | ||
const authToken = token.value; | ||
|
||
cy.request({ | ||
method: 'POST', | ||
url: '/api/articles', | ||
body: { | ||
article: { | ||
title, | ||
description, | ||
body, | ||
tagList: [] | ||
} | ||
}, | ||
headers: { | ||
Authorization: `Token ${authToken}` | ||
} | ||
}).then((response) => { | ||
cy.visit('/article/' + response.body.article.slug); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import PageObject from '../PageObject'; | ||
|
||
class ArticlePageObject extends PageObject { | ||
url = '/editor'; | ||
|
||
get articleTitle() { | ||
return cy.getByDataQa('article_title'); | ||
} | ||
|
||
typeArticleTitle(title) { | ||
this.articleTitle.clear().type(title); | ||
} | ||
|
||
get articleDesc() { | ||
return cy.getByDataQa('article_desc'); | ||
} | ||
|
||
typeArticleDesc(desc) { | ||
this.articleDesc.clear().type(desc); | ||
} | ||
|
||
get articleBody() { | ||
return cy.getByDataQa('article_body'); | ||
} | ||
|
||
typeArticleBody(body) { | ||
this.articleBody.clear().type(body); | ||
} | ||
|
||
publishArticle() { | ||
cy.getByDataQa('publish_btn').click(); | ||
} | ||
|
||
editArticle() { | ||
cy.getByDataQa('edit_btn').click(); | ||
} | ||
|
||
deleteArticle() { | ||
cy.getByDataQa('delete_btn').click(); | ||
} | ||
|
||
updateArticle() { | ||
cy.contains('button.btn', 'Update').click(); | ||
} | ||
} | ||
|
||
export default ArticlePageObject; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import PageObject from '../PageObject'; | ||
|
||
class SettingsPageObject extends PageObject { | ||
url = '/settings'; | ||
|
||
get usernameField() { | ||
return cy.getByDataQa('username-set'); | ||
} | ||
|
||
typeUsernameField(username) { | ||
this.usernameField.clear().type(username); | ||
} | ||
|
||
get bioField() { | ||
return cy.getByDataQa('bio-set'); | ||
} | ||
|
||
typeBioField(bio) { | ||
this.bioField.clear().type(bio); | ||
} | ||
|
||
get emailField() { | ||
return cy.getByDataQa('email-set'); | ||
} | ||
|
||
typeEmailField(email) { | ||
this.emailField.clear().type(email); | ||
} | ||
|
||
get passField() { | ||
return cy.getByDataQa('pass-set'); | ||
} | ||
|
||
typePassField(pass) { | ||
this.passField.clear().type(pass); | ||
} | ||
|
||
updateSettings() { | ||
cy.getByDataQa('updateBtn-set').click(); | ||
} | ||
|
||
logoutFromSettings() { | ||
cy.getByDataQa('logoutBtn-set').click(); | ||
} | ||
} | ||
|
||
export default SettingsPageObject; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The use of
new Object(generateUser)
is unnecessary. You can directly assignuser = generateUser;
sincegenerateUser
is already an object.