Skip to content
Commits on Source (2)
......@@ -3,71 +3,66 @@
context('Blogs', () => {
before(() => {
cy.clearCookies();
cy.getCookie('minds_sess')
.then((sessionCookie) => {
cy.getCookie('minds_sess').then(sessionCookie => {
if (sessionCookie === null) {
return cy.login(true);
}
});
});
beforeEach(()=> {
beforeEach(() => {
cy.preserveCookies();
cy.server();
cy.route('POST', '**/api/v1/blog/new').as('postBlog');
cy.route('GET', '**/api/v1/blog/**').as('getBlog');
cy.route('DELETE', '**/api/v1/blog/**').as('deleteBlog');
});
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();
cy.get('.m-blog--edit--error').contains('Error: You must provide a title');
cy.get('minds-textarea .m-editor').type('Title');
cy.get('.m-button--submit').click();
cy.get('.m-blog--edit--error').contains('Error: You must upload a banner');
})
it('should be able to create a new blog', () => {
// upload avatar first
cy.visit(`/${Cypress.env().username}`);
const uploadAvatar = () => {
cy.visit(`/${Cypress.env().username}`, { timeout: 30000 });
cy.get('.m-channel--name .minds-button-edit button:first-child').click();
cy.uploadFile('.minds-avatar input[type=file]', '../fixtures/avatar.jpeg', 'image/jpg');
cy.uploadFile(
'.minds-avatar input[type=file]',
'../fixtures/avatar.jpeg',
'image/jpg'
);
cy.get('.m-channel--name .minds-button-edit button:last-child').click();
};
// create blog
cy.visit('/blog/edit/new');
const createBlogPost = (title, body, nsfw = false, schedule = false) => {
cy.visit('/blog/edit/new', { timeout: 30000 });
cy.uploadFile('.minds-banner input[type=file]', '../fixtures/international-space-station-1776401_1920.jpg', 'image/jpg');
cy.get('minds-textarea .m-editor').type('Title');
cy.uploadFile(
'.minds-banner input[type=file]',
'../fixtures/international-space-station-1776401_1920.jpg',
'image/jpg'
);
cy.get('m-inline-editor .medium-editor-element').type('Content\n');
cy.get('minds-textarea .m-editor').type(title);
cy.get('m-inline-editor .medium-editor-element').type(body);
// click on plus button
// cy.get('.medium-editor-element > .medium-insert-buttons > button.medium-insert-buttons-show').click();
cy.get('.medium-editor-element > .medium-insert-buttons > button.medium-insert-buttons-show').click();
// click on camera
// cy.get('ul.medium-insert-buttons-addons > li > button.medium-insert-action:first-child').contains('photo_camera').click();
cy.get('ul.medium-insert-buttons-addons > li > button.medium-insert-action:first-child').contains('photo_camera').click();
// upload the image
// cy.uploadFile('.medium-media-file-input', '../fixtures/international-space-station-1776401_1920.jpg', 'image/jpg');
cy.uploadFile('.medium-media-file-input', '../fixtures/international-space-station-1776401_1920.jpg', 'image/jpg');
// open license dropdown & select first license
cy.get('.m-license-info select').select('All rights reserved');
// click on hashtags dropdown
cy.get('.m-category-info m-hashtags-selector .m-dropdown--label-container').click();
cy.get(
'.m-category-info m-hashtags-selector .m-dropdown--label-container'
).click();
// select #ART
cy.get('.m-category-info m-dropdown m-form-tags-input > div > span').contains('#art').click();
cy.get('.m-category-info m-dropdown m-form-tags-input > div > span')
.contains('#art')
.click();
// type in another hashtag manually
cy.get('.m-category-info m-hashtags-selector m-form-tags-input input').type('hashtag{enter}').click();
cy.get('.m-category-info m-hashtags-selector m-form-tags-input input')
.type('hashtag{enter}')
.click();
// click away
cy.get('.m-category-info m-hashtags-selector .minds-bg-overlay').click();
......@@ -76,155 +71,212 @@ context('Blogs', () => {
cy.get('.m-visibility-info select').select('Loggedin');
// open metadata form
cy.get('.m-blog-edit--toggle-wrapper .m-blog-edit--toggle').contains('Metadata').click();
cy.get('.m-blog-edit--toggle-wrapper .m-blog-edit--toggle')
.contains('Metadata')
.click();
// set url slug
cy.get('.m-blog-edit--field input[name=slug]').type('123');
// set meta title
cy.get('.m-blog-edit--field input[name=custom_meta_title]').type('Test');
// set meta description
cy.get('.m-blog-edit--field textarea[name=custom_meta_description]').type('This is a test blog');
cy.get('.m-blog-edit--field textarea[name=custom_meta_description]').type(
'This is a test blog'
);
// set meta author
cy.get('.m-blog-edit--field input[name=custom_meta_author]').type('Minds Test');
// set as nsfw
cy.get('.m-mature-info a').click();
cy.get('.m-mature-info a span').contains('Mature content');
cy.route("POST", "**/api/v1/blog/new").as("postBlog");
cy.route("GET", "**/api/v1/blog/**").as("getBlog");
cy.get('.m-button--submit').click({ force: true }); // TODO: Investigate why disabled flag is being detected
cy.wait('@postBlog').then((xhr) => {
cy.get('.m-blog-edit--field input[name=custom_meta_author]').type(
'Minds Test'
);
if (nsfw) {
cy.get('.m-mature-info a').click();
cy.get('.m-mature-info a span').contains('Mature content');
}
if (schedule) {
cy.get('.m-poster-date-selector__input').click();
cy.get(
'td.c-datepicker__day-body.c-datepicker__day--selected + td'
).click();
cy.get('a.c-btn.c-btn--flat.js-ok').click();
// get setted date to compare
let scheduledDate;
cy.get('div.m-poster-date-selector__input div.m-tooltip--bubble')
.invoke('text')
.then(text => {
scheduledDate = text;
});
}
cy.get('.m-button--submit', { timeout: 5000 }).click({ force: true }); // TODO: Investigate why disabled flag is being detected
cy.wait('@postBlog').then(xhr => {
expect(xhr.status).to.equal(200);
expect(xhr.response.body.status).to.equal("success");
});
expect(xhr.response.body.status).to.equal('success');
cy.wait('@getBlog').then((xhr) => {
expect(xhr.status).to.equal(200);
expect(xhr.response.body.status).to.equal("success");
expect(xhr.response.body).to.have.property("blog");
cy.wait('@getBlog').then(xhr => {
expect(xhr.status).to.equal(200);
expect(xhr.response.body.status).to.equal('success');
expect(xhr.response.body).to.have.property('blog');
});
});
cy.location('pathname')
.should('contains', `/${Cypress.env().username}/blog`);
cy.get('.m-blog--title').contains('Title');
cy.get('.minds-blog-body p').contains('Content');
cy.location('pathname', { timeout: 30000 }).should(
'contains',
`/${Cypress.env().username}/blog`
);
cy.get('.m-blog--title').contains(title);
cy.get('.minds-blog-body p').contains(body);
cy.get('.m-license-info span').contains('all-rights-reserved');
// cleanup
if (schedule) {
cy.wait(1000);
cy.get('div.m-blog-container div.mdl-grid div.minds-body span')
.invoke('text')
.then(text => {
const time_created = new Date(text).getTime();
scheduledDate = new Date(scheduledDate).getTime();
expect(scheduledDate).to.equal(time_created);
});
}
};
//open dropdown
const deleteBlogPost = () => {
cy.get('m-post-menu button.minds-more').click();
cy.get('m-post-menu ul.minds-dropdown-menu li').contains('Delete').click();
cy.get('m-post-menu ul.minds-dropdown-menu li')
.contains('Delete')
.click();
cy.get('m-post-menu m-modal-confirm .mdl-button--colored').click();
});
it('should be able to create a new scheduled blog', () => {
// upload avatar first
cy.visit(`/${Cypress.env().username}`);
cy.get('minds-newsfeed-poster').then((poster) => {
if (poster.find('.m-poster-date-selector__input').length > 0) {
cy.get('.m-channel--name .minds-button-edit button:first-child').click();
cy.wait(100);
cy.uploadFile('.minds-avatar input[type=file]', '../fixtures/avatar.jpeg', 'image/jpg');
cy.get('.m-channel--name .minds-button-edit button:last-child').click();
// create blog
cy.visit('/blog/edit/new');
cy.uploadFile('minds-banner #file', '../fixtures/international-space-station-1776401_1920.jpg', 'image/jpg');
cy.get('minds-textarea .m-editor').type('Title');
cy.get('m-inline-editor .medium-editor-element').type('Content\n');
// click on plus button
cy.get('.medium-editor-element > .medium-insert-buttons > button.medium-insert-buttons-show').click();
// click on camera
cy.get('ul.medium-insert-buttons-addons > li > button.medium-insert-action:first-child').contains('photo_camera').click();
// upload the image
cy.uploadFile('.medium-media-file-input', '../fixtures/international-space-station-1776401_1920.jpg', 'image/jpg');
// open license dropdown & select first license
cy.get('.m-license-info select').select('All rights reserved');
cy.wait('@deleteBlog').then(xhr => {
expect(xhr.status).to.equal(200);
expect(xhr.response.body.status).to.equal('success');
});
};
const editBlogPost = (title, body) => {
cy.location('pathname').should(
'contains',
`/${Cypress.env().username}/blog`
);
cy.get('m-post-menu').click();
cy.get('.minds-dropdown-menu li')
.first()
.click();
cy.location('pathname').should('contains', '/blog/edit');
cy.get('minds-textarea .m-editor').type(title);
cy.get('m-inline-editor .medium-editor-element').type(body);
// click on hashtags dropdown
cy.get('.m-category-info m-hashtags-selector .m-dropdown--label-container').click();
// select #ART
cy.get('.m-category-info m-dropdown m-form-tags-input > div > span').contains('#art').click();
// type in another hashtag manually
cy.get('.m-category-info m-hashtags-selector m-form-tags-input input').type('hashtag{enter}').click();
cy.get('.m-button--submit').click();
// click away
cy.get('.m-category-info m-hashtags-selector .minds-bg-overlay').click();
cy.wait('@postBlog').then(xhr => {
expect(xhr.status).to.equal(200);
expect(xhr.response.body.status).to.equal('success');
// select visibility
cy.get('.m-visibility-info select').select('Loggedin');
cy.wait('@getBlog').then(xhr => {
expect(xhr.status).to.equal(200);
expect(xhr.response.body.status).to.equal('success');
expect(xhr.response.body).to.have.property('blog');
});
});
// open metadata form
cy.get('.m-blog-edit--toggle-wrapper .m-blog-edit--toggle').contains('Metadata').click();
// set url slug
cy.get('.m-blog-edit--field input[name=slug]').type('123');
// set meta title
cy.get('.m-blog-edit--field input[name=custom_meta_title]').type('Test');
// set meta description
cy.get('.m-blog-edit--field textarea[name=custom_meta_description]').type('This is a test blog');
// set meta author
cy.get('.m-blog-edit--field input[name=custom_meta_author]').type('Minds Test');
cy.location('pathname').should(
'contains',
`/${Cypress.env().username}/blog`
);
// set as nsfw
cy.get('.m-mature-info a').click();
cy.get('.m-mature-info a span').contains('Mature content');
cy.get('.m-blog--title').contains(title);
cy.get('.minds-blog-body p').contains(body);
};
// set scheduled date
cy.get('.m-poster-date-selector__input').click();
cy.get('td.c-datepicker__day-body.c-datepicker__day--selected + td').click();
cy.get('a.c-btn.c-btn--flat.js-ok').click();
it('should be able to create a new scheduled blog', () => {
uploadAvatar();
createBlogPost('Title', 'Content', true, true);
deleteBlogPost();
});
// get setted date to compare
let scheduledDate;
cy.get('div.m-poster-date-selector__input div.m-tooltip--bubble')
.invoke('text').then((text) => {
scheduledDate = text;
});
it('should not be able to create a new blog if no title or banner are specified', () => {
cy.visit('/blog/edit/new', { timeout: 30000 });
cy.get('.m-button--submit').click();
cy.get('.m-blog--edit--error').contains('Error: You must provide a title');
cy.get('minds-textarea .m-editor').type('Title');
cy.get('.m-button--submit').click();
cy.get('.m-blog--edit--error').contains('Error: You must upload a banner');
});
cy.wait(1000);
it('should be able to create a new blog', () => {
const title = 'Title';
const body = 'Content';
cy.get('.m-button--submit').click({ force: true }); // TODO: Investigate why disabled flag is being detected
uploadAvatar();
createBlogPost(title, body, true);
deleteBlogPost();
});
cy.location('pathname', { timeout: 30000 })
.should('contains', `/${Cypress.env().username}/blog`);
it('should create an activity for the blog post', () => {
const identifier = Math.floor(Math.random() * 100);
const title = 'Test Post for Activity ' + identifier;
const body = 'Some content here ' + identifier;
cy.get('.m-blog--title').contains('Title');
cy.get('.minds-blog-body p').contains('Content');
createBlogPost(title, body);
cy.visit(`/${Cypress.env().username}`);
//:nth-child(3) > .mdl-card > .m-rich-embed > minds-rich-embed > .m-rich-embed-src > .meta > .m-rich-embed--title
cy.get('minds-activity:first .m-blurb').contains(body);
cy.get('minds-activity:first .m-rich-embed--title')
.first()
.contains(title);
cy.get('minds-activity:first .thumbnail')
.should('have.attr', 'href')
.then(href => {
cy.visit(href);
});
cy.location('pathname').should(
'contains',
`/${Cypress.env().username}/blog`
);
deleteBlogPost();
cy.location('pathname').should(
'contains',
`/blog/owner`
);
});
cy.get('.m-license-info span').contains('all-rights-reserved');
it('should update the activity when blog is updated', () => {
const identifier = Math.floor(Math.random() * 100);
const title = 'Test Post for Activity ' + identifier;
const body = 'Some content here ' + identifier;
cy.wait(1000);
createBlogPost(title, body);
cy.visit(`/${Cypress.env().username}`);
cy.get('minds-activity:first .m-blurb').contains(body);
cy.get('minds-activity:first .m-rich-embed--title')
.first()
.contains(title);
// compare setted date with time_created
cy.get('div.m-blog-container div.mdl-grid div.minds-body span')
.invoke('text').then((text) => {
const time_created = new Date(text).getTime();
scheduledDate = new Date(scheduledDate).getTime();
expect(scheduledDate).to.equal(time_created);
});
cy.get('minds-activity:first .thumbnail')
.should('have.attr', 'href')
.then(href => {
cy.visit(href);
});
// cleanup
const newtitle = title + ' changed';
const newbody = body + ' changed';
editBlogPost(newtitle, newbody);
//open dropdown
cy.get('m-post-menu button.minds-more').click();
cy.get('m-post-menu ul.minds-dropdown-menu li').contains('Delete').click();
cy.get('m-post-menu m-modal-confirm .mdl-button--colored').click();
}
});
cy.visit(`/${Cypress.env().username}`);
cy.get('minds-activity:first .m-blurb').contains(body);
cy.get('minds-activity:first .m-rich-embed--title')
.first()
.contains(title);
cy.get('minds-activity:first .thumbnail')
.should('have.attr', 'href')
.then(href => {
cy.visit(href);
});
deleteBlogPost();
});
})
});
This diff is collapsed.