From 093a281b75905d344df403b3245e792ff0ebae71 Mon Sep 17 00:00:00 2001 From: "Arthur Detroux (ard)" Date: Fri, 14 Jan 2022 10:46:30 +0000 Subject: [PATCH] [IMP] website_sale: add tour for snippet products This PR added new templates and features to the dynamic snippet products. The goal of this commit is to test these features by selecting every newly made template, saving, and adding a product to the cart. Another tour was added to test the functionality of the recently viewed product filter. task-2677203 Part-of: odoo/odoo#80128 --- .../tours/website_sale_snippet_products.js | 84 +++++++++++++++++++ addons/website_sale/tests/__init__.py | 1 + .../tests/test_website_sale_snippets.py | 30 +++++++ 3 files changed, 115 insertions(+) create mode 100644 addons/website_sale/static/tests/tours/website_sale_snippet_products.js create mode 100644 addons/website_sale/tests/test_website_sale_snippets.py diff --git a/addons/website_sale/static/tests/tours/website_sale_snippet_products.js b/addons/website_sale/static/tests/tours/website_sale_snippet_products.js new file mode 100644 index 00000000000..875b97616e8 --- /dev/null +++ b/addons/website_sale/static/tests/tours/website_sale_snippet_products.js @@ -0,0 +1,84 @@ +/** @odoo-module */ + +import wTourUtils from 'website.tour_utils'; +import wSaleTourUtils from 'website_sale.tour_utils'; + +const optionBlock = 'dynamic_snippet_products'; +const productsSnippet = {id: 's_dynamic_snippet_products', name: 'Products'}; +const templates = [ + "dynamic_filter_template_product_product_add_to_cart", + "dynamic_filter_template_product_product_view_detail", + "dynamic_filter_template_product_product_mini_image", + "dynamic_filter_template_product_product_mini_price", + "dynamic_filter_template_product_product_mini_name", + "dynamic_filter_template_product_product_centered", + "dynamic_filter_template_product_product_borderless_1", + "dynamic_filter_template_product_product_borderless_2", + "dynamic_filter_template_product_product_banner", + "dynamic_filter_template_product_product_horizontal_card", + "dynamic_filter_template_product_product_horizontal_card_2", + "dynamic_filter_template_product_product_card_group", +]; + +function changeTemplate(templateKey) { + const templateClass = templateKey.replace(/dynamic_filter_template_/, "s_"); + return [ + wTourUtils.changeOption(optionBlock, 'we-select[data-name="template_opt"] we-toggler', 'template'), + wTourUtils.changeOption(optionBlock, `we-button[data-select-data-attribute="website_sale.${templateKey}"]`), + { + content: 'Check the template is applied', + trigger: `iframe .s_dynamic_snippet_products.${templateClass} .carousel`, + run: () => null, // It's a check + }, + ]; +} + +let templatesSteps = []; +for (const templateKey of templates) { + templatesSteps = templatesSteps.concat(changeTemplate(templateKey)); +} +wTourUtils.registerWebsitePreviewTour('website_sale.snippet_products', { + test: true, + url: '/', + edition: true, +}, +[ + wTourUtils.dragNDrop(productsSnippet), + wTourUtils.clickOnSnippet(productsSnippet), + ...templatesSteps, + ...changeTemplate('dynamic_filter_template_product_product_add_to_cart'), + ...wTourUtils.clickOnSave(), + { + trigger: "iframe .s_dynamic_snippet_products .o_carousel_product_card_body .js_add_cart", + run: 'click', + }, + wSaleTourUtils.goToCart({backend: true}), +]); + +wTourUtils.registerWebsitePreviewTour('website_sale.products_snippet_recently_viewed', { + test: true, + url: '/', + edition: true, +}, +[ + wTourUtils.dragNDrop(productsSnippet), + wTourUtils.clickOnSnippet(productsSnippet), + wTourUtils.changeOption(optionBlock, 'we-select[data-name="filter_opt"] we-toggler', 'filter'), + wTourUtils.changeOption(optionBlock, 'we-select[data-name="filter_opt"] we-button:contains("Recently Viewed")', 'filter'), + ...changeTemplate('dynamic_filter_template_product_product_add_to_cart'), + ...wTourUtils.clickOnSave(), + { + content: 'make delete icon appear', + trigger: 'iframe .s_dynamic_snippet_products .o_carousel_product_card', + run: function () { + const $iframe = $('.o_iframe').contents(); + const $productCard = $iframe.find('.o_carousel_product_card:has(a img[alt="Storage Box"])'); + console.log($productCard); + $productCard.find('.js_remove').attr('style', 'display: block;'); + } + }, + { + trigger: 'iframe .s_dynamic_snippet_products .o_carousel_product_card .js_remove', + run: 'click', + }, +]); diff --git a/addons/website_sale/tests/__init__.py b/addons/website_sale/tests/__init__.py index 8f35f53e0c6..f5b59d1a2a0 100644 --- a/addons/website_sale/tests/__init__.py +++ b/addons/website_sale/tests/__init__.py @@ -21,3 +21,4 @@ from . import test_website_sale_product from . import test_website_sale_shop_variant_exclusion from . import test_website_editor from . import test_website_sale_reorder_from_portal +from . import test_website_sale_snippets diff --git a/addons/website_sale/tests/test_website_sale_snippets.py b/addons/website_sale/tests/test_website_sale_snippets.py new file mode 100644 index 00000000000..574f9dc3124 --- /dev/null +++ b/addons/website_sale/tests/test_website_sale_snippets.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo.tests import HttpCase, tagged +from odoo.addons.website.tools import MockRequest + + +@tagged('post_install', '-at_install', 'website_snippets') +class TestSnippets(HttpCase): + + def test_01_snippet_products_edition(self): + self.start_tour('/', 'website_sale.snippet_products', login='admin') + + def test_02_snippet_products_remove(self): + self.user = self.env['res.users'].search([('login', '=', 'admin')]) + self.website_visitor = self.env['website.visitor'].search([('partner_id', '=', self.user.partner_id.id)]) + before_tour_product_ids = self.website_visitor.product_ids.ids + with MockRequest(self.env, website=self.env['website'].get_current_website()): + if not self.website_visitor: + self.website_visitor = self.env['website.visitor'].create({'partner_id': self.user.partner_id.id}) + self.product = self.env['product.product'].create({ + 'name': 'Storage Box', + 'website_published': True, + 'image_512': b'/product/static/img/product_product_9-image.jpg', + 'display_name': 'Bin', + 'description_sale': 'Pedal-based opening system', + }) + self.website_visitor._add_viewed_product(self.product.id) + self.start_tour('/', 'website_sale.products_snippet_recently_viewed', login='admin') + after_tour_product_ids = self.website_visitor.product_ids.ids + self.assertEqual(before_tour_product_ids, after_tour_product_ids, "There shouldn't be any new product in recently viewed after this tour")