Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion barcode_scanner/static/src/js/services/feedback_service.esm.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import {Reactive} from "@web/core/utils/reactive";
import {registry} from "@web/core/registry";

const NOTIFICATION_TYPES = {
success: "success",
warning: "warning",
error: "danger",
info: "info",
};

const DEFAULT_PROFILES = {
success: {
vibration: [35],
Expand Down Expand Up @@ -83,7 +90,9 @@ export class BarcodeScannerFeedbackService extends Reactive {
const signal = {level, message: options.message || "", at: Date.now()};
this.lastSignal = signal;
if (options.notify && options.message) {
this.notification.add(options.message, {type: level});
this.notification.add(options.message, {
type: NOTIFICATION_TYPES[level] || "info",
});
}
if (this.enabled.flash) {
this.flashOnce(level, options.flashDurationMs || 180);
Expand Down
39 changes: 39 additions & 0 deletions barcode_scanner/static/tests/feedback_service.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import {describe, expect, test} from "@odoo/hoot";
import {BarcodeScannerFeedbackService} from "@barcode_scanner/js/services/feedback_service.esm";

function makeFeedback(notifications) {
const feedback = new BarcodeScannerFeedbackService({
add: (...args) => notifications.push(args),
});
feedback.enabled = {audio: false, vibration: false, flash: false};
return feedback;
}

describe("BarcodeScannerFeedbackService", () => {
test("error feedback uses the danger notification type", () => {
const notifications = [];
const feedback = makeFeedback(notifications);
const message = "Unable to apply the cycle count";

feedback.error({message, notify: true});

expect(notifications).toEqual([[message, {type: "danger"}]]);
feedback.destroy();
});

test("feedback levels map to valid Odoo notification types", () => {
const cases = [
["success", "success"],
["warning", "warning"],
["info", "info"],
["error", "danger"],
];
for (const [level, type] of cases) {
const notifications = [];
const feedback = makeFeedback(notifications);
feedback[level]({message: level, notify: true});
expect(notifications).toEqual([[level, {type}]]);
feedback.destroy();
}
});
});
Loading