diff --git a/addons/website/static/src/snippets/s_table_of_content/000.js b/addons/website/static/src/snippets/s_table_of_content/000.js index 059bc790dd1..362df3c66a3 100644 --- a/addons/website/static/src/snippets/s_table_of_content/000.js +++ b/addons/website/static/src/snippets/s_table_of_content/000.js @@ -52,7 +52,12 @@ const TableOfContent = publicWidget.Widget.extend({ position += $mainNavBar.length ? $mainNavBar.outerHeight() : 0; position += isHorizontalNavbar ? this.$el.outerHeight() : 0; this._scrollingElement = $().getScrollingElement(); - this._scrollingElement.scrollspy({target: this.$el.find('.s_table_of_content_navbar'), method: 'offset', offset: position + 100, alwaysKeepFirstActive: true}); + new ScrollSpy(this._scrollingElement, { + target: this.$el.find('.s_table_of_content_navbar'), + method: 'offset', + offset: position + 100, + alwaysKeepFirstActive: true + }); }, }); diff --git a/addons/website/static/tests/tours/snippet_table_of_content.js b/addons/website/static/tests/tours/snippet_table_of_content.js index 2e9adb2bb43..5bcc42f66ce 100644 --- a/addons/website/static/tests/tours/snippet_table_of_content.js +++ b/addons/website/static/tests/tours/snippet_table_of_content.js @@ -2,6 +2,23 @@ import wTourUtils from 'website.tour_utils'; +const scrollToHeading = function (position) { + return { + content: `Scroll to h1 number ${position}`, + trigger: `iframe h1:eq(${position})`, + run: function () { + this.$anchor[0].scrollIntoView(true); + }, + }; +}; +const checkTOCNavBar = function (tocPosition, activeHeaderPosition) { + return { + content: `Check that the header ${activeHeaderPosition} is active for TOC ${tocPosition}`, + trigger: `iframe .s_table_of_content:eq(${tocPosition}) .table_of_content_link:eq(${activeHeaderPosition}).active `, + run: () => {}, // This is a check. + }; +}; + wTourUtils.registerWebsitePreviewTour('snippet_table_of_content', { test: true, url: '/', @@ -12,4 +29,13 @@ wTourUtils.registerWebsitePreviewTour('snippet_table_of_content', { // To make sure that the public widgets of the two previous ones started. wTourUtils.dragNDrop({id: 's_banner', name: 'Banner'}), ...wTourUtils.clickOnSave(), + checkTOCNavBar(0, 0), + checkTOCNavBar(1, 0), + scrollToHeading(1), + checkTOCNavBar(0, 1), + checkTOCNavBar(1, 0), + scrollToHeading(2), + checkTOCNavBar(1, 0), + scrollToHeading(3), + checkTOCNavBar(1, 1), ]);