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

solution #280

Open
wants to merge 2 commits 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
50 changes: 49 additions & 1 deletion cypress/e2e/article.cy.js
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();
Comment on lines +25 to +26

Choose a reason for hiding this comment

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

Ensure that cy.register() and cy.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.

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

Choose a reason for hiding this comment

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

The verifyDeletedArticle method should accurately verify that the article has been deleted. Ensure this method checks the absence of the article in the list or any other appropriate verification.

});
});
32 changes: 25 additions & 7 deletions cypress/e2e/settings.cy.js
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

Choose a reason for hiding this comment

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

Ensure that cy.register() and cy.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.

settingsPage.visit();
});

it('should provide an ability to update username', () => {

settingsPage.editUsername(user.username);
settingsPage.submitEdit();
settingsPage.verifyProfilePage(user.username);

Choose a reason for hiding this comment

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

The verifyProfilePage method should accurately verify that the username has been updated. Ensure this method checks the displayed username on the profile page.

});

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

Choose a reason for hiding this comment

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

The verifyLogout method should accurately verify that the user has been logged out. Ensure this method checks for the absence of user-specific elements or the presence of a login prompt.

});
});
22 changes: 21 additions & 1 deletion cypress/e2e/signIn.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);

Choose a reason for hiding this comment

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

Ensure that cy.register() is defined in your Cypress support commands. If this command is not implemented, the test will fail when trying to register a user.

Expand All @@ -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();

Choose a reason for hiding this comment

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

The assertLoginFailed method should accurately verify that the login attempt has failed. Ensure this method checks for an error message or any other indication of a failed login.

});

it('shouldn\'t provide an ability to log in with wrong password', () => {
signInPage.typeEmail(user.email);
signInPage.typePassword(wrongPassword);

signInPage.clickSignInBtn();

signInPage.assertLoginFailed();

Choose a reason for hiding this comment

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

The assertLoginFailed method should accurately verify that the login attempt has failed. Ensure this method checks for an error message or any other indication of a failed login.

});
});
56 changes: 55 additions & 1 deletion cypress/e2e/signUp.cy.js
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();

Choose a reason for hiding this comment

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

The assertSignUpFailed method should accurately verify that the sign-up attempt with a wrong username has failed. Ensure this method checks for an error message or any other indication of a failed sign-up.

});

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

Choose a reason for hiding this comment

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

The assertSignUpFailed method should accurately verify that the sign-up attempt with a wrong email has failed. Ensure this method checks for an error message or any other indication of a failed sign-up.

});

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

Choose a reason for hiding this comment

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

The assertSignUpFailed method should accurately verify that the sign-up attempt with a wrong password has failed. Ensure this method checks for an error message or any other indication of a failed sign-up.

});
});
20 changes: 19 additions & 1 deletion cypress/e2e/user.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

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

Ensure that cy.register() and cy.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.

});

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');
});
});
35 changes: 29 additions & 6 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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!') => {

Choose a reason for hiding this comment

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

The username parameter is not typically required for login operations. Consider removing it from the login command unless your backend specifically requires it.

cy.request('POST', '/api/users', {

Choose a reason for hiding this comment

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

Ensure that the API endpoint /api/users is correct for the login operation. Typically, login endpoints might be something like /api/login or /api/auth/login.

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);
});
});
});
79 changes: 79 additions & 0 deletions cypress/support/pages/article.pageObject.js
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;
Loading