Skip to content

Commit

Permalink
Fixes authentication tests (#381)
Browse files Browse the repository at this point in the history
* remove Dummy

* cleans up auth tests

* fmt
  • Loading branch information
elliotBraem authored Jun 12, 2024
1 parent 297fec3 commit a456139
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 75 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ yarn-error.log*
target
neardev
data.json
/test-results
2 changes: 0 additions & 2 deletions apps/new/widget/Dummy.jsx

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
48 changes: 48 additions & 0 deletions playwright-tests/tests/auth.spec.js
Original file line number Diff line number Diff line change
@@ -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");
});
});
34 changes: 0 additions & 34 deletions playwright-tests/tests/userlogin.spec.js

This file was deleted.

38 changes: 0 additions & 38 deletions playwright-tests/tests/userlogout.spec.js

This file was deleted.

2 changes: 2 additions & 0 deletions playwright-tests/util/constants.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/**
* constants
*/

export const ROOT_SRC = "builddao.testnet/widget/Index";
2 changes: 1 addition & 1 deletion playwright.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit a456139

Please sign in to comment.