From a3dd4e34bd534b44354f115568fe3585cb821465 Mon Sep 17 00:00:00 2001 From: Benjamin Vray Date: Tue, 15 Mar 2022 13:36:27 +0100 Subject: [PATCH] [IMP] website_sale: adapt tests to the new customize options *: website_sale_autocomplete, website_sale_loyalty Adapt tests to the new customization options which are now accessible in edit mode with the other options. But also adapt the tests that run in the backend where the page is now moved in an iframe in edit mode. See merge commit for more information. task-2710582 --- .../static/src/js/tours/tour_utils.js | 4 +- .../tests/tours/website_sale_complete_flow.js | 4 +- ...ebsite_sale_shop_custom_attribute_value.js | 2 +- .../tours/website_sale_shop_customize.js | 363 +++++++++++------- .../tours/website_sale_shop_list_view_b2c.js | 78 ++-- .../website_sale/views/snippets/snippets.xml | 6 +- .../static/tests/autocomplete_tour.js | 2 +- .../static/tests/tours/test_gift_card_tour.js | 29 +- .../tests/tours/test_promo_main_tour.js | 18 +- .../tests/test_shop_sale_coupon.py | 2 + 10 files changed, 288 insertions(+), 220 deletions(-) diff --git a/addons/website_sale/static/src/js/tours/tour_utils.js b/addons/website_sale/static/src/js/tours/tour_utils.js index b604261d6f7..1a20277a1da 100644 --- a/addons/website_sale/static/src/js/tours/tour_utils.js +++ b/addons/website_sale/static/src/js/tours/tour_utils.js @@ -5,10 +5,10 @@ odoo.define("website_sale.tour_utils", function (require) { const _t = core._t; - function goToCart(quantity = 1, position = "bottom") { + function goToCart({quantity = 1, position = "bottom", backend = false} = {}) { return { content: _t("Go to cart"), - trigger: `a:has(.my_cart_quantity:containsExact(${quantity}))`, + trigger: `${backend ? "iframe" : ""} a:has(.my_cart_quantity:containsExact(${quantity}))`, position: position, run: "click", }; diff --git a/addons/website_sale/static/tests/tours/website_sale_complete_flow.js b/addons/website_sale/static/tests/tours/website_sale_complete_flow.js index 990dc1bb3c4..647965b83a9 100644 --- a/addons/website_sale/static/tests/tours/website_sale_complete_flow.js +++ b/addons/website_sale/static/tests/tours/website_sale_complete_flow.js @@ -27,7 +27,7 @@ odoo.define('website_sale_tour.tour', function (require) { content: "Click on add to cart", trigger: '#add_to_cart', }, - tourUtils.goToCart(2), + tourUtils.goToCart({quantity: 2}), { content: "Check for 2 products in cart and proceed to checkout", extra_trigger: '#cart_products tr:contains("Storage Box Test") input.js_quantity:propValue(2)', @@ -222,7 +222,7 @@ odoo.define('website_sale_tour.tour', function (require) { content: "Click on add to cart", trigger: '#add_to_cart', }, - tourUtils.goToCart(2), + tourUtils.goToCart({quantity: 2}), { content: "Check for 2 products in cart and proceed to checkout", extra_trigger: '#cart_products tr:contains("Storage Box Test") input.js_quantity:propValue(2)', diff --git a/addons/website_sale/static/tests/tours/website_sale_shop_custom_attribute_value.js b/addons/website_sale/static/tests/tours/website_sale_shop_custom_attribute_value.js index 3a8e7d465da..4a2c467d917 100644 --- a/addons/website_sale/static/tests/tours/website_sale_shop_custom_attribute_value.js +++ b/addons/website_sale/static/tests/tours/website_sale_shop_custom_attribute_value.js @@ -22,7 +22,7 @@ odoo.define("website_sale.tour_shop_custom_attribute_value", function (require) trigger: 'a:contains(ADD TO CART)', run: 'click', }, - tourUtils.goToCart(), + tourUtils.goToCart(), { trigger: 'span:contains(Custom TEST: Wood)', extra_trigger: '#cart_products', diff --git a/addons/website_sale/static/tests/tours/website_sale_shop_customize.js b/addons/website_sale/static/tests/tours/website_sale_shop_customize.js index bf5f4ccfd3c..a556518e8e5 100644 --- a/addons/website_sale/static/tests/tours/website_sale_shop_customize.js +++ b/addons/website_sale/static/tests/tours/website_sale_shop_customize.js @@ -1,147 +1,220 @@ -odoo.define('website_sale.tour_shop_customize', function (require) { - 'use strict'; +/** @odoo-module **/ - var tour = require("web_tour.tour"); - const tourUtils = require('website_sale.tour_utils'); +import tour from 'web_tour.tour'; +import tourUtils from 'website_sale.tour_utils'; - tour.register('shop_customize', { - test: true, - url: '/shop', - }, - [ - { - content: "open customize menu", - trigger: '#customize-menu > a', - }, - { - content: "click on 'Attributes & Variants filters'", - trigger: "#customize-menu label:contains(Attributes & Variants filters)", - }, - { - content: "select product attribute Steel", - extra_trigger: 'body:not(:has(#customize-menu:visible .dropdown-menu:visible))', - trigger: 'form.js_attributes input:not(:checked) + label:contains(Steel - Test)', - }, - { - content: "check the selection", - trigger: 'form.js_attributes input:checked + label:contains(Steel - Test)', - run: function () {}, // it's a check - }, - { - content: "select product", - extra_trigger: 'body:not(:has(.oe_website_sale .oe_product_cart:eq(3)))', - trigger: '.oe_product_cart a:contains("Test Product")', - }, - { - content: "open customize menu", - trigger: '#customize-menu > a', - extra_trigger: '#product_detail', - }, - { - content: "check page loaded after enable variant group", - trigger: '#customize-menu label:contains(List View of Variants)', - run: function () {}, // it's a check - }, - { - content: "check list view of variants is disabled initially", - trigger: 'body:not(:has(.js_product_change))', - run: function () {}, - }, - { - content: "click on 'List View of Variants'", - trigger: "#customize-menu label:contains(List View of Variants)", - }, - { - content: "check page loaded after list of variant customization enabled", - trigger: '.js_product_change', - run: function () {}, // it's a check - }, - { - context: "check variant price", - trigger: '.custom-radio:contains("Aluminium") .badge:contains("+") .oe_currency_value:contains("50.4")', - run: function () {}, - }, - { - content: "check price is 750", - trigger: ".product_price .oe_price .oe_currency_value:containsExact(750.00)", - run: function () {}, - }, - { - content: "switch to another variant", - trigger: ".js_product label:contains('Aluminium')", - }, - { - content: "verify that price has changed when changing variant", - trigger: ".product_price .oe_price .oe_currency_value:containsExact(800.40)", - run: function () {}, - }, - { - content: "open customize menu", - trigger: '#customize-menu > a', - }, - { - content: "remove 'List View of Variants'", - trigger: "#customize-menu label:contains(List View of Variants):has(input:checked)", - }, - { - content: "check page loaded after list of variant customization disabled", - trigger: ".js_product:not(:has(.js_product_change))", - run: function () {}, // it's a check - }, - { - content: "check price is 750", - trigger: ".product_price .oe_price .oe_currency_value:containsExact(750.00)", - run: function () {}, - }, - { - content: "switch to Aluminium variant", - trigger: '.js_product input[data-value_name="Aluminium"]', - }, - { - content: "verify that price has changed when changing variant", - trigger: ".product_price .oe_price .oe_currency_value:containsExact(800.40)", - run: function () {}, // it's a check - }, - { - content: "switch back to Steel variant", - trigger: ".js_product label:contains('Steel - Test')", - }, - { - content: "check price is 750", - trigger: ".product_price .oe_price .oe_currency_value:containsExact(750.00)", - run: function () {}, - }, - { - content: "click on 'Add to Cart' button", - trigger: "a:contains(ADD TO CART)", - }, - { - content: "check quantity", - trigger: '.my_cart_quantity:containsExact(1),.o_extra_menu_items .fa-plus', - run: function () {}, // it's a check - }, - tourUtils.goToCart(), - { - content: "click on shop", - trigger: "a:contains(Continue Shopping)", - extra_trigger: 'body:not(:has(#products_grid_before .js_attributes))', - }, - { - content: "open customize menu bis", - extra_trigger: '#products_grid_before .js_attributes', - trigger: '#customize-menu > a', - }, - { - content: "remove 'Attributes & Variants filters'", - trigger: "#customize-menu label:contains(Attributes & Variants filters):has(input:checked)", - }, - { - content: "finish", - extra_trigger: 'body:not(:has(#products_grid_before .js_attributes))', - trigger: '#wrap:not(:has(li:has(.my_cart_quantity):visible))', - run: function () {}, // it's a check - }, - ] - ); - - }); +tour.register('shop_customize', { + test: true, + url: '/shop?enable_editor=1', +}, + [ + { + content: "open customize tab", + extra_trigger: '#oe_snippets.o_loaded', + trigger: '.o_we_customize_snippet_btn', + }, + { + content: "click on 'Attributes'", + extra_trigger: '#oe_snippets .o_we_customize_panel', + trigger: 'we-button[data-name="attributes_opt"]', + }, + { + content: "check that the iframe is reloading", + trigger: '.o_loading_dummy', + run: () => {}, // It's a check. + }, + { + content: "click on save button after the reload", + trigger: 'div:not(.o_loading_dummy) > #oe_snippets button[data-action="save"]', + run: 'click', + }, + { + content: "wait to exit edit mode", + trigger: '.o_website_editor:not(.editor_has_snippets)', + }, + { + content: "select product attribute Steel", + trigger: 'iframe form.js_attributes input:not(:checked) + label:contains(Steel - Test)', + }, + { + content: "check the selection", + trigger: 'iframe form.js_attributes input:checked + label:contains(Steel - Test)', + run: function () {}, // it's a check + }, + { + content: "select product", + extra_trigger: 'iframe body:not(:has(.oe_website_sale .oe_product_cart:eq(3)))', + trigger: 'iframe .oe_product_cart a:contains("Test Product")', + }, + { + content: "wait the product page to be loaded", + trigger: 'iframe #product_detail', + run: function () {}, + }, + { + content: "check list view of variants is disabled initially", + trigger: 'iframe body:not(:has(.js_product_change))', + run: function () {}, + }, + { + content: "enter edit mode", + trigger: '.o_edit_website_container > a', + }, + { + content: "open customize tab", + extra_trigger: '#oe_snippets.o_loaded', + trigger: '.o_we_customize_snippet_btn', + }, + { + content: "open 'Variants' selector", + extra_trigger: '#oe_snippets .o_we_customize_panel', + trigger: '[data-name="variants_opt"] we-toggler', + }, + { + content: "click on 'Products List' of the 'Variants' selector", + trigger: 'we-button[data-name="variants_products_list_opt"]', + }, + { + content: "check that the iframe is reloading", + trigger: '.o_loading_dummy', + run: () => {}, // It's a check. + }, + { + content: "click on save button after the reload", + trigger: 'div:not(.o_loading_dummy) > #oe_snippets button[data-action="save"]', + run: 'click', + }, + { + content: "wait to exit edit mode", + trigger: '.o_website_editor:not(.editor_has_snippets)', + }, + { + context: "check variant price", + trigger: 'iframe .custom-radio:contains("Aluminium") .badge:contains("+") .oe_currency_value:contains("50.4")', + run: function () {}, + }, + { + content: "check price is 750", + trigger: "iframe .product_price .oe_price .oe_currency_value:containsExact(750.00)", + run: function () {}, + }, + { + content: "switch to another variant", + trigger: "iframe .js_product label:contains('Aluminium')", + }, + { + content: "verify that price has changed when changing variant", + trigger: "iframe .product_price .oe_price .oe_currency_value:containsExact(800.40)", + run: function () {}, + }, + { + content: "enter edit mode", + trigger: '.o_edit_website_container > a', + }, + { + content: "open customize tab", + extra_trigger: '#oe_snippets.o_loaded', + trigger: '.o_we_customize_snippet_btn', + }, + { + content: "open 'Variants' selector", + extra_trigger: '#oe_snippets .o_we_customize_panel', + trigger: '[data-name="variants_opt"] we-toggler', + }, + { + content: "click on 'Options' of the 'Variants' selector", + trigger: 'we-button[data-name="variants_options_opt"]', + }, + { + content: "check that the iframe is reloading", + trigger: '.o_loading_dummy', + run: () => {}, // It's a check. + }, + { + content: "click on save button after the reload", + trigger: 'div:not(.o_loading_dummy) > #oe_snippets button[data-action="save"]', + run: 'click', + }, + { + content: "wait to exit edit mode", + trigger: '.o_website_editor:not(.editor_has_snippets)', + }, + { + content: "check page loaded after list of variant customization disabled", + trigger: "iframe .js_product:not(:has(.js_product_change))", + run: function () {}, // it's a check + }, + { + content: "check price is 750", + trigger: "iframe .product_price .oe_price .oe_currency_value:containsExact(750.00)", + run: function () {}, + }, + { + content: "switch to Aluminium variant", + trigger: 'iframe .js_product input[data-value_name="Aluminium"]', + }, + { + content: "verify that price has changed when changing variant", + trigger: "iframe .product_price .oe_price .oe_currency_value:containsExact(800.40)", + run: function () {}, // it's a check + }, + { + content: "switch back to Steel variant", + trigger: "iframe .js_product label:contains('Steel - Test')", + }, + { + content: "check price is 750", + trigger: "iframe .product_price .oe_price .oe_currency_value:containsExact(750.00)", + run: function () {}, + }, + { + content: "click on 'Add to Cart' button", + trigger: "iframe a:contains(ADD TO CART)", + }, + { + content: "check quantity", + trigger: 'iframe .my_cart_quantity:containsExact(1),.o_extra_menu_items .fa-plus', + run: function () {}, // it's a check + }, + tourUtils.goToCart({backend: true}), + { + content: "click on shop", + trigger: "iframe a:contains(Continue Shopping)", + extra_trigger: 'iframe body:not(:has(#products_grid_before .js_attributes))', + }, + { + content: "enter edit mode", + trigger: '.o_edit_website_container > a', + }, + { + content: "open customize tab", + extra_trigger: '#oe_snippets.o_loaded', + trigger: '.o_we_customize_snippet_btn', + }, + { + content: "remove 'Attributes'", + extra_trigger: '#oe_snippets .o_we_customize_panel', + trigger: 'we-button[data-name="attributes_opt"]', + }, + { + content: "check that the iframe is reloading", + trigger: '.o_loading_dummy', + run: () => {}, // It's a check. + }, + { + content: "click on save button after the reload", + trigger: 'div:not(.o_loading_dummy) > #oe_snippets button[data-action="save"]', + run: 'click', + }, + { + content: "wait to exit edit mode", + trigger: '.o_website_editor:not(.editor_has_snippets)', + }, + { + content: "finish", + extra_trigger: 'iframe body:not(:has(#products_grid_before .js_attributes))', + trigger: 'iframe #wrap:not(:has(li:has(.my_cart_quantity):visible))', + run: function () {}, // it's a check + }, + ], +); diff --git a/addons/website_sale/static/tests/tours/website_sale_shop_list_view_b2c.js b/addons/website_sale/static/tests/tours/website_sale_shop_list_view_b2c.js index 1a977c00c2d..a798aef7dfe 100644 --- a/addons/website_sale/static/tests/tours/website_sale_shop_list_view_b2c.js +++ b/addons/website_sale/static/tests/tours/website_sale_shop_list_view_b2c.js @@ -1,8 +1,7 @@ -odoo.define('website_sale.tour_shop_list_view_b2c', function (require) { -'use strict'; +/** @odoo-module **/ -var tour = require('web_tour.tour'); -const tourUtils = require('website_sale.tour_utils'); +import tour from 'web_tour.tour'; +import tourUtils from 'website_sale.tour_utils'; tour.register('shop_list_view_b2c', { test: true, @@ -12,62 +11,83 @@ tour.register('shop_list_view_b2c', { { content: "check price on /shop", trigger: '.oe_product_cart .oe_currency_value:contains("825.00")', - run: function () {}, + run: () => {}, // It's a check. }, { content: "select product", trigger: '.oe_product_cart a:contains("Test Product")', }, { - content: "check list view of variants is disabled initially (when on /product page)", + content: "check products list is disabled initially (when on /product page)", trigger: 'body:not(:has(.js_product_change))', extra_trigger: '#product_details', - run: function () {}, + run: () => {}, // It's a check. }, { - content: "open customize menu", - trigger: '#customize-menu > a', - extra_trigger: 'body:not(.notReady)', + content: "go to edit mode", + trigger: 'a.o_frontend_to_backend_edit_btn', }, { - content: "click on 'List View of Variants'", - trigger: '#customize-menu label:contains(List View of Variants)', + content: "open customize tab", + extra_trigger: '#oe_snippets.o_loaded', + trigger: '.o_we_customize_snippet_btn', }, { - content: "check page loaded after list of variant customization enabled", - trigger: '.js_product_change', - run: function () {}, + content: "open 'Variants' selector", + extra_trigger: '#oe_snippets .o_we_customize_panel', + trigger: '[data-name="variants_opt"] we-toggler', + }, + { + content: "click on 'Products List' of the 'Variants' selector", + trigger: 'we-button[data-name="variants_products_list_opt"]', + }, + { + content: "check that the iframe is reloading", + trigger: '.o_loading_dummy', + run: () => {}, // It's a check. + }, + { + content: "click on save button after the reload", + trigger: 'div:not(.o_loading_dummy) > #oe_snippets button[data-action="save"]', + run: 'click', + }, + { + content: "wait to exit edit mode", + trigger: '.o_website_editor:not(.editor_has_snippets)', + }, + { + content: "check page loaded after 'Products List' enabled", + trigger: 'iframe .js_product_change', + run: () => {}, // It's a check. }, { context: "check variant price", - trigger: '.custom-radio:contains("Aluminium") .badge:contains("+") .oe_currency_value:contains("55.44")', - run: function () {}, + trigger: 'iframe .custom-radio:contains("Aluminium") .badge:contains("+") .oe_currency_value:contains("55.44")', + run: () => {}, // It's a check. }, { content: "check price is 825", - trigger: '.product_price .oe_price .oe_currency_value:containsExact("825.00")', - run: function () {}, + trigger: 'iframe .product_price .oe_price .oe_currency_value:containsExact(825.00)', + run: () => {}, // It's a check. }, { content: "switch to another variant", - trigger: '.js_product label:contains("Aluminium")', + trigger: 'iframe .js_product label:contains("Aluminium")', }, { content: "verify that price has changed when changing variant", - trigger: '.product_price .oe_price .oe_currency_value:containsExact("880.44")', - run: function () {}, + trigger: 'iframe .product_price .oe_price .oe_currency_value:containsExact(880.44)', + run: () => {}, // It's a check. }, { content: "click on 'Add to Cart' button", - trigger: 'a:contains(ADD TO CART)', + trigger: 'iframe a:contains(ADD TO CART)', }, - tourUtils.goToCart(), + tourUtils.goToCart({backend: true}), { content: "check price on /cart", - trigger: '#cart_products .oe_currency_value:containsExact("880.44")', - run: function () {}, + trigger: 'iframe #cart_products .oe_currency_value:containsExact(880.44)', + run: () => {}, // It's a check. }, - ] + ], ); - -}); diff --git a/addons/website_sale/views/snippets/snippets.xml b/addons/website_sale/views/snippets/snippets.xml index 192b8b6d317..bfc265951d8 100644 --- a/addons/website_sale/views/snippets/snippets.xml +++ b/addons/website_sale/views/snippets/snippets.xml @@ -221,9 +221,9 @@ data-customize-website-views="website_sale.product_quantity" data-no-preview="true" data-reload="/"/> - - Options - Products List + + Options + Products List a', - }, - { - content: 'enable "Promo Code" if needed', - trigger: '#customize-menu label:contains(Promo Code)', - run: function () { - if (!$('#customize-menu label:contains(Promo Code) input').prop('checked')) { - $('#customize-menu label:contains(Promo Code)').click(); - } - } + content: "wait the /cart page", + trigger: '#cart_products', }, { content: 'Click on "I have a promo code"', - extra_trigger: '.show_coupon', trigger: '.show_coupon', }, { content: 'insert gift card code', - extra_trigger: 'form[name="coupon_code"]', trigger: 'form[name="coupon_code"] input[name="promo"]', run: 'text GIFT_CARD' }, { - content: 'validate the git card', + content: 'validate the gift card', trigger: 'form[name="coupon_code"] .a-submit', }, { @@ -54,7 +42,6 @@ tour.register('shop_sale_gift_card', { }, { content: 'Click on "I have a promo code"', - extra_trigger: '.show_coupon', trigger: '.show_coupon', }, { @@ -64,13 +51,13 @@ tour.register('shop_sale_gift_card', { run: 'text 10PERCENT' }, { - content: 'validate the git card', + content: 'validate the gift card', trigger: 'form[name="coupon_code"] .a-submit', }, { content: 'check gift card amount', trigger: '.oe_currency_value:contains("-45.00")', - trigger: '.oe_website_sale .oe_cart', + extra_trigger: '.oe_website_sale .oe_cart', run: function () {}, // it's a check }, { @@ -95,11 +82,11 @@ tour.register('shop_sale_gift_card', { content: "click on 'Add to Cart' button", trigger: "a:contains(ADD TO CART)", }, - tourUtils.goToCart(2), + tourUtils.goToCart({quantity: 2}), { content: 'check gift card amount', trigger: '.oe_currency_value:contains("-45.00")', - trigger: '.oe_website_sale .oe_cart', + extra_trigger: '.oe_website_sale .oe_cart', run: function () {}, // it's a check }, ], diff --git a/addons/website_sale_loyalty/static/tests/tours/test_promo_main_tour.js b/addons/website_sale_loyalty/static/tests/tours/test_promo_main_tour.js index ab9bbaf82fb..c7ef1ff8df7 100644 --- a/addons/website_sale_loyalty/static/tests/tours/test_promo_main_tour.js +++ b/addons/website_sale_loyalty/static/tests/tours/test_promo_main_tour.js @@ -24,21 +24,7 @@ tour.register('shop_sale_loyalty', { content: "click on 'Add to Cart' button", trigger: "a:contains(ADD TO CART)", }, - tourUtils.goToCart(2), - { - content: "open customize menu", - extra_trigger: '.oe_website_sale .oe_cart', - trigger: '#customize-menu > a', - }, - { - content: "enable 'Promo Code' if needed", - trigger: "#customize-menu label:contains(Promo Code)", - run: function () { - if (!$('#customize-menu label:contains(Promo Code) input').prop('checked')) { - $('#customize-menu label:contains(Promo Code)').click(); - } - } - }, + tourUtils.goToCart({quantity: 2}), { content: "click on 'I have a promo code'", extra_trigger: '.show_coupon', @@ -107,7 +93,7 @@ tour.register('shop_sale_loyalty', { content: "click on 'Add to Cart' button", trigger: "a:contains(ADD TO CART)", }, - tourUtils.goToCart(3), + tourUtils.goToCart({quantity: 3}), { content: "check reduction amount got recomputed and merged both discount lines into one only", extra_trigger: '.oe_currency_value:contains("-75.50"):not(#cart_total .oe_currency_value:contains("-75.50"))', diff --git a/addons/website_sale_loyalty/tests/test_shop_sale_coupon.py b/addons/website_sale_loyalty/tests/test_shop_sale_coupon.py index 391c4f45b6c..1c3c63f4c69 100644 --- a/addons/website_sale_loyalty/tests/test_shop_sale_coupon.py +++ b/addons/website_sale_loyalty/tests/test_shop_sale_coupon.py @@ -90,6 +90,7 @@ class TestUi(TestSaleProductAttributeValueCommon, HttpCase): })], }) + self.env.ref("website_sale.reduction_code").write({"active": True}) self.start_tour("/", 'shop_sale_loyalty', login="admin") def test_02_admin_shop_gift_card_tour(self): @@ -161,6 +162,7 @@ class TestUi(TestSaleProductAttributeValueCommon, HttpCase): 'code': 'GIFT_CARD', }) + self.env.ref("website_sale.reduction_code").write({"active": True}) self.start_tour('/', 'shop_sale_gift_card', login='admin') self.assertEqual(len(gift_card_program.coupon_ids), 2, 'There should be two coupons, one with points, one without')