summaryrefslogtreecommitdiff
path: root/addons/website_links/static/src
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2019-03-25 10:05:27 +0000
committerChristophe Simonis <chs@odoo.com>2019-03-25 11:13:41 +0000
commit5df4746c9aa144e6e3fce44fea43dac1089a5c51 (patch)
treef4ce932a76563e26b8d131805d49b405fcf9ad8f /addons/website_links/static/src
parent39e71353c5d58f7af6b3270911a24d98b73cad4e (diff)
parent230ad8c381e927025efabff0f5f8c2debc432249 (diff)
[MERGE] forward port branch saas-12.2 up to 230ad8c381e
closes odoo/odoo#32088 Signed-off-by: Christophe Simonis <chs@odoo.com>
Diffstat (limited to 'addons/website_links/static/src')
-rw-r--r--addons/website_links/static/src/js/test_ui_flow.js84
-rw-r--r--addons/website_links/static/src/js/website_links.js5
-rw-r--r--addons/website_links/static/src/js/website_links_charts.js19
3 files changed, 99 insertions, 9 deletions
diff --git a/addons/website_links/static/src/js/test_ui_flow.js b/addons/website_links/static/src/js/test_ui_flow.js
new file mode 100644
index 00000000000..11872441308
--- /dev/null
+++ b/addons/website_links/static/src/js/test_ui_flow.js
@@ -0,0 +1,84 @@
+odoo.define('website_links.website_links_tour', function (require) {
+'use strict';
+
+var tour = require("web_tour.tour");
+
+tour.register('website_links_tour', {
+ test: true,
+ url: '/r',
+},
+ [
+ // 1. Create a tracked URL
+ {
+ content: "check that existing links are shown",
+ trigger: '#o_website_links_recent_links .btn_shorten_url_clipboard',
+ run: function () {}, // it's a check
+ },
+ {
+ content: "fill the form and submit it",
+ trigger: '#o_website_links_link_tracker_form input#url',
+ run: function () {
+ var url = window.location.host + '/aboutus';
+ $('#o_website_links_link_tracker_form input#url').val(url);
+ $('.o_website_links_utm_forms input#campaign-select').val(1).change();
+ $('.o_website_links_utm_forms input#channel-select').val(1).change();
+ $('.o_website_links_utm_forms input#source-select').val(1).change();
+ $('#btn_shorten_url').click();
+ },
+ },
+ // 2. Visit it
+ {
+ content: "check that link was created and visit it",
+ // Depending of the speed of `requests.get` from `_get_title_from_url`,
+ // the link name will either be "About us" (page title) or
+ // "http://url/aboutus" (page url).
+ extra_trigger: '#o_website_links_recent_links .truncate_text:first():contains("About us"), #o_website_links_recent_links .truncate_text:first():contains("aboutus")',
+ trigger: '#o_website_links_link_tracker_form #generated_tracked_link:contains("/r/")',
+ run: function () {
+ window.location.href = $('#generated_tracked_link').text();
+ },
+ },
+ {
+ content: "check that we landed on correct page with correct query strings",
+ trigger: '.s_title h1:containsExact("About us")',
+ run: function () {
+ var expectedUrl = "/aboutus?utm_campaign=Sale&utm_source=Search+engine&utm_medium=Website";
+ if (window.location.pathname + window.location.search !== expectedUrl) {
+ console.error("The link was not correctly created.");
+ }
+ window.location.href = '/r';
+ },
+ },
+ // 3. Check that counter got incremented and charts are correctly displayed
+ {
+ content: "filter recently used links",
+ trigger: '#filter-recently-used-links',
+ },
+ {
+ content: "visit link stats page",
+ trigger: '#o_website_links_recent_links a:containsExact("Stats"):first',
+ },
+ {
+ content: "check click number and ensure graphs are initialized",
+ extra_trigger: '.website_links_click_chart .title:contains("1 clicks")',
+ trigger: '.nvd3.nv-pieChart',
+ run: function () {}, // it's a check
+ },
+ {
+ content: "click on Last Month tab",
+ trigger: '.o_website_links_chart .graph-tabs a:contains("Last Month")',
+ },
+ {
+ content: "ensure tab is correctly resized",
+ trigger: '.nvd3.nv-lineChart',
+ run: function () {
+ var width = $('#last_month_charts .nvd3.nv-lineChart .nv-background rect').width();
+ if (width < 50) {
+ console.error("The graphs are probably not resized on tab change.");
+ }
+ },
+ },
+ ]
+);
+
+});
diff --git a/addons/website_links/static/src/js/website_links.js b/addons/website_links/static/src/js/website_links.js
index fd637079512..7ebb60c0c2c 100644
--- a/addons/website_links/static/src/js/website_links.js
+++ b/addons/website_links/static/src/js/website_links.js
@@ -7,7 +7,6 @@ var publicWidget = require('web.public.widget');
var _t = core._t;
var SelectBox = publicWidget.Widget.extend({
- xmlDependencies: ['/website_links/static/src/xml/recent_link.xml'],
events: {
'change': '_onChange',
},
@@ -106,6 +105,7 @@ var SelectBox = publicWidget.Widget.extend({
var RecentLinkBox = publicWidget.Widget.extend({
template: 'website_links.RecentLink',
+ xmlDependencies: ['/website_links/static/src/xml/recent_link.xml'],
events: {
'click .btn_shorten_url_clipboard': '_toggleCopyButton',
'click .o_website_links_edit_code': '_editCode',
@@ -459,6 +459,7 @@ publicWidget.registry.websiteLinks = publicWidget.Widget.extend({
* @param {Event} ev
*/
_onFormSubmit: function (ev) {
+ var self = this;
ev.preventDefault();
if ($('#btn_shorten_url').hasClass('btn-copy')) {
@@ -510,7 +511,7 @@ publicWidget.registry.websiteLinks = publicWidget.Widget.extend({
$('#generated_tracked_link').html(link.short_url);
$('#generated_tracked_link').css('display', 'inline');
- this.recentLinks._addLink(link);
+ self.recentLinks._addLink(link);
// Clean URL and UTM selects
$('#campaign-select').select2('val', '');
diff --git a/addons/website_links/static/src/js/website_links_charts.js b/addons/website_links/static/src/js/website_links_charts.js
index d4604f1718e..4d72e8e2cf7 100644
--- a/addons/website_links/static/src/js/website_links_charts.js
+++ b/addons/website_links/static/src/js/website_links_charts.js
@@ -188,6 +188,7 @@ publicWidget.registry.websiteLinksCharts = publicWidget.Widget.extend({
$('#all_time_charts').prepend(_t("There is no data to show"));
$('#last_month_charts').prepend(_t("There is no data to show"));
$('#last_week_charts').prepend(_t("There is no data to show"));
+ return;
}
var formattedClicksByDay = {};
@@ -202,27 +203,27 @@ publicWidget.registry.websiteLinksCharts = publicWidget.Widget.extend({
// Process all time line chart data
var now = moment();
- self.charts.all_time_bar = new BarChart(beginDate, now, formattedClicksByDay);
+ self.charts.all_time_bar = new BarChart(this, beginDate, now, formattedClicksByDay);
self.charts.all_time_bar.attachTo($('#all_time_clicks_chart'));
// Process month line chart data
beginDate = moment().subtract(30, 'days');
- self.charts.last_month_bar = new BarChart(beginDate, now, formattedClicksByDay);
+ self.charts.last_month_bar = new BarChart(this, beginDate, now, formattedClicksByDay);
self.charts.last_month_bar.attachTo($('#last_month_clicks_chart'));
// Process week line chart data
beginDate = moment().subtract(7, 'days');
- self.charts.last_week_bar = new BarChart(beginDate, now, formattedClicksByDay);
+ self.charts.last_week_bar = new BarChart(this, beginDate, now, formattedClicksByDay);
self.charts.last_week_bar.attachTo($('#last_week_clicks_chart'));
// Process pie charts
- self.charts.all_time_pie = new PieChart(_clicksByCountry);
+ self.charts.all_time_pie = new PieChart(this, _clicksByCountry);
self.charts.all_time_pie.attachTo($('#all_time_countries_charts'));
- self.charts.last_month_pie = new PieChart(_lastMonthClicksByCountry);
+ self.charts.last_month_pie = new PieChart(this, _lastMonthClicksByCountry);
self.charts.last_month_pie.attachTo($('#last_month_countries_charts'));
- self.charts.last_week_pie = new PieChart(_lastWeekClicksByCountry);
+ self.charts.last_week_pie = new PieChart(this, _lastWeekClicksByCountry);
self.charts.last_week_pie.attachTo($('#last_week_countries_charts'));
var rowWidth = $('#all_time_countries_charts').parent().width();
@@ -310,7 +311,11 @@ publicWidget.registry.websiteLinksCharts = publicWidget.Widget.extend({
_onGraphTabClick: function (ev) {
ev.preventDefault();
$('.graph-tabs li a').tab('show');
- _.chain(this.charts).pluck('chart').invoke('update'); // Force NVD3 to redraw the chart
+
+ setTimeout(function () {
+ // Force NVD3 to redraw the chart
+ window.dispatchEvent(new Event('resize'));
+ }, 0);
},
/**
* @private