Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tests #14

Draft
wants to merge 5 commits into
base: validation-checks
Choose a base branch
from
Draft
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
27 changes: 27 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: Playwright Tests
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
timeout-minutes: 60
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: npm ci
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
with:
name: playwright-report
path: playwright-report/
retention-days: 30
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,10 @@ yarn-error.log*
# typescript
*.tsbuildinfo
next-env.d.ts
node_modules/
/test-results/
/playwright-report/
/blob-report/
/playwright/.cache/
/playwright-report
/e2e
Binary file modified bun.lockb
Binary file not shown.
3 changes: 3 additions & 0 deletions next.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const nextConfig: NextConfig = {
}
return config;
},
compiler: {
reactRemoveProperties: process.env.NODE_ENV === 'production'
}
};

export default nextConfig;
19 changes: 16 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@
"dev": "bunx --bun next dev",
"build": "next build",
"start": "next start",
"lint": "bunx --bun next lint"
"lint": "bunx --bun next lint",
"test:e2e": "playwright test",
"test:e2e:ui": "playwright test --ui",
"test": "playwright test",
"test:ui": "playwright test --ui",
"test:debug": "playwright test --debug",
"test:coverage": "playwright test --coverage",
"test:report": "playwright show-report",
"test:codegen": "playwright codegen"
},
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
Expand All @@ -31,15 +39,20 @@
"next": "15.0.1",
"next-themes": "^0.3.0",
"postal-mime": "^2.3.2",
"react": "19.0.0-rc-69d4b800-20241021",
"react-dom": "19.0.0-rc-69d4b800-20241021",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-toastify": "^10.0.6",
"tailwind-merge": "^2.5.4",
"tailwindcss-animate": "^1.0.7",
"use-debounce": "^10.0.4",
"zod": "^3.23.8",
"zustand": "^5.0.1"
},
"devDependencies": {
"@playwright/browser-chromium": "^1.42.1",
"@playwright/browser-firefox": "^1.42.1",
"@playwright/browser-webkit": "^1.42.1",
"@playwright/test": "^1.49.0",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18",
Expand Down
71 changes: 71 additions & 0 deletions playwright-report/index.html

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { defineConfig } from '@playwright/test';

export default defineConfig({
testDir: './src/tests',
testMatch: '**/*.ts',
use: {
headless: true,
viewport: { width: 1280, height: 720 },
screenshot: 'only-on-failure',
},
webServer: {
command: 'bun run start',
url: 'http://localhost:3000',
reuseExistingServer: !process.env.CI,
timeout: 120 * 1000, // 120 seconds
},
retries: 1,
reporter: [['html'], ['list']],
});
2 changes: 2 additions & 0 deletions src/app/[id]/ConnectEmails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const ConnectEmails = () => {
.catch((err) => toast.error(err.message ?? err));
}
}}
id="drag-and-drop-emails"
data-testid="drag-and-drop-emails"
style={{
backgroundImage: `url("data:image/svg+xml,%3csvg width='100%25' height='100%25' xmlns='http://www.w3.org/2000/svg'%3e%3crect width='100%25' height='100%25' fill='none' stroke='%23E2E2E2FF' stroke-width='4' stroke-dasharray='6%2c 14' stroke-dashoffset='2' stroke-linecap='square'/%3e%3c/svg%3e")`,
}}
Expand Down
7 changes: 7 additions & 0 deletions src/app/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ const Pattern = ({ params }: { params: Promise<{ id: string }> }) => {

return (
<div className="mx-auto flex flex-col gap-10 py-16">
<div className="fixed left-1/2 top-4 z-50 -translate-x-1/2 rounded-lg bg-warning px-4 py-2 text-white shadow-lg">
<p className="text-sm font-medium">
🚧 This feature is currently in beta. Some functionality may be limited or subject to
change.
</p>
</div>

<>
<div>
<div className="mb-2 flex items-center justify-between">
Expand Down
20 changes: 13 additions & 7 deletions src/app/[id]/proofs/[proofId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const ProofInfo = ({ params }: { params: Promise<{ id: string; proofId: string }
<div className="flex flex-col gap-4">
<div className="flex flex-col justify-between gap-1 md:flex-row">
<div className="text-base font-medium text-grey-700">Job Id</div>
<div className="gap-1 text-base font-medium text-grey-800">
<div className="gap-1 text-base font-medium text-grey-800" id="job-id">
{proofId}
<span className="ml-1">
<Button
Expand All @@ -142,13 +142,13 @@ const ProofInfo = ({ params }: { params: Promise<{ id: string; proofId: string }
</div>
<div className="flex flex-col justify-between gap-1 md:flex-row">
<div className="text-base font-medium text-grey-700">Blueprint</div>
<div className="text-base font-medium text-grey-800">
<div className="text-base font-medium text-grey-800" id="blueprint-title">
{blueprint?.props.title} (v{blueprint?.props.version})
</div>
</div>
<div className="flex flex-col justify-between gap-1 md:flex-row">
<div className="text-base font-medium text-grey-700">Outputs</div>
<div className="text-base font-medium text-grey-800">
<div className="text-base font-medium text-grey-800" id="outputs">
{emailProof?.publicData
? Object.entries(emailProof.publicData)
.map(([key, value]) => `{"${key}": "${value}"}`)
Expand All @@ -158,27 +158,32 @@ const ProofInfo = ({ params }: { params: Promise<{ id: string; proofId: string }
</div>
<div className="flex flex-col justify-between gap-1 md:flex-row">
<div className="text-base font-medium text-grey-700">Date created</div>
<div className="text-base font-medium text-grey-800">
<div className="text-base font-medium text-grey-800" id="date-created">
{emailProof?.startedAt ? formatDateAndTime(emailProof.startedAt) : '-'}
</div>
</div>
<div className="flex flex-col justify-between gap-1 md:flex-row">
<div className="text-base font-medium text-grey-700">Time taken</div>
<div className="text-base font-medium text-grey-800">
<div className="text-base font-medium text-grey-800" id="time-taken">
{emailProof?.provedAt && emailProof?.startedAt
? `${((new Date(emailProof.provedAt).getTime() - new Date(emailProof.startedAt).getTime()) / 1000).toString()} seconds`
: '-'}
</div>
</div>
<div className="flex flex-col justify-between gap-1 md:flex-row">
<div className="text-base font-medium text-grey-700">Status</div>
<div className="text-base font-medium text-grey-800">{handleGetStatusChip(status)}</div>
<div className="text-base font-medium text-grey-800" id="status">
{handleGetStatusChip(status)}
</div>
</div>
</div>
{emailProof ? (
<div>
<h4 className="rounded text-base font-medium text-grey-900">Generated proof</h4>
<div className="overflow-x-auto border border-grey-500 bg-neutral-100 px-3 py-2 text-grey-600">
<div
className="overflow-x-auto border border-grey-500 bg-neutral-100 px-3 py-2 text-grey-600"
id="generated-proof"
>
<pre>{JSON.stringify(emailProof.proofData, null, 2)}</pre>
</div>
</div>
Expand All @@ -194,6 +199,7 @@ const ProofInfo = ({ params }: { params: Promise<{ id: string; proofId: string }
dangerouslySetInnerHTML={{
__html: parsedEmail.html!,
}}
id="email-render"
/>
</div>
) : null}
Expand Down
6 changes: 5 additions & 1 deletion src/app/components/BlueprintCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,15 @@ interface BlueprintCardProps {

const BlueprintCard = ({ blueprint }: BlueprintCardProps) => {
return (
<div className="rounded-2xl border bg-white p-6 transition-shadow hover:shadow-md">
<div
className="rounded-2xl border bg-white p-6 transition-shadow hover:shadow-md"
data-testid="blueprint-card"
>
<div className="mb-2 flex items-center justify-between">
<div className="flex flex-row flex-wrap items-center gap-2">
<h2 className="text-xl font-bold">{blueprint.props.title}</h2>
<span
data-testid={`blueprint-status-${blueprint.props.status}`}
className={`hidden flex-row gap-1 rounded-full px-2 py-1 text-xs font-semibold md:flex ${getStatusColorLight(
blueprint.props.status
)}`}
Expand Down
3 changes: 2 additions & 1 deletion src/app/components/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ export default function SearchBar() {
<div className="relative w-full max-w-md">
<Input
type="text"
size='sm'
variant='sm'
placeholder="Search blueprints.."
className="w-full rounded-lg border px-4 py-2 pl-10"
onChange={(e) => {
handleSearch(e.target.value);
}}
defaultValue={searchParams.get('search')?.toString()}
startIcon={<Image src="/assets/SearchIcon.svg" alt="search" width={16} height={16} />}
data-testid="search-bar"
/>
</div>
);
Expand Down
158 changes: 158 additions & 0 deletions src/app/create/[id]/blueprintFormSchema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
import { z } from 'zod';

export function getPrefixRegex(parts: { is_public: boolean; regex_def: string }[]): string {
let prefixRegex = '';
for (let part of parts) {
if (!part.is_public) prefixRegex = prefixRegex + part.regex_def;
if (!part.is_public && !part.regex_def)
throw new Error('Part has to have a nonempty regex with is_public = false');
else break;
}
if (!prefixRegex)
throw new Error('Part has to have a regex with is_public = false in order to find it later');
return JSON.stringify(prefixRegex);
}

export const blueprintFormSchema = z.object({
title: z.string().min(1, {
message: 'Title must be at least 1 characters.',
}),
slug: z.string().regex(/[\w\-\_\@]+\/[\w\-\_\@)]+/, {
message: "Needs to match this pattern 'xxxx/yyyy'",
}),
circuitName: z
.string()
.min(1)
.regex(
/^[a-zA-Z_][a-zA-Z0-9_]*$/,
'Invalid name, must start with a letter, digit, or underscore, and can only contain letters, digits or underscores.'
),
description: z.string().min(1),
tags: z.string().transform((str, ctx) => {
try {
return str.split(',');
} catch (e) {
ctx.addIssue({ code: 'custom', message: 'Invalid tags' });
return z.NEVER;
}
}),
emailQuery: z.string(),
ignoreBodyHashCheck: z.boolean(),
enableMasking: z.boolean(),
shaPrecomputeSelector: z.string().transform((value) => value.replace(/(?<!\\)"/g, '\\"')),
senderDomain: z.string().refine((value) => !value.includes('@'), {
message: "Sender domain should not contain '@' symbol, only the domain",
}),
emailBodyMaxLength: z.coerce.number().transform((n, ctx) => {
if (n % 64 !== 0) {
ctx.addIssue({ code: 'custom', message: 'Must be a multiple of 64' });
}
return n;
}),
emailHeaderMaxLength: z.coerce
.number()
.transform((n, ctx) => {
if (n % 64 !== 0) {
ctx.addIssue({ code: 'custom', message: 'Must be a multiple of 64' });
}
return n;
})
.default(1024),
decomposedRegexes: z.array(
z.object({
name: z
.string()
.min(1)
.transform((value, ctx) => {
if (value.includes(' ')) {
ctx.addIssue({
code: 'custom',
message:
'Warning: Name contains spaces or dashes. They will be replaced with underscores.',
});
return value.replace(/[ -]/g, '_');
}
return value;
}),
maxLength: z.coerce.number().positive().default(64),
location: z.string().regex(/(body)|(header)/),
parts: z
.string()
.transform((str, ctx) => {
// Check if the string contains 'is_public'
if (!str.includes('is_public')) {
ctx.addIssue({
code: 'custom',
message:
'Each parts config must include at least one "is_public" field, and at least one thats true and one thats false. Please add it for now until we fix this requirement.',
});
return z.NEVER;
}
let parsed;

try {
parsed = JSON.parse(str);
} catch (e) {
ctx.addIssue({ code: 'custom', message: 'Invalid JSON' });
return z.NEVER;
}
// Validate the structure of the parsed JSON
if (!Array.isArray(parsed)) {
ctx.addIssue({ code: 'custom', message: 'Parts must be an array' });
return z.NEVER;
}
for (let i = 0; i < parsed.length; i++) {
const part = parsed[i];
if (typeof part !== 'object' || part === null) {
ctx.addIssue({ code: 'custom', message: `Part ${i} must be an object` });
return z.NEVER;
}

if (!('is_public' in part) || typeof part.is_public !== 'boolean') {
ctx.addIssue({
code: 'custom',
message: `Part ${i} must have a boolean 'is_public' field`,
});
return z.NEVER;
}

if (!('regex_def' in part) || typeof part.regex_def !== 'string') {
ctx.addIssue({
code: 'custom',
message: `Part ${i} must have a string 'regex_def' field`,
});
return z.NEVER;
}
}
try {
// try to map and see if it works
getPrefixRegex(parsed);
return parsed;
} catch (e: any) {
ctx.addIssue({ code: 'custom', message: (e as Error).message });
return z.NEVER;
}
})
.optional()
.or(z.array(z.any())), // this is that when we pre-populate the form directly with an array, the form will still accept it
})
),
externalInputs: z.array(
z.object({
name: z.string().min(1),
maxLength: z.coerce.number().positive().default(64),
})
),
});
// .refine(
// (
// data // make sure if values contain body, then ignoreBodyHashCheck must be false
// ) =>
// !data.ignoreBodyHashCheck ||
// !data.decomposedRegexes.some((decomposedRegex) => decomposedRegex.location === 'body'),
// {
// message:
// 'Ignore body hash check must be false if you want to extract data from the email body',
// path: ['parameters', 'ignoreBodyHashCheck'],
// }
// );
Loading