Initial Commit

This commit is contained in:
2019-11-21 12:25:31 +01:00
commit f4aabcb9b1
13959 changed files with 787761 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
var system = require('system');
// Thalie Base URL
var thelia2_base_url = '';
if (casper.cli.has('thelia2_base_url')){
thelia2_base_url = casper.cli.get('thelia2_base_url');
casper.test.comment('CasperJS will use Thelia on : '+ thelia2_base_url);
} else if (system.env.thelia2_base_url){
thelia2_base_url = system.env.thelia2_base_url;
casper.test.comment('CasperJS will use Thelia (ENV) on : '+ thelia2_base_url);
} else {
thelia2_base_url = 'http://dev.thelia.net/index_dev.php/';
casper.test.comment('CasperJS will use fallback URL for tests : '+ thelia2_base_url);
casper.test.comment('If you want to use custom URL just set the environment variable `thelia2_base_url`');
}
// Administrator account
var administrator = {
login: "thelia2",
password: "thelia2"
};
// Default
var thelia2_store_name = "Thelia V2";
var screenshot_enabled = true;
if (casper.cli.has('thelia2_screenshot_disabled')) {
screenshot_enabled = false;
}
// Screenshot Dir
var screenshot_dir = 'tests/functionnal/casperjs/screenshot/';
if (casper.cli.has('thelia2_screenshot_path')){
screenshot_dir = casper.cli.get('thelia2_screenshot_path');
}
casper.test.comment('Screenshots will be saved under : '+ screenshot_dir);
// Default Viewport size
casper.options.viewportSize = {width: 1024, height: 768};
casper.test.comment('Viewport size: '+ casper.options.viewportSize.width + 'x' + casper.options.viewportSize.height);
// Default timeout in ms
var thelia_default_timeout = 15000;
// for the waitFor method
casper.options.waitTimeout = thelia_default_timeout;
casper.options.logLevel = "info";
casper.test.comment('Default timeout: '+ thelia_default_timeout + ' ms');
// Email created during front/20_register.js test
var thelia_customer = {
"email": null,
"password": "thelia"
};
casper.test.done();

View File

@@ -0,0 +1,164 @@
/**
* Created by julien on 16/10/14.
*/
var x = require('casper').selectXPath;
var errors = [], resourceErrors = [];
casper.test.begin('Back Office - Pages', 100, function suite(test) {
var pages = [
{"url": "admin", "title": "Back-office home"},
{"url": "admin/home", "title": "Back-office home"},
{"url": "admin/catalog", "title": "Categories"},
{"url": "admin/customers", "title": "Customer"},
{"url": "admin/orders", "title": "Orders"},
{"url": "admin/categories", "title": "Categories"},
{"url": "admin/products", "title": "Categories"},
{"url": "admin/folders", "title": "Folders"},
{"url": "admin/coupon", "title": "Coupons"},
{"url": "admin/configuration", "title": "Configuration"},
{"url": "admin/configuration/variables", "title": "Thelia System Variables"},
{"url": "admin/configuration/store", "title": "Store"},
{"url": "admin/configuration/system-logs", "title": "System Logs"},
{"url": "admin/configuration/messages", "title": "Thelia Mailing Templates"},
{"url": "admin/configuration/currencies", "title": "Currencies"},
{"url": "admin/configuration/templates", "title": "Thelia Product Templates"},
{"url": "admin/configuration/attributes", "title": "Thelia Product Attributes"},
{"url": "admin/configuration/shipping_zones", "title": "Thelia Shipping zones"},
{"url": "admin/configuration/countries", "title": "Countries"},
{"url": "admin/configuration/profiles", "title": "Administration profiles"},
{"url": "admin/configuration/administrators", "title": "Back-office users"},
{"url": "admin/configuration/mailingSystem", "title": "Thelia Mailing System"},
{"url": "admin/configuration/adminLogs", "title": "Administration logs"},
{"url": "admin/configuration/features", "title": "Thelia Product Features"},
{"url": "admin/configuration/advanced", "title": "Advanced configuration"},
{"url": "admin/modules", "title": "Modules"},
{"url": "admin/hooks", "title": "Hooks"},
{"url": "admin/module-hooks", "title": "Modules attachments"},
{"url": "admin/configuration/taxes_rules", "title": "Taxes rules"},
{"url": "admin/configuration/languages", "title": "Thelia Languages"},
{"url": "admin/configuration/translations", "title": "Translation"},
{"url": "admin/brand", "title": "Brands"},
{"url": "admin/export", "title": "Exports"},
{"url": "admin/import", "title": "Imports"},
{"url": "admin/sales", "title": "Sales management"},
{"url": "admin/logout", "title": "Welcome"}
];
casper.on('page.error', function(msg, trace) {
this.echo("Error: " + msg, "ERROR");
errors.push(msg);
});
casper.on('resource.error', function(resourceError) {
var message = [
"Failed to load resource :", resourceError.url,
"-", resourceError.errorCode,
":", resourceError.errorString
].join(' ');
this.echo(message, "ERROR");
resourceErrors.push(message);
});
casper.start(thelia2_base_url + 'admin/login', function() {
test.comment('Login to back Office');
// trick too update the number of planned tests : 100 - 2 - (2x number of urls) !!
test.skip(98 - (pages.length * 2));
test.assertTitle("Welcome - Thelia Back Office");
test.assertExists('body.login-page', "This is the login page");
if (screenshot_enabled) {
this.capture(screenshot_dir + "login.png");
}
casper.evaluate(function(username, password) {
document.querySelector('#username').value = username;
document.querySelector('#password').value = password;
}, administrator.login, administrator.password);
this.click('body.login-page button[type="submit"]');
this.echo('Waiting...');
});
casper.then(function(){
this.echo('Done');
this.echo('Processing ' + pages.length + ' URLs');
casper.eachThen(pages, function(response) {
var page = response.data;
this.echo('Loading page : ' + page.url);
casper.thenOpen(thelia2_base_url + page.url);
casper.waitForSelector("footer.footer",
function success() {
var pageTitle = this.getTitle().replace(" - Thelia Back Office", "");
var imageName = page.url + ".png";
test.assertExists(
"footer.footer",
"Page " + page.url + " [" + pageTitle + "] loaded"
);
test.assertEquals(
pageTitle,
page.title,
"The page title is correct : " + pageTitle
);
if (screenshot_enabled) {
this.capture(screenshot_dir + imageName);
}
},
function fail() {
// try to catch exception
if (this.exists('span.exception_title')) {
var exceptionTitle = this.fetchText('span.exception_title');
var exceptionMessage = this.fetchText('span.exception_message');
this.echo(
"Exception title : " + exceptionTitle + " " + exceptionMessage,
"ERROR"
);
}
test.assertExists(
"footer.footer",
"Page " + page.url + " can't be loaded !"
);
}
);
});
});
casper.run(function() {
test.done();
if (errors.length > 0) {
this.echo(errors.length + ' JavaScript errors found', "WARNING");
} else {
this.echo('No Javascript errors found', "INFO");
}
if (resourceErrors.length > 0) {
this.echo(resourceErrors.length + ' Resources errors found', "WARNING");
} else {
this.echo('No resources errors found', "INFO");
}
casper.exit();
});
});

View File

@@ -0,0 +1,17 @@
casper.test.comment('== Front Homepage ==');
casper.test.begin('Front Homepage', 2, function suite(test) {
casper.start(thelia2_base_url, function() {
test.assertTitle(thelia2_store_name, "This is the home page : " + this.getTitle());
test.assertExists('form#form-search', "main search form is found");
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/10_home.png');
}
});
casper.run(function() {
test.done();
});
});

View File

@@ -0,0 +1,139 @@
casper.test.comment('== Register ==');
casper.test.begin('Register', 15, function suite(test) {
var newEmail = '';
casper.start(thelia2_base_url + "register", function() {
test.assertTitle("Register - " + thelia2_store_name, "title is the one expected");
test.assertExists('form#form-register', "register form is found");
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/20_register.png');
}
casper.test.comment('== Register blank account');
this.fill('form#form-register', {
'thelia_customer_create[title]': '',
'thelia_customer_create[firstname]': '',
'thelia_customer_create[lastname]': '',
'thelia_customer_create[email]': '',
'thelia_customer_create[phone]': '',
'thelia_customer_create[cellphone]': '',
'thelia_customer_create[company]': '',
'thelia_customer_create[address1]': '',
'thelia_customer_create[address2]': '',
'thelia_customer_create[zipcode]': '',
'thelia_customer_create[city]': '',
'thelia_customer_create[country]': '',
'thelia_customer_create[password]': '',
'thelia_customer_create[password_confirm]': '',
'thelia_customer_create[newsletter]': ''
}, true);
});
casper.then(function() {
casper.test.comment('== Register thelia account');
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/20_register-ko.png');
}
test.assertExists('.group-title.has-error', 'title can not be empty');
test.assertExists('.group-firstname.has-error', 'firstname can not be empty');
test.assertExists('.group-lastname.has-error', 'lastname can not be empty');
test.assertExists('.group-email.has-error', 'email can not be empty');
test.assertExists('.group-address1.has-error', 'address1 can not be empty');
test.assertExists('.group-zip.has-error', 'zipcode can not be empty');
test.assertExists('.group-city.has-error', 'city can not be empty');
test.assertExists('.group-password.has-error', 'password can not be empty');
test.assertExists('.group-password_confirm.has-error', 'password confirm can not be empty');
this.fill('form#form-register', {
'thelia_customer_create[title]': 1,
'thelia_customer_create[firstname]': 'thelia',
'thelia_customer_create[lastname]': 'thelia',
'thelia_customer_create[email]': 'test@thelia.net',
'thelia_customer_create[email_confirm]': 'test@thelia.net',
'thelia_customer_create[phone]': '',
'thelia_customer_create[cellphone]': '',
'thelia_customer_create[company]': 'OpenStudio',
'thelia_customer_create[address1]': '4 rue Rochon',
'thelia_customer_create[address2]': '',
'thelia_customer_create[zipcode]': '63000',
'thelia_customer_create[city]': 'Clermont-Ferrand',
'thelia_customer_create[country]': 64,
'thelia_customer_create[password]': 'thelia',
'thelia_customer_create[password_confirm]': 'thelia',
'thelia_customer_create[newsletter]': ''
}, false);
this.click('form#form-register button[type="submit"]');
});
casper.waitForSelector(
'.group-email .help-block',
function(){
test.assertSelectorHasText('.group-email .help-block', 'This email already exists.');
// generate a new email and save it
// we're going to use this new account later
newEmail = Math.random().toString(36).substr(2,7) + '@thelia.net';
thelia_customer.email = newEmail;
this.fill('form#form-register', {
'thelia_customer_create[email]': newEmail,
'thelia_customer_create[email_confirm]': newEmail,
'thelia_customer_create[password]': 'thelia',
'thelia_customer_create[password_confirm]': 'thelia'
}, false);
this.click('form#form-register button[type="submit"]');
},
function(){
this.die("Selector '.group-email .help-block' not found. It should contain 'This email already exists'");
},
thelia_default_timeout
);
casper.waitForSelector(
'.navbar-customer a.account',
function() {
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/20_register-ok.png');
}
test.assertSelectorHasText('.navbar-customer a.account', 'My Account');
test.assertExists('a.logout', 'Logout button exists');
casper.test.comment('== Logout');
this.click('a.logout');
},
function(){
this.die("'My account' button not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'a.login',
function() {
test.assertExists('a.login', 'Login button exists');
},
function() {
this.die('Login button doesn\'t exist');
},
thelia_default_timeout
);
casper.run(function() {
test.done();
});
});

View File

@@ -0,0 +1,102 @@
casper.test.comment('== Login ==');
casper.test.begin('Login', 5, function suite(test) {
casper.start(thelia2_base_url + "login", function() {
test.assertTitle("Login - " + thelia2_store_name, "title is the one expected");
test.assertExists('form#form-login', "login form is found");
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/30_login.png');
}
casper.test.comment('== Login with a bad account');
this.fill('form#form-login', {
'thelia_customer_login[account]': "1"
}, false);
});
casper.then(function(){
casper.evaluate(function(username, password) {
document.querySelector('#email').value = username;
document.querySelector('#password').disabled = false;
document.querySelector('#password').value = password;
}, 'chuck-norris@thelia.net', 'thelia');
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/30_login-ko-0.png');
}
this.click('form#form-login button[type="submit"]');
});
casper.waitForSelector(
'form#form-login .alert-danger',
function(){
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/30_login-ko.png');
}
test.assertSelectorHasText('form#form-login .alert-danger', 'Wrong email or password. Please try again');
casper.test.comment('== Login with a good account');
casper.evaluate(function(username, password) {
document.querySelector('#email').value = username;
document.querySelector('#password').disabled = false;
document.querySelector('#password').value = password;
document.querySelector('#remerber_me').checked = false;
}, 'test@thelia.net', 'azerty');
this.click('form#form-login button[type="submit"]');
},
function(){
this.die("Selector 'form#form-login .alert-danger' not found. It should contain the message 'Wrong email or password. Please try again'");
},
thelia_default_timeout
);
casper.waitForSelector(
'a.logout',
function(){
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/30_login-ok.png');
}
test.assertExists('a.logout', 'Logout button exists');
casper.test.comment('== Logout');
this.click('a.logout');
},
function(){
this.die("Logout button not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'a.login',
function() {
test.assertExists('a.login', 'Login button exists');
casper.evaluate(function(username, password) {
document.querySelector('#email-mini').value = username;
document.querySelector('#password-mini').value = password;
}, thelia_customer.email, thelia_customer.password);
this.click('form#form-login-mini button[type="submit"]');
},
function() {
this.die('Login button not found');
},
thelia_default_timeout
);
casper.run(function() {
test.done();
});
});

View File

@@ -0,0 +1,76 @@
casper.test.comment('== Cart ==');
casper.test.begin('Cart', 5, function suite(test) {
var productUrl = '';
casper.start(thelia2_base_url, function() {
var productsUrl = this.getElementsAttribute('a.product-info', 'href');
productUrl = productsUrl[Math.floor(Math.random() * productsUrl.length)];
this.echo("product : " + productUrl);
this.thenOpen(productUrl, function() {
this.echo(this.getTitle());
});
});
casper.waitForSelector(
"#pse-submit",
function(){
test.assertExists("#pse-submit", "Add to cart button exists");
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/40_product.png');
}
this.echo("Submit add to cart");
var isDisabled = this.evaluate(function() {
return document.querySelector("#pse-submit").hasAttribute('disabled');
});
if (isDisabled) {
this.skipTest("This product doesn't have any quantity")
}
this.click("#pse-submit");
},
function(){
this.die("Add to cart button not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'.bootbox h3.text-center',
function() {
//this.echo(this.getHTML());
test.assertSelectorHasText('.bootbox h3.text-center', 'The product has been added to your cart');
if (screenshot_enabled) {
this.captureSelector(screenshot_dir + 'front/40_added-to-cart.png', '.bootbox');
}
},
function(){
this.die("'The product has been added to your cart' pop-in not found");
},
thelia_default_timeout
);
casper.thenOpen(thelia2_base_url + "cart", function() {
this.echo(this.getTitle());
test.assertExists("#cart .table-cart", "Cart table exists");
test.assertElementCount("#cart .table-cart tbody tr h3.name a", 1, "Cart contains 1 product")
var link = this.getElementInfo('#cart .table-cart tbody tr h3.name a');
test.assertTruthy( link.attributes.href == productUrl, "This is the right product in cart");
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/40_cart.png');
}
});
casper.run(function() {
test.done();
});
});

View File

@@ -0,0 +1,54 @@
casper.test.comment('== Order process ==');
casper.test.begin('Order process', 4, function suite(test) {
casper.start(thelia2_base_url + "order/delivery", function goToDelivery() {
casper.waitForSelector(
'#delivery-module-list-block .radio',
function then() {
casper.test.comment('== Page loaded : ' + this.getCurrentUrl());
test.assertTitle("Billing and delivery - Cart - " + thelia2_store_name, "title is the one expected for url : " + this.getCurrentUrl());
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/50_delivery_list.png');
}
test.assertEval(function () {
return __utils__.findAll("#form-cart-delivery table.table-address tr").length >= 1;
}, "We expect at least one delivery address");
this.click('form#form-cart-delivery button[type="submit"]');
},
function timeout() {
test.assertElementCount("table.table-cart-mini tbody tr", 1, "cart contain 1 product");
if (this.getCurrentUrl() == thelia2_base_url + "order/invoice") {
test.info("with a virtual product, the delivery page is skipped");
test.skip(1);
} else {
this.die("impossible to load delivery methods");
}
}
);
});
casper.waitForSelector(
'.footer-container',
function(){
test.assertTitle("My order - Cart - " + thelia2_store_name, "title is the one expected for url : " + this.getCurrentUrl());
test.assertElementCount("table.table-cart tbody tr", 1, "cart contain 1 product");
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/50_delivery_order.png');
}
},
function(){
this.die("The 'title' tag didn't change");
},
thelia_default_timeout
);
casper.run(function() {
test.done();
});
});

View File

@@ -0,0 +1,249 @@
casper.test.comment('== Newsletter ==');
casper.test.begin('Newsletter', 12, function suite(test) {
var newEmail = '';
casper.start(thelia2_base_url + "newsletter", function() {
if (this.exists('.navbar-customer .logout')) {
this.click('.navbar-customer .logout');
}
});
casper.thenOpen(thelia2_base_url + "newsletter", function(){
test.assertTitle("Newsletter - Thelia V2", "title is the one expected");
});
casper.waitForSelector(
'.navbar-customer .register',
function() {
test.assertExists('.navbar-customer .register', 'user is disconnected');
test.assertExists('form#form-newsletter', "newsletter form is found");
casper.test.comment("== User isn't connected");
test.assertExists('form#form-newsletter #firstname_newsletter', 'firstname field is displayed');
test.assertExists('form#form-newsletter #lastname_newsletter', 'lastname field is displayed');
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/60_newsletter.png');
}
casper.test.comment('== Newsletter blank submission');
this.fill('form#form-newsletter', {
'thelia_newsletter[email]': '',
'thelia_newsletter[firstname]': 'Thelia',
'thelia_newsletter[lastname]': 'Thelia'
}, true);
},
function(){
this.die("Select '.navbar-customer .register' not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'#email_newsletter',
function(){
casper.evaluate(function(email) {
document.querySelector('#email_newsletter').value = email;
}, '');
this.click('form#form-newsletter button[type="submit"]');
},
function(){
this.die("'email' field in newsletter form not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'form#form-newsletter .group-email.has-error',
function(){
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/60_newsletter-ko-0.png');
}
test.assertExists('form#form-newsletter .group-email.has-error', 'email can not be empty');
},function(){
this.die("Can't find newsletter form error");
},
thelia_default_timeout
);
casper.waitForSelector(
'form#form-newsletter',
function(){
casper.test.comment('== Test submission');
this.fill('form#form-newsletter', {
'thelia_newsletter[email]': 'test@thelia.net',
'thelia_newsletter[firstname]': 'Thelia',
'thelia_newsletter[lastname]': 'Thelia'
}, true);
casper.evaluate(function(email) {
document.querySelector('#email_newsletter').value = email;
}, 'test@thelia.net');
this.click('form#form-newsletter button[type="submit"]');
},
function() {
this.die("Newsletter form not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'form#form-newsletter',
function(){
casper.test.comment('== Existing email on submission');
this.fill('form#form-newsletter', {
'thelia_newsletter[email]': 'test@thelia.net',
'thelia_newsletter[firstname]': 'Thelia',
'thelia_newsletter[lastname]': 'Thelia'
}, true);
casper.evaluate(function(email) {
document.querySelector('#email_newsletter').value = email;
}, 'test@thelia.net');
this.click('form#form-newsletter button[type="submit"]');
},
function(){
this.die("Newsletter form not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'form#form-newsletter .group-email.has-error',
function(){
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/60_newsletter-ko-0.png');
}
test.assertExists('form#form-newsletter .group-email.has-error', 'email already exist');
},
function(){
this.die("Newsletter form error message not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'form#form-newsletter',
function(){
casper.test.comment('== Great email on submission');
newEmail = Math.random().toString(36).substr(2,7) + '@thelia.net';
this.fill('form#form-newsletter', {
'thelia_newsletter[email]': newEmail,
'thelia_newsletter[firstname]': 'Thelia',
'thelia_newsletter[lastname]': 'Thelia'
}, true);
casper.evaluate(function(email) {
document.querySelector('#email_newsletter').value = email;
}, newEmail);
this.click('form#form-newsletter button[type="submit"]');
},
function(){
this.die("Newsletter form not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'form#form-newsletter .group-email.has-success',
function(){
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/60_newsletter-ok-0.png');
}
test.assertExists('form#form-newsletter .group-email.has-success', 'subscription with success');
},
function(){
this.die("Newsletter form success message not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'#email-mini',
function(){
casper.test.comment('== Login user');
casper.evaluate(function(username, password) {
document.querySelector('#email-mini').value = username;
document.querySelector('#password-mini').value = password;
}, 'test@thelia.net', 'azerty');
this.click('form#form-login-mini button[type="submit"]');
},
function(){
this.die("Newsletter form 'email-mini' field not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'a.logout',
function(){
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/60_newsletter-ok-1.png');
}
test.assertExists('a.logout', 'Logout button exists');
test.assertDoesntExist('form#form-newsletter #firstname_newsletter', "firstname field doesn't exist");
test.assertDoesntExist('form#form-newsletter #lastname_newsletter', "lastname field doesn't exist");
},
function(){
this.die("Logout button not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'form#form-newsletter',
function(){
casper.test.comment('== Subscribe again');
this.fill('form#form-newsletter', {
'thelia_newsletter[email]': 'test@thelia.net'
}, true);
casper.evaluate(function(email) {
document.querySelector('#email_newsletter').value = email;
}, 'test@thelia.net');
this.click('form#form-newsletter button[type="submit"]');
},
function(){
this.die("Newsletter form not found");
},
thelia_default_timeout
);
casper.waitForSelector(
'form#form-newsletter .group-email.has-error',
function(){
if (screenshot_enabled) {
this.capture(screenshot_dir + 'front/60_newsletter-ko-1.png');
}
test.assertExists('form#form-newsletter .group-email.has-error', 'this user is already registered');
},
function(){
this.die("Newsletter form error message not found");
},
thelia_default_timeout
);
casper.run(function() {
test.done();
});
});

View File

@@ -0,0 +1,141 @@
var xp = require('casper').selectXPath;
casper.test.comment('== Hook - changing position ==');
casper.test.begin('Front Homepage', 12, function suite(test) {
var modules = {
newProducts: {
// block id in FO
id: "products-new",
// title in BO
title: "Block New Products"
},
promoProducts: {
id: "products-offer",
title: "Block Promo Products"
}
};
var modulePromoProductId = null;
// Try to login
casper.start(thelia2_base_url + 'admin/login', function() {
test.comment('Login to back Office');
test.assertTitle("Welcome - Thelia Back Office");
test.assertExists('div.loginpage', "This is the login page");
casper.evaluate(function(username, password) {
document.querySelector('#username').value = username;
document.querySelector('#password').value = password;
}, administrator.login, administrator.password);
this.click('div.loginpage button[type="submit"]');
});
casper.waitForSelector('body .homepage', function(){
test.assertTitle("Back-office home - Thelia Back Office", "This is the dashboard");
});
// Get current order
casper.thenOpen(thelia2_base_url, function() {
var order = [], i;
test.comment('Get current order on home page');
test.assertTitle(thelia2_store_name, "This is the home page : " + this.getTitle());
homeModules = this.getElementsInfo('#content > section');
for (i=0 ; i<homeModules.length ; i++){
order.push(homeModules[i].attributes['id'])
}
test.assertTruthy(
homeModules.length == 2,
"2 modules on home page : " + order.join(", ")
);
test.assertTruthy(
order.join() == [modules.newProducts.id, modules.promoProducts.id].join(),
"The order of the module on the home page is good : " + order.join(', ')
);
});
// Change Order
casper.thenOpen(thelia2_base_url + 'admin/module-hooks', function() {
test.comment('Change order');
test.assertTitle("Hooks position - Thelia Back Office", "This is the page to manage modules hooks");
var linePromoProducts = null;
linePromoProducts = this.getElementInfo(
xp('//tr[@class="hook-module"]/td[normalize-space(.)="' + modules.promoProducts.title + '"]/..')
);
test.assertTruthy(linePromoProducts != null, "The module Promo Product exist");
modulePromoProductId = linePromoProducts.attributes['data-module-id'];
// trigger position change
this.click('tr[data-module-id="' + modulePromoProductId + '"] a.u-position-up');
casper.waitFor(
function(){
var linePromoProductPosition = this.getElementInfo(
'tr[data-module-id="' + modulePromoProductId + '"] .moduleHookPositionChange'
);
return linePromoProductPosition.text == "1";
},
function(){
test.comment('Position for hooks position has changed');
}
);
});
// Get new order
// Get current order
casper.thenOpen(thelia2_base_url, function() {
test.comment('Get new order on home page');
test.assertTitle(thelia2_store_name, "This is the home page : " + this.getTitle());
homeModules = this.getElementsInfo('#content > section');
test.assertTruthy(
homeModules.length == 2,
"2 modules on home page"
);
order = [
homeModules[0].attributes['id'],
homeModules[1].attributes['id']
];
test.assertTruthy(
order.join() == [modules.promoProducts.id, modules.newProducts.id].join(),
"The order of the module on the home page has change : " + order.join(', ')
);
});
casper.thenOpen(thelia2_base_url + 'admin/logout', function() {
test.comment('logout');
test.assertTitle("Welcome - Thelia Back Office");
});
casper.run(function() {
test.done();
});
});

View File

@@ -0,0 +1,221 @@
var xp = require('casper').selectXPath;
casper.test.comment('== Hook - changing position ==');
casper.test.begin('Front Homepage', 22, function suite(test) {
var modules = {
newProducts: {
// block id in FO
id: "products-new",
// title in BO
title: "Block New Products"
},
promoProducts: {
id: "products-offer",
title: "Block Promo Products"
},
blockCurrency: {
id: 'nav-currency',
title: 'Block Currency'
}
};
// Try to login
casper.start(thelia2_base_url + 'admin/login', function() {
test.comment('Login to back Office');
test.assertTitle("Welcome - Thelia Back Office");
test.assertExists('div.loginpage', "This is the login page");
casper.evaluate(function(username, password) {
document.querySelector('#username').value = username;
document.querySelector('#password').value = password;
}, administrator.login, administrator.password);
this.click('div.loginpage button[type="submit"]');
});
casper.waitForSelector('body .homepage', function(){
test.assertTitle("Back-office home - Thelia Back Office", "This is the dashboard");
});
// be sure to have the good configuration
casper.thenOpen(thelia2_base_url, function() {
test.comment('Get current configuration on home page');
test.assertTitle(thelia2_store_name, "This is the home page : " + this.getTitle());
// 2 modules in hook home.body
test.assertElementCount(
'#content > section',
2,
"2 modules on home page (hook: home.body)"
);
// module currency exists
test.assertExists(
".nav-secondary .navbar-currency",
"Module Currency selector exists"
);
// module currency exists
test.assertExists(
".nav-secondary .navbar-currency",
"Module Currency selector exists"
);
});
// deactivation of module hook
casper.thenOpen(thelia2_base_url + 'admin/module-hooks', function() {
test.comment('deactivate module hook for Promo products');
test.assertTitle("Hooks position - Thelia Back Office", "This is the page to manage modules hooks");
var moduleHookTag = null,
hookId = null;
moduleHookTag = this.getElementInfo(
xp('//tr[@class="hook-module"]/td[normalize-space(.)="' + modules.promoProducts.title + '"]/..')
);
test.assertTruthy(moduleHookTag != null, "The module Promo Product exist");
hookId = moduleHookTag.attributes['data-module-id'];
// test if activated
test.assertExist(
'tr[data-module-id="' + hookId + '"] .switch-on',
'module hook for Promo products is activated'
);
// trigger toggle activation
this.click('tr[data-module-id="' + hookId + '"] div.module-hook-activation .switch-left');
test.comment('waiting...');
casper.waitForSelector('tr[data-module-id="' + hookId + '"] .switch-off', function(){
test.comment('Status for hook position has changed');
});
});
// deactivation of module Block Currency
casper.thenOpen(thelia2_base_url + 'admin/modules', function() {
var moduleIdTag = null,
moduleId = null;
test.comment('deactivate module Block Currency');
test.assertTitle("Modules - Thelia Back Office", "This is the page to manage modules hooks");
moduleIdTag = this.getElementInfo(
xp('//tr/td[normalize-space(.)="' + modules.blockCurrency.title + '"]/../td[1]')
);
test.assertTruthy(moduleIdTag != null, "The module Block Currency exists");
moduleId = moduleIdTag.text;
// test if activated
test.assertExist(
'.make-switch[data-id="' + moduleId + '"] .switch-on',
'module Block Currency is activated'
);
// trigger toggle activation
this.click('.make-switch[data-id="' + moduleId + '"] .switch-left');
test.comment('waiting...');
casper.waitForSelector('.make-switch[data-id="' + moduleId + '"] .switch-off', function(){
test.comment('Status for module has changed');
});
});
// deactivation of hook main.navbar-primary
casper.thenOpen(thelia2_base_url + 'admin/hooks', function() {
test.comment('deactivate hook main.navbar-primary');
test.assertTitle("Hooks - Thelia Back Office", "This is the page to manage modules hooks");
var hookTag = null,
hookId = null;
hookTag = this.getElementInfo(
xp('//tr/td/a[normalize-space(.)="main.navbar-primary"]/../../td[1]')
);
test.assertTruthy(hookTag != null, "The hook main.navbar-primary exists");
hookId = hookTag.text;
// test if activated
test.assertExist(
'.make-switch[data-id="' + hookId + '"] .switch-on',
'hook main.navbar-primary is activated'
);
// trigger toggle activation
this.click('.make-switch[data-id="' + hookId + '"] .switch-left');
test.comment('waiting...');
casper.waitForSelector('.make-switch[data-id="' + hookId + '"] .switch-off', function(){
test.comment('Status for hook has changed');
});
});
// Test the new home page
casper.thenOpen(thelia2_base_url, function() {
test.comment('Get new configuration on home page');
test.assertTitle(thelia2_store_name, "This is the home page : " + this.getTitle());
// 1 module in hook home.body
test.assertElementCount(
'#content > section',
1,
"1 module on home page"
);
test.assertDoesntExist(
modules.promoProducts.id,
"The module on the home page is ok"
);
// module currency should not exist
test.assertDoesntExist(
".nav-secondary .navbar-currency",
"Module Currency selector doesn't exist"
);
// module currency exists
test.assertDoesntExist(
"header.container .nav-main",
"Main navigation doesn't exists"
);
});
casper.thenOpen(thelia2_base_url + 'admin/logout', function() {
test.comment('logout');
test.assertTitle("Welcome - Thelia Back Office", "This is the good title. url: " + this.getCurrentUrl());
});
casper.run(function() {
test.done();
});
});