Skip to content
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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions cypress/e2e/article.cy.js
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);

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 assign user = generateUser; since generateUser is already an object.

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);

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(articleDataString) is unnecessary. You can directly assign const article = articleDataString; since articleDataString is already an object.

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);

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(articleDataString) is unnecessary. You can directly assign const article = articleDataString; since articleDataString is already an object.

cy.createArticle(article.title, article.description, article.body);
});
articlePage.editArticle();
cy.task('generateArticle').then((articleDataString) => {
const articleUpdated = new Object(articleDataString);

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(articleDataString) is unnecessary. You can directly assign const articleUpdated = articleDataString; since articleDataString is already an object.

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);

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(articleDataString) is unnecessary. You can directly assign const article = articleDataString; since articleDataString is already an object.

cy.createArticle(article.title, article.description, article.body);
});
articlePage.deleteArticle();
});
});
35 changes: 25 additions & 10 deletions cypress/e2e/settings.cy.js
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);

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 assign user = generateUser; since generateUser is already an object.

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();
});
});
7 changes: 7 additions & 0 deletions cypress/e2e/signIn.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ describe('Sign In page', () => {
});

it('should not provide an ability to log in with wrong credentials', () => {
signInPage.visit();
cy.register(user.email, user.username, user.password);

signInPage.typeEmail(user.email);
signInPage.typePassword('test123');
signInPage.clickSignInBtn();

signInPage.assertErrorMessage('email or password: is invalid');
});
});
28 changes: 26 additions & 2 deletions cypress/e2e/signUp.cy.js
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);

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 assign user = generateUser; since generateUser is already an object.

});
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.');
});
});
27 changes: 24 additions & 3 deletions cypress/e2e/user.cy.js
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);

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 assign user = generateUser; since generateUser is already an object.

});
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();
});
});
49 changes: 49 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the login command, the username parameter is not used in the request body. Consider removing it from the parameters if it's not needed for the login process.


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);
});
});
});
1 change: 1 addition & 0 deletions cypress/support/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare namespace Cypress {
interface Chainable<Subject> {
getByDataCy(selector: string): Chainable<any>
getByDataQa(selector: string): Chainable<any>
register(email: string, username: string, password: string): Chainable<any>
}
}
47 changes: 47 additions & 0 deletions cypress/support/pages/article.pageObject.js
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;
47 changes: 47 additions & 0 deletions cypress/support/pages/settings.pageObject.js
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;
5 changes: 5 additions & 0 deletions cypress/support/pages/signIn.pageObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ class SignInPageObject extends PageObject {
this.signInBtn
.click();
}

assertErrorMessage(message) {
cy.get('ul.error-messages li')
.should('contain.text', message);
}
}

export default SignInPageObject;
Loading