Commit 4157b7cf authored by Brian Hatchet's avatar Brian Hatchet :speech_balloon:

Optimizing unit tests

1 merge request!499Feat/closed channels 602
Pipeline #77384023 running with stages
......@@ -2,14 +2,15 @@
context('Blogs', () => {
before(() => {
if (cy.getCookie('minds_sess') === null) {
cy.login(true);
cy.location('pathname', { timeout: 30000 })
.should('eq', `/newsfeed/subscriptions`);
}
})
cy.getCookie('minds_sess')
.then((sessionCookie) => {
if (sessionCookie === null) {
cy.login(true);
}
});
});
it('should not be able to create a new blog if no title or banner are specified', () => {
it('should not be able to create a new blog if no title or banner are specified', () => {
cy.visit('/blog/edit/new');
cy.get('.m-button--submit').click();
......@@ -108,11 +109,6 @@ context('Blogs', () => {
cy.get('.m-mature-info a span').contains('Mature content');
cy.get('.m-button--submit').click({ force: true }); // TODO: Investigate why disabled flag is being detected
cy.clock();
cy.clock().then((clock) => { clock.tick(1000); });
cy.wait(1000);
cy.location('pathname', { timeout: 30000 })
.should('contains', `/${Cypress.env().username}/blog`);
......
......@@ -2,31 +2,26 @@ context('Boost Console', () => {
const postContent = "Test boost, please reject..." + Math.random().toString(36);
before(() => {
if (cy.getCookie('minds_sess') === null) {
cy.login(true);
cy.wait(5000);
}
cy.getCookie('minds_sess')
.then((sessionCookie) => {
if (sessionCookie === null) {
cy.login(true);
}
});
});
beforeEach(() => {
cy.visit('/newsfeed/subscriptions');
cy.wait(3000);
cy.location('pathname', { timeout: 30000 })
.should('eq', `/newsfeed/subscriptions`);
cy.visit('/newsfeed/subscribed');
newBoost(postContent, 100);
});
it('should show a new boost in the console', () => {
cy.visit('/boost/console/newsfeed/history');
cy.wait(3000);
cy.get('m-boost-console-card:nth-child(1) div.m-boost-card--manager-item.m-boost-card--state')
.should('not.contain', 'revoked');
cy.get('m-boost-console-card:nth-child(1) .m-boost-card--manager-item--buttons > button')
.click();
cy.wait(1000);
cy.get('m-boost-console-card:nth-child(1) .m-mature-message span')
.contains(postContent);
});
......@@ -38,7 +33,6 @@ context('Boost Console', () => {
cy.get('m-boost-console-card:nth-child(1) .m-boost-card--manager-item--buttons > button')
.click();
cy.wait(1000);
cy.get('m-boost-console-card:nth-child(1) div.m-boost-card--manager-item.m-boost-card--state')
.contains('revoked');
......@@ -46,29 +40,31 @@ context('Boost Console', () => {
function navToConsole() {
cy.visit('/boost/console/newsfeed/history');
cy.wait(3000);
cy.location('pathname', { timeout: 30000 })
.should('eq', `/boost/console/newsfeed/history`);
}
function newBoost(text, views) {
cy.server();
cy.route("POST", '**/api/v2/boost/**').as('boostPost');
cy.post(text);
cy.wait(2000);
cy.get('#boost-actions')
.first()
.click();
cy.wait(5000);
cy.get('.m-boost--creator-section-amount input')
.type(views);
cy.get('m-overlay-modal > div.m-overlay-modal > m-boost--creator button')
.click();
cy.wait(5000);
cy.wait('@boostPost', { requestTimeout: 5000 }).then((xhr) => {
cy.log(xhr);
expect(xhr.status).to.equal(200);
expect(xhr.response.body.status).to.deep.equal("success");
});
cy.get('.m-overlay-modal')
.should('not.be.visible')
}
......
context('Boost Impressions', () => {
before(() => {
if (cy.getCookie('minds_sess') === null) {
cy.login(true);
}
});
beforeEach(() => {
cy.getCookie('minds_sess')
.then((sessionCookie) => {
if (sessionCookie === null) {
cy.login(true);
}
});
cy.visit('/newsfeed/subscriptions');
cy.wait(3000);
cy.location('pathname', { timeout: 30000 })
.should('eq', `/newsfeed/subscriptions`);
});
......@@ -19,45 +18,33 @@ context('Boost Impressions', () => {
cy.route("POST", "**/api/v2/analytics/views/activity/*").as("analytics");
//load, scroll, wait to trigger analytics
cy.wait(3000);
cy.scrollTo(0, 500);
cy.wait(3000);
//assert
cy.wait('@analytics', { requestTimeout: 5000 }).then((xhr) => {
cy.wait('@analytics').then((xhr) => {
expect(xhr.status).to.equal(200);
expect(xhr.response.body).to.deep.equal({ status: 'success' });
});
});
it('should register views on boost rotate forward', () => {
it('should register views on boost rotate', () => {
//stub endpoint
cy.server();
cy.route("POST", "**/api/v2/analytics/views/boost/*").as("analytics");
cy.wait(3000);
//rotate forward and wait to trigger analytics
cy.get('m-newsfeed--boost-rotator > div > ul > li:nth-child(2) > i')
cy.get('m-newsfeed--boost-rotator > div > ul > li:nth-child(3) > i')
.click();
cy.wait(3000);
//assert
cy.wait('@analytics', { requestTimeout: 5000 }).then((xhr) => {
expect(xhr.status).to.equal(200);
expect(xhr.response.body.status).to.deep.equal("success");
});
});
it.only('should register views on boost rotate backward', () => {
//stub endpoint
cy.server();
cy.route("POST", "**/api/v2/analytics/views/boost/*").as("analytics");
cy.wait(3000);
//rotate forward and wait to trigger analytics
cy.get('m-newsfeed--boost-rotator > .m-boost-rotator-tabs > li:nth-child(1) > i')
cy.get('m-newsfeed--boost-rotator > div > ul > li:nth-child(2) > i')
.click();
cy.wait(3000);
//assert
cy.wait('@analytics', { requestTimeout: 5000 }).then((xhr) => {
......
context('Channel', () => {
before(() => {
if (cy.getCookie('minds_sess') === null) {
cy.login(true);
cy.location('pathname', { timeout: 30000 })
.should('eq', `/newsfeed/subscriptions`);
}
cy.getCookie('minds_sess')
.then((sessionCookie) => {
if (sessionCookie === null) {
cy.login(true);
}
});
cy.visit(`/${Cypress.env().username}`);
})
......
......@@ -34,71 +34,68 @@ context('Comment Threads', () => {
before(() => {
//make a post new.
if (cy.getCookie('minds_sess') === null) {
login();
}
cy.getCookie('minds_sess')
.then((sessionCookie) => {
if (sessionCookie === null) {
cy.login(true);
}
});
cy.visit('/newsfeed/subscriptions');
cy.location('pathname', { timeout: 30000 })
.should('eq', `/newsfeed/subscriptions`);
cy.post('test post');
//manually sign-out.
cy.get(hamburgerMenu).click();
cy.get(logoutButton).click();
cy.get(commentButton(1)).click();
});
after(() => {
/*after(() => {
//delete the post
cy.wait(1000);
cy.get(postMenu).click();
cy.get(deletePostOption).click();
cy.get(deletePostButton).click();
});
beforeEach(() => {
login();
cy.wait(2000);
});
});*/
it('should allow a user to post a tier 1 comment', () => {
cy.get(commentButton(2)).click();
cy.get(commentInput(2)).type(testMessage[1]);
cy.get(commentInput(1)).type(testMessage[1]);
cy.get(postCommentButton).click();
cy.get(commentContent(2)).contains(testMessage[1]);
cy.get(commentContent(1)).contains(testMessage[1]);
});
it('should allow a user to post a tier 2 comment', () => {
//expand top comment, then top reply button.
cy.get(commentButton(2)).click();
cy.get(replyButton(2)).click();
cy.get(commentInput(2)).first().type(testMessage[2]);
cy.get(replyButton(1)).click();
cy.get(commentInput(1)).first().type(testMessage[2]);
cy.get(postCommentButton).first().click();
cy.get(commentContent(2)).contains(testMessage[2]);
cy.get(commentContent(1)).contains(testMessage[2]);
});
it('should allow a user to post a tier 3 comment', () => {
//expand top comment, then top reply button.
cy.get(commentButton(2)).click();
cy.get(replyButton(2)).click();
cy.get(replyButton(1)).click();
cy.wait(1000);
//there are two reply buttons now, use the last one.
cy.get(replyButton(2)).last().click();
cy.get(replyButton(1)).last().click();
cy.wait(1000);
//check the comments.
cy.get(commentInput(2)).first().type(testMessage[3]);
cy.get(commentInput(1)).first().type(testMessage[3]);
cy.get(postCommentButton).first().click();
cy.get(commentContent(2)).contains(testMessage[3]);
cy.get(commentContent(1)).contains(testMessage[3]);
});
it('should allow the user to vote up and down comments', () => {
//expand top comment, then top reply button.
cy.get(commentButton(2)).click();
cy.get(replyButton(2)).click();
cy.get(replyButton(1)).click();
cy.wait(1000);
//there are two reply buttons now, use the last one.
cy.get(replyButton(2)).last().click();
cy.get(replyButton(1)).last().click();
cy.wait(1000);
//click thumbs up and down
......@@ -112,12 +109,4 @@ context('Comment Threads', () => {
.each((counter) => expect(counter.context.innerHTML).to.eql('1'));
});
function login() {
cy.login(true);
cy.location('pathname', { timeout: 30000 })
.should('eq', `/newsfeed/subscriptions`);
cy.get(channelButton).click();
}
})
context('Discovery', () => {
before(() => {
if (cy.getCookie('minds_sess') === null) {
cy.login(true);
cy.location('pathname', { timeout: 30000 })
.should('eq', `/newsfeed/subscriptions`);
}
cy.getCookie('minds_sess')
.then((sessionCookie) => {
if (sessionCookie === null) {
cy.login(true);
}
});
cy.visit('/newsfeed/global/top');
});
it('should allow a user to post on the discovery page', () => {
cy.visit('/newsfeed/global/top');
cy.post("test!!");
});
it('should be able to filter by hot', () => {
cy.visit('/newsfeed/global/top');
cy.get('.m-sort-selector--algorithm-dropdown ul > li:nth-child(1)')
.click()
.should('have.css', 'color', 'rgb(70, 144, 223)'); // selected color
......@@ -22,7 +22,6 @@ context('Discovery', () => {
});
it('should be able to filter by top', () => {
cy.visit('/newsfeed/global/hot');
cy.get('.m-sort-selector--algorithm-dropdown ul > li:nth-child(2)')
.click()
.should('have.css', 'color', 'rgb(70, 144, 223)'); // selected color
......@@ -30,13 +29,10 @@ context('Discovery', () => {
});
it('should be able to filter by time in the top feed', () => {
cy.visit('/newsfeed/global/top');
cy.get('.m-sort-selector--period-dropdown').click();
cy.get('.m-sort-selector--period-dropdown ul > li:nth-child(5)').click();
cy.url().should('include', '=1y');
cy.get('.m-sort-selector--period-dropdown').click();
cy.get('.m-sort-selector--period-dropdown ul > li:nth-child(4)').click();
cy.url().should('include', '=30d');
......@@ -55,7 +51,6 @@ context('Discovery', () => {
});
it('should filter by latest', () => {
cy.visit('/newsfeed/global/hot');
cy.get('.m-sort-selector--algorithm-dropdown ul > li:nth-child(3)')
.click()
.should('have.css', 'color', 'rgb(70, 144, 223)'); // selected color
......@@ -64,28 +59,24 @@ context('Discovery', () => {
});
it('should filter by image', () => {
cy.visit('/newsfeed/global/hot');
cy.get('.m-sort-selector--custom-type-dropdown').click();
cy.get('.m-sort-selector--custom-type-dropdown ul > li:nth-child(2)').click();
cy.url().should('include', '=images');
});
it('should filter by video', () => {
cy.visit('/newsfeed/global/hot');
cy.get('.m-sort-selector--custom-type-dropdown').click();
cy.get('.m-sort-selector--custom-type-dropdown ul > li:nth-child(3)').click();
cy.url().should('include', '=videos');
});
it('should filter by blog', () => {
cy.visit('/newsfeed/global/hot');
cy.get('.m-sort-selector--custom-type-dropdown').click();
cy.get('.m-sort-selector--custom-type-dropdown ul > li:nth-child(4)').click();
cy.url().should('include', '=blog');
});
it('should filter by channels', () => {
cy.visit('/newsfeed/global/hot');
cy.get('.m-sort-selector--custom-type-dropdown').click();
cy.get('.m-sort-selector--custom-type-dropdown ul > li:nth-child(5)').click();
cy.url().should('include', '=channels');
......@@ -118,11 +109,13 @@ context('Discovery', () => {
});
it('should allow the user to filter by a single hashtag', () => {
cy.visit('/newsfeed/global/top');
cy.get('.m-hashtagsSidebarSelector__list > ul > li:nth-child(1) .m-hashtagsSidebarSelectorList__visibility > i')
.click(); // Will fail on non-configured users
});
it('should allow the user to turn off single hashtag filter and view all posts', () => {
cy.visit('/newsfeed/global/top');
cy.get('.m-hashtagsSidebarSelector__list > ul > li:nth-child(1) .m-hashtagsSidebarSelectorList__visibility > i')
.click();
})
......
context('Groups', () => {
before(() => {
if (cy.getCookie('minds_sess') === null) {
cy.login(true);
cy.location('pathname', { timeout: 30000 })
.should('eq', `/newsfeed/subscriptions`);
}
cy.getCookie('minds_sess')
.then((sessionCookie) => {
if (sessionCookie === null) {
cy.login(true);
}
});
})
it('should create and edit a group', () => {
......
context('Newsfeed', () => {
before(() => {
if (cy.getCookie('minds_sess') === null) {
cy.login(true);
cy.location('pathname', { timeout: 30000 })
.should('eq', `/newsfeed/subscriptions`);
}
cy.getCookie('minds_sess')
.then((sessionCookie) => {
if (sessionCookie === null) {
cy.login(true);
}
});
})
it('should post an activity picking hashtags from the dropdown', () => {
......
......@@ -24,6 +24,7 @@ context('Onboarding', () => {
const getTopic = (i) => `m-onboarding--topics > div > ul > li:nth-child(${i}) span`;
before(() => {
cy.clearCookies();
cy.visit('/login');
//type values
......
......@@ -3,11 +3,12 @@ context('Remind', () => {
const remindText = 'remind test text';
before(() => {
if (cy.getCookie('minds_sess') === null) {
cy.login(true);
cy.location('pathname', { timeout: 30000 })
.should('eq', `/newsfeed/subscriptions`);
}
cy.getCookie('minds_sess')
.then((sessionCookie) => {
if (sessionCookie === null) {
cy.login(true);
}
});
});
beforeEach(() => {
......
context('Topbar', () => {
before(() => {
if (cy.getCookie('minds_sess') === null) {
cy.login(true);
cy.location('pathname', { timeout: 30000 })
.should('eq', `/newsfeed/subscriptions`);
}
cy.getCookie('minds_sess')
.then((sessionCookie) => {
if (sessionCookie === null) {
cy.login(true);
}
});
});
it("clicking on the dropdown on the right should allow to go to the user's channel", () => {
......
......@@ -11,10 +11,12 @@ context('Wire', () => {
const modal = 'm-overlay-modal > div.m-overlay-modal';
before(() => {
if (cy.getCookie('minds_sess') === null) {
cy.login();
cy.wait(2000);
}
cy.getCookie('minds_sess')
.then((sessionCookie) => {
if (sessionCookie === null) {
cy.login(true);
}
});
});
it('should allow a user to send a wire to another user', () => {
......
......@@ -61,8 +61,14 @@ Cypress.Commands.add('uploadFile', (selector, fileName, type = '') => {
});
Cypress.Commands.add('post', (message) => {
cy.server();
cy.route("POST", '**/v1/newsfeed**').as('postActivity');
cy.get('m-text-input--autocomplete-container textarea').type(message);
cy.get('.m-posterActionBar__PostButton').click();
cy.wait('@postActivity').then((xhr) => {
expect(xhr.status).to.equal(200);
expect(xhr.response.body.status).to.deep.equal("success");
});
});
function b64toBlob(b64Data, contentType, sliceSize = 512) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment