feat: add workforce evidence and sourced economic context map layers

This commit is contained in:
2026-11-04 11:27:37 +02:00
parent 21ebad73e7
commit a9241ff26b
11 changed files with 358 additions and 16 deletions
+20 -1
View File
@@ -55,15 +55,34 @@ class InvestmentThematicMapTest extends TestCase
$record = $this->record($prefix, [$this->proof(), $this->proof('infrastructure'), $this->proof('resource', 'methodology'), $this->proof('demand')]);
$before = $record->fresh()->getRawOriginal('workflow_context');
$response = $this->getJson($this->url($prefix))->assertOk()->assertJsonPath('matched_count', 1)
->assertJsonPath('thematic_records.0.id', $record->id)->assertJsonCount(2, 'thematic_records.0.evidence')
->assertJsonPath('thematic_records.0.id', $record->id)->assertJsonCount(3, 'thematic_records.0.evidence')
->assertJsonPath('thematic_records.0.evidence.0.source', 'Synthetic public source')
->assertJsonPath('thematic_records.0.evidence.0.period', '2026')
->assertJsonPath('thematic_records.0.evidence.0.scope', 'Synthetic district')
->assertJsonPath('thematic_records.0.evidence.2.category', 'economic_potential')
->assertJsonPath('thematic_records.0.evidence.2.source_category', 'demand')
->assertJsonPath('thematic_records.0.state', 'hypothesis')->assertJsonCount(0, 'features')->assertJsonCount(1, 'unlocated');
$this->assertStringNotContainsString('PRIVATE-DRAFT-MUST-NOT-LEAK', $response->getContent());
$this->assertSame($before, $record->fresh()->getRawOriginal('workflow_context'));
}
public function test_workforce_is_explicit_and_economic_context_preserves_each_source_without_inferred_totals(): void
{
$prefix = 'THEME-'.Str::uuid();
$this->record($prefix, [$this->proof('workforce'), $this->proof('activity'), $this->proof('supply'), $this->proof('demand'), $this->proof('workforce', 'methodology')]);
$r = $this->getJson($this->url($prefix))->assertOk()->assertJsonCount(4, 'thematic_records.0.evidence')
->assertJsonPath('thematic_records.0.evidence.0.category', 'workforce')
->assertJsonPath('thematic_records.0.evidence.0.source_category', 'workforce')
->assertJsonPath('thematic_records.0.state', 'hypothesis')->assertJsonCount(0, 'features')->json('thematic_records.0');
foreach (['activity', 'supply', 'demand'] as $i => $source) {
$this->assertSame('economic_potential', $r['evidence'][$i + 1]['category']);
$this->assertSame($source, $r['evidence'][$i + 1]['source_category']);
$this->assertSame('2026', $r['evidence'][$i + 1]['period']);
}
$this->assertArrayNotHasKey('available_workers', $r);
$this->assertArrayNotHasKey('potential_score', $r);
}
public function test_unpublished_future_restricted_and_unselected_private_evidence_are_not_disclosed(): void
{
$prefix = 'THEME-'.Str::uuid();
+20
View File
@@ -62,6 +62,26 @@ final class ProactiveInvestmentTest extends TestCase
return $input;
}
public function test_workforce_evidence_saves_recovers_and_requires_existing_explicit_publication(): void
{
$input = F::input();
$input['proactive']['evidence'][0]['category'] = 'workforce';
$id = $this->postJson('/minhas-oportunidades/drafts', $input)->assertCreated()->json('id');
$o = Opportunity::findOrFail($id);
$analysis = app(OpportunityManagement::class)->values($o)['proactive'];
$this->assertSame('workforce', $analysis['evidence'][0]['category']);
$this->assertNull(app(ProactiveInvestment::class)->publicData($o));
$this->publish($o);
$this->getJson('/api/v1/investment/map?opportunity_id='.$id)->assertOk()
->assertJsonPath('thematic_records.0.evidence.0.category', 'workforce')
->assertJsonPath('thematic_records.0.evidence.0.source', $analysis['evidence'][0]['source'])
->assertJsonCount(1, 'thematic_records.0.evidence')->assertJsonCount(0, 'features');
$analysis['evidence'][0]['category'] = 'demand';
$this->putJson('/minhas-oportunidades/'.$id.'/draft', ['etag' => app(OpportunityManagement::class)->etag($o->fresh()), 'proactive' => $analysis,
'reason' => 'SYNTHETIC QA later private changes must not replace the published workforce source'])->assertOk();
$this->getJson('/api/v1/investment/map?opportunity_id='.$id)->assertOk()->assertJsonPath('thematic_records.0.evidence.0.category', 'workforce');
}
public function test_legacy_records_without_analysis_add_no_publication_lookup(): void
{
$o = new Opportunity;
@@ -137,7 +137,7 @@ test('default preserves every opportunity and one map, with sourced thematic evi
'Partial coverage',
'2026-10-01',
'não representam a posição exacta',
'não são inferidos',
'sem índice',
])
assert.ok(html.includes(text), text);
assert.match(html, /2 fichas com evidência temática pública/);
@@ -216,7 +216,7 @@ test('changing query data never retains previous evidence; loading and incomplet
);
assert.match(html, /Sem evidência pública local/);
assert.match(html, /A resposta está limitada/);
assert.match(html, /não significa ausência do recurso/);
assert.match(html, /não significa ausência de recursos/);
});
test('theme selection survives reload in the tab and unavailable or invalid storage does not break the map', () => {
@@ -276,3 +276,63 @@ test('theme selection survives reload in the tab and unavailable or invalid stor
else globalThis.window = previous;
}
});
test('workforce and economic context preserve source categories and incompatible periods without inferred totals or borrowed points', () => {
const Component = setup();
const extra = [
{
...records[0],
id: 4,
title: 'Workforce evidence',
evidence: [{ ...proof('workforce'), source_category: 'workforce' }],
},
{
...records[1],
id: 5,
title: 'Economic context',
evidence: [
{
...proof('economic_potential'),
id: 'supply',
source_category: 'supply',
period: '2023',
},
{
...proof('economic_potential'),
id: 'demand',
source_category: 'demand',
period: '2026',
},
],
},
];
const data = { ...props, records: [...records, ...extra] };
flat(Component(data))
.find((node) => node.type === 'select')
.props.onChange({ target: { value: 'workforce' } });
let tree = Component(data);
assert.deepEqual(
flat(tree).find((node) => node.type === Map).props.points,
[],
);
let html = renderToStaticMarkup(tree);
assert.match(html, /Workforce evidence/);
assert.match(html, /Categoria de origem: Mão-de-obra/);
assert.match(html, /não mede trabalhadores disponíveis/);
flat(tree)
.find((node) => node.type === 'select')
.props.onChange({ target: { value: 'economic_potential' } });
tree = Component(data);
html = renderToStaticMarkup(tree);
assert.match(html, /Economic context/);
assert.match(html, /Categoria de origem: Oferta/);
assert.match(html, /Categoria de origem: Procura/);
assert.match(html, /2023/);
assert.match(html, /2026/);
assert.match(html, /sem índice, previsão de retorno ou viabilidade/);
assert.doesNotMatch(html, /Workforce evidence/);
assert.deepEqual(
flat(tree).find((node) => node.type === Map).props.points,
[],
);
});