feat: consolidar desenvolvimentos do portal InvestMoz

This commit is contained in:
2026-11-03 23:32:32 +02:00
parent 1da273f1f3
commit 36c8cadb49
345 changed files with 110714 additions and 2799 deletions
+126
View File
@@ -81,6 +81,132 @@ const props = {
criteria: ['Venda da empresa', 'Agricultura'],
};
const flush = () => new Promise((resolve) => setImmediate(resolve));
function nodes(tree) {
if (!tree || typeof tree !== 'object') return [];
if (Array.isArray(tree)) return tree.flatMap(nodes);
return [tree, ...nodes(tree.props?.children)];
}
await test('radius replaces only the area, combines public classification, preserves links and reports missing point coverage', async () => {
const h = harness();
const scoped = {
...props,
radiusAvailable: true,
areaLabel: 'Synthetic province',
catalogueUrl:
props.catalogueUrl +
'&province_id=qa-province&district_id=qa-district',
classifications: [
{ target_type: 'sector', target_id: '4', label: 'QA sector' },
],
};
let tree = h.render(scoped);
const radius = nodes(tree).find((node) => node.type === 'fieldset').props
.children[1].props.children[1];
radius.props.onChange({ target: { value: '25' } });
const classification = nodes(tree).find(
(node) =>
node.type === 'select' &&
node.props.children[0]?.props?.children ===
'Sem classificação adicional',
);
classification.props.onChange({ target: { value: 'sector:4:' } });
tree = h.render(scoped);
h.start();
const url = new URL(h.requests[0].url, 'https://portal.invalid');
assert.equal(url.searchParams.get('near_business'), 'current');
assert.equal(url.searchParams.get('radius_km'), '25');
assert.equal(url.searchParams.has('province_id'), false);
assert.equal(url.searchParams.has('district_id'), false);
assert.equal(url.searchParams.get('sector'), '4');
assert.equal(url.searchParams.get('association_target'), '4');
h.requests[0].resolve({
data: [
{
id: 'near',
slug: 'near',
title: 'Nearby',
distance_km: 1.5,
location_recorded_at: '2026-10-02T10:00:00Z',
},
],
geographicCoverage: {
origin_id: 'current',
origin_title: 'Public reference',
radius_km: 25,
origin_recorded_at: '2026-10-01T10:00:00Z',
with_public_point: 4,
without_public_point: 8,
source: 'Published location register',
method: 'Geodesic, not road',
},
});
await flush();
let html = renderToStaticMarkup(h.render(scoped));
assert.match(html, /Raio de 25 km/);
assert.match(html, /4 com ponto utilizável; 8 sem ponto público/);
assert.match(html, /Localização registada em/);
assert.match(html, /Published location register/);
assert.match(html, /near_business=current&radius_km=25/);
assert.match(html, /Geodesic, not road/);
tree = h.render(scoped);
nodes(tree)
.find((node) => node.type === 'fieldset')
.props.children[1].props.children[1].props.onChange({
target: { value: '' },
});
html = renderToStaticMarkup(h.render(scoped));
assert.match(html, /A consultar/);
assert.doesNotMatch(html, /Nearby|8 sem ponto/);
h.start();
assert.equal(
new URL(h.requests[1].url, 'https://portal.invalid').searchParams.get(
'province_id',
),
'qa-province',
);
assert.equal(
new URL(h.requests[1].url, 'https://portal.invalid').searchParams.has(
'radius_km',
),
false,
);
const changed = { ...scoped, currentId: 'new-reference' };
h.render(changed);
h.start();
assert.equal(
new URL(h.requests[2].url, 'https://portal.invalid').searchParams.has(
'near_business',
),
false,
);
});
await test('missing point reference has no radius selector, and a radius response without coverage is a recoverable failure', async () => {
const h = harness();
assert.match(
renderToStaticMarkup(h.render(props)),
/requer um ponto primário público exacto/,
);
assert.equal(
nodes(h.render(props)).some((node) => node.type === 'fieldset'),
false,
);
const scoped = { ...props, radiusAvailable: true };
const tree = h.render(scoped);
nodes(tree)
.find((node) => node.type === 'fieldset')
.props.children[1].props.children[1].props.onChange({
target: { value: '10' },
});
h.render(scoped);
h.start();
h.requests[0].resolve({ data: [] });
await flush();
const html = renderToStaticMarkup(h.render(scoped));
assert.match(html, /Tentar novamente/);
assert.doesNotMatch(html, /Não foram encontrados/);
});
await test('explicit public classification changes matching criteria and is cleared when the source record changes', async () => {
const h = harness();