Skip to content

Commit

Permalink
Feat: Versione 1.1.13 - aggiornamento domini validi, scroll pagina pe…
Browse files Browse the repository at this point in the history
…r audit componente feedback
  • Loading branch information
lorenzo-vernocchi committed Dec 20, 2024
1 parent 29b0c0f commit d4170f7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 5 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pa-website-validator-ng",
"version": "1.1.12",
"version": "1.1.13",
"main": "index.js",
"type": "module",
"scripts": {
Expand Down
12 changes: 11 additions & 1 deletion src/audits/municipality_feedback/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

import { checkFeedbackComponent } from "../../utils/municipality/utils.js";
import { errorHandling } from "../../config/commonAuditsParts.js";
import { setTimeout } from "timers/promises";

import { Page } from "puppeteer";
import { Audit, GlobalResultsMulti } from "../Audit.js";
import * as ejs from "ejs";
import { __dirname } from "../esmHelpers.js";
import { redirectUrlIsInternal } from "../../utils/utils.js";
import { redirectUrlIsInternal, scrollToBottom } from "../../utils/utils.js";

const auditId = "municipality-feedback-element";
const code = "C.SI.2.5";
Expand Down Expand Up @@ -91,6 +92,15 @@ class FeedbackAudit extends Audit {
height: 2160,
});

await scrollToBottom(page);

await Promise.race([
setTimeout(10000),
page.waitForNetworkIdle({
idleTime: 2000,
}),
]);

this.titleSubHeadings = ["Elementi errati o non trovati"];

const item = {
Expand Down
22 changes: 21 additions & 1 deletion src/audits/municipality_user_experience_evaluation/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { Audit, GlobalResultsMulti } from "../Audit.js";
import { Page } from "puppeteer";
import * as ejs from "ejs";
import { __dirname } from "../esmHelpers.js";
import { redirectUrlIsInternal } from "../../utils/utils.js";
import { redirectUrlIsInternal, scrollToBottom } from "../../utils/utils.js";
import { setTimeout } from "timers/promises";

const auditId = "municipality-user-experience-evaluation";
const code = "C.SI.2.6";
Expand Down Expand Up @@ -82,6 +83,20 @@ class UserExperienceEvaluationAudit extends Audit {
return;
}

await page.setViewport({
width: 3840,
height: 2160,
});

await scrollToBottom(page);

await Promise.race([
setTimeout(10000),
page.waitForNetworkIdle({
idleTime: 2000,
}),
]);

this.titleSubHeadings = ["Elementi errati o non trovati"];

const item = {
Expand Down Expand Up @@ -126,6 +141,11 @@ class UserExperienceEvaluationAudit extends Audit {
});
}

await page.setViewport({
width: 800,
height: 600,
});

return {
score: this.score > 0 ? 1 : 0,
};
Expand Down
21 changes: 21 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,26 @@ const redirectUrlIsInternal = async (page: Page) => {
return redirectedHost.includes(host);
};

const scrollToBottom = async (page: Page) => {
await page.evaluate(async () => {
await new Promise((resolve) => {
const distance = 100;
const delay = 50;
let totalHeight = 0;
const timer = setInterval(() => {
const scrollHeight = document.body.scrollHeight;
window.scrollBy(0, distance);
totalHeight += distance;

if (totalHeight >= scrollHeight) {
clearInterval(timer);
resolve("");
}
}, delay);
});
});
};

export {
toMenuItem,
checkOrder,
Expand All @@ -610,4 +630,5 @@ export {
requestTimeout,
getRedirectedUrl,
redirectUrlIsInternal,
scrollToBottom,
};

0 comments on commit d4170f7

Please sign in to comment.