Skip to content

Commit 542c01e

Browse files
Merge pull request #275 from Rishab87/frontend-tests
added frontend tests
2 parents 8a86d15 + 1c99147 commit 542c01e

10 files changed

+108
-5
lines changed

README.md

+18
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,24 @@ You can control the number of workers by setting the `WORKERS` environment varia
264264
- For setting up the frontend, follow the instructions in the [Frontend Setup Guide](./docs/frontend/docker-setup.md).
265265
</br>
266266
- For setting up the backend, follow the instructions in the [Backend Setup Guide](./docs/backend/docker-setup.md).
267+
268+
### Testing
269+
#### Frontend
270+
```bash
271+
cd frontend
272+
npm test
273+
```
274+
#### Backend'
275+
- FastAPI
276+
```bash
277+
cd backend
278+
pytest
279+
```
280+
- Tauri
281+
```bash
282+
cd frontend/src-tauri/
283+
cargo test
284+
```
267285

268286
## Additional Resources
269287

frontend/babel.config.cjs

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
presets: [
3+
["@babel/preset-env", { targets: { node: "current" } }],
4+
"@babel/preset-typescript",
5+
["@babel/preset-react", { runtime: "automatic" }],
6+
],
7+
}

frontend/jest.config.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { Config } from '@jest/types';
2+
3+
const config: Config.InitialOptions = {
4+
preset: 'ts-jest',
5+
testEnvironment: 'jsdom',
6+
transform: {
7+
'^.+\\.(js|jsx|ts|tsx)$': 'babel-jest',
8+
},
9+
moduleNameMapper: {
10+
'^@/(.*)$': '<rootDir>/src/$1',
11+
'\\.(css|less|sass|scss)$': 'identity-obj-proxy',
12+
},
13+
transformIgnorePatterns: ['/node_modules/(?!(ldrs)/)'],
14+
setupFilesAfterEnv: ['<rootDir>/jest.setup.ts'],
15+
};
16+
17+
export default config;

frontend/jest.setup.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import '@testing-library/jest-dom';

frontend/package.json

+18-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"scripts": {
77
"dev": "vite",
88
"build": "tsc && vite build",
9+
"test": "jest",
10+
"test:watch": "jest --watch",
911
"preview": "vite preview",
1012
"tauri": "tauri",
1113
"setup:linux": "cd scripts && ./setup_env.sh",
@@ -40,22 +42,37 @@
4042
"react-image-crop": "^11.0.7",
4143
"react-router-dom": "^6.24.1",
4244
"tailwind-merge": "^2.3.0",
43-
"tailwindcss-animate": "^1.0.7"
45+
"tailwindcss-animate": "^1.0.7",
46+
"ts-node": "^10.9.2",
47+
"vite-plugin-environment": "^1.1.3"
4448
},
4549
"devDependencies": {
50+
"@babel/preset-env": "^7.26.7",
51+
"@babel/preset-react": "^7.26.3",
52+
"@babel/preset-typescript": "^7.26.0",
53+
"@jest/types": "^29.6.3",
4654
"@tauri-apps/cli": "^2.0.0-beta.21",
55+
"@testing-library/jest-dom": "^6.6.3",
56+
"@testing-library/react": "^16.2.0",
57+
"@testing-library/user-event": "^14.6.1",
58+
"@types/jest": "^29.5.14",
4759
"@types/node": "^20.17.16",
4860
"@types/react": "^18.2.15",
4961
"@types/react-dom": "^18.2.7",
5062
"@vitejs/plugin-react": "^4.2.1",
5163
"autoprefixer": "^10.4.20",
64+
"babel-jest": "^29.7.0",
5265
"eslint": "^8.57.1",
5366
"eslint-config-prettier": "^9.1.0",
5467
"eslint-config-react-app": "^7.0.1",
68+
"identity-obj-proxy": "^3.0.0",
69+
"jest": "^29.7.0",
70+
"jest-environment-jsdom": "^29.7.0",
5571
"postcss": "^8.4.49",
5672
"prettier": "^3.3.3",
5773
"prettier-plugin-tailwindcss": "^0.6.8",
5874
"tailwindcss": "^3.4.17",
75+
"ts-jest": "^29.2.5",
5976
"typescript": "5.1.x",
6077
"vite": "^5.0.0",
6178
"vite-plugin-eslint": "^1.8.1"

frontend/src/Config/Backend.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
export const BACKED_URL =
2-
import.meta.env.BACKEND_URL || 'http://localhost:8000';
2+
process.env.BACKEND_URL || 'http://localhost:8000';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { render } from '@testing-library/react';
2+
import AITagging from '../AITagging/AITaging';
3+
import Album from '../Album/Album';
4+
import Dashboard from '../Dashboard/Dashboard';
5+
import Memories from '../Memories/Memories';
6+
import SecureFolder from '../SecureFolderPage/SecureFolder';
7+
import Settings from '../SettingsPage/Settings';
8+
import { InitialPage } from '../Setupscreen/Setup';
9+
import Videos from '../VideosPage/Videos';
10+
import { ROUTES } from '@/constants/routes';
11+
import QueryClientProviders from '@/Config/QueryClientProvider';
12+
import { BrowserRouter } from 'react-router-dom';
13+
import { ThemeProvider } from '@/contexts/ThemeContext';
14+
15+
const pages = [
16+
{ path: ROUTES.LAYOUT.HOME, Component: Dashboard },
17+
{ path: ROUTES.LAYOUT.VIDEOS, Component: Videos },
18+
{ path: ROUTES.LAYOUT.SETTINGS, Component: Settings },
19+
{ path: ROUTES.LAYOUT.AI, Component: AITagging },
20+
{ path: ROUTES.LAYOUT.ALBUM, Component: Album },
21+
{ path: ROUTES.LAYOUT.SECURE_FOLDER, Component: SecureFolder },
22+
{ path: ROUTES.LAYOUT.MEMORIES, Component: Memories },
23+
{ path: ROUTES.INITIAL, Component: InitialPage },
24+
];
25+
26+
describe('Page rendering tests', () => {
27+
pages.forEach(({ path, Component }) => {
28+
test(`renders ${path} without crashing`, () => {
29+
render(
30+
<ThemeProvider>
31+
<QueryClientProviders>
32+
<BrowserRouter>
33+
<Component />
34+
</BrowserRouter>
35+
</QueryClientProviders>
36+
</ThemeProvider>,
37+
);
38+
});
39+
});
40+
});

frontend/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"lib": ["ES2020", "DOM", "DOM.Iterable"],
66
"module": "ESNext",
77
"skipLibCheck": true,
8+
"esModuleInterop": true,
89

910
/* Bundler mode */
1011
"moduleResolution": "bundler",
@@ -26,6 +27,6 @@
2627
"@/*": ["./src/*"]
2728
}
2829
},
29-
"include": ["src"],
30+
"include": ["src", "jest.setup.ts"],
3031
"references": [{ "path": "./tsconfig.node.json" }]
3132
}

frontend/vite.config.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import { defineConfig } from 'vite';
22
import react from '@vitejs/plugin-react';
33
import path from 'path';
44
import eslint from 'vite-plugin-eslint';
5+
import EnivromentPlugin from 'vite-plugin-environment';
56

67
// https://vitejs.dev/config/
78
export default defineConfig(async () => ({
8-
plugins: [react(), eslint()],
9+
plugins: [react(), eslint(), EnivromentPlugin('all')],
910

1011
resolve: {
1112
alias: {

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"lint:check": "cd frontend && eslint --max-warnings 0 --config .eslintrc.json .",
1111
"lint:fix": "cd frontend && eslint --max-warnings 0 --config .eslintrc.json . --fix",
1212
"format:fix": "cd frontend && prettier --write \"**/*.{ts,tsx,json}\"",
13-
"format:check": "cd frontend && prettier --check \"**/*.{ts,tsx,json}\""
13+
"format:check": "cd frontend && prettier --check \"**/*.{ts,tsx,json}\"",
14+
"cargo:check": "cd backend && cargo check"
1415
},
1516
"devDependencies": {
1617
"husky": "^9.1.7"

0 commit comments

Comments
 (0)