Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Commit

Permalink
feat: check cookies per pagine di eventi
Browse files Browse the repository at this point in the history
  • Loading branch information
simone-amadio-acn committed Feb 6, 2023
1 parent 60e02e6 commit 1496ffd
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 95 deletions.
6 changes: 5 additions & 1 deletion src/audits/municipality/bookingAppointmentAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// @ts-ignore
import lighthouse from "lighthouse";
import { loadPageData } from "../../utils/utils";
import { getRandomMunicipalityThirdLevelPagesUrl } from "../../utils/municipality/utils";
import {
getRandomMunicipalityThirdLevelPagesUrl,
getServicePageUrl,
} from "../../utils/municipality/utils";
import { auditDictionary } from "../../storage/auditDictionary";

const Audit = lighthouse.Audit;
Expand Down Expand Up @@ -48,6 +51,7 @@ class LoadAudit extends Audit {
const randomServices: string[] =
await getRandomMunicipalityThirdLevelPagesUrl(
url,
await getServicePageUrl(url),
'[data-element="service-link"]'
);

Expand Down
2 changes: 2 additions & 0 deletions src/audits/municipality/bootstrapItaliaDoubleCheckAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getRandomMunicipalityFirstLevelPagesUrl,
getRandomMunicipalitySecondLevelPagesUrl,
getRandomMunicipalityThirdLevelPagesUrl,
getServicePageUrl,
} from "../../utils/municipality/utils";
import { auditScanVariables } from "../../storage/municipality/auditScanVariables";
import { cssClasses } from "../../storage/municipality/cssClasses";
Expand Down Expand Up @@ -102,6 +103,7 @@ class LoadAudit extends Audit {
)),
...(await getRandomMunicipalityThirdLevelPagesUrl(
url,
await getServicePageUrl(url),
'[data-element="service-link"]',
auditVariables.numberOfServicesToBeScanned
)),
Expand Down
6 changes: 5 additions & 1 deletion src/audits/municipality/contactsAssistencyAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// @ts-ignore
import lighthouse from "lighthouse";
import { getPageElementDataAttribute, loadPageData } from "../../utils/utils";
import { getRandomMunicipalityThirdLevelPagesUrl } from "../../utils/municipality/utils";
import {
getRandomMunicipalityThirdLevelPagesUrl,
getServicePageUrl,
} from "../../utils/municipality/utils";
import { CheerioAPI } from "cheerio";
import { auditDictionary } from "../../storage/auditDictionary";

Expand Down Expand Up @@ -59,6 +62,7 @@ class LoadAudit extends Audit {
const randomServices: string[] =
await getRandomMunicipalityThirdLevelPagesUrl(
url,
await getServicePageUrl(url),
'[data-element="service-link"]'
);

Expand Down
8 changes: 8 additions & 0 deletions src/audits/municipality/cookieDomainCheckAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import {
getRandomMunicipalityFirstLevelPagesUrl,
getRandomMunicipalitySecondLevelPagesUrl,
getRandomMunicipalityThirdLevelPagesUrl,
getServicePageUrl,
} from "../../utils/municipality/utils";
import { auditScanVariables } from "../../storage/municipality/auditScanVariables";
import { getButtonUrl, loadPageData } from "../../utils/utils";

const Audit = lighthouse.Audit;

Expand Down Expand Up @@ -84,11 +86,17 @@ class LoadAudit extends Audit {
)),
...(await getRandomMunicipalityThirdLevelPagesUrl(
url,
await getServicePageUrl(url),
'[data-element="service-link"]',
auditVariables.numberOfServicesToBeScanned
)),
...(await getRandomMunicipalityThirdLevelPagesUrl(
url,
await getButtonUrl(
await loadPageData(url),
url,
`[data-element="live-button-events"]`
),
'[data-element="event-link"]',
auditVariables.numberOfEventsToBeScanned
)),
Expand Down
6 changes: 5 additions & 1 deletion src/audits/municipality/fontsCheckAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// @ts-ignore
import lighthouse from "lighthouse";
import { allowedFonts } from "../../storage/municipality/allowedFonts";
import { getRandomMunicipalityThirdLevelPagesUrl } from "../../utils/municipality/utils";
import {
getRandomMunicipalityThirdLevelPagesUrl,
getServicePageUrl,
} from "../../utils/municipality/utils";
import puppeteer from "puppeteer";
import { auditDictionary } from "../../storage/auditDictionary";

Expand Down Expand Up @@ -52,6 +55,7 @@ class LoadAudit extends Audit {
const randomServices: string[] =
await getRandomMunicipalityThirdLevelPagesUrl(
url,
await getServicePageUrl(url),
'[data-element="service-link"]'
);

Expand Down
6 changes: 5 additions & 1 deletion src/audits/municipality/metatagAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// @ts-ignore
import lighthouse from "lighthouse";
import { loadPageData } from "../../utils/utils";
import { getRandomMunicipalityThirdLevelPagesUrl } from "../../utils/municipality/utils";
import {
getRandomMunicipalityThirdLevelPagesUrl,
getServicePageUrl,
} from "../../utils/municipality/utils";
import { CheerioAPI } from "cheerio";
import { ValidatorResult } from "jsonschema";
import * as jsonschema from "jsonschema";
Expand Down Expand Up @@ -64,6 +67,7 @@ class LoadAudit extends Audit {
const randomServices: string[] =
await getRandomMunicipalityThirdLevelPagesUrl(
url,
await getServicePageUrl(url),
'[data-element="service-link"]'
);

Expand Down
28 changes: 8 additions & 20 deletions src/audits/municipality/secondLevelPagesAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lighthouse from "lighthouse";
import {
buildUrl,
getButtonUrl,
getHREFValuesDataAttribute,
getPageElementDataAttribute,
loadPageData,
Expand Down Expand Up @@ -105,7 +106,7 @@ class LoadAudit extends lighthouse.Audit {
}

$ = await loadPageData(secondLevelPageUrl);
const secondaryMenuDataElement = `[data-element="${primaryMenuItem.secondary_item_data_element}"]`;
const secondaryMenuDataElement = `[data-element="${primaryMenuItem.secondary_item_data_element[0]}"]`;
let secondLevelPagesNames = [];

if (key !== "live" && primaryMenuItem.dictionary.length > 0) {
Expand All @@ -114,27 +115,14 @@ class LoadAudit extends lighthouse.Audit {
secondaryMenuDataElement
);
} else {
const buttons = $(secondaryMenuDataElement);
for (const button of buttons) {
const elementObj = $(button).attr();
if (
elementObj !== null &&
elementObj !== undefined &&
"onclick" in elementObj &&
elementObj.onclick.includes("location.href")
) {
const onClick: string = elementObj.onclick;
let secondPageLink = onClick.substring(
onClick.indexOf("'") + 1,
onClick.lastIndexOf("'")
);
if (!secondPageLink.includes(url)) {
secondPageLink = await buildUrl(url, secondPageLink);
}
for (const dataElement of primaryMenuItem.secondary_item_data_element) {
const buttonDataElement = `[data-element="${dataElement}"]`;
const pageLinkUrl = await getButtonUrl($, url, buttonDataElement);

$ = await loadPageData(secondPageLink);
if (pageLinkUrl.length > 0) {
const $2 = await loadPageData(pageLinkUrl);
secondLevelPagesNames.push(
$('[data-element="page-name"]').text().trim() ?? ""
$2('[data-element="page-name"]').text().trim() ?? ""
);
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/audits/municipality/serviziAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ import {
missingMenuItems,
toMenuItem,
} from "../../utils/utils";
import { getRandomMunicipalityThirdLevelPagesUrl } from "../../utils/municipality/utils";
import {
getRandomMunicipalityThirdLevelPagesUrl,
getServicePageUrl,
} from "../../utils/municipality/utils";
import {
contentTypeItemsBody,
contentTypeItemsHeaders,
Expand Down Expand Up @@ -88,6 +91,7 @@ class LoadAudit extends Audit {
const randomServices: string[] =
await getRandomMunicipalityThirdLevelPagesUrl(
url,
await getServicePageUrl(url),
'[data-element="service-link"]',
auditVariables.numberOfServicesToBeScanned
);
Expand Down
11 changes: 7 additions & 4 deletions src/storage/municipality/menuItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const primaryMenuItems = {
name: "Amministrazione",
regExp: /^Amministrazione$/i,
data_element: "management",
secondary_item_data_element: "management-category-link",
secondary_item_data_element: ["management-category-link"],
dictionary: [
"aree amministrative",
"documenti e dati",
Expand All @@ -20,15 +20,15 @@ export const primaryMenuItems = {
name: "Novità",
regExp: /^Novità$/i,
data_element: "news",
secondary_item_data_element: "news-category-link",
secondary_item_data_element: ["news-category-link"],
dictionary: ["avvisi", "comunicati", "notizie"],
},
services: {
label: "SERVIZI",
name: "Servizi",
regExp: /^Servizi$/i,
data_element: "all-services",
secondary_item_data_element: "service-category-link",
secondary_item_data_element: ["service-category-link"],
dictionary: [
"educazione e formazione",
"salute, benessere e assistenza",
Expand All @@ -52,7 +52,10 @@ export const primaryMenuItems = {
name: "Vivere [nome del Comune]",
regExp: /^Vivere /i,
data_element: "live",
secondary_item_data_element: "live-button",
secondary_item_data_element: [
"live-button-locations",
"live-button-events",
],
dictionary: ["luoghi", "eventi"],
},
};
Expand Down
Loading

0 comments on commit 1496ffd

Please sign in to comment.