Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added web e2e tests and CI integration #3

Merged
merged 6 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: CI

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

services:
postgres:
image: postgres

env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
POSTGRES_DB: mynance

options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432

steps:
- name: checkout branch
uses: actions/checkout@v3

- name: Install dependecies
run: yarn

- name: Install playwright driver
run: yarn playwright install chromium

- name: Create db
env:
SERVER_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/mynance
run: yarn db-push

- name: Run CI
env:
SERVER_DATABASE_URL: postgresql://postgres:postgres@localhost:5432/mynance
run: yarn ci
1 change: 0 additions & 1 deletion apps/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"lint": "eslint .",
"start": "react-native start",
"test": "jest",
"test:watch": "jest --watch",
"dev": "yarn ios"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/screens/Home/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const HomeScreen = () => {
const navigation = useNavigation<StackNavigationProp<RootStackParamList>>();

if (isLoading) {
return <ActivityIndicator testID='loading'/>;
return <ActivityIndicator testID="loading" />;
}

if (isError) {
Expand Down
3 changes: 3 additions & 0 deletions apps/web/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
1 change: 1 addition & 0 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@types/react-dom": "^18.2.4",
"babel-plugin-react-native-web": "^0.18.4",
"eslint": "^8.19.0",
"eslint-config-next": "13.5.2",
"tsconfig": "*",
"typescript": "^4.7.4"
}
Expand Down
2 changes: 1 addition & 1 deletion apps/web/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default function User({ users }) {
}}
>
<h1>
Seems you haven't started yet, please add your information below
{"Seems you haven't started yet, please add your information below"}
</h1>
<InformationForm refreshData={refreshData} />
</div>
Expand Down
8 changes: 4 additions & 4 deletions apps/web/pages/user/[id].tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { useRouter } from "next/router";
import axios from "axios";
import { useEffect, useState } from "react";
import { useCallback, useEffect, useState } from "react";
import { UserDetail } from "@mynance/shared-ui";

export default function User() {
const router = useRouter();
const { id } = router.query;
const [user, setUser] = useState(null);

const refreshData = async () => {
const refreshData = useCallback(async () => {
try {
const URL = `http://localhost:8000/users/${id}`;
const response = await axios.get(URL);
Expand All @@ -17,7 +17,7 @@ export default function User() {
} catch (error) {
console.error("Error fetching user data:", error);
}
};
}, [id]);

useEffect(() => {
// Fetch user data when the component mounts
Expand All @@ -28,7 +28,7 @@ export default function User() {
if (id) {
fetchUser();
}
}, [id]);
}, [id, refreshData]);

if (!user) {
return <p>Loading...</p>;
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@
"dev": "dotenv -- turbo dev",
"build": "dotenv -- turbo build",
"test": "dotenv -- turbo test",
"test:watch": "dotenv -- turbo test:watch",
"dev:test": "dotenv -- turbo dev:test",
"e2e:test": "dotenv -- turbo e2e:test",
"lint": "turbo lint",
"ci": "turbo run build lint e2e:test test",
"clean": "turbo clean && rm -rf node_modules",
"format": "prettier --write \"**/*.{ts,tsx,js,jsx,json,md}\" --ignore-path .gitignore",
"postinstall": "prisma generate && yarn pod-install",
"pod-install": "cd apps/mobile && npx pod-install && cd ../../"
"pod-install": "cd apps/mobile && npx pod-install && cd ../../",
"db-push": "cd apps/server && npx prisma db push"
},
"devDependencies": {
"dotenv-cli": "^7.3.0",
Expand Down
18 changes: 18 additions & 0 deletions packages/web-e2e-tests/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "web-e2e-tests",
"version": "0.0.1",
"private": true,
"scripts": {
"dev:test": "playwright test",
"start:api": "cd ../../apps/server && yarn start",
"start:server": "cd ../../apps/web && yarn start",
"e2e:test": "start-test start:api 8000 start:server 3000 \"playwright test\""
},
"dependencies": {
"start-server-and-test": "^2.0.1",
"web": "*"
},
"devDependencies": {
"@playwright/test": "^1.38.1"
}
}
6 changes: 6 additions & 0 deletions packages/web-e2e-tests/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from "@playwright/test";

export default defineConfig({
testDir: "tests",
fullyParallel: true,
});
33 changes: 33 additions & 0 deletions packages/web-e2e-tests/tests/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { test, expect } from "@playwright/test";

test("simple test", async ({ page }) => {
await page.goto("http://localhost:3000/");
const deleteUser = page.getByText("Delete user");
if (await deleteUser.isVisible()) {
await deleteUser.click();
}
await page.getByPlaceholder("Name").click();
await page.getByPlaceholder("Name").fill("Test user");
await page.getByPlaceholder("Name").press("Tab");
await page.getByPlaceholder("Current account balance").fill("2000");
await page.getByText("Register information").click();
await page.getByText("NAME: Test user").click();
await page.getByText("BALANCE: 2000€").click();
await page.getByText("Check user").click();
await page.getByRole("button", { name: "Add Movement" }).click();
await page.getByPlaceholder("Description").click();
await page.getByPlaceholder("Description").fill("Movement");
await page.getByPlaceholder("Amount").click();
await page.getByPlaceholder("Amount").fill("500");
await page.getByRole("button", { name: "Add", exact: true }).click();
await page.getByRole("button", { name: "Add Expense" }).click();
await page.getByPlaceholder("Name").click();
await page.getByPlaceholder("Name").fill("Expenses");
await page.getByPlaceholder("Description").click();
await page.getByPlaceholder("Description").fill("expense");
await page.getByPlaceholder("Amount").click();
await page.getByPlaceholder("Amount").fill("200");
await page.getByRole("button", { name: "Add", exact: true }).click();
await page.getByText("2500€").click();
await page.getByText("200€").click();
});
8 changes: 8 additions & 0 deletions packages/web-e2e-tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "tsconfig/base",
"include": ["."],
"exclude": ["dist", "build", "node_modules"],
"compilerOptions": {
"strict": true
}
}
24 changes: 14 additions & 10 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@
"start": {
"dependsOn": ["build"]
},
"test": {
"dependsOn": ["^build"]
},
"e2e:test": {
"dependsOn": ["^build"]
},
"lint": {},
"dev": {
"cache": false,
"persistent": true,
"dotEnv": [".env.production.local", ".env.local", ".env.production", ".env"]
"dotEnv": [
".env.production.local",
".env.local",
".env.production",
".env"
]
},
"dev:server": {
"cache": false,
"persistent": true
},
"test": {
"cache": false
},
"lint": {},
"clean": {
"dev:test": {
"cache": false
}
}
Expand Down
Loading