Skip to content

Commit 3039a4f

Browse files
committed
feat(pat inject): After failed ajax request, remove loading and executing classes from target and trigger elements.
1 parent f47ea84 commit 3039a4f

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

src/pat/inject/inject.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,11 @@ const inject = {
662662

663663
// clean up
664664
cfgs.forEach((cfg) => {
665-
if ("$injected" in cfg) cfg.$injected.remove();
665+
if ("$injected" in cfg) {
666+
cfg.$injected.remove();
667+
}
668+
cfg.$target.removeClass(cfg.loadingClass);
669+
$el.removeClass(cfg.executingClass);
666670
});
667671
$el.off("pat-ajax-success.pat-inject");
668672
$el.off("pat-ajax-error.pat-inject");

src/pat/inject/inject.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1095,6 +1095,38 @@ describe("pat-inject", function () {
10951095
delete global.fetch;
10961096
});
10971097

1098+
it("Removes loading and executing classes.", async () => {
1099+
document.body.innerHTML = `
1100+
<a
1101+
class="pat-inject i-am-executing"
1102+
href="test.html"
1103+
>link</a>
1104+
<div id="someid" class="i-am-loading" />
1105+
`;
1106+
1107+
$a = $(".pat-inject");
1108+
pattern.init($a);
1109+
1110+
// Invoke error case
1111+
pattern._onInjectError(
1112+
$a,
1113+
[
1114+
{
1115+
$target: $("#someid"),
1116+
loadingClass: "i-am-loading",
1117+
executingClass: "i-am-executing",
1118+
},
1119+
],
1120+
{
1121+
jqxhr: { status: 404 },
1122+
}
1123+
);
1124+
await utils.timeout(1); // wait a tick for async to settle.
1125+
1126+
expect(document.querySelector(".pat-inject").getAttribute("class")).toEqual("pat-inject"); // prettier-ignore
1127+
expect(document.querySelector("#someid").getAttribute("class")).toEqual("");
1128+
});
1129+
10981130
it("Doesnt get error page from meta tags if query string present", async () => {
10991131
delete global.window.location;
11001132
global.window.location = {

0 commit comments

Comments
 (0)