Reviste Clientes y le da una cámara a la foto del cliente
Las tres vistas y el buscador de Clientes pasan a ser herencias en modo primary atadas a la acción. Siguen siendo xpath sobre lo nativo, no vistas escritas de cero, pero el compromiso de no mostrar el correo aguanta por construcción y no por propagación de contexto: al registro se llega también desde una miga, un enlace o el POS, y ahí un invisible por contexto habría dejado el correo a la vista. Contactos nativo conserva su correo y su RFC, con test que lo fija. De la ficha sale el cuaderno de pestañas entero. Traía un segundo correo, un segundo bloque de dirección y una copia de las notas, y además ofrecía una pestaña de Facturación en un sistema que no factura (BRIEF §5.7). La caja de botones estadísticos se sustituye completa: media docena de módulos del core cuelgan los suyos ahí, y quitarlos uno por uno ataría la vista a qué módulos estén instalados. Quedan los dos del diseño. El widget de foto hereda del ImageField nativo, así que subir, limpiar y guardar siguen siendo los del core; lo que agrega es el menú del diseño y un diálogo de captura con la cámara TRASERA por defecto, que es el caso de uso —el mostrador retrata al cliente, no se hace una selfie—. El stream se libera al cerrar, al salir con Escape, al navegar dentro del cliente y al dejar la página; también si el diálogo se cierra antes de que la cámara termine de encender. Sin contexto seguro el navegador ni siquiera define navigator.mediaDevices, así que en las tablets no habrá diálogo de cámara hasta que producción tenga TLS. El widget no ofrece un botón que reventaría: oculta «Tomar fotografía» y deja «Subir archivo» con capture=environment, que abre la cámara nativa de Android sin exigir https. Queda anotado en despliegue.md. Las iniciales sobre durazno son un widget propio y no avatar_128: el mixin del core dibuja UNA letra sobre un color derivado del id, dentro de un SVG en base64 servido como imagen, así que ninguna hoja de estilo puede volverlo el durazno del diseño ni darle las dos letras. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
efa42e511a
commit
a9cd2ee3a9
14 files changed
+1305
-2
No files matched your search
@@ -0,0 +1,183 @@
|
||||
/** Part of Beyond. Collina Systems proprietary module. */
|
||||
import { expect, test, describe } from "@odoo/hoot";
|
||||
import { click, queryAll, queryFirst } from "@odoo/hoot-dom";
|
||||
import { animationFrame } from "@odoo/hoot-mock";
|
||||
import {
|
||||
defineModels,
|
||||
fields,
|
||||
models,
|
||||
mountView,
|
||||
patchWithCleanup,
|
||||
} from "@web/../tests/web_test_helpers";
|
||||
import { browser } from "@web/core/browser/browser";
|
||||
|
||||
/**
|
||||
* Unit tests for beyond_image_camera.
|
||||
*
|
||||
* The one that matters most is the secure-context one: production has no TLS
|
||||
* yet, so navigator.mediaDevices does not exist on the branch tablets and the
|
||||
* widget must not offer a button that would throw. That is the case a person
|
||||
* cannot easily check by hand — dev runs on localhost, where the camera
|
||||
* always works.
|
||||
*/
|
||||
|
||||
describe.current.tags("desktop");
|
||||
|
||||
class ResPartner extends models.Model {
|
||||
_name = "res.partner";
|
||||
|
||||
name = fields.Char();
|
||||
image_1920 = fields.Binary();
|
||||
|
||||
_records = [{ id: 1, name: "Alejandro Mcdonald", image_1920: "FOTO==" }];
|
||||
}
|
||||
|
||||
defineModels([ResPartner]);
|
||||
|
||||
const VISTA = /* xml */ `
|
||||
<form>
|
||||
<field name="image_1920" widget="beyond_image_camera"/>
|
||||
</form>`;
|
||||
|
||||
/** Fakes a camera: one track whose stop() we can watch. */
|
||||
function camaraFalsa({ camaras = 1 } = {}) {
|
||||
const pista = { stop: () => (pista.detenida = true), detenida: false, kind: "video" };
|
||||
const stream = { getTracks: () => [pista] };
|
||||
patchWithCleanup(browser, {
|
||||
navigator: {
|
||||
...browser.navigator,
|
||||
mediaDevices: {
|
||||
getUserMedia: async () => stream,
|
||||
enumerateDevices: async () =>
|
||||
Array.from({ length: camaras }, () => ({ kind: "videoinput" })),
|
||||
},
|
||||
},
|
||||
});
|
||||
return pista;
|
||||
}
|
||||
|
||||
/** Takes the camera away, the way an http:// page does. */
|
||||
function sinCamara() {
|
||||
patchWithCleanup(browser, {
|
||||
navigator: { ...browser.navigator, mediaDevices: undefined },
|
||||
});
|
||||
}
|
||||
|
||||
test("el menú de la foto se abre al pasar el mouse y se cierra al salir", async () => {
|
||||
camaraFalsa();
|
||||
await mountView({ type: "form", resModel: "res.partner", resId: 1, arch: VISTA });
|
||||
|
||||
expect(".beyond_foto_menu").toHaveCount(0);
|
||||
|
||||
await queryFirst(".beyond_foto").dispatchEvent(new MouseEvent("mouseenter"));
|
||||
await animationFrame();
|
||||
expect(".beyond_foto_menu").toHaveCount(1);
|
||||
|
||||
await queryFirst(".beyond_foto").dispatchEvent(new MouseEvent("mouseleave"));
|
||||
await animationFrame();
|
||||
expect(".beyond_foto_menu").toHaveCount(0);
|
||||
});
|
||||
|
||||
test("un toque fija el menú y otro lo suelta (en táctil no hay hover)", async () => {
|
||||
camaraFalsa();
|
||||
await mountView({ type: "form", resModel: "res.partner", resId: 1, arch: VISTA });
|
||||
|
||||
await click(".beyond_foto");
|
||||
await animationFrame();
|
||||
expect(".beyond_foto_menu").toHaveCount(1);
|
||||
|
||||
// Fijado: salir con el mouse ya no lo cierra.
|
||||
await queryFirst(".beyond_foto").dispatchEvent(new MouseEvent("mouseleave"));
|
||||
await animationFrame();
|
||||
expect(".beyond_foto_menu").toHaveCount(1);
|
||||
|
||||
await click(".beyond_foto");
|
||||
await animationFrame();
|
||||
expect(".beyond_foto_menu").toHaveCount(0);
|
||||
});
|
||||
|
||||
test("sin cámara no se ofrece «Tomar fotografía», y sí «Subir archivo»", async () => {
|
||||
// Es el caso de las tablets de sucursal mientras producción no tenga TLS:
|
||||
// fuera de contexto seguro el navegador ni siquiera define mediaDevices.
|
||||
sinCamara();
|
||||
await mountView({ type: "form", resModel: "res.partner", resId: 1, arch: VISTA });
|
||||
|
||||
await click(".beyond_foto");
|
||||
await animationFrame();
|
||||
|
||||
const opciones = queryAll(".beyond_foto_opcion").map((b) => b.textContent.trim());
|
||||
expect(opciones).not.toInclude("Tomar fotografía");
|
||||
expect(opciones).toInclude("Subir archivo");
|
||||
});
|
||||
|
||||
test("con cámara sí se ofrece «Tomar fotografía»", async () => {
|
||||
camaraFalsa();
|
||||
await mountView({ type: "form", resModel: "res.partner", resId: 1, arch: VISTA });
|
||||
|
||||
await click(".beyond_foto");
|
||||
await animationFrame();
|
||||
|
||||
const opciones = queryAll(".beyond_foto_opcion").map((b) => b.textContent.trim());
|
||||
expect(opciones).toInclude("Tomar fotografía");
|
||||
});
|
||||
|
||||
test("«Subir archivo» pide la cámara trasera, no la frontal", async () => {
|
||||
// Coherencia con el diálogo propio: el caso de uso es el mostrador
|
||||
// fotografiando al cliente, no una selfie.
|
||||
sinCamara();
|
||||
await mountView({ type: "form", resModel: "res.partner", resId: 1, arch: VISTA });
|
||||
|
||||
await click(".beyond_foto");
|
||||
await animationFrame();
|
||||
|
||||
expect("input[type=file]").toHaveAttribute("capture", "environment");
|
||||
});
|
||||
|
||||
test("«Eliminar» limpia el campo", async () => {
|
||||
camaraFalsa();
|
||||
await mountView({ type: "form", resModel: "res.partner", resId: 1, arch: VISTA });
|
||||
|
||||
await click(".beyond_foto");
|
||||
await animationFrame();
|
||||
await click(".beyond_foto_borrar");
|
||||
await animationFrame();
|
||||
|
||||
// Sin imagen no hay nada que borrar: la opción desaparece.
|
||||
expect(".beyond_foto_borrar").toHaveCount(0);
|
||||
});
|
||||
|
||||
test("cerrar el diálogo apaga la cámara", async () => {
|
||||
// Una cámara que se queda encendida deja el testigo del aparato prendido
|
||||
// y parece que el local está grabando.
|
||||
const pista = camaraFalsa();
|
||||
await mountView({ type: "form", resModel: "res.partner", resId: 1, arch: VISTA });
|
||||
|
||||
await click(".beyond_foto");
|
||||
await animationFrame();
|
||||
await click(".beyond_foto_opcion"); // «Tomar fotografía»
|
||||
await animationFrame();
|
||||
await animationFrame();
|
||||
expect(".beyond_camara_video").toHaveCount(1);
|
||||
expect(pista.detenida).toBe(false);
|
||||
|
||||
await click(".beyond_camara_dialogo .btn-secondary:last-child"); // Cancelar
|
||||
await animationFrame();
|
||||
|
||||
expect(pista.detenida).toBe(true);
|
||||
});
|
||||
|
||||
test("con una sola cámara no se ofrece cambiarla", async () => {
|
||||
camaraFalsa({ camaras: 1 });
|
||||
await mountView({ type: "form", resModel: "res.partner", resId: 1, arch: VISTA });
|
||||
|
||||
await click(".beyond_foto");
|
||||
await animationFrame();
|
||||
await click(".beyond_foto_opcion");
|
||||
await animationFrame();
|
||||
await animationFrame();
|
||||
|
||||
const botones = queryAll(".beyond_camara_dialogo .modal-footer .btn").map((b) =>
|
||||
b.textContent.trim()
|
||||
);
|
||||
expect(botones).not.toInclude("Cambiar de cámara");
|
||||
});
|
||||
Reference in new issue
Block a user