Skip to content

Commit

Permalink
Feat: Funzione check ordine voci menu - Versione 1.0.14
Browse files Browse the repository at this point in the history
  • Loading branch information
luca.carrisi committed Nov 12, 2024
1 parent 1b9bdb7 commit 325f05c
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 10 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.0.13",
"version": "1.0.14",
"main": "index.js",
"type": "module",
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions src/audits/municipality_security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class MunicipalitySecurityAudit extends SecurityAudit {
} else {
status = "fail";
message = this.redResult.replace("[url]", this.url);

if (this.message !== "") {
message += this.message;
}
}

return await ejs.renderFile(__dirname + `/${FOLDER_NAME}/template.ejs`, {
Expand Down
4 changes: 2 additions & 2 deletions src/audits/municipality_service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { CheerioAPI } from "cheerio";

import {
checkBreadcrumb,
checkOrder,
checkOrderLoose,
getPageElementDataAttribute,
missingMenuItems,
redirectUrlIsInternal,
Expand Down Expand Up @@ -120,7 +120,7 @@ class ServiceAudit extends Audit {
let indexElements = await getServicesFromIndex($, mandatoryIndexVoices);

const mandatoryMenuItems = mandatoryIndexVoices.map(toMenuItem);
const orderResult = checkOrder(mandatoryMenuItems, indexElements);
const orderResult = checkOrderLoose(mandatoryMenuItems, indexElements);

const indexElementsWithContent: string[] = [];

Expand Down
2 changes: 1 addition & 1 deletion src/audits/school_first_level_menu/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class SchoolFirstLevelMenuAudit extends Audit {
code = "C.SC.1.4";
mainTitle = "VOCI DI MENÙ DI PRIMO LIVELLO";
greenResult =
"Le voci del menù sono corrett, nell'ordine giusto e inviano a pagine interne al dominio della scuola.";
"Le voci del menù sono corrette, nell'ordine giusto e inviano a pagine interne al dominio della scuola.";
yellowResult =
"L'ordine delle voci del menu è corretto ma sono presenti fino a 3 voci aggiuntive. Tutte le voci inviano a pagine interne al dominio della scuola.";
redResult =
Expand Down
4 changes: 4 additions & 0 deletions src/audits/school_security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ class SchoolSecurityAudit extends SecurityAudit {
} else {
status = "fail";
message = this.redResult.replace("[url]", this.url);

if (this.message !== "") {
message += this.message;
}
}

return await ejs.renderFile(__dirname + "/school_security/template.ejs", {
Expand Down
4 changes: 2 additions & 2 deletions src/audits/school_service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as cheerio from "cheerio";
import { CheerioAPI } from "cheerio";
import {
checkBreadcrumb,
checkOrder,
checkOrderLoose,
getElementHrefValuesDataAttribute,
getPageElementDataAttribute,
missingMenuItems,
Expand Down Expand Up @@ -128,7 +128,7 @@ class SchoolServiceAudit extends Audit {
let indexElements = await getServicesFromIndex($, mandatoryVoices);

const mandatoryMenuItems = mandatoryVoices.map(toMenuItem);
const orderResult = checkOrder(mandatoryMenuItems, indexElements);
const orderResult = checkOrderLoose(mandatoryMenuItems, indexElements);

//For Contatti we don't check its content
const indexElementsWithContent: string[] = ["Contatti"];
Expand Down
2 changes: 1 addition & 1 deletion src/audits/security/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class SecurityAudit extends Audit {
cipherSuite = await checkCipherSuite(url);
} catch {
item[0].protocol = protocol;
this.message = redResult + " Certificato non trovato";
this.message = " certificato non trovato";
return {
score: 0,
details: {
Expand Down
2 changes: 1 addition & 1 deletion src/storage/auditDictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ export const auditDictionary = {
},
"school-menu-structure-match-model": {
greenResult:
"Le voci del menù sono corrett, nell'ordine giusto e inviano a pagine interne al dominio della scuola.",
"Le voci del menù sono corrette, nell'ordine giusto e inviano a pagine interne al dominio della scuola.",
yellowResult:
"L'ordine delle voci del menu è corretto ma sono presenti fino a 3 voci aggiuntive. Tutte le voci inviano a pagine interne al dominio della scuola.",
redResult:
Expand Down
36 changes: 36 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,41 @@ const toMenuItem = (str: string): MenuItem => ({
regExp: new RegExp(`^${str}$`),
});

const checkOrderLoose = (
mandatoryElements: MenuItem[],
foundElements: string[],
): OrderType => {
const newMandatoryElements = mandatoryElements.filter((e) =>
foundElements.some((f) => e.regExp.test(f)),
);
const newFoundElements = foundElements.filter((e) =>
newMandatoryElements.some((f) => f.regExp.test(e)),
);

const elementsNotInSequence: string[] = [];

function checkOrderRecursive(correctArray: MenuItem[], checkArray: string[]) {
for (let i = 0; i < correctArray.length; i++) {
if (!correctArray[i].regExp.test(checkArray[i])) {
elementsNotInSequence.push(checkArray[i]);

checkOrderRecursive(
correctArray.filter((el) => el.name !== checkArray[i]),
checkArray.filter((el) => el !== checkArray[i]),
);
return;
}
}
}

checkOrderRecursive(newMandatoryElements, newFoundElements);

return {
numberOfElementsNotInSequence: elementsNotInSequence.length,
elementsNotInSequence: elementsNotInSequence,
};
};

const checkOrder = (
mandatoryElements: MenuItem[],
foundElements: string[],
Expand Down Expand Up @@ -571,6 +606,7 @@ const redirectUrlIsInternal = async (page: Page) => {
export {
toMenuItem,
checkOrder,
checkOrderLoose,
missingMenuItems,
loadPageData,
loadPage,
Expand Down

0 comments on commit 325f05c

Please sign in to comment.