|
| 1 | +# ObjectStack Testing Strategy |
| 2 | + |
| 3 | +This document outlines the testing strategy designed to ensure the reliability and spec-compliance of the ObjectStack UI ecosystem. The goal is to enable **AI-Driven Development** where the test suite acts as a strict guardrail and feedback loop. |
| 4 | + |
| 5 | +## 1. Philosophy: Validating the "Protocol" |
| 6 | + |
| 7 | +ObjectUI is a **renderer**. Its primary job is to faithfully translate a JSON Protocol (`@objectstack/spec`) into a UI. Therefore, our tests must be structured around verifying this translation Contract. |
| 8 | + |
| 9 | +### The "AI Feedback Loop" Principle |
| 10 | +Tests should be descriptive enough that an AI Agent reading a failure message can understand: |
| 11 | +1. Which part of the Spec failed. |
| 12 | +2. What the JSON input was. |
| 13 | +3. What the expected DOM output was. |
| 14 | + |
| 15 | +## 2. Test Layers |
| 16 | + |
| 17 | +### A. Spec Compliance Tests (The Contract) |
| 18 | +* **Location**: `apps/console/src/__tests__/SpecCompliance.test.tsx` (and similar in packages) |
| 19 | +* **Purpose**: To verify that **every** field type and layout definition in the Spec renders correctly in the reference app (Console). |
| 20 | +* **Methodology**: |
| 21 | + * Iterate over the "Kitchen Sink" schema (which contains one of everything). |
| 22 | + * Render the component. |
| 23 | + * Assert semantic HTML attributes (e.g., `input[type="password"]` for `type: "password"`). |
| 24 | + * **Crucial**: These tests ensure that adding a new feature to the spec doesn't break existing renderers. |
| 25 | + |
| 26 | +### B. Component Unit Tests (The Atoms) |
| 27 | +* **Location**: `packages/components/src/__tests__` |
| 28 | +* **Purpose**: Test individual UI primitives (e.g., `Text`, `Badge`, `Card`) in isolation. |
| 29 | +* **Methodology**: |
| 30 | + * Test `className` merging (Tailwind). |
| 31 | + * Test property mapping (JSON props -> React props). |
| 32 | + * Test event handling. |
| 33 | + |
| 34 | +### C. Logic/kernel Tests (The Brain) |
| 35 | +* **Location**: `packages/core`, `packages/react` |
| 36 | +* **Purpose**: Test the non-visual logic. |
| 37 | +* **Methodology**: |
| 38 | + * Expression evaluation (`visible: "${data.age > 18}"`). |
| 39 | + * Data context scoping. |
| 40 | + * Action dispatching. |
| 41 | + |
| 42 | +## 3. The "Kitchen Sink" as the Gold Standard |
| 43 | +The `examples/kitchen-sink` package is not just a demo; it is the **Conformance Suite**. |
| 44 | +* **Rule**: If a feature exists in ObjectStack, it MUST be represented in the Kitchen Sink. |
| 45 | +* **CI**: The Console tests import the Kitchen Sink schema and run assertions against it. |
| 46 | + |
| 47 | +## 4. Implementation Guide (For Developers & AI) |
| 48 | + |
| 49 | +When implementing a new feature: |
| 50 | + |
| 51 | +1. **Update the Spec**: Add the type to `@object-ui/types` or `@objectstack/spec`. |
| 52 | +2. **Update the Kitchen Sink**: Add an example usage in `examples/kitchen-sink`. |
| 53 | +3. **Run Compliance Tests**: `pnpm test` in `apps/console`. It should fail (missing renderer). |
| 54 | +4. **Implement Renderer**: Add the code in `@object-ui/components`. |
| 55 | +5. **Pass Tests**: Compliance tests pass when the new element is rendered correctly. |
| 56 | + |
| 57 | +## 5. Directory Structure for Tests |
| 58 | + |
| 59 | +``` |
| 60 | +apps/console/src/__tests__/ |
| 61 | +├── SpecCompliance.test.tsx # <-- The "Grand Unified Test" using Kitchen Sink |
| 62 | +├── AppStructure.test.tsx # Tests routing and shell |
| 63 | +└── ... |
| 64 | +
|
| 65 | +packages/components/src/__tests__/ |
| 66 | +├── atoms/ # Button, Badge, etc. |
| 67 | +├── fields/ # Input, Select, etc. |
| 68 | +└── ... |
| 69 | +``` |
0 commit comments