Criar Hotel: a mudança de sector feita pelo investidor no editor continua directa (C10)
tests / ci (push) Canceled after 0s

O sector escolhido pelo próprio investidor no editor do dossier substitui a
actividade, como aprovado em C10; o que chega de outra referência ou da
página de entrada continua a ser só proposta. Retirar a actividade também
passa a exigir a escolha explícita.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MzJmxFy3izprXr5dSq91jM
This commit is contained in:
Claude
2026-12-04 21:11:45 +02:00
committed by nala
parent 7446970c64
commit 2c03a0091e
3 changed files with 26 additions and 5 deletions
+3 -1
View File
@@ -690,7 +690,9 @@ final class InvestorContext
}
// Remove inherited subordinate geography only when its source was actually replaced.
foreach ($fields as $key => $value) {
if (! array_key_exists($key, $proposed) && in_array($key, ['province_id', 'district_id', 'admin_post_id', 'locality_id', 'province', 'district', 'location', 'special_zone_id', 'investment_regime'], true) && isset($provenance[$key]['key'])) {
// The activity is only removed when the investor asks for it explicitly.
$explicitIntention = in_array($key, self::INTENTION_FIELDS, true) && in_array($key, $data['replace_fields'] ?? [], true);
if (! array_key_exists($key, $proposed) && ($explicitIntention || in_array($key, ['province_id', 'district_id', 'admin_post_id', 'locality_id', 'province', 'district', 'location', 'special_zone_id', 'investment_regime'], true)) && isset($provenance[$key]['key'])) {
unset($fields[$key],$provenance[$key]);
}
}
+17 -3
View File
@@ -969,9 +969,23 @@ function ScopedContextEditor({
className={input + ' max-w-full min-w-0'}
disabled={busy}
value={selected('sector')}
onChange={(e) =>
change('sector', e.target.value)
}
onChange={(e) => {
change('sector', e.target.value);
// A sector chosen here is the investor's own
// decision (C10): it replaces the activity.
// One arriving from another reference or
// from the entry page stays a proposal.
if (view.context.fields.sector)
setReplace((current) => [
...current.filter(
(key) =>
key !== 'sector_id' &&
key !== 'sector',
),
'sector_id',
'sector',
]);
}}
>
<option value="">Sem sector escolhido</option>
{view.context.selection.sector &&
@@ -5,6 +5,7 @@ namespace Tests\Feature;
use App\Models\Sector;
use App\Models\User;
use App\Services\InvestmentZones;
use App\Services\InvestorPath;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Str;
@@ -128,11 +129,15 @@ class InvestmentContextContinuityTest extends TestCase
$apply(['sector' => null]);
$this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.fields.sector_id', (string) $tourism->id);
// The dossier choice shows each dossier's activity.
$listed = collect(app(\App\Services\InvestorPath::class)->contexts($owner))->firstWhere('id', $id);
$listed = collect(app(InvestorPath::class)->contexts($owner))->firstWhere('id', $id);
$this->assertSame([(string) $tourism->id, $tourism->name], [$listed['sector_id'], $listed['sector']]);
$apply(['sector' => 'sector:'.$agro->id], ['sector_id', 'sector']);
$this->getJson('/investimentos/'.$id.'/contexto')->assertJsonPath('context.fields.sector_id', (string) $agro->id)->assertJsonPath('context.fields.sector', $agro->name);
// Removing the activity is also an explicit decision (C10 explicit changes keep working).
$apply(['sector' => null], ['sector_id', 'sector']);
$this->assertArrayNotHasKey('sector_id', $this->getJson('/investimentos/'.$id.'/contexto')->json('context.fields'));
}
public function test_the_business_plan_executive_summary_fields_are_saved_in_the_draft(): void