From 7df1cf332ef2d7d536e0fc3123475a2faf4fbb1d Mon Sep 17 00:00:00 2001 From: Benoit Socias Date: Thu, 31 Mar 2022 14:54:00 +0000 Subject: [PATCH] [FIX] website_blog: refresh options UI after adding a new tag Since [1] adding a new tag on a blog does not refresh the tag list in the options tab. That commit sorts the `methodsNames` alphabetically. Previously, the unspecified order of the methods just happened to make the add operation work. After this commit the tag list is reset that happens during `setTags` is prevented when a new tag is created. If at a later stage a mechanism is created to allow specifying the order of the `methodsNames`, it should be used instead of this dirty ad-hoc way. [1]: https://github.com/odoo/odoo/commit/a48a30f954afcb6ff3a59c4f32b05fd0c2cfcd2b task-2811746 X-original-commit: e35e1128f5a569f386429b5e532d4b96e9348191 Part-of: odoo/odoo#109479 --- addons/website_blog/__manifest__.py | 3 + addons/website_blog/static/src/js/options.js | 9 +++ .../static/tests/tours/blog_tags_tour.js | 55 +++++++++++++++++++ addons/website_blog/tests/test_ui.py | 3 + 4 files changed, 70 insertions(+) create mode 100644 addons/website_blog/static/tests/tours/blog_tags_tour.js diff --git a/addons/website_blog/__manifest__.py b/addons/website_blog/__manifest__.py index 5b7bbca28af..3c295939672 100644 --- a/addons/website_blog/__manifest__.py +++ b/addons/website_blog/__manifest__.py @@ -39,6 +39,9 @@ 'website_blog/static/src/js/tours/website_blog.js', 'website_blog/static/src/js/systray_items/*.js', ], + 'web.assets_tests': [ + 'website_blog/static/tests/**/*', + ], 'web.assets_frontend': [ 'website_blog/static/src/scss/website_blog.scss', 'website_blog/static/src/js/contentshare.js', diff --git a/addons/website_blog/static/src/js/options.js b/addons/website_blog/static/src/js/options.js index 72760d65992..31a32ff86c3 100644 --- a/addons/website_blog/static/src/js/options.js +++ b/addons/website_blog/static/src/js/options.js @@ -98,6 +98,10 @@ options.registry.BlogPostTagSelection = options.Class.extend({ * @see this.selectClass for params */ setTags(previewMode, widgetValue, params) { + if (this._preventNextSetTagsCall) { + this._preventNextSetTagsCall = false; + return; + } this.tagIDs = JSON.parse(widgetValue).map(tag => tag.id); }, /** @@ -121,6 +125,11 @@ options.registry.BlogPostTagSelection = options.Class.extend({ 'display_name': widgetValue, }; this.tagIDs.push(newTagID); + // TODO Find a smarter way to achieve this. + // Because of the invocation order of methods, setTags will be called + // after createTag. This would reset the tagIds to the value before + // adding the newly created tag. It therefore needs to be prevented. + this._preventNextSetTagsCall = true; }, //-------------------------------------------------------------------------- diff --git a/addons/website_blog/static/tests/tours/blog_tags_tour.js b/addons/website_blog/static/tests/tours/blog_tags_tour.js new file mode 100644 index 00000000000..b560555ba86 --- /dev/null +++ b/addons/website_blog/static/tests/tours/blog_tags_tour.js @@ -0,0 +1,55 @@ +/** @odoo-module **/ + +import wTourUtils from 'website.tour_utils'; + + +/** + * Makes sure that blog tags can be created and removed. + */ +wTourUtils.registerWebsitePreviewTour('blog_tags', { + test: true, + url: '/blog', +}, [{ + content: "Go to first blog", + trigger: "iframe article[name=blog_post] a", + }, + wTourUtils.clickOnEdit(), + wTourUtils.clickOnSnippet('#o_wblog_post_top .o_wblog_post_page_cover'), + { + content: "Open tag dropdown", + trigger: "we-customizeblock-option:contains(Tags) .o_we_m2m we-toggler", + }, { + content: "Enter tag name", + trigger: "we-customizeblock-option:contains(Tags) we-selection-items .o_we_m2o_create input", + run: "text testtag", + }, { + content: "Click Create", + trigger: "we-customizeblock-option:contains(Tags) we-selection-items .o_we_m2o_create we-button", + }, { + content: "Verify tag appears in options", + trigger: "we-customizeblock-option:contains(Tags) we-list input[data-name=testtag]", + run: () => {}, // it's a check + }, + ...wTourUtils.clickOnSave(), + { + content: "Verify tag appears in blog post", + trigger: "iframe #o_wblog_post_content .badge:contains(testtag)", + run: () => {}, // it's a check + }, + wTourUtils.clickOnEdit(), + wTourUtils.clickOnSnippet('#o_wblog_post_top .o_wblog_post_page_cover'), + { + content: "Remove tag", + trigger: "we-customizeblock-option:contains(Tags) we-list tr:has(input[data-name=testtag]) we-button.fa-minus", + }, { + content: "Verify tag does not appear in options anymore", + trigger: "we-customizeblock-option:contains(Tags) we-list:not(:has(input[data-name=testtag]))", + run: () => {}, // it's a check + }, + ...wTourUtils.clickOnSave(), + { + content: "Verify tag does not appear in blog post anymore", + trigger: "iframe #o_wblog_post_content div:has(.badge):not(:contains(testtag))", + run: () => {}, // it's a check + }] +); diff --git a/addons/website_blog/tests/test_ui.py b/addons/website_blog/tests/test_ui.py index 5ddf6c08a93..62e0173ee9f 100644 --- a/addons/website_blog/tests/test_ui.py +++ b/addons/website_blog/tests/test_ui.py @@ -20,3 +20,6 @@ class TestUi(odoo.tests.HttpCase): }) self.start_tour(self.env['website'].get_client_action_url('/'), 'blog', login='admin') + + def test_blog_post_tags(self): + self.start_tour(self.env['website'].get_client_action_url('/blog'), 'blog_tags', login='admin')