fix: complete InvesteMoz validation and error corrections
This commit is contained in:
@@ -1,35 +1,112 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {opportunityFillGroups,opportunityErrorGroup,opportunityMissingGroups} from '../../resources/js/lib/opportunity-fill-flow.ts';
|
||||
import {territorialSearchParams} from '../../resources/js/lib/territorial-search-params.ts';
|
||||
import {documentFacetLabel} from '../../resources/js/lib/document-facet-label.ts';
|
||||
import {
|
||||
opportunityFillGroups,
|
||||
opportunityErrorGroup,
|
||||
opportunityMissingGroups,
|
||||
} from '../../resources/js/lib/opportunity-fill-flow.ts';
|
||||
import { territorialSearchParams } from '../../resources/js/lib/territorial-search-params.ts';
|
||||
import { documentFacetLabel } from '../../resources/js/lib/document-facet-label.ts';
|
||||
|
||||
test('adaptive groups keep every applicable schema field once, including new specialized fields',()=>{
|
||||
const keys=['official_title','locations','sector_id','documents','currency','real_estate','future_schema_field','currency'];
|
||||
const groups=opportunityFillGroups(keys);
|
||||
assert.deepEqual(groups.flatMap(group=>group.fields).sort(),[...new Set(keys)].sort());
|
||||
assert.ok(groups.find(group=>group.id==='specific').fields.includes('future_schema_field'));
|
||||
assert.deepEqual(opportunityFillGroups(['official_title']).map(group=>group.id),['idea']);
|
||||
assert.deepEqual(opportunityFillGroups([]),[]);
|
||||
void test('adaptive groups keep every applicable schema field once, including new specialized fields', () => {
|
||||
const keys = [
|
||||
'official_title',
|
||||
'locations',
|
||||
'sector_id',
|
||||
'documents',
|
||||
'currency',
|
||||
'real_estate',
|
||||
'future_schema_field',
|
||||
'currency',
|
||||
];
|
||||
const groups = opportunityFillGroups(keys);
|
||||
assert.deepEqual(
|
||||
groups.flatMap((group) => group.fields).sort(),
|
||||
[...new Set(keys)].sort(),
|
||||
);
|
||||
assert.ok(
|
||||
groups
|
||||
.find((group) => group.id === 'specific')
|
||||
.fields.includes('future_schema_field'),
|
||||
);
|
||||
assert.deepEqual(
|
||||
opportunityFillGroups(['official_title']).map((group) => group.id),
|
||||
['idea'],
|
||||
);
|
||||
assert.deepEqual(opportunityFillGroups([]), []);
|
||||
});
|
||||
test('saved pending fields and validation errors point to the correct existing group without inventing applicability',()=>{
|
||||
const groups=opportunityFillGroups(['official_title','locations','total_investment']);
|
||||
assert.equal(opportunityErrorGroup(groups,{'canonical.total_investment':'Valor em falta'}),'finance');
|
||||
assert.equal(opportunityErrorGroup(groups,{'canonical.locations.0':'Local em falta'}),'territory');
|
||||
assert.deepEqual(opportunityMissingGroups(groups,['locations.0','canonical.total_investment']).map(group=>group.id),['territory','finance']);
|
||||
assert.equal(opportunityErrorGroup(groups,{reason:'Motivo em falta'}),undefined);
|
||||
void test('saved pending fields and validation errors point to the correct existing group without inventing applicability', () => {
|
||||
const groups = opportunityFillGroups([
|
||||
'official_title',
|
||||
'locations',
|
||||
'total_investment',
|
||||
]);
|
||||
assert.equal(
|
||||
opportunityErrorGroup(groups, {
|
||||
'canonical.total_investment': 'Valor em falta',
|
||||
}),
|
||||
'finance',
|
||||
);
|
||||
assert.equal(
|
||||
opportunityErrorGroup(groups, {
|
||||
'canonical.locations.0': 'Local em falta',
|
||||
}),
|
||||
'territory',
|
||||
);
|
||||
assert.deepEqual(
|
||||
opportunityMissingGroups(groups, [
|
||||
'locations.0',
|
||||
'canonical.total_investment',
|
||||
]).map((group) => group.id),
|
||||
['territory', 'finance'],
|
||||
);
|
||||
assert.equal(
|
||||
opportunityErrorGroup(groups, { reason: 'Motivo em falta' }),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
test('territorial search replaces old descendants while retaining all selected non-territorial filters',()=>{
|
||||
const entries=[['province_id','old'],['district_id','old-child'],['locality_id','old-leaf'],['category','zee'],['q','Nacala'],['page','5']];
|
||||
const scoped=territorialSearchParams(entries,[{id:'new',location_type:'province'}]);
|
||||
assert.equal(scoped.get('province_id'),'new');assert.equal(scoped.has('district_id'),false);assert.equal(scoped.has('locality_id'),false);
|
||||
assert.equal(scoped.get('category'),'zee');assert.equal(scoped.get('q'),'Nacala');assert.equal(scoped.has('page'),false);
|
||||
const all=territorialSearchParams(entries,[]);assert.equal(all.has('province_id'),false);assert.equal(all.get('category'),'zee');
|
||||
const unchanged=territorialSearchParams(entries);assert.equal(unchanged.get('district_id'),'old-child');
|
||||
void test('territorial search replaces old descendants while retaining all selected non-territorial filters', () => {
|
||||
const entries = [
|
||||
['province_id', 'old'],
|
||||
['district_id', 'old-child'],
|
||||
['locality_id', 'old-leaf'],
|
||||
['category', 'zee'],
|
||||
['q', 'Nacala'],
|
||||
['page', '5'],
|
||||
];
|
||||
const scoped = territorialSearchParams(entries, [
|
||||
{ id: 'new', location_type: 'province' },
|
||||
]);
|
||||
assert.equal(scoped.get('province_id'), 'new');
|
||||
assert.equal(scoped.has('district_id'), false);
|
||||
assert.equal(scoped.has('locality_id'), false);
|
||||
assert.equal(scoped.get('category'), 'zee');
|
||||
assert.equal(scoped.get('q'), 'Nacala');
|
||||
assert.equal(scoped.has('page'), false);
|
||||
const all = territorialSearchParams(entries, []);
|
||||
assert.equal(all.has('province_id'), false);
|
||||
assert.equal(all.get('category'), 'zee');
|
||||
const unchanged = territorialSearchParams(entries);
|
||||
assert.equal(unchanged.get('district_id'), 'old-child');
|
||||
});
|
||||
test('document facets have readable labels while original query identifiers remain unchanged',()=>{
|
||||
const original=['agronegocio','education','media','pt','turismo'];
|
||||
assert.deepEqual(original.map(documentFacetLabel),['Agronegócio','Formação e competências','Imagens e conteúdos de apoio','Português','Turismo']);
|
||||
assert.deepEqual(original,['agronegocio','education','media','pt','turismo']);
|
||||
assert.equal(documentFacetLabel('Tema definido pela Tempo'),'Tema definido pela Tempo');
|
||||
void test('document facets have readable labels while original query identifiers remain unchanged', () => {
|
||||
const original = ['agronegocio', 'education', 'media', 'pt', 'turismo'];
|
||||
assert.deepEqual(original.map(documentFacetLabel), [
|
||||
'Agronegócio',
|
||||
'Formação e competências',
|
||||
'Imagens e conteúdos de apoio',
|
||||
'Português',
|
||||
'Turismo',
|
||||
]);
|
||||
assert.deepEqual(original, [
|
||||
'agronegocio',
|
||||
'education',
|
||||
'media',
|
||||
'pt',
|
||||
'turismo',
|
||||
]);
|
||||
assert.equal(
|
||||
documentFacetLabel('Tema definido pela Tempo'),
|
||||
'Tema definido pela Tempo',
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user