Skip to content

Commit

Permalink
Provide a rough overall summary - previously I wasn't sure if it ran …
Browse files Browse the repository at this point in the history
…on only one page and reported the result, or whether it ran on all pages
  • Loading branch information
thomaspaulin committed Aug 2, 2021
1 parent 982a60c commit be12cf3
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
50 changes: 46 additions & 4 deletions __tests__/email.spec.ts
@@ -1,16 +1,58 @@
"use strict";

import {PageReport, CheckerReport} from "../reports";
import {buildEmail, buildErrorReport, buildPageSummary, SenderDetails} from "../email";
import exp from "constants";
import {CheckerReport, PageReport} from "../reports";
import {buildEmail, buildEmailTemplate, buildErrorReport, buildPageSummary, SenderDetails} from "../email";

describe("Email sending and formatting", () => {
const url = "http://localhost:1313/2021/03/deckgl-displaying-live-flight-info/";
const l = "https://www.mapadsbox.com/mapbox-gljs";
const l2 = "https://cors-anywhere.herokuapp.com/";
const l3 = "https://hgis.uw.edu/";
const l4 = "https://www.colourhunt.com/palettadsfe/cjf74j2eqdg3w0119my22vt6f/";
const l5 = "https://www.awix.com/blog/2017/10/how-to-choose-the-perfect-color-palette-for-your-business";

const url2 = "http://localhost:1313/2021/07/ullage-rockets/";
const u2_l = "https://en.wikipedia.org/wiki/Saturn_V";
const u2_l2 = "https://en.wikipedia.org/wiki/Ullage_motor";
const u2_l3 = "https://en.wikipedia.org/wiki/Ullage_(wine)";
const u2_l4 = "https://unece.org/DAM/trans/doc/2011/wp29grpe/LNG_TF-02-06e.pdf";

describe("The introduction", () => {
const cr = new CheckerReport("http://localhost:1313");

beforeEach(() => {
const pr = new PageReport(url);
pr.reportChecked(l);
pr.reportChecked(l2);
pr.reportChecked(l3);

pr.reportBroken(l, "title", "HTTP_404");
cr.savePageReport(pr);

const pr2 = new PageReport(url2)
pr2.reportChecked(u2_l);
pr2.reportChecked(u2_l2);
pr2.reportChecked(u2_l3);
pr2.reportChecked(u2_l4);

pr2.reportBroken(u2_l2, "ullage rockets", "HTTP_403");
cr.savePageReport(pr2);
});

it("should mention how many pages were scanned", () => {
const template = buildEmailTemplate(cr);
expect(template).toContain("In doing so I scanned <strong>2</strong> pages");
});

it("should mention how many links were checked across all pages", () => {
const template = buildEmailTemplate(cr);
expect(template).toContain("which contained a total of <strong>7</strong> links")
});

it("should mention how many links broken across all pages", () => {
const template = buildEmailTemplate(cr);
expect(template).toContain(" links. Of these, <strong>2</strong> were broken links")
});
});

describe("The summary line for a page", () => {
describe("when reporting how many links checked", () => {
Expand Down
14 changes: 12 additions & 2 deletions email.ts
Expand Up @@ -58,10 +58,20 @@ export function buildPageSummary(pageUrl: string, pageReport: PageReport) {
return `<li>${pageIntro}${buildSummaryLine(pageReport)}<h4>Broken Links:</h4><ul>${listItems}</ul></li><hr>`;
}

function buildEmailTemplate(report: CheckerReport) {
export function buildEmailTemplate(report: CheckerReport) {
const site = report.baseUrl;
const header = `<html lang="en"><head><title>Broken links found while parsing ${site}</title><style>.no-bullets { list-style-type: none; } .no-bullets > li { margin-bottom: 1.5em; } li > h5 { margin: 1em 0 1em 0; }</style></head><body>`;
const intro = `${header}Hi there,<br><p>I found the following broken links when scanning <a href="${site}">${site}</a>.</p>`;

let scannedPageCount = 0;
let totalCheckedCount = 0;
let totalBrokenCount = 0;
for (const [, pageReport] of report.pageReports) {
scannedPageCount++;
totalCheckedCount += pageReport?.checked?.size || 0;
totalBrokenCount += pageReport?.broken?.size || 0;
}

const intro = `${header}Hi there,<br><p>I scanned <a href="${site}">${site}</a>. In doing so I scanned <strong>${scannedPageCount}</strong> pages which contained a total of <strong>${totalCheckedCount}</strong> links. Of these, <strong>${totalBrokenCount}</strong> were broken links.</p>`;
let html = `${intro}<ul class="no-bullets">`;
for (const [pageUrl , pageReport] of report.pageReports) {
if (pageReport.broken.size > 0) {
Expand Down

0 comments on commit be12cf3

Please sign in to comment.