[MERGE] with parent branch

bzr revid: dizzy.zala@gmail.com-20140326101812-jv4bvrruwfy93wv9
This commit is contained in:
Dharmraj Jhala (OpenERP)
2014-03-26 15:48:12 +05:30
2 changed files with 52 additions and 246 deletions
@@ -1,103 +0,0 @@
function waitFor (ready, callback, timeout, timeoutMessageCallback) {
timeout = timeout || 10000;
var start = new Date().getTime();
var condition = ready();
var interval = setInterval(function() {
if ((new Date().getTime() - start < timeout) && !condition ) {
condition = ready();
} else {
if(!condition) {
var message = timeoutMessageCallback ? timeoutMessageCallback() : "Timeout after "+timeout+" ms";
console.log('{ "event": "error", "message": "'+message+'" }');
console.log("Waiting for...\n"+ready);
phantom.exit(1);
} else {
clearInterval(interval);
callback();
}
}
}, 100);
}
function run (test) {
var options = JSON.parse(phantom.args);
var timeout = options.timeout ? Math.round(parseFloat(options.timeout)*1000) : 60000;
var scheme = options.scheme ? options.scheme+'://' : 'http://';
var host = options.host ? options.host : 'localhost';
var port = options.port ? ':'+options.port : '';
var path = options.path ? options.path : '/login';
var queryParams = [];
if (options.db) queryParams.push('db='+options.db);
if (options.user) queryParams.push('login='+options.user);
if (options.password) queryParams.push('key='+options.password);
if (options.redirect) queryParams.push('redirect='+options.redirect);
var query = queryParams.length > 0 ? '?'+queryParams.join('&') : '';
var hashParams = [];
if (options.action) hashParams.push('action='+options.action);
var hash = hashParams.length > 0 ? '#'+hashParams.join('&') : '';
var url = scheme+host+port+path+query+hash;
var page = require('webpage').create();
page.viewportSize = { width: 1440, height: 900 };
page.onError = function(message, trace) {
console.log('{ "event": "error", "message": "'+message+'"}');
phantom.exit(1);
};
page.onAlert = function(message) {
console.log(message);
phantom.exit(1);
};
page.onConsoleMessage = function(message) {
console.log(message);
try {
var result = JSON.parse(message);
if (result.event === 'success') {
phantom.exit(0);
} else {
phantom.exit(1);
}
} catch (exception) {
phantom.exit(1);
}
};
page.onCallback = function(data) {
if (data.event && data.event === 'start') {
test(page, timeout);
}
};
var maxRetries = 10;
var retryDelay = 1000; // ms
var tries = 0;
page.open(url, function openPage (status) {
if (status !== 'success') {
tries++;
if (tries < maxRetries) {
setTimeout(function () {
page.open(url, openPage);
}, retryDelay);
} else {
console.log('{ "event": "error", "message": "'+url+' failed to load '+tries+' times ('+status+')"}');
phantom.exit(1);
}
} else {
page.evaluate(function () {
window.callPhantom({ event: 'start' });
});
}
});
}
module.exports = {
waitFor: waitFor,
run: run
}
@@ -2,234 +2,143 @@
'use strict';
var website = openerp.website;
var _t = openerp._t;
website.EditorBar.include({
start: function () {
this.registerTour(new website.EditorShopTour(this));
var res = this._super();
return res;
this.registerTour(new website.Tour.Shop(this));
return this._super();
},
});
website.EditorShopTour = website.Tour.extend({
website.Tour.Shop = website.Tour.extend({
id: 'shop',
name: "Create a product",
testPath: '/shop',
init: function (editor) {
init: function () {
var self = this;
self.steps = [
{
title: "Welcome to your shop",
content: "You successfully installed the e-commerce. This guide will help you to create your product and promote your sales.",
template: self.popover({ next: "Start Tutorial", end: "Skip It" }),
title: _t("Welcome to your shop"),
content: _t("You successfully installed the e-commerce. This guide will help you to create your product and promote your sales."),
popover: { next: _t("Start Tutorial"), end: _t("Skip It") },
},
{
element: '#content-menu-button',
placement: 'left',
title: "Create your first product",
content: "Click here to add a new product.",
template: self.popover({ fixed: true }),
title: _t("Create your first product"),
content: _t("Click here to add a new product."),
popover: { fixed: true },
},
{
element: 'a[data-action=new_product]',
placement: 'left',
title: "Create a new product",
content: "Select 'New Product' to create it and manage its properties to boost your sales.",
template: self.popover({ fixed: true }),
title: _t("Create a new product"),
content: _t("Select 'New Product' to create it and manage its properties to boost your sales."),
popover: { fixed: true },
},
{
element: '.modal:contains("New Product") input[type=text]',
element: '.modal #editor_new_product input[type=text]',
sampleText: 'New Product',
placement: 'right',
title: "Choose name",
content: "Enter a name for your new product then click 'Continue'.",
title: _t("Choose name"),
content: _t("Enter a name for your new product then click 'Continue'."),
},
{
waitNot: '.modal input[type=text]:not([value!=""])',
element: '.modal button.btn-primary',
placement: 'right',
title: "Create Product",
content: "Click <em>Continue</em> to create the product.",
title: _t("Create Product"),
content: _t("Click <em>Continue</em> to create the product."),
},
{
waitFor: '#website-top-navbar button[data-action="save"]:visible',
title: "New product created",
content: "This page contains all the information related to the new product.",
template: self.popover({ next: "Continue" }),
waitFor: 'body:has(button[data-action=save]:visible):has(.js_sale)',
title: _t("New product created"),
content: _t("This page contains all the information related to the new product."),
popover: { next: _t("Continue") },
},
{
element: '.product_price .oe_currency_value',
sampleText: '20.50',
placement: 'left',
title: "Change the price",
content: "Edit the price of this product by clicking on the amount.",
title: _t("Change the price"),
content: _t("Edit the price of this product by clicking on the amount."),
},
{
waitNot: '.product_price .oe_currency_value:containsExact(1.00)',
element: '#wrap img.img:first',
placement: 'top',
title: "Update image",
content: "Click here to set an image describing your product.",
title: _t("Update image"),
content: _t("Click here to set an image describing your product."),
},
{
element: 'button.hover-edition-button:visible',
placement: 'top',
title: "Update image",
content: "Click here to set an image describing your product.",
title: _t("Update image"),
content: _t("Click here to set an image describing your product."),
},
{
wait: 500,
element: '.well a.pull-right',
placement: 'bottom',
title: "Select an Image",
content: "Let's select an existing image.",
template: self.popover({ fixed: true }),
title: _t("Select an Image"),
content: _t("Let's select an existing image."),
popover: { fixed: true },
},
{
element: 'img[alt=imac]',
placement: 'bottom',
title: "Select an Image",
content: "Let's select an imac image.",
template: self.popover({ fixed: true }),
title: _t("Select an Image"),
content: _t("Let's select an imac image."),
popover: { fixed: true },
},
{
waitNot: 'img[alt=imac]',
element: '.modal-content button.save',
placement: 'bottom',
title: "Select this Image",
content: "Click to add the image to the product decsription.",
template: self.popover({ fixed: true }),
title: _t("Select this Image"),
content: _t("Click to add the image to the product decsription."),
popover: { fixed: true },
},
{
waitNot: '.modal-content:visible',
element: 'button[data-action=snippet]',
placement: 'bottom',
title: "Describe the Product",
content: "Insert blocks like text-image, or gallery to fully describe the product.",
template: self.popover({ fixed: true }),
title: _t("Describe the Product"),
content: _t("Insert blocks like text-image, or gallery to fully describe the product."),
popover: { fixed: true },
},
{
snippet: '#snippet_structure .oe_snippet:eq(7)',
placement: 'bottom',
title: "Drag & Drop a block",
content: "Drag the 'Big Picture' block and drop it in your page.",
template: self.popover({ fixed: true }),
title: _t("Drag & Drop a block"),
content: _t("Drag the 'Big Picture' block and drop it in your page."),
popover: { fixed: true },
},
{
element: 'button[data-action=save]',
placement: 'right',
title: "Save your modifications",
content: "Once you click on save, your product is updated.",
template: self.popover({ fixed: true }),
title: _t("Save your modifications"),
content: _t("Once you click on save, your product is updated."),
popover: { fixed: true },
},
{
waitFor: '#website-top-navbar button[data-action="edit"]:visible',
element: '.js_publish_management button.js_publish_btn.btn-danger',
placement: 'top',
title: "Publish your product",
content: "Click to publish your product so your customers can see it.",
title: _t("Publish your product"),
content: _t("Click to publish your product so your customers can see it."),
},
{
waitFor: '.js_publish_management button.js_publish_btn.btn-success:visible',
title: "Congratulations",
content: "Congratulations! You just created and published your first product.",
template: self.popover({ next: "Close Tutorial" }),
title: _t("Congratulations"),
content: _t("Congratulations! You just created and published your first product."),
popover: { next: _t("Close Tutorial") },
},
];
return this._super();
}
});
website.EditorShopTest = website.Tour.extend({
id: 'shop_buy_product',
name: "Try to buy products",
path: '/shop',
testPath: '/shop',
init: function (editor) {
var self = this;
self.steps = [
{
title: 'begin-test',
template: self.popover({ next: "Start Test"}),
backdrop: true,
},
{
title: "select ipod",
element: '.oe_product_cart a:contains("iPod")',
},
{
title: "select ipod 32Go",
element: 'input[name="product_id"]:not([checked])',
},
{
title: "click on add to cart",
waitFor: 'input[name="product_id"]:eq(1)[checked]',
element: 'form[action="/shop/add_cart/"] button',
},
{
title: "add suggested",
element: 'form[action="/shop/add_cart/"] button.btn-link:contains("Add to Cart")',
},
{
title: "add one more iPod",
waitFor: '.my_cart_quantity:contains(2)',
element: '#mycart_products tr:contains("iPod: 32 Gb") a.js_add_cart_json:eq(1)',
},
{
title: "remove Headphones",
waitFor: '#mycart_products tr:contains("iPod: 32 Gb") input.js_quantity[value=2]',
element: '#mycart_products tr:contains("Apple In-Ear Headphones") a.js_add_cart_json:first',
},
{
title: "set one iPod",
waitNot: '#mycart_products tr:contains("Apple In-Ear Headphones")',
element: '#mycart_products input.js_quantity',
sampleText: '1',
},
{
title: "go to checkout",
waitFor: '#mycart_products input.js_quantity[value=1]',
element: 'a[href="/shop/checkout/"]',
},
{
title: "test with input error",
element: 'form[action="/shop/confirm_order/"] button',
callback: function (tour) {
$("input[name='phone']").val("");
},
},
{
title: "test without input error",
waitFor: 'form[action="/shop/confirm_order/"] .has-error',
element: 'form[action="/shop/confirm_order/"] button',
callback: function (tour) {
if ($("input[name='name']").val() === "")
$("input[name='name']").val("website_sale-test-shoptest");
if ($("input[name='email']").val() === "")
$("input[name='email']").val("website_sale-test-shoptest@website_sale-test-shoptest.optenerp.com");
$("input[name='phone']").val("123");
$("input[name='street']").val("123");
$("input[name='city']").val("123");
$("input[name='zip']").val("123");
$("select[name='country_id']").val("21");
},
},
{
title: "Pay Now",
element: 'button:contains("Pay Now")',
},
{
title: "finish",
waitFor: '.oe_website_sale:contains("Thank you for your order")',
}
];
return this._super();
},
});
// for test without editor bar
$(document).ready(function () {
website.Tour.add(website.EditorShopTest);
});
}());