Remove redundant stockType field mapping, refactor location handling in identifier mapper, and update related tests.
This commit is contained in:
@@ -118,7 +118,6 @@ export function mapLookupItemToForm({
|
||||
setField('identifierCode', textValue('identifier_code'));
|
||||
setField('name', textValue('name'));
|
||||
setField('description', textValue('description'));
|
||||
setField('stockType', textValue('stock_type'));
|
||||
setField('level', textValue('level'));
|
||||
setField('quantity', numberValue('quantity_initial'));
|
||||
setField('uom', textValue('uom_symbol'));
|
||||
@@ -138,14 +137,14 @@ export function mapLookupItemToForm({
|
||||
setField('expirationDate', '');
|
||||
}
|
||||
|
||||
const canSetLocation = !String(nextForm.locationId || '').trim();
|
||||
const locationUuid = nonEmptyText(lookupItem?.location_initial_uuid_b64);
|
||||
if (canSetLocation && locationUuid) {
|
||||
if (locationUuid) {
|
||||
const matchingLocation = locations.find((entry) => entry.uuid_b64 === locationUuid);
|
||||
if (matchingLocation) {
|
||||
nextForm.locationId = String(matchingLocation.id);
|
||||
setField('locationId', String(matchingLocation.id));
|
||||
if (nextLocationSearch !== matchingLocation.name) {
|
||||
nextLocationSearch = matchingLocation.name;
|
||||
didUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ describe('identifier lookup form mapper', () => {
|
||||
expect(result.form.name).toBe('Yogurt');
|
||||
expect(result.form.search).toBe('Yogurt');
|
||||
expect(result.form.description).toBe('Plain yogurt');
|
||||
expect(result.form.stockType).toBe('measured');
|
||||
expect(result.form.stockType).toBe('binary');
|
||||
expect(result.form.level).toBe('low');
|
||||
expect(result.form.quantity).toBe('0');
|
||||
expect(result.form.uom).toBe('ml');
|
||||
@@ -124,7 +124,7 @@ describe('identifier lookup form mapper', () => {
|
||||
expect(result.form.name).toBe('');
|
||||
expect(result.form.search).toBe('');
|
||||
expect(result.form.description).toBe('');
|
||||
expect(result.form.stockType).toBe('');
|
||||
expect(result.form.stockType).toBe('descriptive');
|
||||
expect(result.form.level).toBe('');
|
||||
expect(result.form.quantity).toBe('');
|
||||
expect(result.form.uom).toBe('');
|
||||
@@ -146,7 +146,7 @@ describe('identifier lookup form mapper', () => {
|
||||
expect(days).toBe(10);
|
||||
});
|
||||
|
||||
it('updates location only when current form location is empty', () => {
|
||||
it('updates location when lookup provides one', () => {
|
||||
const lookupItem = {
|
||||
location_initial_uuid_b64: 'loc-fridge',
|
||||
};
|
||||
@@ -165,9 +165,23 @@ describe('identifier lookup form mapper', () => {
|
||||
locations,
|
||||
});
|
||||
|
||||
expect(withExistingLocation.form.locationId).toBe('8');
|
||||
expect(withExistingLocation.locationSearch).toBeNull();
|
||||
expect(withExistingLocation.form.locationId).toBe('5');
|
||||
expect(withExistingLocation.locationSearch).toBe('Fridge');
|
||||
expect(withoutLocation.form.locationId).toBe('5');
|
||||
expect(withoutLocation.locationSearch).toBe('Fridge');
|
||||
});
|
||||
|
||||
it('keeps location unchanged when lookup location is null', () => {
|
||||
const form = createForm({ locationId: '9' });
|
||||
const result = mapLookupItemToForm({
|
||||
form,
|
||||
lookupItem: {
|
||||
location_initial_uuid_b64: null,
|
||||
},
|
||||
locations: [{ id: 5, uuid_b64: 'loc-fridge', name: 'Fridge' }],
|
||||
});
|
||||
|
||||
expect(result.form.locationId).toBe('9');
|
||||
expect(result.locationSearch).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user