From a456139c9568b6d91afedd83c7fb7eb1ce6041b0 Mon Sep 17 00:00:00 2001
From: Elliot Braem <16282460+elliotBraem@users.noreply.github.com>
Date: Wed, 12 Jun 2024 16:33:43 -0400
Subject: [PATCH] Fixes authentication tests (#381)
* remove Dummy
* cleans up auth tests
* fmt
---
.gitignore | 1 +
apps/new/widget/Dummy.jsx | 2 -
package.json | 1 +
playwright-tests/tests/auth.spec.js | 48 +++++++++++++++++++++++
playwright-tests/tests/userlogin.spec.js | 34 ----------------
playwright-tests/tests/userlogout.spec.js | 38 ------------------
playwright-tests/util/constants.js | 2 +
playwright.config.js | 2 +-
8 files changed, 53 insertions(+), 75 deletions(-)
delete mode 100644 apps/new/widget/Dummy.jsx
create mode 100644 playwright-tests/tests/auth.spec.js
delete mode 100644 playwright-tests/tests/userlogin.spec.js
delete mode 100644 playwright-tests/tests/userlogout.spec.js
diff --git a/.gitignore b/.gitignore
index bb8d4523..e0ed2d14 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,4 @@ yarn-error.log*
target
neardev
data.json
+/test-results
diff --git a/apps/new/widget/Dummy.jsx b/apps/new/widget/Dummy.jsx
deleted file mode 100644
index 5b785072..00000000
--- a/apps/new/widget/Dummy.jsx
+++ /dev/null
@@ -1,2 +0,0 @@
-// dummy file for pages that are yet to be created
-return
dummy
;
diff --git a/package.json b/package.json
index 5ea93c64..a6c632e7 100644
--- a/package.json
+++ b/package.json
@@ -18,6 +18,7 @@
"start": "yarn dev:gateway",
"serve": "webpack serve",
"test": "npx playwright test",
+ "test:ui": "npx playwright test --ui",
"lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"prepare": "simple-git-hooks"
},
diff --git a/playwright-tests/tests/auth.spec.js b/playwright-tests/tests/auth.spec.js
new file mode 100644
index 00000000..aef3295b
--- /dev/null
+++ b/playwright-tests/tests/auth.spec.js
@@ -0,0 +1,48 @@
+import { test, expect } from "@playwright/test";
+import { ROOT_SRC } from "../util/constants";
+
+test.describe("User is not logged in", () => {
+ test.use({
+ storageState: "playwright-tests/storage-states/wallet-not-connected.json",
+ });
+
+ test.beforeEach(async ({ page }) => {
+ await page.goto(`/${ROOT_SRC}`);
+ });
+
+ test("To verify that the sign in button is visible in the home page and when clicked navigates to login page", async ({
+ page,
+ }) => {
+ const signInButton = page.getByRole("button", { name: "Sign in" }).nth(1);
+ await expect(signInButton).toBeVisible();
+ await signInButton.click();
+ expect(page.url()).toContain("/join");
+ });
+});
+
+test.describe("User is logged in", () => {
+ test.use({
+ storageState: "playwright-tests/storage-states/wallet-connected.json",
+ });
+
+ test.beforeEach(async ({ page }) => {
+ await page.goto(`/${ROOT_SRC}`);
+ });
+
+ test("To verify that the user is logged in succesfully", async ({ page }) => {
+ const LoggedInButton = page.getByRole("button", { name: "anybody.near" });
+ await expect(LoggedInButton).toHaveText("anybody.near");
+ });
+
+ test("To verify that the sign out button is visible in the dropdown and when clicked navigates to logout page", async ({
+ page,
+ }) => {
+ const LoggedInButton = page.getByRole("button", { name: "anybody.near" });
+ await expect(LoggedInButton).toHaveText("anybody.near");
+ await LoggedInButton.click();
+ const dropdownItems = await page.$$(".dropdown-item");
+ const secondDropdownItem = dropdownItems[1];
+ await secondDropdownItem.click();
+ expect(page.url()).toContain("/logout");
+ });
+});
diff --git a/playwright-tests/tests/userlogin.spec.js b/playwright-tests/tests/userlogin.spec.js
deleted file mode 100644
index 61ee2762..00000000
--- a/playwright-tests/tests/userlogin.spec.js
+++ /dev/null
@@ -1,34 +0,0 @@
-import { test, expect } from "@playwright/test";
-import jsonData from "../storage-states/wallet-connected.json";
-
-const originFilter = jsonData.origins[0];
-const localStorageData = originFilter.localStorage;
-
-async function setLocalStorage(page, data) {
- for (const item of data) {
- await page.evaluate(({ name, value }) => {
- localStorage.setItem(name, value);
- }, item);
- }
-}
-
-test.beforeEach(async ({ page }) => {
- await page.goto("http://localhost:8080");
- await page.goto("/buildhub.near/widget/components.Navbar");
-});
-
-test("To verify that the sign in button is visible in the home page and when clicked navigates to login page", async ({
- page,
-}) => {
- const signInButton = page.getByRole("button", { name: "Sign in" }).nth(1);
- await expect(signInButton).toBeVisible();
- await signInButton.click();
- await expect(page).toHaveURL("https://www.nearbuilders.org/join");
-});
-
-test("To verify that the user is logged in succesfully", async ({ page }) => {
- await setLocalStorage(page, localStorageData);
- await page.goto("/buildhub.near/widget/components.Navbar");
- const LoggedInButton = page.getByText("anybody.near").nth(1);
- await expect(LoggedInButton).toHaveText("anybody.near");
-});
diff --git a/playwright-tests/tests/userlogout.spec.js b/playwright-tests/tests/userlogout.spec.js
deleted file mode 100644
index ea75fa1e..00000000
--- a/playwright-tests/tests/userlogout.spec.js
+++ /dev/null
@@ -1,38 +0,0 @@
-import { test, expect } from "@playwright/test";
-import jsonData from "../storage-states/wallet-connected.json";
-
-const originFilter = jsonData.origins[0];
-const localStorageData = originFilter.localStorage;
-
-async function setLocalStorage(page, data) {
- for (const item of data) {
- await page.evaluate(({ name, value }) => {
- localStorage.setItem(name, value);
- }, item);
- }
-}
-
-test.beforeEach(async ({ page }) => {
- await page.goto("http://localhost:8080");
- await page.goto("/buildhub.near/widget/components.Navbar");
-});
-
-test("To verify that the sign out button is visible in the dropdown and when clicked navigates to logout page", async ({
- page,
-}) => {
- await setLocalStorage(page, localStorageData);
- await page.goto("/buildhub.near/widget/components.buttons.UserDropdown");
- const LoggedInButton = page.getByRole("button", { name: "anybody.near" });
- await expect(LoggedInButton).toHaveText("anybody.near");
- await LoggedInButton.click();
- const dropdownItems = await page.$$(".dropdown-item");
- const secondDropdownItem = dropdownItems[1];
- await secondDropdownItem.click();
- expect(page).toHaveURL("/logout");
-});
-
-test("To verify that the user is logged out succesfully", async ({ page }) => {
- await page.goto("/buildhub.near/widget/components.Navbar");
- const signInButton = page.getByRole("button", { name: "Sign in" }).nth(1);
- await expect(signInButton).toBeVisible();
-});
diff --git a/playwright-tests/util/constants.js b/playwright-tests/util/constants.js
index ecc9bb16..c9e97b25 100644
--- a/playwright-tests/util/constants.js
+++ b/playwright-tests/util/constants.js
@@ -1,3 +1,5 @@
/**
* constants
*/
+
+export const ROOT_SRC = "builddao.testnet/widget/Index";
diff --git a/playwright.config.js b/playwright.config.js
index 033e6117..aee6ac95 100644
--- a/playwright.config.js
+++ b/playwright.config.js
@@ -96,7 +96,7 @@ export default defineConfig({
/* Run your local dev server before starting the tests */
webServer: {
- command: "npm run dev",
+ command: "npm run dev:testnet",
port: 8080,
reuseExistingServer: !process.env.CI,
},