Angular-based project for testing different scenarios of SITNA API usage, including safe monkey patching techniques.
- Node.js (v18 or higher)
- npm or yarn
npm installnpm startRuns the app at http://localhost:4200/
Parcel:
npm run serve:parcelVite:
npm run serve:viteHTTP Server (after build):
npm run build
npm run serve:httpnpm test
npm run test:watch
npm run test:coveragenpm run e2esrc/app/services/- Angular services for SITNA configurationsrc/app/components/- Base components (SitnaMap, ScenarioSelector)src/app/scenarios/- Scenario components demonstrating different testing patternssrc/app/utils/- Monkey patching and sandboxing utilitiessrc/types/- TypeScript type definitionssrc/environments/- Configuration filessrc/assets/config/- Custom SITNA configuration files (e.g., predefined-layers.json)tests/scenarios/- Jest test files
Each scenario is an Angular component accessible via routing:
- Basic Map Initialization - Standard SITNA map initialization without patching
The project uses the npm package version of API SITNA from node_modules/api-sitna:
- Package: Installed via
npm install api-sitna(seepackage.json) - Import: The library is imported in
src/main.tsusingimport('api-sitna') - Base URL: Set to
/js/api-sitna/inmain.tsandwebpack.config.js - Webpack: Automatically copies required SITNA assets (css, layout, lib, resources, wmts) from
node_modules/api-sitnatodist/js/api-sitna/during build - Configuration: All config files reference local paths (e.g.,
js/api-sitna/layout/responsive)
SITNA configuration is loaded from src/environments/sitna-config.json via SitnaConfigLoaderService.
Two patching strategies are available:
- Manual Patching (
src/app/utils/monkey-patch.ts) - Direct function/property patching - Meld Patching (
src/app/utils/sitna-meld-patch.ts) - Using meld library for AOP-style patching
Scenario-Based Testing: The application uses a scenario registry pattern where each test case is an independent Angular component with its own configuration and behavior.
Service Layer: Core functionality is organized into focused services:
SitnaConfigService- Map configuration managementMapLifecycleService- Map initialization with reactive state (signals)LoggingService- Application-wide logging with test environment detectionErrorHandlingService- Centralized error handling
Type Safety: Comprehensive TypeScript definitions for SITNA API in src/types/api-sitna/ provide type-safe development experience.
Monkey Patching Utilities: Reusable utilities with automatic cleanup/restore mechanisms to safely modify SITNA behavior for testing without side effects.
Why Monkey Patching? The sandbox uses monkey patching to test SITNA API behavior without modifying the library source code. This approach allows:
- Testing different API scenarios safely
- Debugging API calls and responses
- Backporting functionality from newer SITNA versions
- Intercepting and logging internal behavior
Meld vs Manual Patching:
- Meld (AOP library) provides cleaner syntax and automatic method wrapping
- Manual patching offers more control for edge cases and property patching
- Both support automatic restoration to prevent test pollution
Scenario Registry: Dynamic route generation from scenario metadata enables:
- Easy addition of new test scenarios
- Metadata-driven UI (tags, descriptions)
- Consistent scenario structure
AppComponent
├── ScenarioSelectorComponent (home page)
└── Scenario Components (lazy-loaded via routes)
├── BasicMapInitializationComponent
├── ProxificationLoggingComponent
└── ProjectionDataBackportComponent
npm run buildOutputs to dist/sitna-sandbox/ directory.
- Angular Builder: Uses custom webpack builder (
@angular-builders/custom-webpack) - Asset Copying: Webpack copies SITNA assets from
node_modules/api-sitnatodist/js/api-sitna/ - Hash Routing: Uses hash-based routing (
/#/route) to prevent conflicts with static asset serving - Output Path:
dist/sitna-sandbox/
Static Hosting (Recommended): Deploy the dist/sitna-sandbox/ folder to any static file server:
# Using http-server
npm run serve:http
# Using nginx (example config)
server {
listen 80;
server_name sitna-sandbox.example.com;
root /path/to/dist/sitna-sandbox;
index index.html;
location / {
try_files $uri $uri/ /index.html;
}
}Docker: Example Dockerfile:
FROM nginx:alpine
COPY dist/sitna-sandbox /usr/share/nginx/html
EXPOSE 80Configuration files in src/environments/:
sitna-config-default.json- Default SITNA map optionssitna-config-example.json- Example configuration template
Scenario-specific configs in each scenario folder (e.g., scenarios/basic-map-initialization/sitna-config.json).
- Modern browsers (Chrome, Firefox, Safari, Edge)
- ES2020 target
- No IE11 support (SITNA API requirement)