Skip to content
This repository has been archived by the owner on Oct 29, 2019. It is now read-only.

Commit

Permalink
Merge pull request #401 from aldryn/feature/plugin-test
Browse files Browse the repository at this point in the history
Add more integration tests
  • Loading branch information
vxsx committed May 26, 2016
2 parents cafdb43 + 4007f05 commit 2070a68
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 443 deletions.
149 changes: 123 additions & 26 deletions aldryn_newsblog/tests/frontend/integration/crud.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,13 @@ casper.test.tearDown(function (done) {
.run(done);
});

/**
* Returns xpath expression to find the to the specific row in the admin.
* Can also be used to find xpath to specific links in that row.
*
* @function generateXPathForAdminSection
* @param {Object} options
* @param {String} options.section module name, e.g. Django CMS
* @param {String} options.row module row, e.g Pages, Users
* @param {String} [options.link] specific link in the row, e.g "Add" or "Change"
*/
var generateXPathForAdminSection = function (options) {
var xpath = '//div[.//caption/a[contains(text(), "' + options.section + '")]]';

if (options.link) {
xpath += '//th[./a[contains(text(), "' + options.row + '")]]';
xpath += '/following-sibling::td/a[contains(text(), "' + options.link + '")]';
} else {
xpath += '//th/a[contains(text(), "' + options.row + '")]';
}

return xpath;
};

casper.test.begin('Creation / deletion of the apphook', function (test) {
casper
.start(globals.adminUrl)
.waitUntilVisible('#content', function () {
test.assertVisible('#content', 'Admin loaded');
this.click(
xPath(generateXPathForAdminSection({
xPath(cms.getXPathForAdminSection({
section: 'Aldryn News & Blog',
row: 'Application configurations',
link: 'Add'
Expand Down Expand Up @@ -115,7 +92,7 @@ casper.test.begin('Creation / deletion of the article', function (test) {
.waitUntilVisible('#content', function () {
test.assertVisible('#content', 'Admin loaded');
this.click(
xPath(generateXPathForAdminSection({
xPath(cms.getXPathForAdminSection({
section: 'Aldryn News & Blog',
row: 'Articles',
link: 'Add'
Expand Down Expand Up @@ -154,7 +131,7 @@ casper.test.begin('Creation / deletion of the article', function (test) {
.thenOpen(globals.adminUrl)
.waitUntilVisible('#content', function () {
this.click(
xPath(generateXPathForAdminSection({
xPath(cms.getXPathForAdminSection({
section: 'Aldryn News & Blog',
row: 'Articles'
}))
Expand All @@ -181,3 +158,123 @@ casper.test.begin('Creation / deletion of the article', function (test) {
test.done();
});
});

casper.test.begin('Latest articles plugin', function (test) {
casper
.start()
.then(cms.addPage({ title: 'Home' }))
.then(cms.addPlugin({
type: 'NewsBlogLatestArticlesPlugin',
content: {
id_latest_articles: 1
}
}))
.thenOpen(globals.editUrl, function () {
test.assertSelectorHasText(
'.cms-plugin p',
'No items available',
'No articles yet'
);
})
.then(cms.openSideframe())
// add articles
.withFrame(0, function () {
this.waitForSelector('.cms-pagetree-breadcrumbs')
.then(function () {
this.click('.cms-pagetree-breadcrumbs a:first-child');
})
.waitForUrl(/admin/)
.waitForSelector('.dashboard', function () {
this.click(xPath(cms.getXPathForAdminSection({
section: 'Aldryn News & Blog',
row: 'Articles',
link: 'Add'
})));
})
.waitForSelector('#article_form', function () {
this.fill('#article_form', {
title: 'First article'
}, false);

})
// wait 3 seconds so the second article is definitely
// created after the first one :)
.wait(3000, function () {
this.click('input[value="Save and add another"]');
})
.waitForSelector('.success', function () {
test.assertSelectorHasText(
'.success',
'The article "First article" was added successfully. You may add another article below.',
'First article added'
);

this.fill('#article_form', {
title: 'Second article'
}, true);
})
.waitForSelector('.success');
})
.thenOpen(globals.editUrl, function () {
test.assertSelectorHasText(
'.cms-plugin p',
'No items available',
'Still no articles yet (no apphooked page yet)'
);
})
.then(cms.addPage({ title: 'Blog' }))
.then(cms.addApphookToPage({
page: 'Blog',
apphook: 'NewsBlogApp'
}))
.then(cms.publishPage({ page: 'Blog' }))
.thenOpen(globals.editUrl, function () {
test.assertSelectorHasText(
'.cms-plugin .article h2 a',
'Second article',
'Latest article is visible on the page'
);
test.assertElementCount(
'.cms-plugin .article',
1,
'Only one latest article is visible on the page'
);
})
// remove articles
.then(cms.openSideframe())
.withFrame(0, function () {
this.waitForSelector('.cms-pagetree-breadcrumbs')
.then(function () {
this.click('.cms-pagetree-breadcrumbs a:first-child');
})
.waitForUrl(/admin/)
.waitForSelector('.dashboard', function () {
this.click(xPath(cms.getXPathForAdminSection({
section: 'Aldryn News & Blog',
row: 'Articles'
})));
})
.waitForSelector('#changelist-form', function () {
this.click('th input[type="checkbox"]');
this.fill('#changelist-form', {
action: 'delete_selected'
}, true);

})
.waitForSelector('.delete-confirmation', function () {
this.click('input[value="Yes, I\'m sure"]');
})
.waitForSelector('.success', function () {
test.assertSelectorHasText(
'.success',
'Successfully deleted 2 articles.',
'Articles deleted'
);
});
})
.then(cms.removePage())
.then(cms.removePage())
.run(function () {
test.done();
});
});
109 changes: 0 additions & 109 deletions aldryn_newsblog/tests/frontend/integration/pages/page.newsblog.crud.js

This file was deleted.

93 changes: 93 additions & 0 deletions aldryn_newsblog/tests/frontend/integration/related-articles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
'use strict';

var helpers = require('djangocms-casper-helpers');
var globals = helpers.settings;
var casperjs = require('casper');
var cms = helpers(casperjs);
var xPath = casperjs.selectXPath;

casper.test.setUp(function (done) {
casper.start()
.then(cms.login())
.run(done);
});

casper.test.tearDown(function (done) {
casper.start()
.then(cms.logout())
.run(done);
});

casper.test.begin('Related articles', function (test) {
casper
.then(cms.addPage({ title: 'Home' }))
.thenOpen(globals.editUrl)
.then(cms.openSideframe())
// add articles
.withFrame(0, function () {
this.waitForSelector('.cms-pagetree-breadcrumbs')
.then(function () {
this.click('.cms-pagetree-breadcrumbs a:first-child');
})
.waitForUrl(/admin/)
.waitForSelector('.dashboard', function () {
this.click(xPath(cms.getXPathForAdminSection({
section: 'Aldryn News & Blog',
row: 'Articles',
link: 'Add'
})));
})
.waitForSelector('#article_form', function () {
test.assertDoesntExist('.field-related .add-related', 'Related articles "Add" are not shown');

this.fill('#article_form', {
title: 'First article'
}, false);

})
// wait 3 seconds so the second article is definitely
// created after the first one :)
.wait(3000, function () {
this.click('input[value="Save and add another"]');
})
.waitForSelector('.success', function () {
test.assertSelectorHasText(
'.success',
'The article "First article" was added successfully. You may add another article below.',
'First article added'
);

test.assertDoesntExist('.field-related .add-related', 'Related articles "Add" are not shown');
test.assertSelectorHasText(
'.sortedm2m',
'First article',
'Correct related articles possibilities are shown'
);

this.fill('#article_form', {
title: 'Second article'
}, true);
})
.waitForSelector('#changelist-form', function () {
this.click('th input[type="checkbox"]');
this.fill('#changelist-form', {
action: 'delete_selected'
}, true);

})
.waitForSelector('.delete-confirmation', function () {
this.click('input[value="Yes, I\'m sure"]');
})
.waitForSelector('.success', function () {
test.assertSelectorHasText(
'.success',
'Successfully deleted 2 articles.',
'Articles deleted'
);
});
})
.then(cms.removePage())
.run(function () {
test.done();
});
});

0 comments on commit 2070a68

Please sign in to comment.