From e1639c2c1ebfc3371618d1c58529d734257639ca Mon Sep 17 00:00:00 2001 From: "Stefan-Calin Crainiciuc (stcc)" Date: Mon, 13 Mar 2023 10:27:04 +0000 Subject: [PATCH] [FIX] web: move test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The test added in dea66e1df317ca8782a68ece6c1e5917f6e8f3ec depends on a `mail` helper, even though it is in the `web` module. opw-3133731 closes odoo/odoo#115104 X-original-commit: e0ac9c41c6852cc147a9dea236421193161d7abe Signed-off-by: Georis François (fge) Signed-off-by: Stefan-Calin Crainiciuc (stcc) --- .../mobile/views/widgets/signature_tests.js | 115 ++++++++++++++++++ .../tests/views/widgets/signature_tests.js | 72 +---------- 2 files changed, 116 insertions(+), 71 deletions(-) create mode 100644 addons/web/static/tests/mobile/views/widgets/signature_tests.js diff --git a/addons/web/static/tests/mobile/views/widgets/signature_tests.js b/addons/web/static/tests/mobile/views/widgets/signature_tests.js new file mode 100644 index 00000000000..fa0d7edc355 --- /dev/null +++ b/addons/web/static/tests/mobile/views/widgets/signature_tests.js @@ -0,0 +1,115 @@ +/** @odoo-module **/ +import { click, getFixture, patchWithCleanup, editInput, nextTick } from "@web/../tests/helpers/utils"; +import { makeView, setupViewRegistries } from "@web/../tests/views/helpers"; +import { SignatureWidget } from "@web/views/widgets/signature/signature"; + +let serverData; +let target; + +QUnit.module("Widgets", (hooks) => { + hooks.beforeEach(() => { + target = getFixture(); + serverData = { + models: { + partner: { + fields: { + display_name: { string: "Name", type: "char" }, + product_id: { + string: "Product Name", + type: "many2one", + relation: "product", + }, + signature: { string: "", type: "string" }, + }, + records: [ + { + id: 1, + display_name: "Pop's Chock'lit", + product_id: 7, + }, + ], + onchanges: {}, + }, + product: { + fields: { + name: { string: "Product Name", type: "char" }, + }, + records: [ + { + id: 7, + display_name: "Veggie Burger", + }, + ], + }, + }, + }; + + setupViewRegistries(); + }); + + QUnit.module("Signature Widget"); + + QUnit.test("Signature widget works inside of a dropdown", async (assert) => { + assert.expect(7); + patchWithCleanup(SignatureWidget.prototype, { + async onClickSignature() { + await this._super.apply(this, arguments); + assert.step("onClickSignature"); + }, + async uploadSignature({signatureImage}) { + await this._super.apply(this, arguments); + assert.step("uploadSignature"); + }, + }); + + await makeView({ + type: "form", + resModel: "partner", + resId: 1, + serverData, + arch: ` +
+
+
+ + + `, + mockRPC: async (route, args) => { + if (route === "/web/sign/get_fonts/") { + return {}; + } + }, + }); + + // change display_name to enable auto-sign feature + await editInput(target, ".o_field_widget[name=display_name] input", "test"); + + // open the signature dialog + await click(target, ".o_statusbar_buttons .dropdown-toggle"); + await click(target, ".o_widget_signature button.o_sign_button"); + + assert.containsOnce(target, ".modal-dialog", "Should have one modal opened"); + + // use auto-sign feature, might take a while + await click(target, ".o_web_sign_auto_button"); + + assert.containsOnce(target, ".modal-footer button.btn-primary"); + + let maxDelay = 100; + while (target.querySelector(".modal-footer button.btn-primary")["disabled"] && maxDelay > 0) { + await nextTick(); + maxDelay--; + } + + assert.equal(maxDelay > 0, true, "Timeout exceeded"); + + // close the dialog and save the signature + await click(target, ".modal-footer button.btn-primary:enabled"); + + assert.containsNone(target, ".modal-dialog", "Should have no modal opened"); + + assert.verifySteps(["onClickSignature", "uploadSignature"], "An error has occurred while signing"); + }); +}); diff --git a/addons/web/static/tests/views/widgets/signature_tests.js b/addons/web/static/tests/views/widgets/signature_tests.js index dc0b00daa0c..09c07a9f7ff 100644 --- a/addons/web/static/tests/views/widgets/signature_tests.js +++ b/addons/web/static/tests/views/widgets/signature_tests.js @@ -1,9 +1,7 @@ /** @odoo-module **/ -import { click, getFixture, patchWithCleanup, editInput, nextTick } from "@web/../tests/helpers/utils"; +import { click, getFixture, patchWithCleanup } from "@web/../tests/helpers/utils"; import { makeView, setupViewRegistries } from "@web/../tests/views/helpers"; -import { patchUiSize } from "@mail/../tests/helpers/patch_ui_size"; import { NameAndSignature } from "@web/core/signature/name_and_signature"; -import { SignatureWidget } from "@web/views/widgets/signature/signature"; let serverData; let target; @@ -22,7 +20,6 @@ QUnit.module("Widgets", (hooks) => { relation: "product", }, sign: { string: "Signature", type: "binary" }, - signature: { string: "", type: "string" }, }, records: [ { @@ -154,71 +151,4 @@ QUnit.module("Widgets", (hooks) => { await click(target, ".o_widget_signature button.o_sign_button"); assert.containsNone(target, ".modal .modal-body a.o_web_sign_auto_button"); }); - - QUnit.test("Signature widget works inside of a dropdown", async (assert) => { - assert.expect(7); - patchWithCleanup(SignatureWidget.prototype, { - async onClickSignature() { - await this._super.apply(this, arguments); - assert.step("onClickSignature"); - }, - async uploadSignature({signatureImage}) { - await this._super.apply(this, arguments); - assert.step("uploadSignature"); - }, - }); - - // force mobile view - patchUiSize({ width: 225 }); - - await makeView({ - type: "form", - resModel: "partner", - resId: 1, - serverData, - arch: ` -
-
-
- - - `, - mockRPC: async (route, args) => { - if (route === "/web/sign/get_fonts/") { - return {}; - } - }, - }); - - // change display_name to enable auto-sign feature - await editInput(target, ".o_field_widget[name=display_name] input", "test"); - - // open the signature dialog - await click(target, ".o_statusbar_buttons .dropdown-toggle"); - await click(target, ".o_widget_signature button.o_sign_button"); - - assert.containsOnce(target, ".modal-dialog", "Should have one modal opened"); - - // use auto-sign feature, might take a while - await click(target, ".o_web_sign_auto_button"); - - assert.containsOnce(target, ".modal-footer button.btn-primary"); - - let maxDelay = 100; - while (target.querySelector(".modal-footer button.btn-primary")["disabled"] && maxDelay > 0) { - await nextTick(); - maxDelay--; - } - - assert.equal(maxDelay > 0, true, "Timeout exceeded"); - - // close the dialog and save the signature - await click(target, ".modal-footer button.btn-primary:enabled"); - - assert.containsNone(target, ".modal-dialog", "Should have no modal opened"); - - assert.verifySteps(["onClickSignature", "uploadSignature"], "An error has occurred while signing"); - }); });