Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/Livewire/Project/Service/EditDomain.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ public function submit()
$this->dispatch('refresh');
$this->dispatch('refreshServices');
$this->dispatch('configurationChanged');
$this->dispatch('close-modal');
} catch (\Throwable $e) {
$originalFqdn = $this->application->getOriginal('fqdn');
if ($originalFqdn !== $this->application->fqdn) {
Expand Down
16 changes: 16 additions & 0 deletions database/factories/ServiceApplicationFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Database\Factories;

use Illuminate\Database\Eloquent\Factories\Factory;

class ServiceApplicationFactory extends Factory
{
public function definition(): array
{
return [
'name' => fake()->unique()->word(),
'service_id' => 1,
];
}
}
42 changes: 38 additions & 4 deletions tests/Feature/Service/EditDomainPortValidationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,39 @@

use App\Livewire\Project\Service\EditDomain;
use App\Models\Environment;
use App\Models\InstanceSettings;
use App\Models\Project;
use App\Models\Server;
use App\Models\Service;
use App\Models\ServiceApplication;
use App\Models\StandaloneDocker;
use App\Models\Team;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;

uses(RefreshDatabase::class);

beforeEach(function () {
// Required base instance settings (id 0)
$instanceSettings = new InstanceSettings;
$instanceSettings->id = 0;
$instanceSettings->save();

// Create user and team
$this->user = User::factory()->create();
$this->team = Team::factory()->create();
$this->user->teams()->attach($this->team, ['role' => 'owner']);
$this->actingAs($this->user);
session(['currentTeam' => ['id' => $this->team->id]]);

// Create server
$this->server = Server::factory()->create([
'team_id' => $this->team->id,
]);

// Create standalone docker destination
$this->destination = StandaloneDocker::factory()->create([
'server_id' => $this->server->id,
]);
// Use the standalone docker destination auto-created with the server
$this->destination = StandaloneDocker::where('server_id', $this->server->id)->firstOrFail();

// Create project and environment
$this->project = Project::factory()->create([
Expand Down Expand Up @@ -132,6 +140,32 @@ function get_service_templates_mock()
->assertSet('showPortWarningModal', true);
});

it('closes the modal after successfully saving domains', function () {
Livewire::test(EditDomain::class, ['applicationId' => $this->serviceApplication->id])
->set('fqdn', 'http://example.com:3000') // Valid domain with a port
->call('submit')
->assertSet('showPortWarningModal', false)
->assertDispatched('close-modal');
});

it('does not close the modal while the port warning is shown', function () {
Livewire::test(EditDomain::class, ['applicationId' => $this->serviceApplication->id])
->set('fqdn', 'http://example.com') // Remove port -> triggers warning, early return
->call('submit')
->assertSet('showPortWarningModal', true)
->assertNotDispatched('close-modal');
});

it('closes the modal after confirming port removal', function () {
Livewire::test(EditDomain::class, ['applicationId' => $this->serviceApplication->id])
->set('fqdn', 'http://example.com') // Remove port
->call('submit')
->assertSet('showPortWarningModal', true)
->call('confirmRemovePort')
->assertSet('showPortWarningModal', false)
->assertDispatched('close-modal');
});

it('does not show warning for services without required port', function () {
// Create a service without required port (e.g., cloudflared)
$serviceWithoutPort = Service::factory()->create([
Expand Down