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

Commit

Permalink
fix: audit non eseguito se non viene trovata almeno una voce per sott…
Browse files Browse the repository at this point in the history
…o menù
  • Loading branch information
simone-amadio-acn authored and tensor5 committed Mar 1, 2023
1 parent 6550e15 commit 4f38ee1
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 39 deletions.
107 changes: 68 additions & 39 deletions src/audits/municipality/secondLevelPagesAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,39 +94,65 @@ class LoadAudit extends lighthouse.Audit {
primaryMenuDataElement
);

let secondLevelPagesNames: string[] = [];
if (secondLevelPageHref.length > 0) {
let secondLevelPageUrl = secondLevelPageHref[0];
if (
(await isInternalUrl(secondLevelPageUrl)) &&
!secondLevelPageUrl.includes(url)
) {
secondLevelPageUrl = await buildUrl(url, secondLevelPageHref[0]);
}
if (secondLevelPageHref.length === 0) {
return {
score: 0,
details: Audit.makeTableDetails(
[{ key: "result", itemType: "text", text: "Risultato" }],
[
{
result: auditData.nonExecuted,
},
]
),
};
}

$ = await loadPageData(secondLevelPageUrl);
const secondaryMenuDataElement = `[data-element="${primaryMenuItem.secondary_item_data_element[0]}"]`;
let secondLevelPagesNames: string[] = [];
let secondLevelPageUrl = secondLevelPageHref[0];
if (
(await isInternalUrl(secondLevelPageUrl)) &&
!secondLevelPageUrl.includes(url)
) {
secondLevelPageUrl = await buildUrl(url, secondLevelPageHref[0]);
}

if (key !== "live" && primaryMenuItem.dictionary.length > 0) {
secondLevelPagesNames = await getPageElementDataAttribute(
$,
secondaryMenuDataElement
);
} else {
for (const dataElement of primaryMenuItem.secondary_item_data_element) {
const buttonDataElement = `[data-element="${dataElement}"]`;
const pageLinkUrl = await getButtonUrl($, url, buttonDataElement);

if (pageLinkUrl.length > 0) {
const $2 = await loadPageData(pageLinkUrl);
secondLevelPagesNames.push(
$2('[data-element="page-name"]').text().trim() ?? ""
);
}
$ = await loadPageData(secondLevelPageUrl);
const secondaryMenuDataElement = `[data-element="${primaryMenuItem.secondary_item_data_element[0]}"]`;

if (key !== "live" && primaryMenuItem.dictionary.length > 0) {
secondLevelPagesNames = await getPageElementDataAttribute(
$,
secondaryMenuDataElement
);
} else {
for (const dataElement of primaryMenuItem.secondary_item_data_element) {
const buttonDataElement = `[data-element="${dataElement}"]`;
const pageLinkUrl = await getButtonUrl($, url, buttonDataElement);

if (pageLinkUrl.length > 0) {
const $2 = await loadPageData(pageLinkUrl);
secondLevelPagesNames.push(
$2('[data-element="page-name"]').text().trim() ?? ""
);
}
}
}

if (secondLevelPagesNames.length === 0) {
return {
score: 0,
details: Audit.makeTableDetails(
[{ key: "result", itemType: "text", text: "Risultato" }],
[
{
result: auditData.nonExecuted,
},
]
),
};
}

for (const pageTitle of secondLevelPagesNames) {
if (primaryMenuItem.dictionary.includes(pageTitle.toLowerCase())) {
item.pagesInVocabulary.push(pageTitle);
Expand All @@ -142,28 +168,31 @@ class LoadAudit extends lighthouse.Audit {

let errorVoices: string[] = [];

const primaryMenuDataElement = `[data-element="${customPrimaryMenuItemsDataElement}"]`;
const secondLevelPageHref = await getHREFValuesDataAttribute(
const customPrimaryMenuDataElement = `[data-element="${customPrimaryMenuItemsDataElement}"]`;
const customSecondLevelPageHref = await getHREFValuesDataAttribute(
$,
primaryMenuDataElement
customPrimaryMenuDataElement
);

for (let secondLevelPageUrl of secondLevelPageHref) {
for (let customSecondLevelPageUrl of customSecondLevelPageHref) {
if (
(await isInternalUrl(secondLevelPageUrl)) &&
!secondLevelPageUrl.includes(url)
(await isInternalUrl(customSecondLevelPageUrl)) &&
!customSecondLevelPageUrl.includes(url)
) {
secondLevelPageUrl = await buildUrl(url, secondLevelPageHref[0]);
customSecondLevelPageUrl = await buildUrl(
url,
customSecondLevelPageHref[0]
);
}

$ = await loadPageData(secondLevelPageUrl);
const secondaryMenuDataElement = `[data-element="${customSecondaryMenuItemsDataElement}"]`;
const secondLevelPagesNames = await getPageElementDataAttribute(
$ = await loadPageData(customSecondLevelPageUrl);
const customSecondaryMenuDataElement = `[data-element="${customSecondaryMenuItemsDataElement}"]`;
const customSecondLevelPagesNames = await getPageElementDataAttribute(
$,
secondaryMenuDataElement
customSecondaryMenuDataElement
);

errorVoices = [...errorVoices, ...secondLevelPagesNames];
errorVoices = [...errorVoices, ...customSecondLevelPagesNames];
}

let pagesInVocabulary = 0;
Expand Down
14 changes: 14 additions & 0 deletions src/audits/school/menuScuolaSecondLevelAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ class LoadAudit extends Audit {
"a"
);

if (headerUlTest.length === 0) {
return {
score: 0,
details: Audit.makeTableDetails(
[{ key: "result", itemType: "text", text: "Risultato" }],
[
{
result: auditData.nonExecuted,
},
]
),
};
}

for (const element of headerUlTest) {
if (element !== "Panoramica") {
if (secondaryMenuItem.dictionary.includes(element.toLowerCase())) {
Expand Down

0 comments on commit 4f38ee1

Please sign in to comment.