Skip to content

Commit

Permalink
test: suggestions/feedback popup (#74)
Browse files Browse the repository at this point in the history
test: Added test for sentry feedback
  • Loading branch information
pajotg authored Jun 6, 2024
1 parent 99e736c commit e1d034c
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .env.development
Original file line number Diff line number Diff line change
@@ -1 +1 @@
VITE_BACKEND_URL="https://testleaphyeasybloqs.com:8443"
VITE_BACKEND_URL="https://testleaphyeasybloqs.com:8443"
3 changes: 3 additions & 0 deletions .env.playwright
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
VITE_BACKEND_URL="https://testleaphyeasybloqs.com:8443"
VITE_SENTRY_DSN="https://[email protected]:8443/2"
VITE_SENTRY_SAMPLE_RATE="1.0"
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default defineConfig({

/* Run your local dev server before starting the tests */
webServer: {
command: 'yarn dev',
command: 'yarn vite -m playwright',
url: 'http://localhost:5173/',
reuseExistingServer: !process.env.CI,
},
Expand Down
2 changes: 1 addition & 1 deletion src/lib/sentry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as Sentry from "@sentry/svelte";

function initSentry() {
if (!import.meta.env.PROD) return;
if (!import.meta.env.VITE_SENTRY_DSN) return;

Sentry.init({
dsn: import.meta.env.VITE_SENTRY_DSN,
Expand Down
51 changes: 51 additions & 0 deletions tests/user_feedback.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { expect, test } from "@playwright/test";
import { goToHomePage, openExample } from "./utils";

test.beforeEach(goToHomePage);

test("User Feedback", async ({ page }) => {
await page.getByText("Leaphy Click").click();

await page.getByRole("button", { name: "Tips" }).click();
await page.getByRole("cell", { name: "Suggestion / Feedback" }).click();
await page.getByPlaceholder("Your name...").fill("test");
await page.getByPlaceholder("Email").fill("test@ing");
await page.locator("textarea").fill("test123");

// Make sure no requests are actually done
await page.route("**/api/2/envelope/*", (route) => {
route.fulfill({
status: 200,
body: "",
});
});

// Wait for the user_report feedback
const feedbackPromise = page.waitForRequest((request) => {
if (!/.*\/api\/2\/envelope\/.*/.test(request.url())) {
return false;
}

let messages = request
.postData()
?.split("\n")
.map((line) => JSON.parse(line));

return messages !== undefined && messages[1].type === "user_report";
});

await page.getByRole("button", { name: "Send" }).click();
let request = await feedbackPromise;

let postData = request.postData();
expect(postData).toBeTruthy();

let messages = (postData as string)
.split("\n")
.map((line) => JSON.parse(line));

let feedback = messages[2];
expect(feedback.name).toBe("test");
expect(feedback.email).toBe("test@ing");
expect(feedback.comments).toBe("test123");
});

0 comments on commit e1d034c

Please sign in to comment.