- Add HasFactory trait to all model classes for factory support - Create factory classes for all models (Classification, Company, ContentRecap, Department, IssueManagement, Journalist, Location, MediaMonitoring, MediaMonitoringTheme, PartnerMedia, SubClassification, SubLocation, Theme, User) - Add unit tests for all models with relationship and attribute validation - Add unit tests for all enums (Channel, ContentType, IsActive, IssueSentiment, MediaClassification, MediaType, SocialMedia) - Add feature tests for factory integration and basic application functionality - Add tests for Filament actions, columns, and media library utilities - Add tests for model policies (Classification, Theme) and traits (WithComment, WithValue) - Update phpunit.xml configuration for test environment - Add test documentation and working tests reference guide - Add ContentType enum casting to ContentRecap model - Add MediaMonitoringTheme relationships and factory support - Establish comprehensive testing infrastructure for improved code quality and reliability
192 lines
6.4 KiB
Markdown
192 lines
6.4 KiB
Markdown
# SIMEDKOM Testing Suite
|
|
|
|
Comprehensive Pest testing suite for the SIMEDKOM media monitoring and management system.
|
|
|
|
## Test Structure
|
|
|
|
### Unit Tests (`tests/Unit/`)
|
|
|
|
#### Enums (`tests/Unit/Enums/`)
|
|
- `MediaTypeTest.php` - Tests for media type enumeration
|
|
- `ContentTypeTest.php` - Tests for content type enumeration
|
|
- `IssueSentimentTest.php` - Tests for issue sentiment enumeration
|
|
- `IsActiveTest.php` - Tests for active status enumeration
|
|
- `ChannelTest.php` - Tests for channel enumeration
|
|
- `MediaClassificationTest.php` - Tests for media classification enumeration
|
|
- `SocialMediaTest.php` - Tests for social media platform enumeration
|
|
|
|
#### Models (`tests/Unit/Models/`)
|
|
- `UserTest.php` - User model tests
|
|
- `ThemeTest.php` - Theme model tests and relationships
|
|
- `ClassificationTest.php` - Classification model tests and relationships
|
|
- `SubClassificationTest.php` - Sub-classification model tests
|
|
- `LocationTest.php` - Location model tests and relationships
|
|
- `SubLocationTest.php` - Sub-location model tests
|
|
- `DepartmentTest.php` - Department model tests
|
|
- `MediaMonitoringTest.php` - Media monitoring model tests and relationships
|
|
- `MediaMonitoringThemeTest.php` - Pivot model tests
|
|
- `IssueManagementTest.php` - Issue management model tests
|
|
- `ContentRecapTest.php` - Content recap model tests
|
|
- `JournalistTest.php` - Journalist model tests and relationships
|
|
- `CompanyTest.php` - Company model tests and relationships
|
|
- `PartnerMediaTest.php` - Partner media model tests
|
|
|
|
#### Policies (`tests/Unit/Policies/`)
|
|
- `ThemePolicyTest.php` - Theme authorization policy tests
|
|
- `ClassificationPolicyTest.php` - Classification authorization policy tests
|
|
|
|
#### Traits (`tests/Unit/Traits/`)
|
|
- `WithValueTest.php` - Enum value trait tests
|
|
- `WithCommentTest.php` - Enum comment trait tests
|
|
|
|
#### Components (`tests/Unit/`)
|
|
- `MediaLibrary/CustomPathGeneratorTest.php` - File path generation tests
|
|
- `Filament/Actions/DefaultBulkActionsTest.php` - Bulk actions tests
|
|
- `Filament/Columns/TimestampColumnsTest.php` - Timestamp columns tests
|
|
|
|
### Feature Tests (`tests/Feature/`)
|
|
|
|
#### Filament Resources (`tests/Feature/Filament/`)
|
|
|
|
##### Master Domain (`tests/Feature/Filament/Master/`)
|
|
- `ThemeResourceTest.php` - Theme resource CRUD operations
|
|
- `ClassificationResourceTest.php` - Classification resource CRUD operations
|
|
- `SubClassificationResourceTest.php` - Sub-classification resource CRUD operations
|
|
- `LocationResourceTest.php` - Location resource CRUD operations
|
|
- `SubLocationResourceTest.php` - Sub-location resource CRUD operations
|
|
- `DepartmentResourceTest.php` - Department resource CRUD operations
|
|
- `UserResourceTest.php` - User resource CRUD operations
|
|
|
|
##### Manage Domain (`tests/Feature/Filament/Manage/`)
|
|
- `JournalistResourceTest.php` - Journalist resource CRUD operations
|
|
- `PartnerResourceTest.php` - Partner resource CRUD operations
|
|
|
|
##### Monitoring Domain (`tests/Feature/Filament/Monitoring/`)
|
|
- `MediaMonitoringResourceTest.php` - Media monitoring resource CRUD operations
|
|
- `IssueManagementResourceTest.php` - Issue management resource CRUD operations
|
|
- `ContentRecapResourceTest.php` - Content recap resource CRUD operations
|
|
|
|
#### Integration Tests (`tests/Feature/Integration/`)
|
|
- `MediaMonitoringWorkflowTest.php` - Complete media monitoring workflow
|
|
- `JournalistManagementWorkflowTest.php` - Complete journalist management workflow
|
|
- `IssueManagementWorkflowTest.php` - Complete issue management workflow
|
|
|
|
## Test Coverage
|
|
|
|
### Domain Coverage
|
|
- **Master Data**: Users, Themes, Classifications, Locations, Departments
|
|
- **Entity Management**: Journalists, Companies, Partners
|
|
- **Core Business**: Media Monitoring, Issue Management, Content Recaps
|
|
|
|
### Component Coverage
|
|
- **Models**: All Eloquent models with relationships and scopes
|
|
- **Enums**: All business domain enumerations with traits
|
|
- **Policies**: Authorization policies for resources
|
|
- **Filament Resources**: CRUD operations, validation, filtering
|
|
- **Custom Components**: Path generators, bulk actions, columns
|
|
- **Workflows**: End-to-end business process testing
|
|
|
|
## Running Tests
|
|
|
|
### All Tests
|
|
```bash
|
|
composer run test
|
|
# or
|
|
php artisan test
|
|
```
|
|
|
|
### Specific Test Suites
|
|
```bash
|
|
# Unit tests only
|
|
php artisan test tests/Unit
|
|
|
|
# Feature tests only
|
|
php artisan test tests/Feature
|
|
|
|
# Specific domain
|
|
php artisan test tests/Feature/Filament/Master
|
|
php artisan test tests/Feature/Filament/Manage
|
|
php artisan test tests/Feature/Filament/Monitoring
|
|
|
|
# Integration tests
|
|
php artisan test tests/Feature/Integration
|
|
```
|
|
|
|
### Specific Test Files
|
|
```bash
|
|
# Single test file
|
|
php artisan test tests/Unit/Models/MediaMonitoringTest.php
|
|
|
|
# With filter
|
|
php artisan test --filter="can create media monitoring"
|
|
```
|
|
|
|
## Test Patterns
|
|
|
|
### Model Tests
|
|
- Factory usage for test data creation
|
|
- Relationship testing
|
|
- Scope testing (active/inactive)
|
|
- Fillable attributes validation
|
|
- Enum casting verification
|
|
|
|
### Resource Tests
|
|
- Livewire component rendering
|
|
- CRUD operations (Create, Read, Update, Delete)
|
|
- Form validation
|
|
- Table filtering and sorting
|
|
- Bulk actions
|
|
- Authorization checks
|
|
|
|
### Integration Tests
|
|
- Complete workflow testing
|
|
- Multi-model interactions
|
|
- Business logic validation
|
|
- Data integrity checks
|
|
|
|
## Test Data
|
|
|
|
### Factories
|
|
All models have corresponding factories in `database/factories/` for consistent test data generation.
|
|
|
|
### Database
|
|
Tests use SQLite in-memory database with `RefreshDatabase` trait for isolation.
|
|
|
|
### Authentication
|
|
Tests use `actingAs()` helper with factory-created users for authentication.
|
|
|
|
## Best Practices
|
|
|
|
### Test Organization
|
|
- Group related tests using `describe()` blocks
|
|
- Use descriptive test names with `it()` statements
|
|
- Follow AAA pattern: Arrange, Act, Assert
|
|
|
|
### Assertions
|
|
- Use Pest's fluent expectations: `expect($value)->toBe()`
|
|
- Chain assertions for related checks
|
|
- Test both positive and negative cases
|
|
|
|
### Data Management
|
|
- Use factories for consistent test data
|
|
- Leverage `RefreshDatabase` for test isolation
|
|
- Create minimal required data for each test
|
|
|
|
### Performance
|
|
- Keep tests focused and fast
|
|
- Use database transactions where possible
|
|
- Mock external dependencies
|
|
|
|
## Maintenance
|
|
|
|
### Adding New Tests
|
|
1. Follow existing naming conventions
|
|
2. Place tests in appropriate domain folders
|
|
3. Include both unit and feature tests for new components
|
|
4. Update this documentation
|
|
|
|
### Test Updates
|
|
- Update tests when business logic changes
|
|
- Maintain test coverage for new features
|
|
- Refactor tests alongside code refactoring
|