Skip to content

Commit

Permalink
feat(e2e): add message tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshxfi committed Aug 1, 2024
1 parent 6ecd76e commit 8cd86fd
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ export function ReceivedMessageCard({
</p>
</CardHeader>
<CardContent>
<div className="flex w-full flex-col gap-2 rounded-lg p-5 whitespace-pre-wrap bg-muted break-words min-w-0">
<div
data-testid="received-msg-content"
className="flex w-full flex-col gap-2 rounded-lg p-5 whitespace-pre-wrap bg-muted break-words min-w-0"
>
{msg.content}
</div>
</CardContent>
Expand Down
5 changes: 4 additions & 1 deletion apps/www/src/app/components/chat-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@ export const ChatList = ({ imageUrl, question, reply, response }: Props) => {
</div>

{reply && (
<div className="max-w-[75%] sm:max-w-[55%] rounded-lg px-3 py-2 whitespace-pre-wrap bg-primary text-primary-foreground mt-6 self-end break-words">
<div
data-testid="msg-content"
className="max-w-[75%] sm:max-w-[55%] rounded-lg px-3 py-2 whitespace-pre-wrap bg-primary text-primary-foreground mt-6 self-end break-words"
>
{reply}
</div>
)}
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/app/notes/components/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export default function NoteForm({ user, currentNote }: Props) {

if (res.data) {
setContent("");
toast.success("Note updated")
toast.success("Note updated");
updateNote(res.data.updateNote);
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"scripts": {
"build": "turbo run build --filter=!./apps/social --filter=!./packages/e2e",
"dev": "turbo run dev",
"test": "turbo run test --filter=./packages/e2e",
"test": "turbo run test",
"start": "turbo run start --filter=!./apps/social",
"dev:test": "pnpm --filter @umamin/e2e dev:test",
"dev:www": "turbo run dev --filter=!./apps/social",
Expand All @@ -28,7 +28,7 @@
"@umamin/eslint-config": "workspace:*",
"@umamin/tsconfig": "workspace:*",
"prettier": "^3.2.5",
"turbo": "^2.0.9"
"turbo": "^2.0.11"
},
"packageManager": "[email protected]",
"engines": {
Expand Down
1 change: 1 addition & 0 deletions packages/db/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"scripts": {
"dev": "turso dev --db-file ./src/dev.db",
"start": "turso dev --db-file ./src/dev.db",
"test": "turso dev --db-file ./src/dev.db",
"clean": "rm -rf ./node_modules .turbo dist",
"check-types": "tsc --noEmit",
"generate": "pnpm drizzle-kit generate",
Expand Down
38 changes: 23 additions & 15 deletions packages/e2e/tests/auth.spec.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
import { test, expect } from "../playwright/fixtures.js";

// Reset storage state for this file to avoid being authenticated
test.use({ storageState: { cookies: [], origins: [] } });
test.describe.configure({ mode: "parallel" });

test.afterEach(async ({ page }) => {
await page.waitForURL("**/login");
await expect(page).toHaveTitle(/Umamin — Login/);
await expect(
page.getByRole("heading", { name: "Umamin Account" })
).toBeVisible();
test("should be authenticated", async ({ page }) => {
await page.goto("/login");
await page.waitForURL("**/inbox");
await expect(page).toHaveTitle(/Umamin — Inbox/);
});

test("should redirect unauthenticated users from inbox", async ({ page }) => {
await page.goto("/inbox");
});
test.describe("Unauthenticated", () => {
test.use({ storageState: { cookies: [], origins: [] } });

test.afterEach(async ({ page }) => {
await page.waitForURL("**/login");
await expect(page).toHaveTitle(/Umamin — Login/);
await expect(
page.getByRole("heading", { name: "Umamin Account" })
).toBeVisible();
});

test("should redirect unauthenticated users from inbox", async ({ page }) => {
await page.goto("/inbox");
});

test("should redirect unauthenticated users from settings", async ({
page,
}) => {
await page.goto("/settings");
test("should redirect unauthenticated users from settings", async ({
page,
}) => {
await page.goto("/settings");
});
});
35 changes: 35 additions & 0 deletions packages/e2e/tests/message.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { nanoid } from "nanoid";
import { test, expect } from "../playwright/fixtures.js";

const content = `this is a test message ${nanoid()}`;

test.describe("Sender", () => {
test("can send a message", async ({ page }) => {
await page.goto("/to/test_user");
await expect(page.getByText("test_user")).toBeVisible();

await page.getByPlaceholder("Type your message...").fill(content);
await page.getByTestId("send-msg-btn").click();
await expect(page.getByTestId("msg-content")).toHaveText(content);
});
});

test.describe("Receiver", () => {
test.use({ storageState: { cookies: [], origins: [] } });

test("should receive a new message", async ({ page }) => {
await page.goto("/login");
await expect(page).toHaveTitle(/Umamin — Login/);
await expect(
page.getByRole("heading", { name: "Umamin Account" })
).toBeVisible();

await page.getByLabel("Username").fill("test_user");
await page.getByLabel("Password").fill("strong_password");
await page.getByRole("button", { name: "Login" }).click();

await page.waitForURL("**/inbox");
await expect(page.getByTestId("username")).toHaveText("@test_user");
await expect(page.getByText(content)).toBeVisible();
});
});
67 changes: 34 additions & 33 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8cd86fd

Please sign in to comment.