From 0062aab2243ebc70dc1cb9482938d08f9f2ab6d7 Mon Sep 17 00:00:00 2001 From: RafaPolit Date: Mon, 23 Sep 2024 15:21:07 -0500 Subject: [PATCH] Added logic for processing to refelct obsolete --- app/shared/getIXSuggestionState.ts | 7 ++--- app/shared/specs/getIXSuggestionState.spec.ts | 29 +++++++++++++++++++ app/shared/types/suggestionSchema.ts | 10 ++++++- app/shared/types/suggestionType.d.ts | 2 +- 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/app/shared/getIXSuggestionState.ts b/app/shared/getIXSuggestionState.ts index 7986d85b28..e45dfa2b34 100644 --- a/app/shared/getIXSuggestionState.ts +++ b/app/shared/getIXSuggestionState.ts @@ -40,7 +40,7 @@ const equalsForType = (type: PropertySchema['type']) => (first: any, second: any EQUALITIES[type] ? EQUALITIES[type](first, second) : first === second; class IXSuggestionState implements IXSuggestionStateType { - labeled: boolean | undefined; + labeled = false; withValue = false; @@ -71,7 +71,6 @@ class IXSuggestionState implements IXSuggestionStateType { { labeledValue, currentValue }: SuggestionValues, propertyType: PropertySchema['type'] ) { - this.labeled = false; if ( labeledValue || (propertyIsSelect(propertyType) && currentValue) || @@ -129,7 +128,6 @@ class IXSuggestionState implements IXSuggestionStateType { setObsolete({ modelCreationDate, date }: SuggestionValues) { if (date < modelCreationDate) { this.obsolete = true; - this.labeled = undefined; this.match = undefined; } } @@ -137,13 +135,14 @@ class IXSuggestionState implements IXSuggestionStateType { setProcessing({ status }: SuggestionValues) { if (status === 'processing') { this.processing = true; + this.obsolete = true; + this.match = undefined; } } setError({ error, status }: SuggestionValues) { if ((error && error !== '') || (status && status === 'failed')) { this.error = true; - this.labeled = undefined; this.match = undefined; } } diff --git a/app/shared/specs/getIXSuggestionState.spec.ts b/app/shared/specs/getIXSuggestionState.spec.ts index 6bc10b84d8..1cf06008bc 100644 --- a/app/shared/specs/getIXSuggestionState.spec.ts +++ b/app/shared/specs/getIXSuggestionState.spec.ts @@ -1,3 +1,4 @@ +/* eslint-disable max-statements */ import { getSuggestionState, SuggestionValues } from '../getIXSuggestionState'; describe('getIXSuggestionState', () => { @@ -83,8 +84,10 @@ describe('getIXSuggestionState', () => { const state = getSuggestionState(values, 'text'); expect(state).toEqual({ + labeled: false, withValue: true, withSuggestion: false, + match: undefined, hasContext: false, obsolete: false, processing: false, @@ -219,13 +222,39 @@ describe('getIXSuggestionState', () => { const state = getSuggestionState(values, 'text'); expect(state).toEqual({ + labeled: false, withValue: false, withSuggestion: true, + match: undefined, hasContext: false, obsolete: true, processing: false, error: false, }); }); + + it('should mark processing when status is processing and set obsolete as true', () => { + const values = { + currentValue: '', + date: 1234, + labeledValue: '', + suggestedValue: 'some value', + modelCreationDate: 1, + status: 'processing', + }; + + const state = getSuggestionState(values, 'text'); + + expect(state).toEqual({ + labeled: false, + withValue: false, + withSuggestion: true, + match: undefined, + hasContext: false, + obsolete: true, + processing: true, + error: false, + }); + }); }); }); diff --git a/app/shared/types/suggestionSchema.ts b/app/shared/types/suggestionSchema.ts index 7d3568d8fa..e0ce40cf38 100644 --- a/app/shared/types/suggestionSchema.ts +++ b/app/shared/types/suggestionSchema.ts @@ -85,7 +85,15 @@ export const IXSuggestionStateSchema = { processing: { type: 'boolean' }, error: { type: 'boolean' }, }, - required: ['withValue', 'withSuggestion', 'hasContext', 'processing', 'obsolete', 'error'], + required: [ + 'labeled', + 'withValue', + 'withSuggestion', + 'hasContext', + 'processing', + 'obsolete', + 'error', + ], }; export const IXSuggestionSchema = { diff --git a/app/shared/types/suggestionType.d.ts b/app/shared/types/suggestionType.d.ts index a42a738dfa..be4626461a 100644 --- a/app/shared/types/suggestionType.d.ts +++ b/app/shared/types/suggestionType.d.ts @@ -81,7 +81,7 @@ export interface IXSuggestionType { } export interface IXSuggestionStateType { - labeled?: boolean; + labeled: boolean; withValue: boolean; withSuggestion: boolean; match?: boolean;