Skip to content

Commit

Permalink
test: add count broken links function test
Browse files Browse the repository at this point in the history
  • Loading branch information
jesperhodge committed Dec 18, 2024
1 parent 780d05b commit ad83a22
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 16 deletions.
20 changes: 4 additions & 16 deletions src/optimizer-page/scan-results/ScanResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SectionCollapsible from '../SectionCollapsible';
import BrokenLinkTable from './BrokenLinkTable';
import LockedInfoIcon from './LockedInfoIcon';
import { LinkCheckResult } from '../types';
import countBrokenLinks from '../utils';

const InfoCard: FC<{ text: string }> = ({ text }) => (
<Card className="mt-4">
Expand All @@ -25,27 +26,14 @@ interface Props {
data: LinkCheckResult | null;
}



const ScanResults: FC<Props> = ({ data }) => {
const intl = useIntl();
const [showLockedLinks, setShowLockedLinks] = useState(true);

const brokenLinkCounts = useMemo(() => {
if (!data?.sections) {
return [];
}
const counts: number[] = [];
data.sections.forEach((section) => {
let count = 0;
section.subsections.forEach((subsection) => {
subsection.units.forEach((unit) => {
unit.blocks.forEach((block) => {
count += block.brokenLinks.length;
});
});
});
counts.push(count);
});
return counts;
return countBrokenLinks(data);
}, [data?.sections]);

if (!data) {
Expand Down
Empty file.
22 changes: 22 additions & 0 deletions src/optimizer-page/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { LinkCheckResult } from './types';

const countBrokenLinks = (data: LinkCheckResult | null): number[] => {
if (!data?.sections) {
return [];
}
const counts: number[] = [];
data.sections.forEach((section) => {
let count = 0;
section.subsections.forEach((subsection) => {
subsection.units.forEach((unit) => {
unit.blocks.forEach((block) => {
count += block.brokenLinks.length;
});
});
});
counts.push(count);
});
return counts;
};

export default countBrokenLinks;

0 comments on commit ad83a22

Please sign in to comment.