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

Add social tests #8

Open
wants to merge 5 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
6 changes: 3 additions & 3 deletions cypress/fixtures/me-user.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"username": "test_anton",
"email": "test_anton@gmail.com",
"username": "test_manual4",
"email": "test_manual4@gmail.com",
"password": "xyzXYZ123_"
}
}
192 changes: 192 additions & 0 deletions cypress/integration/finish_mama_project/social.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
///<reference types='cypress' />
import { getRandomNumber } from '/cypress/support/utils.js';
import { login } from '/cypress/support/shared.js';
import meUser from '/cypress/fixtures/me-user.json';
import { setJwtToken } from '/cypress/support/utils';

function selectFirstArticle() {
waitForArticlesList();
cy.get('@articleList')
.find('.article-preview')
// .should('have.length', 12)
.should('have.length.greaterThan', 2)
.eq(0)
.as('firstArticle');
}
function waitForArticlesList() {
cy.get('@articleList')
.contains('.article-preview', 'Loading')
.should('not.be.visible');
}

function openGlobalFeed() {
cy.get('.feed-toggle a.nav-link[ng-class*=all]').click();
}

function checkActiveYourFeed() {
cy.get('@yourFeed').should('have.class', 'active');
}

function subscribeFromUser() {
// meUser.username
cy.get('@firstArticle').find('.author').as('describedAuthor').click();
cy.get('@describedAuthor')
.invoke('text')
.invoke('trim')
.as('subscribedAuthorName');
cy.get('follow-btn button')
.should('contain', 'Follow')
.click()
.as('followButton');
// TODO: improve selector
cy.get('@followButton').should('contain', 'Unfollow');
}

function unsubscribeFromUser() {
checkActiveYourFeed();
selectFirstArticle();
cy.get('@firstArticle').find('.author').as('undescribedAuthor').click();
cy.get('@undescribedAuthor')
.invoke('text')
.invoke('trim')
.as('unsubscribedAuthorName');
cy.get('follow-btn button')
.should('contain', 'Unfollow')
.click()
.as('UnfollowButton');
// TODO: improve selector
cy.get('@UnfollowButton').should('contain', 'Follow');

}

function unsubscribeFromAll() {
cy.get('@buttonHome').click();
waitForArticlesList();
cy.get('@articleList').find('.article-preview')
.then(articles => {
cy.log(articles.length);
if (articles.length > 2) {
cy.wrap(articles).eq(0).click();
unsubscribeFromUser();
unsubscribeFromAll();
}
});
}

function goToHomePage() {
cy.get('@appHeader')
.find('[show-authed=true] [ui-sref="app.home"]').as('buttonHome')
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we find better selector? Is it <a>?

Copy link
Collaborator Author

@SvetlanaVet SvetlanaVet Jan 30, 2023

Choose a reason for hiding this comment

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

if use <a> then find two elements
https://disk.yandex.com/i/qKPV5o6XviIHlg

.click();
}

function deleteAllMyArticles() {
cy.get('@appHeader').find('[ui-sref*=username]').click();
debugger;
cy.wait(5000);
Copy link
Contributor

Choose a reason for hiding this comment

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

Add comment why do you need it here.

Copy link
Collaborator Author

@SvetlanaVet SvetlanaVet Jan 30, 2023

Choose a reason for hiding this comment

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

I don't understand what is wrong! But without cy.wait(5000) it doesn't work. I tryed to use

cy.location('hash').should('eq', '#/@test_manual4');

or

cy.url().should("include", "#/@test_manual4");

but it doesn't work too
I attach video

https://www.awesomescreenshot.com/video/14393554?key=918860b78fd72922afa44bb567f51de3

Help me, please

// waitForArticlesList();

cy.get('.articles-toggle .nav-link[ui-sref*=main]').should('have.class', 'active');
cy.get('@articleList').find('.article-preview')
.then(articles => {
cy.log(articles.length);
if (articles.length > 2) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why 2? Why not 0?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

we have two '.article-preview' when the page is empty
https://disk.yandex.com/i/tI8JGQJCKhwxXA

deleteMyArticle();
deleteAllMyArticles();
}
});
}

function deleteMyArticle() {

cy.get('@articleList').find('.article-preview').eq(0).click();
cy.get('.article-actions button[ng-click*=delete]').click();
checkActiveYourFeed();
}

describe('Social', () => {

beforeEach(() => {
cy.visit('/');
cy.get('.navbar').should('be.visible').as('appHeader');

// cy.get('@token')
cy.readFile('token.txt')
.should('not.be.empty')
.then(token => {
cy.visit('/', {
onBeforeLoad: (window) => setJwtToken(window, token)
});
});

cy.get('.navbar').should('be.visible')
.should('contain.text', meUser.username);

cy.get('article-list').as('articleList');
cy.get('@appHeader').find('[show-authed=true] [ui-sref="app.home"]').as('buttonHome');
cy.get('.feed-toggle a.nav-link[ng-class*=feed]').as('yourFeed');
cy.location('hash').should('eq', '#/');
});

it('should do subscribe to user', () => {

deleteAllMyArticles();
unsubscribeFromAll();
openGlobalFeed();
selectFirstArticle();
subscribeFromUser();

cy.get('@subscribedAuthorName').then((authorName) => {
cy.log(authorName);
console.log(authorName);

goToHomePage();

cy.get('.home-page').should('contain', authorName);
});

});

it('should do unsubscribe from user', () => {

deleteAllMyArticles();

cy.get('@buttonHome').click();

checkActiveYourFeed();
waitForArticlesList();

cy.get('@articleList').find('.article-preview')
.then(articles => {
cy.log(articles.length);
if (articles.length === 2) {

openGlobalFeed();
selectFirstArticle();
subscribeFromUser();

cy.get('@subscribedAuthorName').then((authorName) => {
cy.log(authorName);
console.log(authorName);

goToHomePage();

cy.get('.home-page').should('contain', authorName);
});
}
});

unsubscribeFromUser();

cy.get('@unsubscribedAuthorName').then((authorName) => {
cy.log(authorName);
console.log(authorName);

goToHomePage();

cy.get('.home-page').should('not.contain', authorName);
});

});


});
14 changes: 13 additions & 1 deletion cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ import './commands'
// require('./commands')
import meUser from '/cypress/fixtures/me-user.json';

// before(() => {
// const { email, password } = meUser;
// cy.request('POST', 'https://api.realworld.io/api/users/login',
// { user: { email, password } })
// .then(({ status, body }) => {
// expect(status).to.eq(200);
// expect(body).to.have.key('user');
// const { user } = body;
// cy.wrap(user.token).as('token');
// });
// });

before(() => {
const { email, password } = meUser;
cy.request('POST', 'https://api.realworld.io/api/users/login',
Expand All @@ -28,6 +40,6 @@ before(() => {
expect(status).to.eq(200);
expect(body).to.have.key('user');
const { user } = body;
cy.wrap(user.token).as('token');
cy.writeFile('token.txt', user.token);
});
});
4 changes: 4 additions & 0 deletions cypress/support/utils.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
export function getRandomNumber(min, max) {
return Math.round(Math.random() * (max - min)) + min;
}

export function setJwtToken(window, token) {
window.localStorage.setItem('jwtToken', token);
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"devDependencies": {
"@faker-js/faker": "^7.6.0",
"chai": "^4.3.7",
"cypress": "~9.7.0",
"cypress": "^9.7.0",
"node-wget": "^0.4.3",
"node-xlsx": "^0.21.0",
"qr-util": "^1.0.1",
Expand Down
49 changes: 49 additions & 0 deletions test_cases/subscribe_to_user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
Subscribe to user test case

# It should do subscribe to user:

## Before

1. Open https://demo.realworld.io/
2. Repeat 2-9 from [login user](/test_cases/login_user.md)
3. Url should be `/#/` — main page

## Delete all my articles

4. Click on button that contain username
5. If articles is list not empty then
* click button **Delete**
* go to step 4

## Delete all subscriptions

6. In feed toggle menu should be active **Your Feed**
7. Your Feed contains text "No articles are here... yet"?
* No, continue.
* Yes, go to step 11.
8. Select first article
9. Click button **Unfollow**
10. Confirm that the button text changes to **Follow**
11. Click **Home**
12. Back to step 4

## Select first article

13. Click **Global Feed** in feed toggle menu
14. List should have 10 article cards
15. Select first article

## Subscribe to user by following him

16. Click button **Follow**
17. Confirm that the button text changes to **Unfollow**

## Check user in your subscription list

18. Click **Home**
17. In feed toggle menu should be active **Your Feed**
19. Check `{author}` should be visible

## Where:

- `{author}` — subscribed author
51 changes: 51 additions & 0 deletions test_cases/unsubscribe_from_user.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Unsubscribe to user test case

# It should do unsubscribe from user:

## Before

1. Open https://demo.realworld.io/
2. Repeat steps 2-9 from [login user](/test_cases/login_user.md)
3. Url should be `/#/` — main page

## Delete all my articles

4. Click on button that contain username
5. If articles is list not empty then
* click button **Delete**
* go to step 4

## Checking for a subscribtion

6. In feed toggle menu should be active **Your Feed**
7. Your Feed contains text "No articles are here... yet"?
* No, go to step 14.
* Yes, continue.

## Subscribe to user by following him

8. Click **Global Feed** in feed toggle menu
9. List should have 10 article cards
10. Select first article
11. Click buttun **Follow**
12. Confirm that the button text changes to **Unfollow**

## Check user in your subscription list

13. Click **Home**
14. In feed toggle menu should be active **Your Feed**
15. Check `{authorFollowed}` should be visible

## Unsubscribe from user by unfollowing him

16. Select first article
17. Click button **Unfollow**
16. Confirm that the button text changes to **Follow**
18. Click **Home**
19. In feed toggle menu should be active **Your Feed**
20. Check that your subscription list does not contain `{authorUnfollowed}`

## Where:

- `{authorFollow}` — subscribed author
- `{authorUnfollow}` - unsubscribed author