diff --git a/addons/web_tour/static/src/js/running_tour_action_helper.js b/addons/web_tour/static/src/js/running_tour_action_helper.js index 4a8024ed2d9..3dc418b2558 100644 --- a/addons/web_tour/static/src/js/running_tour_action_helper.js +++ b/addons/web_tour/static/src/js/running_tour_action_helper.js @@ -102,14 +102,22 @@ var RunningTourActionHelper = core.Class.extend({ bubbles: true, })); } else if (values.$element.is("select")) { - var $options = values.$element.children("option"); + var $options = values.$element.find("option"); $options.prop("selected", false).removeProp("selected"); var $selectedOption = $options.filter(function () { return $(this).val() === text; }); if ($selectedOption.length === 0) { $selectedOption = $options.filter(function () { return $(this).text().trim() === text; }); } + const regex = /option\s+([0-9]+)/; + if ($selectedOption.length === 0 && regex.test(text)) { + // Extract position as 1-based, as the nth selectors. + const position = parseInt(regex.exec(text)[1]); + $selectedOption = $options.eq(position - 1); // eq is 0-based. + } $selectedOption.prop("selected", true); this._click(values); + // For situations where an `oninput` is defined. + values.$element.trigger("input"); } else { values.$element.focusIn(); values.$element.trigger($.Event( "keydown", {key: '_', keyCode: 95})); diff --git a/addons/website/static/src/snippets/s_searchbar/000.js b/addons/website/static/src/snippets/s_searchbar/000.js index 256994d7715..41c78dadb2c 100644 --- a/addons/website/static/src/snippets/s_searchbar/000.js +++ b/addons/website/static/src/snippets/s_searchbar/000.js @@ -64,15 +64,16 @@ publicWidget.registry.searchBar = publicWidget.Widget.extend({ for (const keyValue of urlParams.split('&')) { const [key, value] = keyValue.split('='); if (value && key !== 'search') { - this.options[key] = value; + // Decode URI parameters: revert + to space then decodeURIComponent. + this.options[decodeURIComponent(key.replace(/\+/g, '%20'))] = decodeURIComponent(value.replace(/\+/g, '%20')); } } } const pathParts = urlPath.split('/'); for (const index in pathParts) { - const value = pathParts[index]; + const value = decodeURIComponent(pathParts[index]); if (index > 0 && /-[0-9]+$/.test(value)) { // is sluggish - this.options[pathParts[index - 1]] = value; + this.options[decodeURIComponent(pathParts[index - 1])] = value; } } diff --git a/addons/website_blog/static/tests/tours/blog_search_with_date.js b/addons/website_blog/static/tests/tours/blog_search_with_date.js new file mode 100644 index 00000000000..8cc98857eeb --- /dev/null +++ b/addons/website_blog/static/tests/tours/blog_search_with_date.js @@ -0,0 +1,28 @@ +/** @odoo-module **/ + +import tour from 'web_tour.tour'; + +/** + * Makes sure that blog search can be used with the date filtering. + */ +tour.register('blog_autocomplete_with_date', { + test: true, + url: '/blog', +}, [{ + content: "Select first month", + trigger: 'select[name=archive]', + run: 'text option 2', +}, { + content: "Enter search term", + trigger: '.o_searchbar_form input', + extra_trigger: '#o_wblog_posts_loop span:has(i.fa-calendar-o):has(a[href="/blog"])', + run: 'text a', +}, { + content: "Wait for suggestions then click on search icon", + extra_trigger: '.o_searchbar_form .o_dropdown_menu .o_search_result_item', + trigger: '.o_searchbar_form button:has(i.oi-search)', +}, { + content: "Ensure both filters are applied", + trigger: '#o_wblog_posts_loop:has(span:has(i.fa-calendar-o):has(a[href="/blog?search=a"])):has(span:has(i.fa-search):has(a[href^="/blog?date_begin"]))', + run: () => {}, // This is a check. +}]); diff --git a/addons/website_blog/tests/test_ui.py b/addons/website_blog/tests/test_ui.py index 62e0173ee9f..93b65ae09f0 100644 --- a/addons/website_blog/tests/test_ui.py +++ b/addons/website_blog/tests/test_ui.py @@ -23,3 +23,8 @@ class TestUi(odoo.tests.HttpCase): def test_blog_post_tags(self): self.start_tour(self.env['website'].get_client_action_url('/blog'), 'blog_tags', login='admin') + + def test_autocomplete_with_date(self): + self.env.ref('website_blog.opt_blog_sidebar_show').active = True + self.env.ref('website_blog.opt_sidebar_blog_index_follow_us').active = False + self.start_tour("/blog", 'blog_autocomplete_with_date')