From 8cd86fdfa110e126ed22e7f001d00c08084d1749 Mon Sep 17 00:00:00 2001 From: Josh Daniel Date: Thu, 1 Aug 2024 12:31:31 +0800 Subject: [PATCH] feat(e2e): add message tests --- .../inbox/components/received/card.tsx | 5 +- apps/www/src/app/components/chat-list.tsx | 5 +- apps/www/src/app/notes/components/form.tsx | 2 +- package.json | 4 +- packages/db/package.json | 1 + packages/e2e/tests/auth.spec.ts | 38 ++++++----- packages/e2e/tests/message.spec.ts | 35 ++++++++++ pnpm-lock.yaml | 67 ++++++++++--------- 8 files changed, 104 insertions(+), 53 deletions(-) create mode 100644 packages/e2e/tests/message.spec.ts diff --git a/apps/www/src/app/(profile)/inbox/components/received/card.tsx b/apps/www/src/app/(profile)/inbox/components/received/card.tsx index 4ce80443..587c0e56 100644 --- a/apps/www/src/app/(profile)/inbox/components/received/card.tsx +++ b/apps/www/src/app/(profile)/inbox/components/received/card.tsx @@ -58,7 +58,10 @@ export function ReceivedMessageCard({

-
+
{msg.content}
diff --git a/apps/www/src/app/components/chat-list.tsx b/apps/www/src/app/components/chat-list.tsx index 8df8a8cb..d2ddc515 100644 --- a/apps/www/src/app/components/chat-list.tsx +++ b/apps/www/src/app/components/chat-list.tsx @@ -28,7 +28,10 @@ export const ChatList = ({ imageUrl, question, reply, response }: Props) => {
{reply && ( -
+
{reply}
)} diff --git a/apps/www/src/app/notes/components/form.tsx b/apps/www/src/app/notes/components/form.tsx index 8ef4f2d9..187f5fc9 100644 --- a/apps/www/src/app/notes/components/form.tsx +++ b/apps/www/src/app/notes/components/form.tsx @@ -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); } diff --git a/package.json b/package.json index f14ef937..35e04363 100644 --- a/package.json +++ b/package.json @@ -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", @@ -28,7 +28,7 @@ "@umamin/eslint-config": "workspace:*", "@umamin/tsconfig": "workspace:*", "prettier": "^3.2.5", - "turbo": "^2.0.9" + "turbo": "^2.0.11" }, "packageManager": "pnpm@9.5.0", "engines": { diff --git a/packages/db/package.json b/packages/db/package.json index a719af7f..f4a4d37d 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -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", diff --git a/packages/e2e/tests/auth.spec.ts b/packages/e2e/tests/auth.spec.ts index 10745167..99d034c6 100644 --- a/packages/e2e/tests/auth.spec.ts +++ b/packages/e2e/tests/auth.spec.ts @@ -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"); + }); }); diff --git a/packages/e2e/tests/message.spec.ts b/packages/e2e/tests/message.spec.ts new file mode 100644 index 00000000..5cdc5ccc --- /dev/null +++ b/packages/e2e/tests/message.spec.ts @@ -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(); + }); +}); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 99bb1075..d6d5f7a9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,8 +18,8 @@ importers: specifier: ^3.2.5 version: 3.3.1 turbo: - specifier: ^2.0.9 - version: 2.0.9 + specifier: ^2.0.11 + version: 2.0.11 apps/social: dependencies: @@ -4559,6 +4559,7 @@ packages: libsql@0.3.19: resolution: {integrity: sha512-Aj5cQ5uk/6fHdmeW0TiXK42FqUlwx7ytmMLPSaUQPin5HKKKuUPD62MAbN4OEweGBBI7q1BekoEN4gPUEL6MZA==} + cpu: [x64, arm64, wasm32] os: [darwin, linux, win32] lilconfig@2.1.0: @@ -5758,38 +5759,38 @@ packages: peerDependencies: typescript: '>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta' - turbo-darwin-64@2.0.9: - resolution: {integrity: sha512-owlGsOaExuVGBUfrnJwjkL1BWlvefjSKczEAcpLx4BI7Oh6ttakOi+JyomkPkFlYElRpjbvlR2gP8WIn6M/+xQ==} + turbo-darwin-64@2.0.11: + resolution: {integrity: sha512-YlHEEhcm+jI1BSZoLugGHUWDfRXaNaQIv7tGQBfadYjo9kixBnqoTOU6s1ubOrQMID+lizZZQs79GXwqM6vohg==} cpu: [x64] os: [darwin] - turbo-darwin-arm64@2.0.9: - resolution: {integrity: sha512-XAXkKkePth5ZPPE/9G9tTnPQx0C8UTkGWmNGYkpmGgRr8NedW+HrPsi9N0HcjzzIH9A4TpNYvtiV+WcwdaEjKA==} + turbo-darwin-arm64@2.0.11: + resolution: {integrity: sha512-K/YW+hWzRQ/wGmtffxllH4M1tgy8OlwgXODrIiAGzkSpZl9+pIsem/F86UULlhsIeavBYK/LS5+dzV3DPMjJ9w==} cpu: [arm64] os: [darwin] - turbo-linux-64@2.0.9: - resolution: {integrity: sha512-l9wSgEjrCFM1aG16zItBsZ206ZlhSSx1owB8Cgskfv0XyIXRGHRkluihiaxkp+UeU5WoEfz4EN5toc+ICA0q0w==} + turbo-linux-64@2.0.11: + resolution: {integrity: sha512-mv8CwGP06UPweMh1Vlp6PI6OWnkuibxfIJ4Vlof7xqjohAaZU5FLqeOeHkjQflH/6YrCVuS9wrK0TFOu+meTtA==} cpu: [x64] os: [linux] - turbo-linux-arm64@2.0.9: - resolution: {integrity: sha512-gRnjxXRne18B27SwxXMqL3fJu7jw/8kBrOBTBNRSmZZiG1Uu3nbnP7b4lgrA/bCku6C0Wligwqurvtpq6+nFHA==} + turbo-linux-arm64@2.0.11: + resolution: {integrity: sha512-wLE5tl4oriTmHbuayc0ki0csaCplmVLj+uCWtecM/mfBuZgNS9ICNM9c4sB+Cfl5tlBBFeepqRNgvRvn8WeVZg==} cpu: [arm64] os: [linux] - turbo-windows-64@2.0.9: - resolution: {integrity: sha512-ZVo0apxUvaRq4Vm1qhsfqKKhtRgReYlBVf9MQvVU1O9AoyydEQvLDO1ryqpXDZWpcHoFxHAQc9msjAMtE5K2lA==} + turbo-windows-64@2.0.11: + resolution: {integrity: sha512-tja3zvVCSWu3HizOoeQv0qDJ+GeWGWRFOOM6a8i3BYnXLgGKAaDZFcjwzgC50tWiAw4aowIVR4OouwIyRhLBaQ==} cpu: [x64] os: [win32] - turbo-windows-arm64@2.0.9: - resolution: {integrity: sha512-sGRz7c5Pey6y7y9OKi8ypbWNuIRPF9y8xcMqL56OZifSUSo+X2EOsOleR9MKxQXVaqHPGOUKWsE6y8hxBi9pag==} + turbo-windows-arm64@2.0.11: + resolution: {integrity: sha512-sYjXP6k94Bqh99R+y3M1Ks6LRIEZybMz+7enA8GKl6JJ2ZFaXxTnS6q+/2+ii1+rRwxohj5OBb4gxODcF8Jd4w==} cpu: [arm64] os: [win32] - turbo@2.0.9: - resolution: {integrity: sha512-QaLaUL1CqblSKKPgLrFW3lZWkWG4pGBQNW+q1ScJB5v1D/nFWtsrD/yZljW/bdawg90ihi4/ftQJ3h6fz1FamA==} + turbo@2.0.11: + resolution: {integrity: sha512-imDlFFAvitbCm1JtDFJ6eG882qwxHUmVT2noPb3p2jq5o5DuXOchMbkVS9kUeC3/4WpY5N0GBZ3RvqNyjHZw1Q==} hasBin: true type-check@0.4.0: @@ -9670,7 +9671,7 @@ snapshots: eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0) eslint-plugin-jsx-a11y: 6.8.0(eslint@8.57.0) eslint-plugin-react: 7.34.2(eslint@8.57.0) eslint-plugin-react-hooks: 4.6.2(eslint@8.57.0) @@ -9688,7 +9689,7 @@ snapshots: eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0) eslint-plugin-jsx-a11y: 6.9.0(eslint@8.57.0) eslint-plugin-react: 7.34.3(eslint@8.57.0) eslint-plugin-react-hooks: 4.6.2(eslint@8.57.0) @@ -9742,7 +9743,7 @@ snapshots: enhanced-resolve: 5.17.0 eslint: 8.57.0 eslint-module-utils: 2.8.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) - eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) + eslint-plugin-import: 2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0) fast-glob: 3.3.2 get-tsconfig: 4.7.5 is-core-module: 2.13.1 @@ -9817,7 +9818,7 @@ snapshots: - eslint-import-resolver-webpack - supports-color - eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.1(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0): + eslint-plugin-import@2.29.1(@typescript-eslint/parser@7.2.0(eslint@8.57.0)(typescript@5.4.5))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0): dependencies: array-includes: 3.1.8 array.prototype.findlastindex: 1.2.5 @@ -12352,32 +12353,32 @@ snapshots: tslib: 1.14.1 typescript: 5.4.5 - turbo-darwin-64@2.0.9: + turbo-darwin-64@2.0.11: optional: true - turbo-darwin-arm64@2.0.9: + turbo-darwin-arm64@2.0.11: optional: true - turbo-linux-64@2.0.9: + turbo-linux-64@2.0.11: optional: true - turbo-linux-arm64@2.0.9: + turbo-linux-arm64@2.0.11: optional: true - turbo-windows-64@2.0.9: + turbo-windows-64@2.0.11: optional: true - turbo-windows-arm64@2.0.9: + turbo-windows-arm64@2.0.11: optional: true - turbo@2.0.9: + turbo@2.0.11: optionalDependencies: - turbo-darwin-64: 2.0.9 - turbo-darwin-arm64: 2.0.9 - turbo-linux-64: 2.0.9 - turbo-linux-arm64: 2.0.9 - turbo-windows-64: 2.0.9 - turbo-windows-arm64: 2.0.9 + turbo-darwin-64: 2.0.11 + turbo-darwin-arm64: 2.0.11 + turbo-linux-64: 2.0.11 + turbo-linux-arm64: 2.0.11 + turbo-windows-64: 2.0.11 + turbo-windows-arm64: 2.0.11 type-check@0.4.0: dependencies: