feat: add environment variable autocomplete component

Adds a new EnvVarInput component that provides autocomplete suggestions for shared environment variables from team, project, and environment scopes. Users can reference variables using {{ syntax.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Andras Bacsai
2025-11-19 10:54:19 +01:00
parent c656e2ac7b
commit c79b5f1e5c
6 changed files with 546 additions and 3 deletions

View File

@@ -0,0 +1,67 @@
<?php
use App\View\Components\Forms\EnvVarInput;
it('renders with default properties', function () {
$component = new EnvVarInput;
expect($component->required)->toBeFalse()
->and($component->disabled)->toBeFalse()
->and($component->readonly)->toBeFalse()
->and($component->defaultClass)->toBe('input')
->and($component->availableVars)->toBe([]);
});
it('uses provided id', function () {
$component = new EnvVarInput(id: 'env-key');
expect($component->id)->toBe('env-key');
});
it('accepts available vars', function () {
$vars = [
'team' => ['DATABASE_URL', 'API_KEY'],
'project' => ['STRIPE_KEY'],
'environment' => ['DEBUG'],
];
$component = new EnvVarInput(availableVars: $vars);
expect($component->availableVars)->toBe($vars);
});
it('accepts required parameter', function () {
$component = new EnvVarInput(required: true);
expect($component->required)->toBeTrue();
});
it('accepts disabled state', function () {
$component = new EnvVarInput(disabled: true);
expect($component->disabled)->toBeTrue();
});
it('accepts readonly state', function () {
$component = new EnvVarInput(readonly: true);
expect($component->readonly)->toBeTrue();
});
it('accepts autofocus parameter', function () {
$component = new EnvVarInput(autofocus: true);
expect($component->autofocus)->toBeTrue();
});
it('accepts authorization properties', function () {
$component = new EnvVarInput(
canGate: 'update',
canResource: 'resource',
autoDisable: false
);
expect($component->canGate)->toBe('update')
->and($component->canResource)->toBe('resource')
->and($component->autoDisable)->toBeFalse();
});

View File

@@ -0,0 +1,53 @@
<?php
use App\Livewire\Project\Shared\EnvironmentVariable\Add;
use Illuminate\Support\Facades\Auth;
it('has availableSharedVariables computed property', function () {
$component = new Add;
// Check that the method exists
expect(method_exists($component, 'availableSharedVariables'))->toBeTrue();
});
it('component has required properties for environment variable autocomplete', function () {
$component = new Add;
expect($component)->toHaveProperty('key')
->and($component)->toHaveProperty('value')
->and($component)->toHaveProperty('is_multiline')
->and($component)->toHaveProperty('is_literal')
->and($component)->toHaveProperty('is_runtime')
->and($component)->toHaveProperty('is_buildtime')
->and($component)->toHaveProperty('parameters');
});
it('returns empty arrays when currentTeam returns null', function () {
// Mock Auth facade to return null for user
Auth::shouldReceive('user')
->andReturn(null);
$component = new Add;
$component->parameters = [];
$result = $component->availableSharedVariables();
expect($result)->toBe([
'team' => [],
'project' => [],
'environment' => [],
]);
});
it('availableSharedVariables method wraps authorization checks in try-catch blocks', function () {
// Read the source code to verify the authorization pattern
$reflectionMethod = new ReflectionMethod(Add::class, 'availableSharedVariables');
$source = file_get_contents($reflectionMethod->getFileName());
// Verify that the method contains authorization checks
expect($source)->toContain('$this->authorize(\'view\', $team)')
->and($source)->toContain('$this->authorize(\'view\', $project)')
->and($source)->toContain('$this->authorize(\'view\', $environment)')
// Verify authorization checks are wrapped in try-catch blocks
->and($source)->toContain('} catch (\Illuminate\Auth\Access\AuthorizationException $e) {');
});