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.spec.js #56

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 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",
Vladimir-Tarasov marked this conversation as resolved.
Show resolved Hide resolved
"email": "test_manual4@gmail.com",
"password": "xyzXYZ123_"
}
188 changes: 188 additions & 0 deletions cypress/integration/finish_mama_project/social.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
///<reference types='cypress' / >
import { getRandomNumber } from '../../support/utils';
import { login } from '../../support/shared';
import meUser from '../../fixtures/me-user.json';
import { setJwtToken } from '../../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')
.click();
}

function deleteAllMyArticles() {
cy.get('@appHeader').find('[ui-sref*=username]').click();
debugger;
cy.wait(5000);
// 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) {
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);
});
});
});
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);
}