Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified assets/scan-report-practice/desktop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions website/scripts/browser-smoke.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,41 @@ try {
0,
"homepage logos and flags are not enlargement links",
);
const outlineLabels = 'Array.from(document.querySelectorAll(".guided-outline button > span:last-child"), el => el.textContent)';
await visit("learn/exercises/01-find-fix-verify/");
const referenceOutline = await evaluate(outlineLabels);
assert.equal(referenceOutline.length, 7);
for (const id of ["11-security-logging-alerting", "12-exceptional-conditions"]) {
await visit(`learn/exercises/${id}/`);
assert.deepEqual(await evaluate(outlineLabels), referenceOutline, id + " guided outline");
}
const resourceSelector = 'a.menu__link[href*="/12-exceptional-conditions/"]';
const resourceLabels = ["12 Mishandling of Exceptional Conditions", "Submission", "Student worksheet", "Safety"];
const labelsIn = region => evaluate(
`Array.from(document.querySelectorAll('${region} ${resourceSelector}'), link => link.textContent.trim())`,
);
assert.deepEqual(await labelsIn(".theme-doc-sidebar-container"), resourceLabels);
await capture("exercise12-student-menu-desktop", 1440, 1000);
await send("Emulation.setDeviceMetricsOverride", {
width: 390, height: 844, deviceScaleFactor: 1, mobile: false,
}, sessionId);
await evaluate('document.querySelector(".navbar__toggle").click()');
await wait('!!document.querySelector(".navbar-sidebar--show .navbar-sidebar")');
await wait('!!document.querySelector(".navbar-sidebar__items--show-secondary")');
assert.deepEqual(await labelsIn(".navbar-sidebar"), resourceLabels);
const mobileSafety = `document.querySelector('.navbar-sidebar a[href$="/12-exceptional-conditions/safety/"]')`;
await evaluate(`${mobileSafety}.scrollIntoView({block:"nearest"})`);
await wait(`(() => {
const link = ${mobileSafety};
const rect = link.getBoundingClientRect();
return link.contains(document.elementFromPoint(rect.x + rect.width / 2, rect.y + rect.height / 2));
})()`);
await capture("exercise12-resource-menu-mobile", 390, 844);
await evaluate(`${mobileSafety}.click()`);
await wait('document.querySelector("h1")?.textContent.trim() === "Safety"');
await visit("learn/exercises/12-exceptional-conditions/");
assert.deepEqual(await evaluate(outlineLabels), referenceOutline);

await wait('document.querySelector(".guided-online-entry button")?.disabled === false');
await evaluate('document.querySelector(".guided-online-entry button").focus()');
for (const type of ["keyDown", "keyUp"]) {
Expand Down
12 changes: 12 additions & 0 deletions website/scripts/guided-content.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import { lookupPages } from "./lookup-pages.mjs";
import { studentResourceTitle } from "./navigation.mjs";

export const tracks = ["npm", "pnpm", "yarn-classic", "yarn-berry", "bun"];
const sharedOutlineLabels = {
scan: "Observe the result",
observe: "Observe the result",
investigate: "Understand the evidence",
understand: "Understand the evidence",
repair: "Review and repair",
verify: "Verify the repair",
};
const exerciseLayouts = {
"01-find-fix-verify": {
kind: "dependency",
Expand Down Expand Up @@ -790,6 +798,10 @@ export function buildGuidedContent(root, lookupParts = lookupPages(root)) {
})),
);
}
for (const stage of lesson.stages) {
if (Object.hasOwn(sharedOutlineLabels, stage.id))
stage.outlineLabel = sharedOutlineLabels[stage.id];
}
// All further reading stays in context, outside required learner progress.
lesson.resources = [
...optionalDiscussion,
Expand Down
8 changes: 7 additions & 1 deletion website/scripts/navigation.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function sidebarLessons(root) {

export function studentResourceTitle(file) {
if (!file.startsWith("exercises/")) return;
if (file.endsWith("/safety.md")) return "Safety";
if (file.endsWith("/worksheet.md")) return "Student worksheet";
if (file.endsWith("/submission-template.md")) return "Submission";
const track = file.match(/\/examples\/([^/]+)\/README\.md$/)?.[1];
Expand All @@ -32,6 +33,11 @@ export function studentCategories(root, files) {
!path.endsWith("/README.md") &&
!path.endsWith("/student-kit-readme.md"),
);
const primary = [prefix + "/submission-template.md", prefix + "/worksheet.md"];
const orderedGuides = [
...primary.filter(path => guides.includes(path)),
...guides.filter(path => !primary.includes(path)),
];
const tracks = studentFiles.filter(
(path) =>
path.startsWith(prefix + "/examples/") && path.endsWith("/README.md"),
Expand All @@ -40,7 +46,7 @@ export function studentCategories(root, files) {
type: "category",
label: title,
link: { type: "doc", id: docId(prefix + "/README.md") },
items: [...guides, ...tracks].map((path) => {
items: [...orderedGuides, ...tracks].map((path) => {
if (parts.length && path === prefix + "/worksheet.md") {
return {
type: "category",
Expand Down
4 changes: 3 additions & 1 deletion website/src/components/GuidedLesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,9 @@ export default function GuidedLesson({ lesson, reference, entryStage }) {
>
<span aria-hidden={item.lookupPart ? undefined : true}>{number}</span>
<span>
{item.lookupPart ? item.title.replace(/^0\.\d+ · /, "") : item.title}
{item.lookupPart
? item.title.replace(/^0\.\d+ · /, "")
: item.outlineLabel ?? item.title}
{item.optional && <small>Optional</small>}
</span>
</button>
Expand Down
13 changes: 13 additions & 0 deletions website/tests/guided-content.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -644,3 +644,16 @@ test("the reporting lesson follows logging and guides students through verificat
assert.match(texts.repair, /report-policy\.mjs/);
assert.match(texts.verify, /checks\.mjs/);
});

test("equivalent app lab stages have matching outline labels and retain their teaching headings", () => {
const labels = lesson => lesson.stages.map(stage => stage.outlineLabel ?? stage.title);
const expected = ["Before you start", "Set up and inspect", "Observe the result",
"Understand the evidence", "Review and repair", "Verify the repair", "Explain and submit"];
for (const id of ["01-find-fix-verify", "04-browser-security-basics", "07-cryptographic-failures",
"09-authentication-failures", "10-software-data-integrity",
"11-security-logging-alerting", "12-exceptional-conditions"]) {
assert.deepEqual(labels(data.lessons[id]), expected, id);
}
assert.equal(data.lessons["12-exceptional-conditions"].stages[2].title, "Compare scan reports");
assert.equal(data.lessons["00-cve-lookup"].stages[1].outlineLabel, undefined);
});
15 changes: 15 additions & 0 deletions website/tests/navigation.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,18 @@ test("lookup student navigation follows Exercise 1 submission, worksheet, track
docId("exercises/01-find-fix-verify/worksheet.md"),
]);
});

test("student sidebars put the two shared resources first and use one safety label", async () => {
const { studentCategories, studentResourceTitle } = await import("../scripts/navigation.mjs");
for (const group of studentCategories(root, inventory(root))) {
const prefix = group.link.id.slice(0, -("__README".length));
const destinations = group.items.map(item => typeof item === "string" ? item : item.link.id);
assert.deepEqual(destinations.slice(0, 2), [
prefix + "__submission-template", prefix + "__worksheet",
], group.label);
if (destinations.includes(prefix + "__safety")) {
const file = prefix.replaceAll("__", "/") + "/safety.md";
assert.equal(studentResourceTitle(file), "Safety", group.label);
}
}
});
Loading