This is a refactored React application that demonstrates the fast-test approach with flat presentation, completely separating UI from business logic using the MVP/MVVM pattern with MobX for state management.
The application follows the fast-test approach with the following key principles:
- All business logic is moved to controllers and stores
- React components are pure presentation layers
- No calculations or complex logic in view components
- Model:
BooksStore(MobX store for state management) - View:
BooksView(Pure React components) - Controller/ViewModel:
BooksController(Presentation logic and form handling)
- State management with MobX observables
- Reactive UI updates with
mobx-react - Computed properties for derived state
src/
├── Books/
│ ├── Books.store.js # MobX store (business logic)
│ ├── Books.controller.js # Controller/ViewModel (presentation logic)
│ ├── Books.view.js # Pure React components (UI only)
│ ├── Books.repository.js # Data access layer
│ └── __tests__/ # Test files
├── Shared/
│ ├── ApiGateway.js # HTTP client
│ ├── config.js # Configuration
│ └── __tests__/ # Test files
├── index.js # Application entry point
├── styles.css # Styling
└── setupTests.js # Test configuration
- ✅ Display books list from API
- ✅ Add new books with form validation
- ✅ Loading states and error handling
- ✅ Real-time updates with MobX reactivity
- ✅ Comprehensive test coverage for all business logic
The application integrates with the provided API:
- Base URL:
https://tdd.demo.reaktivate.com/v1/books/[user] - Swagger:
https://tdd.demo.reaktivate.com/api-docs/
Note: The API uses SSL self-signed certificates. You may need to open any API endpoint in your browser first and "allow" the certificate.
- Node.js (version 14 or higher)
- npm or yarn
- Clone the repository
- Install dependencies:
npm install
npm startThe application will open at http://localhost:3000
npm testThis will run all tests in watch mode. Press a to run all tests or q to quit.
The application includes comprehensive tests covering:
- BooksStore: State management, API integration, error handling
- BooksController: Form validation, presentation logic
- BooksRepository: Data access layer, API calls
- ApiGateway: HTTP request handling
- BooksView: Component rendering, user interactions
- Form validation and submission
- Loading states and error display
src/
├── Books/__tests__/
│ ├── Books.store.test.js # Store business logic tests
│ ├── Books.controller.test.js # Controller logic tests
│ ├── Books.repository.test.js # Repository tests
│ └── Books.view.test.js # UI component tests
└── Shared/__tests__/
└── ApiGateway.test.js # HTTP client tests
- Business logic is completely separated from UI
- All logic can be tested without React components
- Fast unit tests without DOM rendering
- Clear separation of concerns
- Easy to modify business logic without touching UI
- Predictable data flow
- Controllers can be reused across different UI frameworks
- Business logic is framework-agnostic
- Easy to swap UI implementations
- MobX provides efficient reactivity
- Minimal re-renders with precise dependency tracking
- Computed properties for derived state
class BooksStore {
@observable books = [];
@observable isLoading = false;
@observable error = null;
@action loadBooks = async () => { /* ... */ };
@action addBook = async (name, author) => { /* ... */ };
@computed get booksCount() { return this.books.length; }
}class BooksController {
@observable newBookName = "";
@observable newBookAuthor = "";
@computed get isFormValid() {
return this.newBookName.trim() !== "" && this.newBookAuthor.trim() !== "";
}
@action handleAddBook = async () => { /* ... */ };
}const BooksView = observer(({ controller }) => (
<div>
{controller.books.map(book => <BookItem book={book} />)}
<AddBookForm controller={controller} />
</div>
));- Never put logic in JSX/TSX files
- Use controllers for presentation logic
- Use stores for business logic
- Keep views as pure as possible
- Test all business logic thoroughly
If you encounter SSL certificate errors:
- Open
https://tdd.demo.reaktivate.com/v1/books/postnikovin your browser - Accept the self-signed certificate
- Try the application again
- Ensure all dependencies are installed:
npm install - Clear Jest cache:
npm test -- --clearCache - Check that all mocks are properly configured
When contributing to this project:
- Follow the fast-test architecture principles
- Write tests for all new business logic
- Keep UI components pure and simple
- Use MobX for state management
- Maintain separation between logic and presentation