Skip to content
33 changes: 25 additions & 8 deletions scripts/screenshots.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ const ROOT = dirname(dirname(fromFileUrl(import.meta.url)));
const DB_KEY = "MDEyMzQ1Njc4OWFiY2RlZjAxMjM0NTY3ODlhYmNkZWY=";
const USERNAME = "screenshots";
const PASSWORD = "screenshots-password";
const STRIPE_KEY = "sk_test_mock";
const TIMEOUT_MS = 60_000;
const RETRY_MS = 200;
const MOBILE_VIEWPORT = { height: 844, width: 390 };

interface AppServer {
baseUrl: string;
enableStripe: () => Promise<void>;
stop: () => Promise<void>;
}

Expand Down Expand Up @@ -117,12 +119,13 @@ const startServer = async (): Promise<AppServer> => {
const tempDir = await Deno.makeTempDir({ prefix: "tickets-screenshots-" });
const port = findAvailablePort();
const baseUrl = `http://127.0.0.1:${port}`;
const dbUrl = `file:${join(tempDir, "screenshots.db")}`;
const child = denoCommand(["run", "-A", "src/index.ts"], {
cwd: ROOT,
env: {
...Deno.env.toObject(),
DB_ENCRYPTION_KEY: DB_KEY,
DB_URL: `file:${join(tempDir, "screenshots.db")}`,
DB_URL: dbUrl,
PORT: String(port),
},
stderr: "inherit",
Expand All @@ -138,6 +141,16 @@ const startServer = async (): Promise<AppServer> => {
if (healthy) {
return {
baseUrl,
enableStripe: async () => {
Deno.env.set("DB_ENCRYPTION_KEY", DB_KEY);
Deno.env.set("DB_URL", dbUrl);
const { settings } = await import("#shared/db/settings.ts");
await settings.update.stripe.activate({
secretKey: STRIPE_KEY,
Comment thread
stefan-burke marked this conversation as resolved.
Resolved
webhookEndpointId: "we_screenshots",
webhookSecret: "whsec_screenshots",
});
},
stop: async () => {
try {
child.kill("SIGTERM");
Expand Down Expand Up @@ -184,13 +197,15 @@ const setupAdmin = async (
await page.goto(`${baseUrl}/admin/settings`);
await page.locator('[name="business_email"]').fill("hello@example.com");
await submit(page, 'form[action="/admin/settings/business-email"]');
await page.goto(`${baseUrl}/admin/settings`);
await page.locator('[name="payment_provider"][value="none"]').check();
await submit(page, 'form[action="/admin/settings/payment-provider"]');
};

const setupApp = async (page: Page, baseUrl: string): Promise<SceneContext> => {
const setupApp = async (
page: Page,
server: AppServer,
): Promise<SceneContext> => {
const { baseUrl } = server;
await setupAdmin(page, baseUrl);
await server.enableStripe();
await page.goto(`${baseUrl}/admin/seeds`);
await page.locator('[name="listing_count"]').fill("5");
await page.locator('[name="attendees_per_listing"]').fill("8");
Expand Down Expand Up @@ -346,10 +361,12 @@ const capturePreparedPage = async (
const captureScenario = async (
scenario: ScreenshotScenario,
page: Page,
baseUrl: string,
server: AppServer,
outputDir: string,
): Promise<void> => {
const { baseUrl } = server;
await setupAdmin(page, baseUrl, scenario.setupUsername);
await server.enableStripe();
await applyTheme(
page,
baseUrl,
Expand Down Expand Up @@ -421,10 +438,10 @@ const main = async (): Promise<void> => {
const page = await context.newPage();
page.setDefaultTimeout(TIMEOUT_MS);
if (scenario) {
await captureScenario(scenario, page, server.baseUrl, outputDir);
await captureScenario(scenario, page, server, outputDir);
return;
}
const sceneContext = await setupApp(page, server.baseUrl);
const sceneContext = await setupApp(page, server);
for (const theme of options.themes) {
const themeDir = join(outputDir, theme);
await Deno.mkdir(themeDir, { recursive: true });
Expand Down
3 changes: 2 additions & 1 deletion src/ui/static/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,8 @@ label > input[type="number"] {
}

label > select[name="quantity"],
label > select[name^="quantity_"] {
label > select[name^="quantity_"],
label > select[name^="child_qty_"] {
width: 8ch;
flex: 0 0 auto;
}
Expand Down