Skip to content

Commit

Permalink
Merge pull request #228 from omsimos/feat/tests
Browse files Browse the repository at this point in the history
implement e2e tests
  • Loading branch information
joshxfi authored Jul 28, 2024
2 parents e8fd63a + 133c2b4 commit eedf30f
Show file tree
Hide file tree
Showing 25 changed files with 493 additions and 824 deletions.
44 changes: 0 additions & 44 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,47 +38,3 @@ jobs:
TURSO_CONNECTION_URL: ${{ secrets.TURSO_CONNECTION_URL }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: pnpm build

e2e:
needs: build
timeout-minutes: 15
runs-on: ubuntu-latest
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
TURBO_REMOTE_ONLY: true

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9.5.0
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install dependencies
run: pnpm install --prefer-offline

- name: Install Playwright Browsers
run: pnpm dlx playwright install --with-deps

- name: Build project
env:
TURSO_CONNECTION_URL: ${{ secrets.TURSO_CONNECTION_URL }}
run: pnpm build

- name: Run Playwright tests
env:
TURSO_CONNECTION_URL: ${{ secrets.TURSO_CONNECTION_URL }}
TURSO_AUTH_TOKEN: ${{ secrets.TURSO_AUTH_TOKEN }}
AES_KEY: ${{ secrets.AES_KEY }}
run: pnpm test

- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright-report/
retention-days: 30
97 changes: 97 additions & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
name: Playwright Tests

on:
push:
branches:
- "**"
pull_request:
branches:
- main

jobs:
e2e:
if: false # Disable this job temporarily
timeout-minutes: 60
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
shardIndex: [1, 2, 3, 4]
shardTotal: [4]
env:
TURBO_TOKEN: ${{ secrets.TURBO_TOKEN }}
TURBO_TEAM: ${{ vars.TURBO_TEAM }}
TURBO_REMOTE_ONLY: true

steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9.5.0
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install dependencies
run: pnpm install --prefer-offline

- name: Install Playwright Browsers
run: pnpm dlx playwright install --with-deps

- name: Build project
env:
TURSO_CONNECTION_URL: ${{ secrets.TURSO_CONNECTION_URL }}
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
run: pnpm build

- name: Run Playwright tests
env:
TURSO_CONNECTION_URL: ${{ secrets.TURSO_CONNECTION_URL }}
TURSO_AUTH_TOKEN: ${{ secrets.TURSO_AUTH_TOKEN }}
AES_KEY: ${{ secrets.AES_KEY }}
run: pnpm test -- -- --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }}

- name: Upload blob report to GitHub Actions Artifacts
if: ${{ !cancelled() }}
uses: actions/upload-artifact@v4
with:
name: blob-report-${{ matrix.shardIndex }}
path: blob-report
retention-days: 1

merge-reports:
# if: ${{ !cancelled() }}
if: false # Disable this job temporarily
needs: [e2e]

runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v4
with:
version: 9.5.0
- uses: actions/setup-node@v4
with:
node-version: 20
cache: "pnpm"

- name: Install dependencies
run: pnpm install --prefer-offline

- name: Download blob reports from GitHub Actions Artifacts
uses: actions/download-artifact@v4
with:
path: all-blob-reports
pattern: blob-report-*
merge-multiple: true

- name: Merge into HTML Report
run: npx playwright merge-reports --reporter html ./all-blob-reports

- name: Upload HTML report
uses: actions/upload-artifact@v4
with:
name: html-report--attempt-${{ github.run_attempt }}
path: playwright-report
retention-days: 14
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,11 @@ export function ReplyDialog(props: Props) {
className="focus-visible:ring-transparent flex-1 text-base resize-none min-h-10 max-h-20"
autoComplete="off"
/>
<Button type="submit" size="icon">
<Button
data-testid="msg-send-reply-btn"
type="submit"
size="icon"
>
{loading ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@ export function SignOutButton() {
const { pending } = useFormStatus();

return (
<Button type="submit" disabled={pending} variant="outline">
<Button
data-testid="logout-btn"
type="submit"
disabled={pending}
variant="outline"
>
{pending && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}
Sign Out
</Button>
Expand Down
113 changes: 52 additions & 61 deletions apps/www/src/app/(user)/to/[username]/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import useBotDetection from "@/hooks/use-bot-detection";
import { Textarea } from "@umamin/ui/components/textarea";
import { useDynamicTextarea } from "@/hooks/use-dynamic-textarea";
import type { UserByUsernameQueryResult } from "../../../queries";
import { ProgressDialog } from "@/app/components/progress-dialog";

const CREATE_MESSAGE_MUTATION = graphql(`
mutation CreateMessage($input: CreateMessageInput!) {
Expand All @@ -41,7 +40,6 @@ export default function ChatForm({ currentUserId, user }: Props) {
const [content, setContent] = useState("");
const [message, setMessage] = useState("");
const [isFetching, setIsFetching] = useState(false);
const [dialogOpen, setDialogOpen] = useState(false);

const inputRef = useDynamicTextarea(content);

Expand Down Expand Up @@ -76,7 +74,7 @@ export default function ChatForm({ currentUserId, user }: Props) {
return;
}

setDialogOpen(true);
setMessage(content.replace(/(\r\n|\n|\r){2,}/g, "\n\n"));
setIsFetching(false);

logEvent(analytics, "send_message");
Expand All @@ -87,65 +85,58 @@ export default function ChatForm({ currentUserId, user }: Props) {
}

return (
<>
<ProgressDialog
type="Message"
description="Your message is anonymous and encrypted. It will be delivered to the recipient's inbox."
open={dialogOpen}
onOpenChange={setDialogOpen}
onProgressComplete={() => {
setMessage(content.replace(/(\r\n|\n|\r){2,}/g, "\n\n"));
setContent("");
}}
/>
<div
className={cn(
"flex flex-col justify-between pb-6 h-full max-h-[400px] relative w-full min-w-0",
user?.quietMode ? "min-h-[250px]" : "min-h-[350px]"
)}
>
<div className="flex flex-col h-full overflow-scroll pt-10 px-5 sm:px-7 pb-5 w-full relative min-w-0 ">
<ChatList
imageUrl={user?.imageUrl}
question={user?.question ?? ""}
reply={message}
<div
className={cn(
"flex flex-col justify-between pb-6 h-full max-h-[400px] relative w-full min-w-0",
user?.quietMode ? "min-h-[250px]" : "min-h-[350px]"
)}
>
<div className="flex flex-col h-full overflow-scroll pt-10 px-5 sm:px-7 pb-5 w-full relative min-w-0 ">
<ChatList
imageUrl={user?.imageUrl}
question={user?.question ?? ""}
reply={message}
/>
</div>

{user?.quietMode ? (
<span className="text-muted-foreground text-center text-sm">
User has enabled quiet mode
</span>
) : (
<form
onSubmit={handleSubmit}
className="px-5 sm:px-7 flex items-center space-x-2 w-full self-center pt-2 max-w-lg"
>
<Textarea
id="message"
required
ref={inputRef}
value={content}
disabled={isFetching}
onChange={(e) => {
setContent(e.target.value);
}}
maxLength={500}
placeholder="Type your message..."
className="focus-visible:ring-transparent text-base resize-none min-h-10 max-h-20"
autoComplete="off"
/>
</div>

{user?.quietMode ? (
<span className="text-muted-foreground text-center text-sm">
User has enabled quiet mode
</span>
) : (
<form
onSubmit={handleSubmit}
className="px-5 sm:px-7 flex items-center space-x-2 w-full self-center pt-2 max-w-lg"
<Button
data-testid="send-msg-btn"
type="submit"
size="icon"
disabled={isFetching}
>
<Textarea
id="message"
required
ref={inputRef}
value={content}
disabled={isFetching}
onChange={(e) => {
setContent(e.target.value);
}}
maxLength={500}
placeholder="Type your message..."
className="focus-visible:ring-transparent text-base resize-none min-h-10 max-h-20"
autoComplete="off"
/>
<Button type="submit" size="icon" disabled={isFetching}>
{isFetching ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<Send className="h-4 w-4" />
)}
<span className="sr-only">Send</span>
</Button>
</form>
)}
</div>
</>
{isFetching ? (
<Loader2 className="w-4 h-4 animate-spin" />
) : (
<Send className="h-4 w-4" />
)}
<span className="sr-only">Send</span>
</Button>
</form>
)}
</div>
);
}
11 changes: 8 additions & 3 deletions apps/www/src/app/components/navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ export async function Navbar() {
</Link>
)}

<Link href="/notes" title="Notes">
<Link data-testid="nav-notes-btn" href="/notes" title="Notes">
<ScrollText className="h-6 w-6" />
</Link>

<Link
data-testid="nav-inbox-btn"
href={user ? "/inbox" : "/login"}
aria-label="home button"
title="Inbox"
Expand All @@ -71,11 +72,15 @@ export async function Navbar() {
</Link>

{user ? (
<Link href="/settings" title="Settings">
<Link
data-testid="nav-settings-btn"
href="/settings"
title="Settings"
>
<UserCog className="w-6 h-6" />
</Link>
) : (
<Link href="/login" title="Login">
<Link data-testid="nav-login-btn" href="/login" title="Login">
<LogIn className="h-6 w-6" />
</Link>
)}
Expand Down
Loading

0 comments on commit eedf30f

Please sign in to comment.