whereKey(0)->exists()) { $settings = new InstanceSettings; $settings->id = 0; $settings->save(); } Once::flush(); $this->team = Team::factory()->create(); $this->user = User::factory()->create(); $this->team->members()->attach($this->user->id, ['role' => 'owner']); session(['currentTeam' => $this->team]); $this->actingAs($this->user); Config::set('cache.default', 'array'); Storage::fake('ssh-keys'); $this->currentPrivateKey = PrivateKey::factory()->create([ 'team_id' => $this->team->id, ]); $this->server = Server::factory()->create([ 'team_id' => $this->team->id, 'private_key_id' => $this->currentPrivateKey->id, ]); }); test('server private key page shows highlighted add dropdown actions', function () { Livewire::test(Show::class, ['server_uuid' => $this->server->uuid]) ->assertSee('Add') ->assertSee('Generate ED25519') ->assertSee('Generate RSA') ->assertSee('Add manually') ->assertSee('Check connection'); }); test('generating a server private key stores it and refreshes the current view', function () { $component = Livewire::test(Show::class, ['server_uuid' => $this->server->uuid]) ->call('generatePrivateKey', 'ed25519') ->assertNoRedirect() ->assertDispatched('success'); $privateKey = PrivateKey::query() ->where('id', '!=', $this->currentPrivateKey->id) ->firstOrFail(); expect($privateKey->team_id)->toBe($this->team->id) ->and($privateKey->public_key)->toStartWith('ssh-ed25519'); $component ->assertDispatched('copyPublicKeyToClipboard', publicKey: $privateKey->public_key) ->assertSee($privateKey->name); }); test('server private key cards include a copy public key button', function () { $keyData = PrivateKey::generateNewKeyPair('rsa'); $alternativeKey = PrivateKey::createAndStore([ 'team_id' => $this->team->id, 'name' => 'Alternative SSH Key', 'description' => 'Created by test', 'private_key' => $keyData['private_key'], ]); Livewire::test(Show::class, ['server_uuid' => $this->server->uuid]) ->assertSee('Copy public key') ->assertSee('Alternative SSH Key') ->assertSeeHtml('copyPublicKeyToClipboard('.Js::from($alternativeKey->public_key)->toHtml().')'); });