[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
This commit is contained in:
@@ -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',
|
||||
|
||||
@@ -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;
|
||||
},
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
@@ -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
|
||||
}]
|
||||
);
|
||||
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user