diff --git a/actions/build/scripts/capture-screenshots/index.test.mjs b/actions/build/scripts/capture-screenshots/index.test.mjs index 37cec7ab9..1235f86ce 100644 --- a/actions/build/scripts/capture-screenshots/index.test.mjs +++ b/actions/build/scripts/capture-screenshots/index.test.mjs @@ -155,21 +155,45 @@ describe("captureScreenshots()", () => { assert.deepEqual([...image.data.subarray(bottom, bottom + 3)], [255, 0, 0]) } }) - it("captures an app without Controls under a same-origin script policy", async () => { + it("fills both viewports for short root and template pages without Controls under a same-origin script policy", async () => { const root = await temporaryDirectory() const screenshots = await temporaryDirectory() await mkdir(path.join(root, "dist")) + await mkdir(path.join(root, ".github")) await writeFile( path.join(root, "dist", "index.html"), - 'Fixture

Replica

', + 'Fixture

Replica

', + ) + await writeFile( + path.join(root, ".github/replica.json"), + JSON.stringify({ + version: 1, + templates: [ + { + id: "settings", + name: "Settings", + category: "Configuration", + description: "Edit settings.", + path: "/settings", + }, + ], + }), ) await captureScreenshots(root, screenshots) - const desktop = await readFile(path.join(screenshots, "desktop.png")) - const narrow = await readFile(path.join(screenshots, "narrow.png")) - assert.deepEqual([desktop.readUInt32BE(16), desktop.readUInt32BE(20)], [1440, 900]) - assert.deepEqual([narrow.readUInt32BE(16), narrow.readUInt32BE(20)], [390, 844]) + for (const directory of ["", "templates/settings"]) { + for (const [name, width, height] of [ + ["desktop", 1440, 900], + ["narrow", 390, 844], + ]) { + for (const suffix of ["", "-dark"]) { + const filename = path.join(directory, `${name}${suffix}.png`) + const image = pngjs.PNG.sync.read(await readFile(path.join(screenshots, filename))) + assert.deepEqual([image.width, image.height], [width, height], filename) + } + } + } }) it("navigates before capture when app boot reads a URL-bound default", async () => { diff --git a/actions/build/scripts/constants.mjs b/actions/build/scripts/constants.mjs index e3a01e559..97cabfdf9 100644 --- a/actions/build/scripts/constants.mjs +++ b/actions/build/scripts/constants.mjs @@ -1,3 +1,5 @@ +import viewports from "../../../hub/client/utils/screenshot-viewports/viewports.json" with { type: "json" } + export const ARTIFACT_NAME = "replica-build-v1" export const SCREENSHOTS_ARTIFACT_NAME = "replica-screenshots-v1" export const CONTENT_TYPES = { @@ -18,7 +20,7 @@ export const MAX_PACKAGE_BYTES = 150 * 1024 * 1024 export const MAX_TEMPLATES = 12 export const MAX_TEMPLATE_MANIFEST_BYTES = 16 * 1024 export const START_ROUTE = "/" -export const VIEWPORTS = [ - { name: "desktop", width: 1440, height: 900 }, - { name: "narrow", width: 390, height: 844 }, -] +export const VIEWPORTS = Object.entries(viewports).map(([name, dimensions]) => ({ + name, + ...dimensions, +})) diff --git a/hub/client/components/prototype-card/index.tsx b/hub/client/components/prototype-card/index.tsx index 1bccb3664..101180eb2 100644 --- a/hub/client/components/prototype-card/index.tsx +++ b/hub/client/components/prototype-card/index.tsx @@ -4,6 +4,7 @@ import { Label } from "@primer/react-brand" import { BuildStateLabel } from "@components/build-state-label" import { HubUserAvatar } from "@components/hub-user-avatar" import { ScrollingScreenshot } from "@components/scrolling-screenshot" +import { screenshotViewportStyles } from "@utils/screenshot-viewports" import type { PrototypeCardData } from "./types" @@ -29,7 +30,7 @@ export function PrototypeCard({ ) const preview = ( -
+
{prototype.reviewBuild ? ( export const FullPage: Story = { - decorators: [previewFrame("395 / 280")], + decorators: [previewFrame(screenshotViewportStyles.desktop.aspectRatio)], } export const NarrowBuildDetail: Story = { @@ -45,7 +47,7 @@ export const NarrowBuildDetail: Story = { alt: "Full-height narrow screenshot of the welcome prototype", src: welcomeNarrowFullPageScreenshot, }, - decorators: [previewFrame("390 / 844")], + decorators: [previewFrame(screenshotViewportStyles.narrow.aspectRatio)], } export const ViewportHeight: Story = { @@ -53,5 +55,5 @@ export const ViewportHeight: Story = { alt: "Viewport-height screenshot of the welcome prototype", src: welcomeScreenshot, }, - decorators: [previewFrame("395 / 280")], + decorators: [previewFrame(screenshotViewportStyles.desktop.aspectRatio)], } diff --git a/hub/client/components/template-card/index.tsx b/hub/client/components/template-card/index.tsx index 5f3313f9c..3fe5654aa 100644 --- a/hub/client/components/template-card/index.tsx +++ b/hub/client/components/template-card/index.tsx @@ -3,6 +3,8 @@ import { ArrowUpRightIcon, BrowserIcon } from "@primer/octicons-react" import { ScrollingScreenshot } from "@components/scrolling-screenshot" import "@components/prototype-card/styles.css" +import { screenshotViewportStyles } from "@utils/screenshot-viewports" + import type { TemplateCardData } from "./types" import "./styles.css" @@ -17,7 +19,7 @@ export function TemplateCard({ }) { return (
-
+
{template.screenshotSrc ? ( export const Ready: Story = {} +export const Default: Story = { + args: { template: templatesData.templates[0]! }, +} + export const FullHeight: Story = { args: { template: templatesData.templates[2]! }, } diff --git a/hub/client/components/template-picker/index.tsx b/hub/client/components/template-picker/index.tsx index af556a6f4..a93861ff5 100644 --- a/hub/client/components/template-picker/index.tsx +++ b/hub/client/components/template-picker/index.tsx @@ -3,6 +3,7 @@ import { useEffect, useRef, useState } from "react" import type { KeyboardEvent } from "react" import { useOptionalHubTheme } from "@hooks/use-hub-theme" +import { screenshotViewportStyles } from "@utils/screenshot-viewports" import type { StartingTemplate } from "./types" import "./styles.css" @@ -166,7 +167,7 @@ export function TemplatePicker({ closeOptions() }} > - + {screenshotSrc && !failedScreenshots.includes(screenshotSrc) ? (