Skip to content

Commit 0b7e952

Browse files
Merge pull request #13 from shadil-rayyan/refactor-e2e-tests
refactor codebase and add initial E2E/unit test setup
2 parents c460cca + 4059bc9 commit 0b7e952

27 files changed

+8620
-2879
lines changed

doc/DeveloperGuide.md

Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
2+
3+
### **`doc/DeveloperGuide.md`**
4+
5+
```markdown
6+
# DevSetup Developer Guide
7+
8+
Welcome to **DevSetup**! This document provides an in-depth guide for developers, covering architecture, folder structure, testing, CI/CD, and best practices to maintain a high-quality, scalable project.
9+
10+
---
11+
12+
## 1. Project Overview
13+
14+
**DevSetup** is a developer tool script generator for multiple operating systems. It allows users to:
15+
16+
- Select OS (Windows, macOS, Linux)
17+
- Choose package manager
18+
- Select development tools
19+
- Generate installation scripts
20+
- Copy or download the script
21+
22+
The app is built with **React 19 + TypeScript**, following **industry-level clean architecture principles**, making it maintainable, testable, and scalable.
23+
24+
---
25+
26+
## 2. Folder Structure
27+
28+
```
29+
30+
src/
31+
├── components/
32+
│ ├── ScriptGenerator/
33+
│ │ ├── ScriptGenerator.tsx
34+
│ │ ├── Header.tsx
35+
│ │ ├── SearchBox.tsx
36+
│ │ ├── OSSelector.tsx
37+
│ │ ├── PackageManagerSelector.tsx
38+
│ │ ├── ToolGrid.tsx
39+
│ │ ├── ToolCard.tsx
40+
│ │ ├── ScriptOutput.tsx
41+
│ │ └── ActionButtons.tsx
42+
│ └── common/ # Shared buttons, layout, icons
43+
44+
├── hooks/
45+
│ ├── useTheme.ts # Theme toggle logic
46+
│ ├── useToolsData.ts # Fetch and manage tool JSON data
47+
│ └── useScriptGenerator.ts # Script generation logic
48+
49+
├── lib/
50+
│ ├── types.ts # TypeScript types for tools and OS
51+
│ ├── constants.ts # App-wide constants
52+
│ └── script.ts # Utility functions for script generation
53+
54+
├── data/
55+
│ └── tools.json # Tool definitions
56+
57+
├── pages/
58+
│ └── index.tsx # Entry page
59+
60+
└── tests/
61+
├── lib/
62+
│ └── script.test.ts
63+
├── hooks/
64+
│ ├── useScriptGenerator.test.ts
65+
│ └── useTheme.test.ts
66+
└── components/
67+
└── ScriptGenerator.test.tsx
68+
69+
````
70+
71+
---
72+
73+
## 3. Architecture Overview
74+
75+
- **Components**: Presentational components only. Each component focuses on **one responsibility**.
76+
- **Hooks**: Handle state and logic. Components call hooks but don't manage state directly.
77+
- **Lib**: Utilities, constants, and TypeScript types.
78+
- **Data**: JSON files defining all tools and categories.
79+
- **Pages**: Next.js page(s) entry point.
80+
81+
**Design Principles**:
82+
83+
1. **Single Responsibility**: Each file/component does one thing.
84+
2. **Separation of Concerns**: UI vs Logic vs Data.
85+
3. **Reusability**: Common components in `components/common/`.
86+
4. **Testability**: All logic is isolated for unit and integration tests.
87+
88+
---
89+
90+
## 4. Testing Strategy
91+
92+
### **Unit Tests**
93+
- Test all hooks, components, and utilities individually.
94+
- Tools:
95+
- `Jest` for assertions
96+
- `React Testing Library` for component rendering
97+
- `jest-axe` for accessibility checks
98+
99+
**Example**:
100+
```ts
101+
import { render } from '@testing-library/react';
102+
import { axe } from 'jest-axe';
103+
import ScriptGenerator from '../ScriptGenerator';
104+
105+
test('should have no accessibility violations', async () => {
106+
const { container } = render(<ScriptGenerator />);
107+
const results = await axe(container);
108+
expect(results).toHaveNoViolations();
109+
});
110+
````
111+
112+
---
113+
114+
### **Integration Tests**
115+
116+
* Test multiple components interacting together.
117+
* Verify flows like:
118+
119+
* OS → Package → Tool selection → Script output
120+
* Theme toggling
121+
* Search filtering
122+
123+
---
124+
125+
### **End-to-End Tests (E2E)**
126+
127+
* Tools: `Playwright`
128+
* Test full user flows in real browsers:
129+
130+
* Select OS, package, and tools
131+
* Copy / download script
132+
* Mobile responsiveness
133+
* Accessibility snapshot
134+
135+
---
136+
137+
### **Performance & SEO**
138+
139+
* Run **Lighthouse** in CI or locally:
140+
141+
* Performance (FCP, LCP, CLS)
142+
* Accessibility
143+
* Best Practices
144+
* SEO
145+
* Ensure scripts are generated quickly, DOM updates efficiently, and components render optimally.
146+
147+
---
148+
149+
### **Security**
150+
151+
* Run `npm audit` or
152+
* periodically
153+
* Keep dependencies updated
154+
* Avoid unsafe operations (`innerHTML`, eval)
155+
156+
---
157+
158+
## 5. CI/CD Workflow
159+
160+
1. **GitHub Actions** triggers on PR and push to main.
161+
2. Runs:
162+
163+
* ESLint & Prettier
164+
* TypeScript compilation
165+
* Unit & integration tests
166+
* Accessibility tests (`jest-axe` / Playwright snapshot)
167+
* Lighthouse audits (performance + SEO)
168+
3. Deploy previews via **Vercel / Netlify**
169+
4. Merge → production deploy
170+
171+
---
172+
173+
## 6. Contribution Guidelines
174+
175+
* **Branching**: Use feature branches: `feature/<name>` or `bugfix/<name>`
176+
* **Commit messages**: Conventional commits
177+
* **Pull requests**: Include tests + screenshots if UI changes
178+
* **Code review**: Ensure accessibility, performance, and type safety
179+
180+
---
181+
182+
## 7. Best Practices
183+
184+
* Keep components small & reusable
185+
* Use TypeScript types everywhere
186+
* Isolate hooks for testability
187+
* Ensure proper contrast and ARIA attributes
188+
* Write meaningful test cases
189+
* Monitor performance & accessibility in CI
190+
191+
---
192+
193+
## 8. Setup Instructions
194+
195+
1. Install dependencies:
196+
197+
```bash
198+
npm install
199+
```
200+
201+
2. Run dev server:
202+
203+
```bash
204+
npm run dev
205+
```
206+
207+
3. Run tests:
208+
209+
```bash
210+
npm run test
211+
```
212+
213+
4. Run accessibility audits:
214+
215+
```bash
216+
npm run test:a11y
217+
```
218+
219+
5. Run Lighthouse performance/SEO:
220+
221+
```bash
222+
npm run audit
223+
```
224+
225+
---
226+
227+
> This guide ensures the project is maintainable, scalable, testable, and up to top-tier industry standards.
228+
229+
```
230+

e2e/scriptGenerator.spec.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// import { test, expect } from '@playwright/test';
2+
3+
// test('user can select OS and generate script', async ({ page }) => {
4+
// await page.goto('http://localhost:3000');
5+
6+
// await page.click('text=LINUX');
7+
// await page.click('text=apt');
8+
9+
// await page.check('input[type="checkbox"]'); // select first tool
10+
// const script = await page.locator('textarea').inputValue();
11+
// expect(script).toContain('sudo apt install');
12+
// });

0 commit comments

Comments
 (0)