diff --git a/Dockerfile.test b/Dockerfile.test new file mode 100644 index 0000000..304ab5a --- /dev/null +++ b/Dockerfile.test @@ -0,0 +1,55 @@ +# Imagen de PRUEBAS de Beyond. +# +# The only thing it adds to the runtime image is a browser. Odoo runs its +# JavaScript suites — hoot unit tests AND tours — through browser_js, which +# drives a real Chrome in headless mode. Without one, `--test-enable` SKIPS +# them silently, and a widget can be dead in the interface while every test +# passes. That is not hypothetical: it happened, with the photo menu of +# beyond_image_camera. +# +# NOT the production image and NOT the dev compose: a third artifact, used by +# scripts/pruebas.sh and by the CI still pending in docs/despliegue.md. +# Producción no lleva navegador. +FROM odoo:19@sha256:84d09c623fc78050c2195161b98897995ba68c87aa4212d0ec0f4f3ce88c7610 + +USER root + +# Chromium de Playwright, fijado por versión de playwright. Tres candidatos +# quedaron descartados por motivos concretos: +# · Ubuntu `chromium` / `chromium-browser` en noble es un paquete de +# transición a snap (2:1snap1) que no se instala en un contenedor. +# · Chrome for Testing publica SOLO linux64 (x86-64), y las máquinas de +# desarrollo del proyecto son arm64: no arranca ni con emulación cómoda. +# · El repositorio apt de Google sirve siempre «la última», así que la +# versión no se puede fijar. +# Playwright publica builds de Chromium para arm64 y amd64 bajo la misma +# versión, así que ESTE MISMO Dockerfile produce el mismo navegador en la +# máquina de desarrollo y en la CI. Se sube a propósito, como el digest. +ARG PLAYWRIGHT_VERSION=1.56.0 +ENV PLAYWRIGHT_BROWSERS_PATH=/opt/navegador + +# python3-websocket: sin él Odoo SALTA las pruebas de navegador en vez de +# fallar — el verde silencioso que este archivo existe para eliminar. +RUN apt-get update \ + && apt-get install -y --no-install-recommends \ + python3-websocket python3-pip \ + ca-certificates fonts-liberation \ + libnss3 libnspr4 libdbus-1-3 libatk1.0-0t64 libatk-bridge2.0-0t64 \ + libcups2t64 libdrm2 libxkbcommon0 libxcomposite1 libxdamage1 \ + libxfixes3 libxrandr2 libgbm1 libxshmfence1 libasound2t64 \ + libpango-1.0-0 libcairo2 libatspi2.0-0t64 \ + && pip3 install --no-cache-dir --break-system-packages \ + "playwright==${PLAYWRIGHT_VERSION}" \ + && python3 -m playwright install chromium \ + && pip3 uninstall -y --break-system-packages playwright \ + && apt-get purge -y python3-pip \ + && apt-get autoremove -y \ + && rm -rf /var/lib/apt/lists/* \ + && chmod -R a+rX /opt/navegador + +# Odoo busca el ejecutable por nombre en PATH: google-chrome, chromium, +# chromium-browser o google-chrome-stable (odoo/tests/common.py). +RUN ln -sf "$(find /opt/navegador -name chrome -type f | head -1)" \ + /usr/local/bin/google-chrome + +USER odoo diff --git a/addons/beyond_base/static/src/fields/beyond_image_camera.js b/addons/beyond_base/static/src/fields/beyond_image_camera.js index c306ab1..c45847d 100644 --- a/addons/beyond_base/static/src/fields/beyond_image_camera.js +++ b/addons/beyond_base/static/src/fields/beyond_image_camera.js @@ -1,8 +1,11 @@ /** Part of Beyond. Collina Systems proprietary module. */ -import { Component, onWillUnmount, useRef, useState } from "@odoo/owl"; +import { Component, onWillUnmount, useExternalListener, useRef, useState } from "@odoo/owl"; import { Dialog } from "@web/core/dialog/dialog"; import { registry } from "@web/core/registry"; -import { useService, useExternalListener } from "@web/core/utils/hooks"; +// useExternalListener viene de OWL, NO de @web/core/utils/hooks: importarlo +// de ahí devuelve undefined y el diálogo de la cámara revienta al renderizar, +// sin decir por qué. Lo cazaron las unitarias en navegador. +import { useService } from "@web/core/utils/hooks"; import { browser } from "@web/core/browser/browser"; import { _t } from "@web/core/l10n/translation"; import { ImageField, imageField } from "@web/views/fields/image/image_field"; @@ -183,10 +186,17 @@ export class BeyondImageCamera extends ImageField { } } - /** Touch has no hover: a tap pins the menu open, another closes it. */ + /** + * Touch has no hover: a tap pins the menu open, another closes it. + * + * The second tap has to actually close it. `abierto = fijado || abierto` + * looked harmless and was not: once open, the right-hand side kept it + * open for ever and the menu could only be dismissed by moving a mouse + * the tablet does not have. + */ alternarMenu() { this.menu.fijado = !this.menu.fijado; - this.menu.abierto = this.menu.fijado || this.menu.abierto; + this.menu.abierto = this.menu.fijado; } cerrarMenu() { diff --git a/addons/beyond_base/static/tests/beyond_image_camera.test.js b/addons/beyond_base/static/tests/beyond_image_camera.test.js index 6049081..cc63896 100644 --- a/addons/beyond_base/static/tests/beyond_image_camera.test.js +++ b/addons/beyond_base/static/tests/beyond_image_camera.test.js @@ -1,6 +1,6 @@ /** Part of Beyond. Collina Systems proprietary module. */ import { expect, test, describe } from "@odoo/hoot"; -import { click, queryAll, queryFirst } from "@odoo/hoot-dom"; +import { click, press, queryAll, queryFirst } from "@odoo/hoot-dom"; import { animationFrame } from "@odoo/hoot-mock"; import { defineModels, @@ -10,6 +10,7 @@ import { patchWithCleanup, } from "@web/../tests/web_test_helpers"; import { browser } from "@web/core/browser/browser"; +import { defineMailModels } from "@mail/../tests/mail_test_helpers"; /** * Unit tests for beyond_image_camera. @@ -23,8 +24,11 @@ import { browser } from "@web/core/browser/browser"; describe.current.tags("desktop"); -class ResPartner extends models.Model { - _name = "res.partner"; +// Un modelo propio y NO res.partner: montar una vista sobre res.partner +// arrastra la maquinaria de mail (el chatter pide discuss.channel) y las +// pruebas mueren antes de llegar al widget. Al widget el modelo le da igual. +class BeyondFoto extends models.Model { + _name = "beyond.foto"; name = fields.Char(); image_1920 = fields.Binary(); @@ -32,22 +36,47 @@ class ResPartner extends models.Model { _records = [{ id: 1, name: "Alejandro Mcdonald", image_1920: "FOTO==" }]; } -defineModels([ResPartner]); +// Montar CUALQUIER formulario despierta la maquinaria de mail (el chatter +// pide discuss.channel) aunque la vista no lo lleve, porque mail parchea la +// vista de formulario en el bundle de pruebas. Sin esto, todas las pruebas +// mueren antes de llegar al widget. +defineMailModels(); +defineModels([BeyondFoto]); const VISTA = /* xml */ `
`; -/** Fakes a camera: one track whose stop() we can watch. */ +/** + * Fakes a camera: a REAL MediaStream whose track we can watch. + * + * It has to be a real one. Assigning a plain object to video.srcObject throws + * in Chromium ("the provided value is not of type MediaStream"), which showed + * up as an opaque "error in the owl lifecycle" and hid what was really being + * tested. A canvas gives us a genuine stream with a genuine track. + */ function camaraFalsa({ camaras = 1 } = {}) { - const pista = { stop: () => (pista.detenida = true), detenida: false, kind: "video" }; - const stream = { getTracks: () => [pista] }; + const lienzo = document.createElement("canvas"); + lienzo.width = 4; + lienzo.height = 4; + const stream = lienzo.captureStream(); + const pista = stream.getVideoTracks()[0]; + pista.detenida = false; + const detenerReal = pista.stop.bind(pista); + pista.stop = () => { + pista.detenida = true; + detenerReal(); + }; + pista.peticiones = []; patchWithCleanup(browser, { navigator: { ...browser.navigator, mediaDevices: { - getUserMedia: async () => stream, + getUserMedia: async (restricciones) => { + pista.peticiones.push(restricciones?.video?.facingMode); + return stream; + }, enumerateDevices: async () => Array.from({ length: camaras }, () => ({ kind: "videoinput" })), }, @@ -65,7 +94,7 @@ function sinCamara() { 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 }); + await mountView({ type: "form", resModel: "beyond.foto", resId: 1, arch: VISTA }); expect(".beyond_foto_menu").toHaveCount(0); @@ -78,9 +107,43 @@ test("el menú de la foto se abre al pasar el mouse y se cierra al salir", async expect(".beyond_foto_menu").toHaveCount(0); }); +test("el contenedor de la foto no recorta el menú", async () => { + // ESTA es la prueba que faltaba. El menú se renderizaba —el t-if pasaba y + // el DOM lo tenía— pero el contenedor llevaba overflow:hidden para + // redondear la imagen, y el menú cuelga por debajo con top:100%: quedaba + // recortado y era inalcanzable. Contar elementos no lo detecta, porque el + // nodo está ahí; ni :visible, porque un elemento recortado conserva su + // tamaño. Lo que hay que afirmar es que nadie lo recorta. + camaraFalsa(); + await mountView({ type: "form", resModel: "beyond.foto", resId: 1, arch: VISTA }); + + await click(".beyond_foto"); + await animationFrame(); + + const menu = queryFirst(".beyond_foto_menu"); + expect(menu).not.toBe(null); + // Solo hasta la hoja del formulario: de ahí para arriba el cliente web + // recorta a propósito (.o_form_view y .o_action_manager son sus + // contenedores de desplazamiento). Lo que no puede recortar es el propio + // widget, que es donde estaba el defecto. + // Solo los dos nodos que este widget controla. De ahí para arriba el + // cliente web recorta a propósito: .o_form_view y .o_action_manager son + // sus contenedores de desplazamiento y siempre llevan overflow:hidden. + for (const selector of [".beyond_foto", ".o_field_widget[name=image_1920]"]) { + const nodo = queryFirst(selector); + if (!nodo) { + continue; + } + const estilo = getComputedStyle(nodo); + expect(`${estilo.overflow} ${estilo.overflowY}`).not.toInclude("hidden", { + message: `${selector} recorta el menú de la foto`, + }); + } +}); + 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 mountView({ type: "form", resModel: "beyond.foto", resId: 1, arch: VISTA }); await click(".beyond_foto"); await animationFrame(); @@ -100,7 +163,7 @@ test("sin cámara no se ofrece «Tomar fotografía», y sí «Subir archivo»", // 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 mountView({ type: "form", resModel: "beyond.foto", resId: 1, arch: VISTA }); await click(".beyond_foto"); await animationFrame(); @@ -112,7 +175,7 @@ test("sin cámara no se ofrece «Tomar fotografía», y sí «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 mountView({ type: "form", resModel: "beyond.foto", resId: 1, arch: VISTA }); await click(".beyond_foto"); await animationFrame(); @@ -125,7 +188,7 @@ 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 mountView({ type: "form", resModel: "beyond.foto", resId: 1, arch: VISTA }); await click(".beyond_foto"); await animationFrame(); @@ -135,7 +198,7 @@ test("«Subir archivo» pide la cámara trasera, no la frontal", async () => { test("«Eliminar» limpia el campo", async () => { camaraFalsa(); - await mountView({ type: "form", resModel: "res.partner", resId: 1, arch: VISTA }); + await mountView({ type: "form", resModel: "beyond.foto", resId: 1, arch: VISTA }); await click(".beyond_foto"); await animationFrame(); @@ -150,7 +213,7 @@ 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 mountView({ type: "form", resModel: "beyond.foto", resId: 1, arch: VISTA }); await click(".beyond_foto"); await animationFrame(); @@ -160,7 +223,7 @@ test("cerrar el diálogo apaga la cámara", async () => { expect(".beyond_camara_video").toHaveCount(1); expect(pista.detenida).toBe(false); - await click(".beyond_camara_dialogo .btn-secondary:last-child"); // Cancelar + await click(".beyond_camara_dialogo .modal-footer button:contains(Cancelar)"); await animationFrame(); expect(pista.detenida).toBe(true); @@ -168,7 +231,7 @@ test("cerrar el diálogo apaga la cámara", async () => { 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 mountView({ type: "form", resModel: "beyond.foto", resId: 1, arch: VISTA }); await click(".beyond_foto"); await animationFrame(); @@ -181,3 +244,55 @@ test("con una sola cámara no se ofrece cambiarla", async () => { ); expect(botones).not.toInclude("Cambiar de cámara"); }); + + +test("el diálogo pide la cámara TRASERA por defecto", async () => { + // El caso de uso es el mostrador retratando al cliente, no una selfie. + const pista = camaraFalsa(); + await mountView({ type: "form", resModel: "beyond.foto", resId: 1, arch: VISTA }); + + await click(".beyond_foto"); + await animationFrame(); + await click(".beyond_foto_opcion"); + await animationFrame(); + await animationFrame(); + + expect(pista.peticiones[0]).toBe("environment"); +}); + +test("el botón de cambio pasa a la cámara frontal", async () => { + const pista = camaraFalsa({ camaras: 2 }); + await mountView({ type: "form", resModel: "beyond.foto", resId: 1, arch: VISTA }); + + await click(".beyond_foto"); + await animationFrame(); + await click(".beyond_foto_opcion"); + await animationFrame(); + await animationFrame(); + + await click(".beyond_camara_dialogo .modal-footer button:contains(Cambiar)"); + await animationFrame(); + await animationFrame(); + + expect(pista.peticiones).toEqual(["environment", "user"]); +}); + +test("cerrar con Escape también apaga la cámara", async () => { + // Cerrar con el teclado es la salida que más se olvida, y una cámara + // encendida deja el testigo del aparato prendido. + const pista = camaraFalsa(); + await mountView({ type: "form", resModel: "beyond.foto", resId: 1, arch: VISTA }); + + await click(".beyond_foto"); + await animationFrame(); + await click(".beyond_foto_opcion"); + await animationFrame(); + await animationFrame(); + expect(".beyond_camara_video").toHaveCount(1); + + await press("Escape"); + await animationFrame(); + + expect(".beyond_camara_dialogo").toHaveCount(0); + expect(pista.detenida).toBe(true); +}); diff --git a/addons/beyond_base/tests/__init__.py b/addons/beyond_base/tests/__init__.py index ebcc205..794d803 100644 --- a/addons/beyond_base/tests/__init__.py +++ b/addons/beyond_base/tests/__init__.py @@ -4,3 +4,4 @@ from . import test_menu_cleanup from . import test_security_groups from . import test_signup from . import test_panel_navbar +from . import test_unitarias_js diff --git a/addons/beyond_base/tests/test_unitarias_js.py b/addons/beyond_base/tests/test_unitarias_js.py new file mode 100644 index 0000000..04ac4e0 --- /dev/null +++ b/addons/beyond_base/tests/test_unitarias_js.py @@ -0,0 +1,32 @@ +# Part of Beyond. Collina Systems proprietary module. +from odoo.tests import HttpCase, tagged + +from odoo.addons.web.tests.test_js import unit_test_error_checker + +# Hoot identifica cada suite por un hash de su ruta. El de «@beyond_base» +# selecciona todas las unitarias de este módulo y ninguna ajena, para no +# arrastrar las ~3700 del core en cada corrida. El algoritmo es el de +# web/tests/test_js.py::HOOTCommon._generate_hash; si algún día cambia, este +# test empieza a correr de más, no de menos. +SUITE_BEYOND = 'd6e526c1' # @beyond_base + + +@tagged('post_install', '-at_install') +class TestBeyondUnitariasJS(HttpCase): + """Corre las unitarias JS de beyond_base en un navegador de verdad. + + Existe porque el runner de hoot vive en el módulo `web`: acotar la suite + con --test-tags=/beyond_base lo deja fuera, y entonces las unitarias no se + ejecutan y la corrida sale verde sin haberlas mirado. Eso ya nos pasó: el + menú de la foto estaba muerto en la interfaz con todas las pruebas en + verde. + """ + + def test_unitarias_de_beyond(self): + self.browser_js( + f'/web/tests?headless&loglevel=2&preset=desktop&timeout=15000' + f'&id={SUITE_BEYOND}', + "", "", login='admin', timeout=1800, + success_signal="[HOOT] Test suite succeeded", + error_checker=unit_test_error_checker, + ) diff --git a/addons/beyond_branch/demo/demo_branches.xml b/addons/beyond_branch/demo/demo_branches.xml index 61ffa77..b7cfd6b 100644 --- a/addons/beyond_branch/demo/demo_branches.xml +++ b/addons/beyond_branch/demo/demo_branches.xml @@ -30,6 +30,7 @@Prefiere cita temprano.
».""" + arch = etree.fromstring(self._arch('beyond_customer.view_beyond_cliente_form')) + notas = arch.xpath("//field[@name='comment']") + self.assertTrue(notas, "la ficha perdió las notas") + self.assertIsNone( + notas[0].get('widget'), + "las notas deben usar el widget propio de un campo HTML") + + def test_anonimizar_va_en_el_pie_y_es_secundario(self): + """En el