@@ -113,6 +113,7 @@ make lint-frontend
113113make lint-backend
114114make test-translations
115115make test-backend
116+ make test-frontend
116117# future slash command for test execution
117118```
118119
@@ -121,6 +122,101 @@ make test-backend
121122- ** Testing** : All linting and tests must pass
122123- ** Translations** : Ensure i18next keys are properly added
123124
125+ ### Unit Testing
126+
127+ #### Overview
128+ The Monitoring Plugin uses a dual testing approach for unit tests:
129+ - ** Frontend Unit Tests** : Jest + TypeScript for React components and utilities
130+ - ** Backend Unit Tests** : Go's built-in testing framework for server functionality
131+
132+ Unit tests focus on isolated function testing and run quickly in CI/CD pipelines, while E2E tests (Cypress) validate full user workflows.
133+
134+ #### Test File Structure
135+
136+ ** Frontend Tests:**
137+ - ** Location** : Co-located with source files in ` web/src/ `
138+ - ** Naming** : ` *.spec.ts ` (e.g., ` format.spec.ts ` , ` utils.spec.ts ` )
139+ - ** Framework** : Jest 30.2.0 with ts-jest
140+ - ** Configuration** : ` web/jest.config.js `
141+
142+ ** Backend Tests:**
143+ - ** Location** : Co-located with source files in ` pkg/ `
144+ - ** Naming** : ` *_test.go ` (e.g., ` server_test.go ` )
145+ - ** Framework** : Go testing package + testify/require
146+ - ** Configuration** : Standard Go test conventions
147+
148+ #### Running Unit Tests
149+
150+ ``` bash
151+ # Run all tests (backend + frontend)
152+ make test-backend
153+ make test-frontend
154+
155+ # Run individually from web directory
156+ cd web && npm run test:unit
157+
158+ # Run Go tests directly
159+ go test ./pkg/... -v
160+ ```
161+
162+ #### When to Create Unit Tests
163+
164+ Create unit tests when:
165+ 1 . ** Adding utility functions** : Pure functions, formatters, data transformations
166+ 2 . ** Adding business logic** : Data processing, calculations, validations
167+ 3 . ** Fixing bugs** : Regression tests to prevent bug recurrence
168+ 4 . ** Adding API handlers** : Backend endpoint logic (Go tests)
169+
170+ #### Key Testing Libraries
171+
172+ ** Frontend:**
173+ - ` jest ` (v30.2.0) - Test runner and assertions
174+ - ` ts-jest ` (v29.4.4) - TypeScript support
175+ - ` @types/jest ` - TypeScript definitions
176+
177+ ** Backend:**
178+ - ` testing ` (stdlib) - Go testing framework
179+ - ` github.com/stretchr/testify ` (v1.9.0) - Assertions and test utilities
180+
181+ #### Frontend Unit Testing Structure
182+
183+ ** Testing Framework & Configuration**
184+ Test Framework: Jest + ts-jest
185+ Configuration File: web/jest.config.js
186+
187+ ** Test File Location & Naming Convention**
188+ Pattern: * .spec.ts files co-located with source code
189+
190+ ** Test Coverage Areas**
191+ - Edge cases (null, undefined, empty values)
192+ - Normal behavior and expected outputs
193+ - Boundary conditions
194+ - Complex scenarios and integration
195+ - Data transformations and formatting
196+
197+ #### Backend Unit Testing Structure
198+
199+ ** Testing Framework & Configuration**
200+ Test Framework: Go's built-in testing package
201+ Assertion Library: github.com/stretchr/testify v1.9.0
202+
203+ ** Test File Location & Naming Convention**
204+ Pattern: * _ test.go files in the same directory as source code
205+
206+ ** Test Helper Functions**
207+ - ` startTestServer() ` - Starts server for testing
208+ - ` prepareServerAssets() ` - Sets up test environment
209+ - ` generateCertificate() ` - Creates TLS certificates for tests
210+ - ` checkHTTPReady() ` - Waits for server to be ready
211+ - ` getRequestResults() ` - Makes HTTP requests
212+
213+ ** Test Coverage Areas**
214+ - HTTP server functionality
215+ - HTTPS/TLS configuration
216+ - Certificate handling
217+ - Security settings (TLS versions, cipher suites)
218+ - Endpoint availability
219+
124220### Cypress E2E Testing
125221
126222#### Overview
0 commit comments