Files
Collina-Matrix/addons/matrix_base/static/tests/matrix_camara.test.js
T
Fernando Dávila 05110c046c Versión inicial de Collina Matrix
Sistema de gestión multisucursal sobre Odoo 19 Community: módulos matrix_*, guiones de alta de instalaciones, suite de pruebas y documentación.
2026-11-21 11:57:28 -06:00

140 lines
5.3 KiB
JavaScript

/** Part of Matrix. Collina Systems proprietary module. */
import { expect, test, describe } from "@odoo/hoot";
import { patchWithCleanup } from "@web/../tests/web_test_helpers";
import { patchTranslations } from "@web/../tests/_framework/translation_test_helpers";
import { browser } from "@web/core/browser/browser";
import {
SIN_CAMARA,
SIN_CONEXION_SEGURA,
SIN_PERMISO,
matrixAvisoNavegador,
matrixCausaDeCamara,
matrixMensajeDeCamara,
} from "@matrix_base/barcode/matrix_camara_mensaje";
/**
* Por qué no abrió la cámara.
*
* El core culpa SIEMPRE al permiso («Odoo needs your authorization first»):
* dice un nombre que no es Matrix y, en un equipo sin cámara, manda a buscar
* un permiso que no arreglaría nada. Aquí se separan las tres causas.
*
* Es justo lo que no se puede comprobar a mano: dev corre en localhost, que
* SIEMPRE es contexto seguro y con la cámara del equipo puesta.
*/
describe.current.tags("desktop");
const UNA_CAMARA = [{ kind: "videoinput" }, { kind: "audioinput" }];
const SIN_VIDEO = [{ kind: "audioinput" }];
function conCamaras(lista) {
patchWithCleanup(browser, {
navigator: {
mediaDevices: {
getUserMedia: () => {},
enumerateDevices: async () => lista,
},
},
});
}
function texto(causa) {
patchTranslations();
return matrixMensajeDeCamara(causa).toString();
}
// ── La causa ────────────────────────────────────────────────────────────
test("sin mediaDevices la causa es la conexión, no el permiso", async () => {
patchWithCleanup(browser, { navigator: { mediaDevices: undefined } });
expect(await matrixCausaDeCamara()).toBe(SIN_CONEXION_SEGURA);
});
test("con cámara enumerada, la causa es el permiso", async () => {
conCamaras(UNA_CAMARA);
expect(await matrixCausaDeCamara()).toBe(SIN_PERMISO);
});
test("sin ninguna cámara enumerada, la causa es que no hay cámara", async () => {
// El discriminador: los navegadores listan las cámaras aunque el permiso
// esté denegado, así que cero videoinput sí significa que no hay.
conCamaras(SIN_VIDEO);
expect(await matrixCausaDeCamara()).toBe(SIN_CAMARA);
});
test("si enumerar falla no se inventa una causa", async () => {
patchWithCleanup(browser, {
navigator: {
mediaDevices: {
getUserMedia: () => {},
enumerateDevices: async () => {
throw new Error("bloqueado");
},
},
},
});
expect(await matrixCausaDeCamara()).toBe(SIN_PERMISO);
});
// ── El mensaje ──────────────────────────────────────────────────────────
test("sin conexión segura se dice eso, no que falten permisos", () => {
const mensaje = texto(SIN_CONEXION_SEGURA);
expect(mensaje).toInclude("conexión segura");
expect(mensaje).not.toInclude("permiso");
});
test("sin cámara no se manda a buscar un permiso que no existe", () => {
const mensaje = texto(SIN_CAMARA);
expect(mensaje).toInclude("no tiene cámara");
expect(mensaje).not.toInclude("permiso");
});
test("con la cámara bloqueada se dice dónde está el permiso", () => {
const mensaje = texto(SIN_PERMISO);
expect(mensaje).toInclude("permiso");
expect(mensaje).toInclude("candado");
});
test("ningún mensaje dice un nombre que no sea Matrix", () => {
for (const causa of [SIN_CONEXION_SEGURA, SIN_CAMARA, SIN_PERMISO]) {
expect(texto(causa)).not.toInclude("Odoo");
}
});
test("los tres dicen qué hacer mientras tanto", () => {
// Un error que solo informa deja a la persona con la caja en la mano y
// sin salida.
for (const causa of [SIN_CONEXION_SEGURA, SIN_CAMARA, SIN_PERMISO]) {
expect(texto(causa)).toInclude("nombre del artículo");
}
});
// ── El navegador que abre la cámara pero no lee ─────────────────────────
const UA_MIUI = "Mozilla/5.0 (Linux; U; Android 14; es-mx; 24048RNCAG Build/UP1A) "
+ "AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/118.0.5993.80 "
+ "Mobile Safari/537.36 XiaoMi/MiuiBrowser/18.3.60915";
const UA_WEBVIEW = "Mozilla/5.0 (Linux; Android 14; 24048RNCAG Build/UP1A; wv) "
+ "AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/129.0.0.0 Mobile Safari/537.36";
const UA_CHROME_ANDROID = "Mozilla/5.0 (Linux; Android 14; 24048RNCAG) AppleWebKit/537.36 "
+ "(KHTML, like Gecko) Chrome/129.0.0.0 Mobile Safari/537.36";
const UA_LAPTOP = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 "
+ "(KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36";
test("en el navegador de MIUI o en una vista web se manda a Chrome", () => {
patchTranslations();
for (const ua of [UA_MIUI, UA_WEBVIEW]) {
const aviso = matrixAvisoNavegador(ua).toString();
expect(aviso).toInclude("Chrome");
expect(aviso).not.toInclude("Odoo");
}
});
test("en Chrome de Android y en una laptop no hay aviso", () => {
expect(matrixAvisoNavegador(UA_CHROME_ANDROID)).toBe("");
expect(matrixAvisoNavegador(UA_LAPTOP)).toBe("");
expect(matrixAvisoNavegador("")).toBe("");
});