From 35e807f424d684ad8468279effbfd9abff5dcecd Mon Sep 17 00:00:00 2001 From: "Manu Vaillant (manv)" Date: Wed, 14 Feb 2024 13:08:07 +0100 Subject: [PATCH] [IMP] point_of_sale: refactor tests for scanning barcodes refactor 'scan_barcode' method to use barcodes function task id: 3674936 closes odoo/odoo#153993 Signed-off-by: Vlad Stroia (vlst) --- addons/point_of_sale/__manifest__.py | 1 + .../tests/tours/BarcodeScanning.tour.js | 34 +++++++++---------- .../static/tests/tours/ProductScreen.tour.js | 8 ++--- .../tours/helpers/ProductScreenTourMethods.js | 23 ------------- .../static/tests/tours/helpers/utils.js | 14 ++++++++ 5 files changed, 36 insertions(+), 44 deletions(-) diff --git a/addons/point_of_sale/__manifest__.py b/addons/point_of_sale/__manifest__.py index 7e31742d641..cf5452b4e51 100644 --- a/addons/point_of_sale/__manifest__.py +++ b/addons/point_of_sale/__manifest__.py @@ -71,6 +71,7 @@ 'point_of_sale/static/src/backend/debug_manager.js', ], 'web.assets_tests': [ + 'barcodes/static/tests/helpers.js', 'point_of_sale/static/tests/tours/**/*', ], diff --git a/addons/point_of_sale/static/tests/tours/BarcodeScanning.tour.js b/addons/point_of_sale/static/tests/tours/BarcodeScanning.tour.js index 9cefc3fd71c..542d92c2a07 100644 --- a/addons/point_of_sale/static/tests/tours/BarcodeScanning.tour.js +++ b/addons/point_of_sale/static/tests/tours/BarcodeScanning.tour.js @@ -3,6 +3,7 @@ import * as ProductScreen from "@point_of_sale/../tests/tours/helpers/ProductScreenTourMethods"; import * as Chrome from "@point_of_sale/../tests/tours/helpers/ChromeTourMethods"; import { registry } from "@web/core/registry"; +import { scan_barcode } from "@point_of_sale/../tests/tours/helpers/utils"; registry.category("web_tour.tours").add("BarcodeScanningTour", { test: true, @@ -16,21 +17,21 @@ registry.category("web_tour.tours").add("BarcodeScanningTour", { ProductScreen.confirmOpeningPopup(), // Add a product with its barcode - ProductScreen.scan_barcode("0123456789"), + scan_barcode("0123456789"), ProductScreen.selectedOrderlineHas("Monitor Stand"), - ProductScreen.scan_barcode("0123456789"), + scan_barcode("0123456789"), ProductScreen.selectedOrderlineHas("Monitor Stand", 2), // Test "Prices product" EAN-13 `23.....{NNNDD}` barcode pattern - ProductScreen.scan_ean13_barcode("2305000000004"), + scan_barcode("2305000000004"), ProductScreen.selectedOrderlineHas("Magnetic Board", 1, "0.00"), - ProductScreen.scan_ean13_barcode("2305000123451"), + scan_barcode("2305000123451"), ProductScreen.selectedOrderlineHas("Magnetic Board", 1, "123.45"), // Test "Weighted product" EAN-13 `21.....{NNDDD}` barcode pattern - ProductScreen.scan_ean13_barcode("2100005000000"), + scan_barcode("2100005000000"), ProductScreen.selectedOrderlineHas("Wall Shelf Unit", 0, "0.00"), - ProductScreen.scan_ean13_barcode("2100005080002"), + scan_barcode("2100005080002"), ProductScreen.selectedOrderlineHas("Wall Shelf Unit", 8), Chrome.endTour(), ].flat(), @@ -42,17 +43,16 @@ registry.category("web_tour.tours").add("BarcodeScanningProductPackagingTour", { steps: () => [ ProductScreen.confirmOpeningPopup(), - // Add the product with its barcode - ProductScreen.scan_barcode("12345601"), + scan_barcode("12345601"), ProductScreen.selectedOrderlineHas("Packaging Product", 1), - ProductScreen.scan_barcode("12345601"), + scan_barcode("12345601"), ProductScreen.selectedOrderlineHas("Packaging Product", 2), // Add the product packaging with its barcode - ProductScreen.scan_barcode("12345610"), + scan_barcode("12345610"), ProductScreen.selectedOrderlineHas("Packaging Product", 12), - ProductScreen.scan_barcode("12345610"), + scan_barcode("12345610"), ProductScreen.selectedOrderlineHas("Packaging Product", 22), Chrome.endTour(), ].flat(), @@ -66,21 +66,21 @@ registry.category("web_tour.tours").add("GS1BarcodeScanningTour", { ProductScreen.confirmOpeningPopup(), // Add the Product 1 with GS1 barcode - ProductScreen.scan_barcode("0108431673020125100000001"), + scan_barcode("0108431673020125100000001"), ProductScreen.selectedOrderlineHas("Product 1"), - ProductScreen.scan_barcode("0108431673020125100000001"), + scan_barcode("0108431673020125100000001"), ProductScreen.selectedOrderlineHas("Product 1", 2), // Add the Product 2 with normal barcode - ProductScreen.scan_barcode("08431673020126"), + scan_barcode("08431673020126"), ProductScreen.selectedOrderlineHas("Product 2"), - ProductScreen.scan_barcode("08431673020126"), + scan_barcode("08431673020126"), ProductScreen.selectedOrderlineHas("Product 2", 2), // Add the Product 3 with normal barcode - ProductScreen.scan_barcode("3760171283370"), + scan_barcode("3760171283370"), ProductScreen.selectedOrderlineHas("Product 3"), - ProductScreen.scan_barcode("3760171283370"), + scan_barcode("3760171283370"), ProductScreen.selectedOrderlineHas("Product 3", 2), Chrome.endTour(), ].flat(), diff --git a/addons/point_of_sale/static/tests/tours/ProductScreen.tour.js b/addons/point_of_sale/static/tests/tours/ProductScreen.tour.js index c51be9d00ef..3963d502f67 100644 --- a/addons/point_of_sale/static/tests/tours/ProductScreen.tour.js +++ b/addons/point_of_sale/static/tests/tours/ProductScreen.tour.js @@ -6,7 +6,7 @@ import * as Chrome from "@point_of_sale/../tests/tours/helpers/ChromeTourMethods import * as ReceiptScreen from "@point_of_sale/../tests/tours/helpers/ReceiptScreenTourMethods"; import { registry } from "@web/core/registry"; import * as Order from "@point_of_sale/../tests/tours/helpers/generic_components/OrderWidgetMethods"; -import { inLeftSide } from "./helpers/utils"; +import { inLeftSide, scan_barcode } from "@point_of_sale/../tests/tours/helpers/utils"; registry.category("web_tour.tours").add("ProductScreenTour", { test: true, @@ -191,13 +191,13 @@ registry.category("web_tour.tours").add("limitedProductPricelistLoading", { [ ProductScreen.confirmOpeningPopup(), - ProductScreen.scan_barcode("0100100"), + scan_barcode("0100100"), ProductScreen.selectedOrderlineHas('Test Product 1', '1.0', '80.0'), - ProductScreen.scan_barcode("0100200"), + scan_barcode("0100200"), ProductScreen.selectedOrderlineHas('Test Product 2', '1.0', '100.0'), - ProductScreen.scan_barcode("0100300"), + scan_barcode("0100300"), ProductScreen.selectedOrderlineHas('Test Product 3', '1.0', '50.0'), Chrome.endTour(), ].flat(), diff --git a/addons/point_of_sale/static/tests/tours/helpers/ProductScreenTourMethods.js b/addons/point_of_sale/static/tests/tours/helpers/ProductScreenTourMethods.js index 37d6a6cdb41..26f174e2912 100644 --- a/addons/point_of_sale/static/tests/tours/helpers/ProductScreenTourMethods.js +++ b/addons/point_of_sale/static/tests/tours/helpers/ProductScreenTourMethods.js @@ -205,29 +205,6 @@ export function clickCloseSession() { }, ]; } -export function scan_barcode(barcode) { - return [ - { - content: `PoS model scan barcode '${barcode}'`, - trigger: ".pos", // The element here does not really matter as long as it is present - run: () => { - window.posmodel.env.services.barcode_reader.scan(barcode); - }, - }, - ]; -} -export function scan_ean13_barcode(barcode) { - return [ - { - content: `PoS model scan EAN13 barcode '${barcode}'`, - trigger: ".pos", // The element here does not really matter as long as it is present - run: () => { - const barcode_reader = window.posmodel.env.services.barcode_reader; - barcode_reader.scan(barcode_reader.parser.sanitize_ean(barcode)); - }, - }, - ]; -} export function goBackToMainScreen() { return [ { diff --git a/addons/point_of_sale/static/tests/tours/helpers/utils.js b/addons/point_of_sale/static/tests/tours/helpers/utils.js index 7d7a8d9c990..b1ac0dd8d28 100644 --- a/addons/point_of_sale/static/tests/tours/helpers/utils.js +++ b/addons/point_of_sale/static/tests/tours/helpers/utils.js @@ -1,5 +1,7 @@ /** @odoo-module */ +import { simulateBarCode } from "@barcodes/../tests/helpers" + export function inLeftSide(steps) { return [ { @@ -26,3 +28,15 @@ export function negateStep(step) { trigger: negate(step.trigger), }; } + +export function scan_barcode(barcode) { + return [ + { + content: `PoS model scan barcode '${barcode}'`, + trigger: "body", // The element here does not really matter as long as it is present + run: () => { + simulateBarCode([...barcode, "Enter"]) + }, + }, + ]; +}