Skip to content

Commit

Permalink
Added logic for processing to refelct obsolete
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaPolit committed Sep 23, 2024
1 parent 6612ef5 commit 0062aab
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 6 deletions.
7 changes: 3 additions & 4 deletions app/shared/getIXSuggestionState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -71,7 +71,6 @@ class IXSuggestionState implements IXSuggestionStateType {
{ labeledValue, currentValue }: SuggestionValues,
propertyType: PropertySchema['type']
) {
this.labeled = false;
if (
labeledValue ||
(propertyIsSelect(propertyType) && currentValue) ||
Expand Down Expand Up @@ -129,21 +128,21 @@ class IXSuggestionState implements IXSuggestionStateType {
setObsolete({ modelCreationDate, date }: SuggestionValues) {
if (date < modelCreationDate) {
this.obsolete = true;
this.labeled = undefined;
this.match = undefined;
}
}

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;
}
}
Expand Down
29 changes: 29 additions & 0 deletions app/shared/specs/getIXSuggestionState.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable max-statements */
import { getSuggestionState, SuggestionValues } from '../getIXSuggestionState';

describe('getIXSuggestionState', () => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 = <SuggestionValues>{
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,
});
});
});
});
10 changes: 9 additions & 1 deletion app/shared/types/suggestionSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
2 changes: 1 addition & 1 deletion app/shared/types/suggestionType.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export interface IXSuggestionType {
}

export interface IXSuggestionStateType {
labeled?: boolean;
labeled: boolean;
withValue: boolean;
withSuggestion: boolean;
match?: boolean;
Expand Down

0 comments on commit 0062aab

Please sign in to comment.