Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pat/inject/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,13 @@ const inject = {
return;
}
let url = cfg.url;
const glue = url.indexOf("?") > -1 ? "&" : "?";
if (cfg.params) {
const glue = url.indexOf("?") > -1 ? "&" : "?";
url = `${url}${glue}${cfg.params}`;
}
history.pushState({ url: url }, "", url);
// Also inject title element if we have one
if ($title.length) {
if ($title?.length) {
const title_el = document.querySelector("title");
if (title_el) {
this._inject(trigger, $title, title_el, {
Expand Down
78 changes: 78 additions & 0 deletions src/pat/inject/inject.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1739,6 +1739,84 @@ describe("pat-inject", function () {
expect(title).toBeTruthy();
expect(title.textContent.trim()).toBe("test"); // Old title
});

it("9.4.3 - Does not break, if no title is found in source", async function () {
document.head.innerHTML = `
<title>test</title>
`;
document.body.innerHTML = `
<a class="pat-inject"
href="test.html"
data-pat-inject="
source: body;
target: body;
history: record;
">link</a>
`;

answer(`
<html>
<body>
OK
</body>
</html>
`);

const inject = document.querySelector(".pat-inject");

pattern.init($(inject));
await utils.timeout(1); // wait a tick for async to settle.

inject.click();

await utils.timeout(1); // wait a tick for async to settle.

expect(document.body.textContent.trim()).toBe("OK");

// Title in head target is not modified.
const title = document.head.querySelector("title");
expect(title).toBeTruthy();
expect(title.textContent.trim()).toBe("test"); // Old title
});

it("9.4.4 - Does not break, if no title is found in target", async function () {
document.head.innerHTML = "";
document.body.innerHTML = `
<a class="pat-inject"
href="test.html"
data-pat-inject="
source: body;
target: body;
history: record;
">link</a>
`;

answer(`
<html>
<head>
<title>hello</title>
<body>
OK
</body>
</html>
`);

const inject = document.querySelector(".pat-inject");

pattern.init($(inject));
await utils.timeout(1); // wait a tick for async to settle.

inject.click();

await utils.timeout(1); // wait a tick for async to settle.

expect(document.body.textContent.trim()).toBe("OK");

// There is no title to be updated in target.
const title = document.head.querySelector("title");
expect(title).toBeFalsy();
});

});

describe("9.5 - support multiple source element matches.", function () {
Expand Down