Commit dd46b3e
authored
Feature: Sandboxes Monitoring - 2 - Testing Infrastructure (#138)
- [ ] 1: API/State Layer #137
- [ ] 2: **THIS PR**
Builds upon the API/State Management layer to provide comprehensive test
coverage for all utility functions and data processing logic. Integrates
unit tests into the CI pipeline for early regression detection.
## Key Features
**Comprehensive Unit Test Coverage (104 tests)**
- **Chart utilities** (25 tests) - Data transformation, axis
calculations, tooltip formatting
- **Formatting functions** (47 tests) - Date/time/number formatting
across locales and formats
- **Sandboxes utilities** (17 tests) - Metrics processing and
transformation logic
- **Team metrics calculations** (15 tests) - Step calculations and
aggregation algorithms
**Development & Load Testing**
- `burst.test.ts` - Tests system behavior under sudden load spikes
- `traffic.test.ts` - Tests sustained traffic patterns and performance
- Configurable test scenarios for different usage patterns
**GitHub Actions CI Integration**
- Dedicated `unit-tests` job that runs before integration tests
- Minimal environment setup (no external services required)
- Fast feedback loop (~1 second execution time)
- Cost-efficient CI pipeline (integration tests only run if unit tests
pass)
**Test Infrastructure**
- Supporting UI components needed for testing (chart-utils, tooltips)
- Proper test isolation and mocking strategies
- Enhanced test documentation and examples
## Test Coverage Architecture
### CI Pipeline Flow
```mermaid
graph LR
subgraph "GitHub Actions"
Push[Push/PR] --> UnitTests["Unit Tests<br/>104 tests<br/>~1s execution"]
UnitTests --> |"✅ Pass"| IntegrationTests["Integration Tests<br/>~30s execution"]
UnitTests --> |"❌ Fail"| Stop[❌ Stop Pipeline]
IntegrationTests --> |"✅ Pass"| Success[✅ All Tests Pass]
IntegrationTests --> |"❌ Fail"| Fail[❌ Integration Failure]
end
subgraph "Test Categories"
UnitTests --> ChartUtils["Chart Utils (25)"]
UnitTests --> Formatting["Formatting (47)"]
UnitTests --> Sandboxes["Sandboxes (17)"]
UnitTests --> Metrics["Team Metrics (15)"]
end
style UnitTests fill:#e1f5fe
style IntegrationTests fill:#e8f5e9
style Success fill:#c8e6c9
style Fail fill:#ffcdd2
style Stop fill:#ffcdd2
```
### Test Coverage Map
```mermaid
graph TB
subgraph "Utility Functions Tested"
subgraph "Chart Utilities"
CalcAvg["calculateAverage()"]
CalcMedian["calculateMedian()"]
CalcCentralTendency["calculateCentralTendency()"]
CalcYAxis["calculateYAxisMax()"]
FillZeros["fillMetricsWithZeros()"]
TransformData["transformMetricsToLineData()"]
CreateSeries["createChartSeries()"]
end
subgraph "Formatting Functions"
FormatNumber["formatNumber()"]
FormatBytes["formatBytes()"]
FormatDuration["formatDuration()"]
FormatDate["formatChartTimestamp*()"]
FormatCompact["formatCompactNumber()"]
FormatDecimal["formatDecimal()"]
FormatPercentage["formatPercentage()"]
end
subgraph "Data Processing"
TransformMetrics["transformMetricsToClientMetrics()"]
CalcStep["calculateStepForDuration()"]
FillTeamMetrics["fillTeamMetricsWithZeros()"]
end
end
subgraph "Test Files"
ChartTests["chart-utils.test.ts<br/>25 tests"]
FormatTests["formatting.test.ts<br/>47 tests"]
SandboxTests["sandboxes.test.ts<br/>17 tests"]
MetricsTests["team-metrics-step.test.ts<br/>15 tests"]
end
ChartTests --> CalcAvg
ChartTests --> CalcMedian
ChartTests --> CalcCentralTendency
ChartTests --> CalcYAxis
ChartTests --> FillZeros
ChartTests --> TransformData
ChartTests --> CreateSeries
FormatTests --> FormatNumber
FormatTests --> FormatBytes
FormatTests --> FormatDuration
FormatTests --> FormatDate
FormatTests --> FormatCompact
FormatTests --> FormatDecimal
FormatTests --> FormatPercentage
SandboxTests --> TransformMetrics
SandboxTests --> CalcStep
MetricsTests --> FillTeamMetrics
style ChartTests fill:#e1f5fe
style FormatTests fill:#fff3e0
style SandboxTests fill:#e8f5e9
style MetricsTests fill:#f3e5f5
```
## Technical Implementation
**Test Architecture**
- Vitest as the test runner with TypeScript support
- Tests focus on pure functions and data transformations
- Mock data generation for consistent test scenarios
- Comprehensive edge case coverage (empty data, boundary conditions,
timezone handling)
**Key Test Files**
- `src/__test__/unit/chart-utils.test.ts` - Chart calculation logic
- `src/__test__/unit/formatting.test.ts` - All formatting utilities
- `src/__test__/unit/sandboxes.test.ts` - Data transformation functions
- `src/__test__/unit/team-metrics-step.test.ts` - Time interval
calculations
- `src/__test__/development/` - Load and performance testing
**CI Pipeline Enhancements**
- Unit tests run first for fast feedback
- Integration tests depend on unit test success
- Parallel test execution for optimal performance
- Clear separation of test types and responsibilities
---
*This PR provides comprehensive test coverage for the API/State
Management layer. All 104 unit tests pass and are integrated into CI.
The testing infrastructure validates that all utility functions work
correctly and provides confidence for further development. Requires PR1
(API layer) to be merged first.*1 parent fde3cd6 commit dd46b3e
File tree
14 files changed
+2438
-807
lines changed- .github/workflows
- src
- __test__
- development
- unit
- features/dashboard/sandboxes/monitoring
- ui/data
14 files changed
+2438
-807
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
10 | 31 | | |
11 | 32 | | |
12 | 33 | | |
| 34 | + | |
13 | 35 | | |
14 | 36 | | |
15 | 37 | | |
| |||
35 | 57 | | |
36 | 58 | | |
37 | 59 | | |
38 | | - | |
| 60 | + | |
39 | 61 | | |
40 | 62 | | |
41 | 63 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
| 15 | + | |
15 | 16 | | |
16 | | - | |
| 17 | + | |
17 | 18 | | |
18 | 19 | | |
19 | | - | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | | - | |
| 28 | + | |
28 | 29 | | |
29 | | - | |
30 | | - | |
| 30 | + | |
| 31 | + | |
31 | 32 | | |
32 | 33 | | |
33 | | - | |
| 34 | + | |
34 | 35 | | |
35 | 36 | | |
36 | 37 | | |
37 | | - | |
38 | | - | |
39 | | - | |
| 38 | + | |
40 | 39 | | |
41 | 40 | | |
42 | 41 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
4 | | - | |
5 | 3 | | |
6 | 4 | | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
7 | 41 | | |
8 | 42 | | |
9 | 43 | | |
| |||
18 | 52 | | |
19 | 53 | | |
20 | 54 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | 55 | | |
26 | 56 | | |
27 | 57 | | |
| |||
42 | 72 | | |
43 | 73 | | |
44 | 74 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | 75 | | |
49 | 76 | | |
50 | 77 | | |
| |||
60 | 87 | | |
61 | 88 | | |
62 | 89 | | |
63 | | - | |
| 90 | + | |
64 | 91 | | |
65 | 92 | | |
66 | 93 | | |
67 | 94 | | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
68 | 106 | | |
69 | 107 | | |
70 | 108 | | |
| |||
77 | 115 | | |
78 | 116 | | |
79 | 117 | | |
80 | | - | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
81 | 122 | | |
82 | 123 | | |
83 | 124 | | |
| |||
121 | 162 | | |
122 | 163 | | |
123 | 164 | | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
129 | 173 | | |
0 commit comments