From 35d3fb57d6793db80cff5d0138ef9be2a4e94df4 Mon Sep 17 00:00:00 2001 From: Jay Savaliya Date: Mon, 16 Oct 2023 16:25:50 +0530 Subject: [PATCH] [FIX] barcodes: handle error message on barcode scanning Before this commit: Got a traceback instead of an error message on scanning a barcode. Reason: Until 16.4 error message send in the object via Eventbus, which removed in https://github.com/odoo/odoo/commit/72dbb75d4de529a35c45273ded472d038a7bb738 so because of that error message will be sent directly(not in object). After this commit: User will get an error message if anything wrong happened. Task:3524284 closes odoo/odoo#138877 Signed-off-by: Aaron Bohy (aab) --- .../static/src/components/barcode_scanner.js | 2 +- .../static/tests/basic/barcode_scan_tests.js | 32 +++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 addons/barcodes/static/tests/basic/barcode_scan_tests.js diff --git a/addons/barcodes/static/src/components/barcode_scanner.js b/addons/barcodes/static/src/components/barcode_scanner.js index da765214bed..916ae62da41 100644 --- a/addons/barcodes/static/src/components/barcode_scanner.js +++ b/addons/barcodes/static/src/components/barcode_scanner.js @@ -21,7 +21,7 @@ export class BarcodeScanner extends Component { try { barcode = await scanBarcode(this.env, this.facingMode); } catch (err) { - error = err.error.message; + error = err.message; } if (barcode) { diff --git a/addons/barcodes/static/tests/basic/barcode_scan_tests.js b/addons/barcodes/static/tests/basic/barcode_scan_tests.js new file mode 100644 index 00000000000..ace6213a10c --- /dev/null +++ b/addons/barcodes/static/tests/basic/barcode_scan_tests.js @@ -0,0 +1,32 @@ +/** @odoo-module **/ + +import { BarcodeScanner } from "@barcodes/components/barcode_scanner"; +import { getFixture, mount } from "@web/../tests/helpers/utils"; +import { contains } from "@web/../tests/utils"; +import { createWebClient } from "@web/../tests/webclient/helpers"; + +import { xml, Component } from "@odoo/owl"; + +QUnit.module("Barcode scan", {}); + +QUnit.test("Display notification for media device permission on barcode scanning", async () => { + navigator.mediaDevices.getUserMedia = function() { + return Promise.reject(new DOMException("", "NotAllowedError")); + }; + + class BarcodeScan extends Component {} + BarcodeScan.components = { BarcodeScanner }; + BarcodeScan.template = xml` +
+ +
+ `; + + const target = getFixture(); + const { env } = await createWebClient({}); + await mount(BarcodeScan, target, { env }); + + await document.querySelector('.o_mobile_barcode').click(); + await contains(".o_notification", { text: "Could not start scanning. Odoo needs your authorization first." }); + +})