simedkom/tests/Unit/Models/ThemeTest.php
Yoga Pangestu 97cdfd6e0b test: add comprehensive test suite and model factories
- 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
2025-12-11 14:50:37 +07:00

48 lines
1.4 KiB
PHP

<?php
use App\Enums\IsActive;
use App\Models\Theme;
use Illuminate\Foundation\Testing\RefreshDatabase;
uses(RefreshDatabase::class);
describe('Theme Model', function () {
it('can create a theme', function () {
$theme = Theme::factory()->create([
'name' => 'Test Theme',
]);
expect($theme->name)->toBe('Test Theme')
->and($theme->exists)->toBeTrue();
});
it('has guarded attributes', function () {
$guarded = ['id'];
expect(Theme::make()->getGuarded())->toEqual($guarded);
});
it('has media monitorings relationship', function () {
$theme = Theme::factory()->create();
expect($theme->mediaMonitorings())->toBeInstanceOf(\Illuminate\Database\Eloquent\Relations\BelongsToMany::class);
});
it('scopes active themes', function () {
Theme::factory()->create(['is_active' => IsActive::ACTIVE]);
Theme::factory()->create(['is_active' => IsActive::INACTIVE]);
$activeThemes = Theme::active()->get();
expect($activeThemes)->toHaveCount(1)
->and($activeThemes->first()->is_active)->toBe(IsActive::ACTIVE);
});
it('casts is_active to enum', function () {
$theme = Theme::factory()->create(['is_active' => IsActive::ACTIVE]);
expect($theme->is_active)->toBeInstanceOf(IsActive::class)
->and($theme->is_active)->toBe(IsActive::ACTIVE);
});
});