diff --git a/base_geoengine/__manifest__.py b/base_geoengine/__manifest__.py index b620bf7b8..be51c50b6 100644 --- a/base_geoengine/__manifest__.py +++ b/base_geoengine/__manifest__.py @@ -25,6 +25,9 @@ "base_geoengine/static/src/css/style.css", "base_geoengine/static/lib/geostats-2.1.0/geostats.css", ], + "web.assets_unit_tests": [ + "base_geoengine/static/tests/**/*.test.js", + ], # Note: Third-party libraries (ol.js, chroma.js, geostats.js) are loaded # dynamically via loadJS() in geoengine_libs.esm.js to avoid bundler issues }, diff --git a/base_geoengine/static/src/js/views/geoengine/geoengine_controller/geoengine_controller.esm.js b/base_geoengine/static/src/js/views/geoengine/geoengine_controller/geoengine_controller.esm.js index 44a360253..1b81849dd 100644 --- a/base_geoengine/static/src/js/views/geoengine/geoengine_controller/geoengine_controller.esm.js +++ b/base_geoengine/static/src/js/views/geoengine/geoengine_controller/geoengine_controller.esm.js @@ -119,14 +119,17 @@ export class GeoengineController extends Component { */ async openRecord(resModel, resId, viewId) { const {views} = await this.view.loadViews({resModel, views: [[false, "form"]]}); - this.actionService.doAction({ - type: "ir.actions.act_window", - res_model: resModel, - views: viewId || [[views.form.id, "form"]], - res_id: resId, - target: "new", - context: {edit: false, create: false}, - }); + return this.actionService.doAction( + { + type: "ir.actions.act_window", + res_model: resModel, + views: viewId || [[views.form.id, "form"]], + res_id: resId, + target: "new", + context: {edit: this.editable, create: false}, + }, + {onClose: () => this.onSaveRecord()} + ); } /** @@ -208,6 +211,7 @@ GeoengineController.template = "base_geoengine.GeoengineController"; GeoengineController.components = {Layout, SearchBar}; GeoengineController.props = { ...standardViewProps, + env: {type: Object, optional: true}, Model: Function, Renderer: Function, archInfo: Object, diff --git a/base_geoengine/static/tests/geoengine_controller.test.js b/base_geoengine/static/tests/geoengine_controller.test.js new file mode 100644 index 000000000..ee662ab13 --- /dev/null +++ b/base_geoengine/static/tests/geoengine_controller.test.js @@ -0,0 +1,73 @@ +// Copyright 2026 Camptocamp SA +// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +import {Component, xml} from "@odoo/owl"; +import { + contains, + defineModels, + fields, + makeMockEnv, + models, + mountView, + mountWithCleanup, + onRpc, + patchWithCleanup, +} from "@web/../tests/web_test_helpers"; +import {describe, expect, test} from "@odoo/hoot"; +import {MainComponentsContainer} from "@web/core/main_components_container"; +import {geoengineView} from "@base_geoengine/js/views/geoengine/geoengine_view.esm"; + +class GeoTest extends models.Model { + _name = "geo.test"; + + name = fields.Char(); + + _records = [{id: 1, name: "Test location"}]; +} + +class OpenRecordRenderer extends Component { + static props = ["*"]; + static template = xml` + + `; + + openRecord() { + return this.props.openRecord("geo.test", 1); + } +} + +defineModels([GeoTest]); +describe.current.tags("desktop"); + +test("editable GeoEngine view opens an editable form dialog and refreshes on close", async () => { + let loadCount = 0; + onRpc("geo.test", "web_search_read", () => { + loadCount++; + }); + patchWithCleanup(geoengineView, {Renderer: OpenRecordRenderer}); + + const env = await makeMockEnv(); + await mountWithCleanup(MainComponentsContainer, {env}); + await mountView({ + env, + type: "geoengine", + resModel: "geo.test", + arch: ` + + + + + + `, + archs: { + "form,false": `
`, + }, + }); + const initialLoadCount = loadCount; + + await contains(".o_test_open_record").click(); + expect(".modal .o_form_view .o_field_widget[name='name'] input").toHaveCount(1); + + await contains(".modal .o_form_button_cancel").click(); + expect(loadCount).toBeGreaterThan(initialLoadCount); +});