diff --git a/apps/web/__e2e__/user.test.js b/apps/web/__e2e__/user.test.js new file mode 100644 index 000000000..eaf9a21a6 --- /dev/null +++ b/apps/web/__e2e__/user.test.js @@ -0,0 +1,37 @@ +const { Page, test, expect } = require("@playwright/test"); +const { getTestId } = require("./utils"); +const { isAbsent } = require("./utils/conditions"); +const dotenv = require("dotenv"); +const path = require("path"); + +dotenv.config({ path: path.join(__dirname, ".env.local") }); + +/** + * @type {Page} + */ +var page = null; +global.page = null; +test.beforeEach(async ({ page: _page }) => { + global.page = _page; + page = _page; + await page.goto("http://localhost:3000/"); +}); + +const USER = { + email: process.env.USER_EMAIL, + password: process.env.USER_PASSWORD, +}; + +test("login user", async () => { + await page.click(getTestId("navitem-login")); + + await page.fill(getTestId("email"), USER.email); + + await page.fill(getTestId("password"), USER.password); + + await page.click(getTestId("submitButton")); + + await page.waitForNavigation(); + + expect(await isAbsent(getTestId("navitem-login"))).toBe(true); +}); diff --git a/apps/web/package.json b/apps/web/package.json index a4dd2daf9..434c45770 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -57,6 +57,7 @@ "@types/quill": "^2.0.5", "babel-eslint": "^10.1.0", "chalk": "^4.1.0", + "dotenv": "^10.0.0", "env-cmd": "^10.1.0", "eslint": "^7.20.0", "eslint-config-react-app": "^6.0.0", diff --git a/apps/web/src/common/db.js b/apps/web/src/common/db.js index eb5d71e98..bd3ae44ad 100644 --- a/apps/web/src/common/db.js +++ b/apps/web/src/common/db.js @@ -4,6 +4,7 @@ import Config from "../utils/config"; import http from "notes-core/utils/http"; import { EV, EVENTS } from "notes-core/common"; import { getCurrentHash, hashNavigate } from "../navigation"; +import { isTesting } from "../utils/platform"; /** * @type {import("notes-core/api").default} @@ -12,27 +13,29 @@ var db; async function initializeDatabase() { const { default: Database } = await import("notes-core/api"); db = new Database(StorageInterface, EventSource); - // db.host({ - // API_HOST: "https://api.notesnook.com", - // AUTH_HOST: "https://auth.streetwriters.co", - // SSE_HOST: "https://events.streetwriters.co", - // }); // db.host({ // API_HOST: "http://localhost:5264", // AUTH_HOST: "http://localhost:8264", // SSE_HOST: "http://localhost:7264", // }); - - db.host({ - API_HOST: "http://192.168.10.23:5264", - AUTH_HOST: "http://192.168.10.23:8264", - SSE_HOST: "http://192.168.10.23:7264", - }); + if (isTesting()) { + db.host({ + API_HOST: "https://api.notesnook.com", + AUTH_HOST: "https://auth.streetwriters.co", + SSE_HOST: "https://events.streetwriters.co", + }); + } else { + db.host({ + API_HOST: "http://192.168.10.23:5264", + AUTH_HOST: "http://192.168.10.23:8264", + SSE_HOST: "http://192.168.10.23:7264", + }); + } await db.init(); - if (!isAppHydrated() && !process.env.REACT_APP_CI) { + if (!isAppHydrated() && !isTesting()) { try { loadDefaultNotes(db); } catch (e) {} diff --git a/apps/web/src/index.js b/apps/web/src/index.js index 76a72d3da..6311fc8a0 100644 --- a/apps/web/src/index.js +++ b/apps/web/src/index.js @@ -6,6 +6,7 @@ import * as serviceWorker from "./serviceWorkerRegistration"; import "./utils/overrides"; import { loadTrackerScript } from "./utils/analytics"; import Config from "./utils/config"; +import { isTesting } from "./utils/platform"; if (process.env.NODE_ENV === "production") { loadTrackerScript(); @@ -19,7 +20,7 @@ async function checkRedirects(db) { if (window.location.pathname === "/") { const skipInitiation = Config.get("skipInitiation", false); const homepage = Config.get("homepage", 0); - if (!process.env.REACT_APP_CI && !isLoggedIn && !skipInitiation) + if (!isTesting() && !isLoggedIn && !skipInitiation) window.location.replace("/signup"); else if (homepage) { const route = HOMEPAGE_ROUTE[homepage]; diff --git a/apps/web/src/views/auth.js b/apps/web/src/views/auth.js index 1e8d60121..05a3158aa 100644 --- a/apps/web/src/views/auth.js +++ b/apps/web/src/views/auth.js @@ -303,6 +303,7 @@ function Auth(props) { styles={{ container: { mt: 50 }, }} + data-test-id="email" id="email" required name="email" @@ -315,6 +316,7 @@ function Auth(props) { styles={{ container: { mt: 2 }, }} + data-test-id="password" id="password" required name="password" @@ -336,6 +338,7 @@ function Auth(props) { )}