-
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
solution #280
base: main
Are you sure you want to change the base?
solution #280
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,72 @@ | ||
/// <reference types='cypress' /> | ||
/// <reference types='../support' /> | ||
|
||
import { faker } from '@faker-js/faker'; | ||
import ArticlePageObject from "../support/pages/article.pageObject"; | ||
|
||
const articlePage = new ArticlePageObject(); | ||
|
||
describe('Article', () => { | ||
before(() => { | ||
let user; | ||
const articleTitle = faker.lorem.sentence(); | ||
const articleDesc = faker.lorem.sentences(2); | ||
const articleBody = faker.lorem.sentences(5); | ||
const articleTag = faker.lorem.word(); | ||
|
||
before(() => { | ||
cy.task('generateUser').then((generateUser) => { | ||
user = generateUser; | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
cy.task('db:clear'); | ||
cy.visit('/'); | ||
cy.register(); | ||
cy.login(); | ||
articlePage.visit(); | ||
}); | ||
|
||
it('should be created using New Article form', () => { | ||
articlePage.typeArticleTitle(articleTitle); | ||
articlePage.typeArticleDesc(articleDesc); | ||
articlePage.typeArticleBody(articleBody); | ||
articlePage.typeArticleTags(articleTag); | ||
|
||
articlePage.clickPublishBtn(); | ||
|
||
articlePage.verifyArticleCreation(articleTitle); | ||
}); | ||
|
||
it('should be edited using Edit button', () => { | ||
articlePage.typeArticleTitle(articleTitle); | ||
articlePage.typeArticleDesc(articleDesc); | ||
articlePage.typeArticleBody(articleBody); | ||
articlePage.typeArticleTags(articleTag); | ||
|
||
articlePage.clickPublishBtn(); | ||
|
||
articlePage.clickEditArticleBtn(); | ||
|
||
articlePage.typeArticleTitle(articleTitle); | ||
articlePage.typeArticleDesc(articleDesc); | ||
articlePage.typeArticleBody(articleBody); | ||
|
||
articlePage.clickPublishBtn(); | ||
|
||
articlePage.verifyArticleCreation(articleTitle); | ||
}); | ||
|
||
it('should be deleted using Delete button', () => { | ||
articlePage.typeArticleTitle(articleTitle); | ||
articlePage.typeArticleDesc(articleDesc); | ||
articlePage.typeArticleBody(articleBody); | ||
articlePage.typeArticleTags(articleTag); | ||
|
||
articlePage.clickPublishBtn(); | ||
|
||
articlePage.clickDeleteArticleBtn(); | ||
|
||
articlePage.verifyDeletedArticle(); | ||
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 |
||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,50 @@ | ||
/// <reference types='cypress' /> | ||
/// <reference types='../support' /> | ||
|
||
import SettingsPageObject from '../support/pages/settings.pageObject'; | ||
|
||
const settingsPage = new SettingsPageObject(); | ||
|
||
describe('Settings page', () => { | ||
before(() => { | ||
let user; | ||
|
||
before(() => { | ||
cy.task('generateUser').then((generateUser) => { | ||
user = generateUser; | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
|
||
cy.task('db:clear'); | ||
cy.visit('/'); | ||
cy.register(); | ||
cy.login(); | ||
Comment on lines
+20
to
+21
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. Ensure that |
||
settingsPage.visit(); | ||
}); | ||
|
||
it('should provide an ability to update username', () => { | ||
|
||
settingsPage.editUsername(user.username); | ||
settingsPage.submitEdit(); | ||
settingsPage.verifyProfilePage(user.username); | ||
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 |
||
}); | ||
|
||
it('should provide an ability to update bio', () => { | ||
|
||
settingsPage.editBio(user.bio); | ||
settingsPage.submitEdit(); | ||
}); | ||
|
||
it('should provide an ability to update an email', () => { | ||
|
||
settingsPage.editEmail(user.email); | ||
settingsPage.submitEdit(); | ||
}); | ||
|
||
it('should provide an ability to update password', () => { | ||
|
||
settingsPage.editPassword(user.password); | ||
settingsPage.submitEdit(); | ||
}); | ||
|
||
it('should provide an ability to log out', () => { | ||
|
||
settingsPage.logoutUser(); | ||
settingsPage.verifyLogout(); | ||
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 |
||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ const homePage = new HomePageObject(); | |
|
||
describe('Sign In page', () => { | ||
let user; | ||
const wrongEmail = 'rodionmail.com'; | ||
const wrongPassword = 'password'; | ||
|
||
before(() => { | ||
cy.task('db:clear'); | ||
|
@@ -17,6 +19,10 @@ describe('Sign In page', () => { | |
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
signInPage.visit(); | ||
}); | ||
|
||
it('should provide an ability to log in with existing credentials', () => { | ||
signInPage.visit(); | ||
cy.register(user.email, user.username, user.password); | ||
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. Ensure that |
||
|
@@ -28,7 +34,21 @@ describe('Sign In page', () => { | |
homePage.assertHeaderContainUsername(user.username); | ||
}); | ||
|
||
it('should not provide an ability to log in with wrong credentials', () => { | ||
it('shouldn\'t provide an ability to log in with wrong email', () => { | ||
signInPage.typeEmail(wrongEmail); | ||
signInPage.typePassword(user.password); | ||
|
||
signInPage.clickSignInBtn(); | ||
|
||
signInPage.assertLoginFailed(); | ||
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 |
||
}); | ||
|
||
it('shouldn\'t provide an ability to log in with wrong password', () => { | ||
signInPage.typeEmail(user.email); | ||
signInPage.typePassword(wrongPassword); | ||
|
||
signInPage.clickSignInBtn(); | ||
|
||
signInPage.assertLoginFailed(); | ||
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 |
||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,66 @@ | ||
/// <reference types='cypress' /> | ||
/// <reference types='../support' /> | ||
|
||
import HomePageObject from "../support/pages/home.pageObject"; | ||
import SignUpPageObject from "../support/pages/signUp.pageObject"; | ||
|
||
const homePage = new HomePageObject(); | ||
const signUpPage = new SignUpPageObject(); | ||
|
||
describe('Sign Up page', () => { | ||
let user; | ||
const wrongUsername = 'rodion'; | ||
const wrongEmail = 'rodionmail.com'; | ||
const wrongPassword = 'password'; | ||
|
||
before(() => { | ||
cy.task('db:clear'); | ||
cy.task('generateUser').then((generateUser) => { | ||
user = generateUser; | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
signUpPage.visit(); | ||
}); | ||
|
||
it('should ...', () => { | ||
it('should provide an ability to sign up with valid credentials', () => { | ||
signUpPage.typeUsername(user.username); | ||
signUpPage.typeEmail(user.email); | ||
signUpPage.typePassword(user.password); | ||
|
||
signUpPage.clickSignUpBtn(); | ||
|
||
homePage.assertHeaderContainUsername(user.username); | ||
}); | ||
|
||
it('shouldn\'t provide an ability to sign up with wrong username', () => { | ||
signUpPage.typeUsername(wrongUsername); | ||
signUpPage.typeEmail(user.email); | ||
signUpPage.typePassword(user.password); | ||
|
||
signUpPage.clickSignUpBtn(); | ||
|
||
signUpPage.assertSignUpFailed(); | ||
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 |
||
}); | ||
|
||
it('shouldn\'t provide an ability to sign up with wrong email', () => { | ||
signUpPage.typeUsername(user.username); | ||
signUpPage.typeEmail(wrongEmail); | ||
signUpPage.typePassword(user.password); | ||
|
||
signUpPage.clickSignUpBtn(); | ||
|
||
signUpPage.assertSignUpFailed(); | ||
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 |
||
}); | ||
|
||
it('shouldn\'t provide an ability to sign up with wrong password', () => { | ||
signUpPage.typeUsername(user.username); | ||
signUpPage.typeEmail(user.email); | ||
signUpPage.typePassword(wrongPassword); | ||
|
||
signUpPage.clickSignUpBtn(); | ||
|
||
signUpPage.assertSignUpFailed(); | ||
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 |
||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,29 @@ | |
/// <reference types='../support' /> | ||
|
||
describe('User', () => { | ||
let user; | ||
|
||
before(() => { | ||
cy.task('generateUser').then((generateUser) => { | ||
user = generateUser; | ||
}); | ||
}); | ||
|
||
beforeEach(() => { | ||
cy.task('db:clear'); | ||
cy.visit('/'); | ||
cy.register(); | ||
cy.login(); | ||
Comment on lines
+16
to
+17
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. Ensure that |
||
}); | ||
|
||
it.skip('should be able to follow the another user', () => { | ||
it('should be able to follow/unfollow the another user', () => { | ||
cy.visit('#/@riot'); | ||
cy.get('.btn.btn-sm.btn-outline-secondary.action-btn').click(); | ||
|
||
cy.get('.btn').should('contain', 'Unfollow'); | ||
|
||
cy.get('.btn.btn-sm.btn-outline-secondary.action-btn').click(); | ||
|
||
cy.get('.btn').should('contain', 'Follow'); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,10 +32,33 @@ Cypress.Commands.add('getByDataCy', (selector) => { | |
cy.get(`[data-cy="${selector}"]`); | ||
}); | ||
|
||
Cypress.Commands.add('register', (email = '[email protected]', username = 'riot', password = '12345Qwert!') => { | ||
cy.request('POST', '/users', { | ||
email, | ||
username, | ||
password | ||
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!') => { | ||
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 |
||
cy.request('POST', '/api/users', { | ||
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. Ensure that the API endpoint |
||
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); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import PageObject from "../PageObject"; | ||
|
||
class ArticlePageObject extends PageObject { | ||
url = '#/editor'; | ||
|
||
get articleTitleField() { | ||
return cy.getByDataCy('article-title-field'); | ||
} | ||
|
||
typeArticleTitle(articleTitle) { | ||
this.articleTitleField.clear().type(articleTitle); | ||
} | ||
|
||
get articleDescField() { | ||
return cy.getByDataCy('article-desc-field'); | ||
} | ||
|
||
typeArticleDesc(articleDesc) { | ||
this.articleDescField.clear().type(articleDesc); | ||
} | ||
|
||
get articleBodyField() { | ||
return cy.getByDataCy('article-body-field'); | ||
} | ||
|
||
typeArticleBody(articleBody) { | ||
this.articleBodyField.clear().type(articleBody); | ||
} | ||
|
||
get articleTagsField() { | ||
return cy.getByDataCy('article-tags-field'); | ||
} | ||
|
||
typeArticleTags(articleTag) { | ||
this.articleTagsField.clear().type(`${articleTag}{enter}`); | ||
} | ||
|
||
get publishBtn() { | ||
return cy.getByDataCy('article-publish-btn'); | ||
} | ||
|
||
clickPublishBtn() { | ||
this.publishBtn.click(); | ||
} | ||
|
||
get container() { | ||
return cy.get('.container'); | ||
} | ||
|
||
verifyArticleCreation(articleTitle) { | ||
this.container.should('contain', articleTitle) | ||
.and('contain', 'Delete Article') | ||
.and('contain', 'Edit Article'); | ||
} | ||
|
||
get deleteArticleBtn() { | ||
return cy.getByDataCy('delete-article-btn'); | ||
} | ||
|
||
clickDeleteArticleBtn() { | ||
this.deleteArticleBtn.click(); | ||
} | ||
|
||
verifyDeletedArticle(articleTitle) { | ||
this.container.should('not.contain', articleTitle) | ||
.and('not.contain', 'Delete Article') | ||
.and('not.contain', 'Edit Article'); | ||
} | ||
|
||
get editArticleBtn() { | ||
return cy.getByDataCy('edit-article-btn'); | ||
} | ||
|
||
clickEditArticleBtn() { | ||
this.editArticleBtn.click(); | ||
} | ||
} | ||
|
||
export default ArticlePageObject; |
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.
Ensure that
cy.register()
andcy.login()
are defined in your Cypress support commands. If these commands are not implemented, the tests will fail when trying to register and log in a user.