Files
coolify/tests/Feature/SettingsAccessListboxTest.php
T
Andras BacsaiandClaude Opus 5.5 a79ee909c6 chore: remove unused components and markup-only tests
- Delete Blade components, component classes, Livewire components and
  views that nothing uses after the redesign.
- Delete tests that only compare Blade/CSS source text; keep the source
  checks for authorization gates, stable wire:key values and escaping.
- Update stale tests to the current UI and behaviour.
- Update DESIGN.md to the current navigation and layout.
- Add a lesson: test behaviour, not source markup.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-28 00:18:16 +02:00

130 lines
4.4 KiB
PHP

<?php
use App\Livewire\Settings\Advanced;
use App\Models\InstanceSettings;
use App\Models\Server;
use App\Models\Team;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Once;
use Livewire\Livewire;
uses(RefreshDatabase::class);
test('instance admin can toggle registration via listbox instantSave', function () {
$rootTeam = Team::find(0) ?? Team::factory()->create(['id' => 0]);
Server::factory()->create(['id' => 0, 'team_id' => $rootTeam->id]);
$settings = InstanceSettings::forceCreate([
'id' => 0,
'is_registration_enabled' => false,
'disable_two_step_confirmation' => false,
]);
Once::flush();
$user = User::factory()->create();
$rootTeam->members()->attach($user->id, ['role' => 'admin']);
$this->actingAs($user);
session(['currentTeam' => ['id' => $rootTeam->id]]);
Livewire::test(Advanced::class)
->assertSet('is_registration_enabled', false)
->assertSee('Registration')
->assertSee('Destructive action confirmation')
->assertDontSee('Only administrators can create accounts.')
->set('is_registration_enabled', true)
->call('instantSave')
->assertDispatched('success');
expect((bool) $settings->fresh()->is_registration_enabled)->toBeTrue();
});
test('instance admin can toggle two-step confirmation via listbox instantSave', function () {
$rootTeam = Team::find(0) ?? Team::factory()->create(['id' => 0]);
Server::factory()->create(['id' => 0, 'team_id' => $rootTeam->id]);
$settings = InstanceSettings::forceCreate([
'id' => 0,
'is_registration_enabled' => true,
'disable_two_step_confirmation' => false,
]);
Once::flush();
$user = User::factory()->create();
$rootTeam->members()->attach($user->id, ['role' => 'admin']);
$this->actingAs($user);
session(['currentTeam' => ['id' => $rootTeam->id]]);
Livewire::test(Advanced::class)
->assertSet('disable_two_step_confirmation', false)
->set('disable_two_step_confirmation', true)
->call('instantSave')
->assertDispatched('success');
expect((bool) $settings->fresh()->disable_two_step_confirmation)->toBeTrue();
});
test('instance admin can configure the image CDN URL at runtime', function () {
$rootTeam = Team::find(0) ?? Team::factory()->create(['id' => 0]);
Server::factory()->create(['id' => 0, 'team_id' => $rootTeam->id]);
$settings = InstanceSettings::forceCreate(['id' => 0]);
Once::flush();
$user = User::factory()->create();
$rootTeam->members()->attach($user->id, ['role' => 'admin']);
$this->actingAs($user);
session(['currentTeam' => ['id' => $rootTeam->id]]);
Livewire::test(Advanced::class)
->assertSee('Image CDN URL')
->set('image_cdn_url', 'https://images.example.com/media/')
->call('submit')
->assertHasNoErrors()
->assertDispatched('success');
expect($settings->fresh()->image_cdn_url)->toBe('https://images.example.com/media');
});
test('open API allowlist warning is hidden when API access is disabled', function () {
$rootTeam = Team::find(0) ?? Team::factory()->create(['id' => 0]);
Server::factory()->create(['id' => 0, 'team_id' => $rootTeam->id]);
InstanceSettings::forceCreate([
'id' => 0,
'is_api_enabled' => false,
'allowed_ips' => null,
]);
Once::flush();
$user = User::factory()->create();
$rootTeam->members()->attach($user->id, ['role' => 'admin']);
$this->actingAs($user);
session(['currentTeam' => ['id' => $rootTeam->id]]);
Livewire::test(Advanced::class)
->assertSet('is_api_enabled', false)
->assertDontSee('API access is open to every source');
});
test('open API allowlist warning is shown when API access is enabled without allowlist', function () {
$rootTeam = Team::find(0) ?? Team::factory()->create(['id' => 0]);
Server::factory()->create(['id' => 0, 'team_id' => $rootTeam->id]);
InstanceSettings::forceCreate([
'id' => 0,
'is_api_enabled' => true,
'allowed_ips' => null,
]);
Once::flush();
$user = User::factory()->create();
$rootTeam->members()->attach($user->id, ['role' => 'admin']);
$this->actingAs($user);
session(['currentTeam' => ['id' => $rootTeam->id]]);
Livewire::test(Advanced::class)
->assertSet('is_api_enabled', true)
->assertSee('API access is open to every source');
});