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

Commit

Permalink
fix: cheerioAPI text(); events missing data-element error handling (#538
Browse files Browse the repository at this point in the history
)
  • Loading branch information
lorenzo-vernocchi authored Nov 5, 2024
1 parent 76892da commit 934d29b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/audits/municipality/serviziAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import lighthouse from "lighthouse";
import { CheerioAPI, text } from "cheerio";
import { CheerioAPI } from "cheerio";
import {
checkBreadcrumb,
checkOrder,
Expand Down Expand Up @@ -172,7 +172,7 @@ class LoadAudit extends Audit {

for (const mandatoryVoiceDataElement of mandatoryVoicesDataElements.paragraph) {
const dataElement = `[data-element="${mandatoryVoiceDataElement.data_element}"]`;
const textContent = text($(dataElement));
const textContent = $(dataElement).text();
if (textContent.length >= 3) {
indexElementsWithContent.push(mandatoryVoiceDataElement.key);
}
Expand Down
4 changes: 2 additions & 2 deletions src/audits/school/serviziAudit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
contentTypeItemsMetadata,
} from "../../storage/school/contentTypeItems";
import { auditDictionary } from "../../storage/auditDictionary";
import { CheerioAPI, text } from "cheerio";
import { CheerioAPI } from "cheerio";
import { auditScanVariables } from "../../storage/school/auditScanVariables";
import {
errorHandling,
Expand Down Expand Up @@ -173,7 +173,7 @@ class LoadAudit extends Audit {

for (const mandatoryVoiceDataElement of mandatoryVoicesDataElements.paragraph) {
const dataElement = `[data-element="${mandatoryVoiceDataElement.data_element}"]`;
const textContent = text($(dataElement));
const textContent = $(dataElement).text();
if (textContent.length >= 3) {
indexElementsWithContent.push(mandatoryVoiceDataElement.key);
}
Expand Down
16 changes: 10 additions & 6 deletions src/utils/municipality/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1058,15 +1058,19 @@ const getPages = async (
break;
}
case "events": {
const primaryPageUrl = await getPrimaryPageUrl(
url,
primaryMenuItems.live.data_element
);

if (!primaryPageUrl) {
throw new DataElementError(primaryMenuItems.live.data_element);
}

requestedPages = await getRandomThirdLevelPagesUrl(
url,
await getButtonUrl(
await loadPageData(
await getPrimaryPageUrl(
url,
primaryMenuItems.live.data_element
)
),
await loadPageData(primaryPageUrl),
url,
`[data-element="${primaryMenuItems.live.secondary_item_data_element[1]}"]`
),
Expand Down

0 comments on commit 934d29b

Please sign in to comment.