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

Commit

Permalink
feat: audit servizi scuole su servizi multipli con caricamento da pager
Browse files Browse the repository at this point in the history
  • Loading branch information
simone-amadio-acn committed Jan 16, 2023
1 parent f9fa51e commit bfc2d87
Show file tree
Hide file tree
Showing 6 changed files with 239 additions and 128 deletions.
90 changes: 87 additions & 3 deletions src/audits/school/cookieDomainCheckAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,93 @@ class LoadAudit extends Audit {
};
}

static async audit(
artifacts: LH.Artifacts & { origin: string }
): Promise<{ score: number; details: LH.Audit.Details.Table }> {
static async audit(artifacts: LH.Artifacts & { origin: string }) {
///** @type {LH.Audit.Details.TableItem[]} */
//const results = [];
//
//results.push(
// {
// total_result: "Fino a 2 voci obbligatorie non sono presenti o 1 voce non è nell'ordine corretto.",
// },
// {
// subItems: {
// type: "subitems",
// items: [
// {
// single_result: "Corretto",
// inspected_page: "https://www.icmarcellinara.edu.it/servizio/registro-elettronico-2/",
// missing_mandatory_elements_found: "",
// mandatory_elements_not_right_order: ""
// },
// ],
// },
// },
// {
// subItems: {
// type: "subitems",
// items: [
// {
// single_result: "Tolleranza",
// inspected_page: "https://www.icmarcellinara.edu.it/servizio/registro-elettronico-2/",
// missing_mandatory_elements_found: "Cosa serve; Tempi e scadenze",
// mandatory_elements_not_right_order: ""
// },
// ],
// },
// },
// {
// subItems: {
// type: "subitems",
// items: [
// {
// single_result: "Tolleranza",
// inspected_page: "https://www.icmarcellinara.edu.it/servizio/area-riservata-docenti/",
// missing_mandatory_elements_found: "",
// mandatory_elements_not_right_order: "Ulteriori informazioni; Contatti"
// },
// ],
// },
// },
//);
//
///** @type {LH.Audit.Details.Table['headings']} */
//const headings = [
// /* eslint-disable max-len */
// { key: "total_result", itemType: "text", text: "Risultato Totale" },
// {
// key: "node",
// itemType: "node",
// subItemsHeading: { key: "single_result", itemType: "text" },
// text: "Risultato singolo",
// },
// {
// key: null,
// itemType: "text",
// subItemsHeading: { key: "inspected_page", itemType: "text" },
// text: "Inspected Page",
// },
// {
// key: null,
// itemType: "text",
// subItemsHeading: { key: "missing_mandatory_elements_found", itemType: "text" },
// text: "Missing Mandatory Elements Found",
// },
// {
// key: null,
// itemType: "text",
// subItemsHeading: { key: "mandatory_elements_not_right_order", itemType: "text" },
// text: "Mandatory Elements Not Right Order",
// },
// /* eslint-enable max-len */
//];
//
//const details = Audit.makeTableDetails(headings, results);
//
//return {
// score: 0.5,
// details,
//};

const url = artifacts.origin;

return await cookieAudit(url, auditData);
Expand Down
4 changes: 1 addition & 3 deletions src/audits/school/fontsCheckAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,7 @@ class LoadAudit extends Audit {
): Promise<LH.Audit.ProductBase> {
const url = artifacts.origin;

const randomService: string[] = await getRandomSchoolServicesUrl(
url
);
const randomService: string[] = await getRandomSchoolServicesUrl(url);

if (randomService.length === 0) {
return {
Expand Down
192 changes: 100 additions & 92 deletions src/audits/school/serviziAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,6 @@ class LoadAudit extends Audit {
},
];

const item = [
{
result: greenResult,
missing_mandatory_elements_found: "",
mandatory_elements_not_right_order: "",
inspected_page: "",
},
];

let score = 1;

const mandatoryVoices = contentTypeItems.Indice;
const mandatoryHeaderVoices = contentTypeItems.Header;
const mandatoryBodyVoices = contentTypeItems.Body;
Expand All @@ -81,11 +70,9 @@ class LoadAudit extends Audit {
const mandatoryMetadata = contentTypeItems.Metadati;
const breadcrumbMandatoryElements = contentTypeItems.Breadcrumb;

const randomService: string[] = await getRandomSchoolServicesUrl(
url
);
const randomServices: string[] = await getRandomSchoolServicesUrl(url, 100);

if (randomService.length === 0) {
if (randomServices.length === 0) {
return {
score: 0,
details: Audit.makeTableDetails(
Expand All @@ -99,100 +86,121 @@ class LoadAudit extends Audit {
};
}

const randomServiceToBeScanned = randomService[0];
item[0].inspected_page = randomServiceToBeScanned;
const items = [
];

const $: CheerioAPI = await loadPageData(randomServiceToBeScanned);
let score = 1;

const indexElements = await getServicesFromIndex($, mandatoryVoices);
const mandatoryMenuItems = mandatoryVoices.map(toMenuItem);
const orderResult = checkOrder(mandatoryMenuItems, indexElements);
for(const randomService of randomServices){
const item = {
result: greenResult,
missing_mandatory_elements_found: "",
mandatory_elements_not_right_order: "",
inspected_page: "",
}

let missingMandatoryItems = missingMenuItems(
indexElements,
mandatoryMenuItems
);
item.inspected_page = randomService;

const title = $('[data-element="service-title"]').text().trim() ?? "";
if (!title) {
missingMandatoryItems.push(mandatoryHeaderVoices[0]);
}
const $: CheerioAPI = await loadPageData(randomService);

const description =
$('[data-element="service-description"]').text().trim() ?? "";
if (!description) {
missingMandatoryItems.push(mandatoryHeaderVoices[1]);
}
const indexElements = await getServicesFromIndex($, mandatoryVoices);
const mandatoryMenuItems = mandatoryVoices.map(toMenuItem);
const orderResult = checkOrder(mandatoryMenuItems, indexElements);

const breadcrumbElements = await getPageElementDataAttribute(
$,
'[data-element="breadcrumb"]',
"li"
);
if (
!breadcrumbElements.includes(breadcrumbMandatoryElements[0]) &&
!breadcrumbElements.includes(breadcrumbMandatoryElements[1])
) {
missingMandatoryItems.push(mandatoryHeaderVoices[2]);
}
let missingMandatoryItems = missingMenuItems(
indexElements,
mandatoryMenuItems
);

const argumentsTag = await getPageElementDataAttribute(
$,
'[data-element="topic-list"]'
);
if (argumentsTag.length <= 0) {
missingMandatoryItems.push(mandatoryHeaderVoices[3]);
}
const title = $('[data-element="service-title"]').text().trim() ?? "";
if (!title) {
missingMandatoryItems.push(mandatoryHeaderVoices[0]);
}

const whatNeeds = $('[data-element="used-for"]').text().trim() ?? "";
if (!whatNeeds) {
missingMandatoryItems.push(mandatoryBodyVoices[0]);
}
const description =
$('[data-element="service-description"]').text().trim() ?? "";
if (!description) {
missingMandatoryItems.push(mandatoryHeaderVoices[1]);
}

const responsibleStructure = await getPageElementDataAttribute(
$,
'[data-element="structures"]',
"a"
);
if (responsibleStructure.length <= 0) {
missingMandatoryItems.push(mandatoryBodyVoices[1]);
}
const breadcrumbElements = await getPageElementDataAttribute(
$,
'[data-element="breadcrumb"]',
"li"
);
if (
!breadcrumbElements.includes(breadcrumbMandatoryElements[0]) &&
!breadcrumbElements.includes(breadcrumbMandatoryElements[1])
) {
missingMandatoryItems.push(mandatoryHeaderVoices[2]);
}

const placeInfo = await getPlaceInfo($, mandatoryPlaceInfo);
if (placeInfo.length > 0) {
missingMandatoryItems = [...missingMandatoryItems, ...placeInfo];
}
const argumentsTag = await getPageElementDataAttribute(
$,
'[data-element="topic-list"]'
);
if (argumentsTag.length <= 0) {
missingMandatoryItems.push(mandatoryHeaderVoices[3]);
}

const metadata = $('[data-element="metadata"]').text().trim() ?? "";
if (
!metadata.toLowerCase().includes(mandatoryMetadata[0].toLowerCase()) ||
!metadata.toLowerCase().includes(mandatoryMetadata[1].toLowerCase())
) {
missingMandatoryItems.push(mandatoryBodyVoices[2]);
}
const whatNeeds = $('[data-element="used-for"]').text().trim() ?? "";
if (!whatNeeds) {
missingMandatoryItems.push(mandatoryBodyVoices[0]);
}

const missingVoicesAmount = missingMandatoryItems.length;
const voicesNotInCorrectOrderAmount =
orderResult.numberOfElementsNotInSequence;
const responsibleStructure = await getPageElementDataAttribute(
$,
'[data-element="structures"]',
"a"
);
if (responsibleStructure.length <= 0) {
missingMandatoryItems.push(mandatoryBodyVoices[1]);
}

if (missingVoicesAmount > 2 || voicesNotInCorrectOrderAmount > 1) {
score = 0;
item[0].result = redResult;
} else if (
(missingVoicesAmount > 0 && missingVoicesAmount <= 2) ||
voicesNotInCorrectOrderAmount === 1
) {
score = 0.5;
item[0].result = yellowResult;
}
const placeInfo = await getPlaceInfo($, mandatoryPlaceInfo);
if (placeInfo.length > 0) {
missingMandatoryItems = [...missingMandatoryItems, ...placeInfo];
}

const metadata = $('[data-element="metadata"]').text().trim() ?? "";
if (
!metadata.toLowerCase().includes(mandatoryMetadata[0].toLowerCase()) ||
!metadata.toLowerCase().includes(mandatoryMetadata[1].toLowerCase())
) {
missingMandatoryItems.push(mandatoryBodyVoices[2]);
}

const missingVoicesAmount = missingMandatoryItems.length;
const voicesNotInCorrectOrderAmount =
orderResult.numberOfElementsNotInSequence;

if (missingVoicesAmount > 2 || voicesNotInCorrectOrderAmount > 1) {
if (score > 0) {
score = 0;
}

item[0].missing_mandatory_elements_found = missingMandatoryItems.join(", ");
item[0].mandatory_elements_not_right_order =
orderResult.elementsNotInSequence.join(", ");
item.result = redResult;
} else if (
(missingVoicesAmount > 0 && missingVoicesAmount <= 2) ||
voicesNotInCorrectOrderAmount === 1
) {
if (score > 0.5) {
score = 0.5;
}

item.result = yellowResult;
}

item.missing_mandatory_elements_found = missingMandatoryItems.join(", ");
item.mandatory_elements_not_right_order =
orderResult.elementsNotInSequence.join(", ");

items.push(item);
}

return {
score: score,
details: Audit.makeTableDetails(headings, item),
details: Audit.makeTableDetails(headings, items),
};
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/config/school/auditConfig-local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export default {
onlyAudits: [
"school-menu-scuola-second-level-structure-match-model",
"school-ux-ui-consistency-bootstrap-italia-double-check",
"school-servizi-structure-match-model"
"school-servizi-structure-match-model",
],
/*
onlyCategories: [
Expand Down
3 changes: 3 additions & 0 deletions src/config/school/auditConfig-online.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ const customAdditionalAudits = [
export default {
extends: "lighthouse:default",
settings: {
onlyAudits: ["school-servizi-structure-match-model"],
/*
onlyCategories: [
"modelCompliance",
"recommendations",
"additionalTests",
"performance",
],
*/
},

passes: [
Expand Down
Loading

0 comments on commit bfc2d87

Please sign in to comment.