From 98e423532afd837ef8961f1089039af659dfad63 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 23 Oct 2023 09:27:33 +0200 Subject: [PATCH 1/5] maint(pat-ajax): Use bare JavaScript submit for tests. --- src/pat/ajax/ajax.test.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/pat/ajax/ajax.test.js b/src/pat/ajax/ajax.test.js index caf07a484..e4206cee5 100644 --- a/src/pat/ajax/ajax.test.js +++ b/src/pat/ajax/ajax.test.js @@ -1,6 +1,7 @@ -import registry from "../../core/registry"; -import pattern from "./ajax"; import $ from "jquery"; +import events from "../../core/events"; +import pattern from "./ajax"; +import registry from "../../core/registry"; import { jest } from "@jest/globals"; var $lab; @@ -47,13 +48,13 @@ describe("pat-ajax", function () { }); it("triggers ajax request on submit", function () { - $form.submit(); + $form[0].dispatchEvent(events.submit_event()); expect(spy_ajax).toHaveBeenCalled(); }); it("honors method='post'", function () { $form.attr("method", "post"); - $form.submit(); + $form[0].dispatchEvent(events.submit_event()); var ajaxargs = $.ajax.mock.calls[$.ajax.mock.calls.length - 1][0]; expect(ajaxargs.url).toEqual("action.html"); expect(ajaxargs.method).toEqual("POST"); @@ -73,7 +74,7 @@ describe("pat-ajax", function () { }); it("does not include submit buttons if not clicked", function () { - $form.submit(); + $form[0].dispatchEvent(events.submit_event()); var ajaxargs = $.ajax.mock.calls[$.ajax.mock.calls.length - 1][0]; expect(ajaxargs.url).toEqual("action.html"); expect(ajaxargs.data).toEqual("input1=value1"); @@ -99,7 +100,7 @@ describe("pat-ajax", function () { document.body.innerHTML = `
`; registry.scan(document.body); jest.spyOn($, "ajax"); - $(".pat-ajax").submit(); + $(".pat-ajax")[0].dispatchEvent(events.submit_event()); const ajaxargs = $.ajax.mock.calls[$.ajax.mock.calls.length - 1][0]; expect(ajaxargs.url).toEqual("somewhere.html"); }); @@ -127,7 +128,7 @@ describe("pat-ajax", function () { `; registry.scan(document.body); jest.spyOn($, "ajax"); - $(".pat-ajax").submit(); + $(".pat-ajax")[0].dispatchEvent(events.submit_event()); const ajaxargs = $.ajax.mock.calls[$.ajax.mock.calls.length - 1][0]; expect(ajaxargs.url).toEqual("else.html"); }); @@ -214,7 +215,7 @@ describe("pat-ajax", function () { data-pat-ajax="browser-cache: cache" />`; registry.scan(document.body); - $(".pat-ajax").submit(); // need jquery submit here + $(".pat-ajax")[0].dispatchEvent(events.submit_event()); const ajaxargs = spy_ajax.mock.calls[spy_ajax.mock.calls.length - 1][0]; expect(ajaxargs.cache).toBe(false); spy_ajax.mockRestore(); From bec5184ab244d29c9a16152673ce4bb31664bd91 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 23 Oct 2023 09:27:54 +0200 Subject: [PATCH 2/5] maint(pat-inject): Use bare JavaScript submit for tests. --- src/pat/inject/inject.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pat/inject/inject.test.js b/src/pat/inject/inject.test.js index 6562730af..4ab1dcf7f 100644 --- a/src/pat/inject/inject.test.js +++ b/src/pat/inject/inject.test.js @@ -1874,7 +1874,7 @@ describe("pat-inject", function () { registry.scan(document.body); await utils.timeout(1); - $(".pat-inject").submit(); // need jquery submit here + document.querySelector(".pat-inject").dispatchEvent(events.submit_event()); const ajaxargs = spy_ajax.mock.calls[spy_ajax.mock.calls.length - 1][0]; expect(ajaxargs.cache).toBe(false); spy_ajax.mockRestore(); From 59bbe4dfc38e43e286919b40e4416d748138efd5 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 23 Oct 2023 09:28:21 +0200 Subject: [PATCH 3/5] maint(pat-sortable): Use bare JavaScript submit for tests. --- src/pat/sortable/sortable.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pat/sortable/sortable.test.js b/src/pat/sortable/sortable.test.js index 23c4e713e..8cbbc0857 100644 --- a/src/pat/sortable/sortable.test.js +++ b/src/pat/sortable/sortable.test.js @@ -118,7 +118,7 @@ describe("pat-sortable", function () { $("#item3").prependTo($("ol")); // Simulate dragging it to the top. const submitCallback = jest.fn(); submitCallback.mockReturnValue(false); - $(form).submit(submitCallback); + form.addEventListener("submit", submitCallback); document .querySelector("#item3 a.sortable-handle") .dispatchEvent(events.dragend_event()); From 09822c5ee25c7195a62f7b6286017ec39cb85812 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 23 Oct 2023 09:29:47 +0200 Subject: [PATCH 4/5] fix(pat-push): Fix form submits not working with pat-inject. --- src/pat/push/push.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pat/push/push.js b/src/pat/push/push.js index 646743a01..11e9552e8 100644 --- a/src/pat/push/push.js +++ b/src/pat/push/push.js @@ -41,7 +41,7 @@ export default Base.extend({ if (this.options.mode === "desktop-notification") { this.desktop_notification(); } else if (this.el.tagName === "FORM") { - this.el.submit(); + this.el.dispatchEvent(events.submit_event()); } else { this.perform_inject(); } From 79436cb71fcacde80b55caf366a431dd1c428ed7 Mon Sep 17 00:00:00 2001 From: Johannes Raggam Date: Mon, 23 Oct 2023 09:30:19 +0200 Subject: [PATCH 5/5] fix(pat-subform): Fix subform submits not working with pat-inject. --- src/pat/subform/subform.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pat/subform/subform.js b/src/pat/subform/subform.js index 205720f7b..053cbec9d 100644 --- a/src/pat/subform/subform.js +++ b/src/pat/subform/subform.js @@ -6,6 +6,7 @@ import $ from "jquery"; import ajax from "../ajax/ajax"; import Base from "../../core/base"; +import events from "../../core/events"; import inject from "../inject/inject"; import logging from "../../core/logging"; @@ -16,7 +17,12 @@ export default Base.extend({ trigger: ".pat-subform", init($el) { - $el.submit(this.submit.bind(this)); + events.add_event_listener( + $el[0], + "submit", + "pat-subform--submit", + this.submit.bind(this) + ); $el.find("input").on("keyup keypress keydown", this.keyboard_handler.bind(this)); $el.find("button[type=submit]").on("click", this.submitClicked.bind(this)); }, @@ -76,7 +82,7 @@ export default Base.extend({ if (!$subform.is(".pat-autosubmit")) { return; } - return $subform.submit(); + $subform[0].dispatchEvent(events.submit_event()); }, submitClicked(ev) {