Skip to content

Commit

Permalink
Merge pull request #92 from plblum/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
plblum authored Sep 28, 2024
2 parents bf5d0e0 + ff3b157 commit c1a9c15
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ export interface IValidatableValueHostBase extends IValueHost, IGatherValueHostN
*/
asyncProcessing: boolean;

/**
* Exposes the current validation state for the ValueHost.
* It combines other properties and issuesFound.
* The same value is delivered to the onValueHostValidationStateChanged callback.
*/
currentValidationState: ValueHostValidationState;

/**
* When Business Logic gathers data from the UI, it runs its own final validation.
* If its own business rule has been violated, it should be passed here where it becomes exposed to
Expand Down
2 changes: 1 addition & 1 deletion packages/jivs-engine/src/Interfaces/ValidationManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface IValidationManager extends IValueHostsManager {
/**
* Provides access to ValidationServices (override IServices).
*/
services: IValidationServices;
readonly services: IValidationServices;

startModifying(): ValidationManagerConfigModifier;
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/jivs-engine/src/Interfaces/ValueHostsManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export interface IValueHostsManager extends IValueHostResolver, IDisposable
/**
* Typecast from IServices
*/
services: IValueHostsServices;
readonly services: IValueHostsServices;

/**
* Adds a ValueHostConfig for a ValueHost not previously added.
Expand Down Expand Up @@ -262,7 +262,7 @@ export function toIValueHostsManager(source: any): IValueHostsManager | null
*/
export interface IValueHostsManagerAccessor
{
valueHostsManager: IValueHostsManager;
readonly valueHostsManager: IValueHostsManager;
}

/**
Expand Down
28 changes: 18 additions & 10 deletions packages/jivs-engine/src/ValueHosts/ValidatableValueHostBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ValueHostConfig, type SetValueOptions } from '../Interfaces/ValueHost';
import { ValueHostBase } from './ValueHostBase';
import type { IValueHostGenerator } from '../Interfaces/ValueHostFactory';
import { IValueHostResolver } from '../Interfaces/ValueHostResolver';
import { IValidatableValueHostBase, ValidatableValueHostBaseConfig, ValidatableValueHostBaseInstanceState } from '../Interfaces/ValidatableValueHostBase';
import { IValidatableValueHostBase, ValidatableValueHostBaseConfig, ValidatableValueHostBaseInstanceState, ValueHostValidationState } from '../Interfaces/ValidatableValueHostBase';
import { BusinessLogicError, IssueFound, ValidateOptions, ValueHostValidateResult, ValidationStatus, ValidationSeverity, SetIssuesFoundErrorCodeMissingBehavior } from '../Interfaces/Validation';
import { IValidationManager, toIValidationManager, toIValidationManagerCallbacks } from '../Interfaces/ValidationManager';
import { IValueHostsManager, toIValueHostsManager } from '../Interfaces/ValueHostsManager';
Expand Down Expand Up @@ -414,15 +414,23 @@ export abstract class ValidatableValueHostBase<TConfig extends ValidatableValueH
// the call to notify to be queued inside of debounce by the time onValueHostValidationStateChanged is invoked,
// so we can leverage the onValueHostValidationStateChanged to advance the mock timer. (Ugh)
toIValidationManager(this.valueHostsManager)?.notifyValidationStateChanged(null, options);
toIValidationManagerCallbacks(this.valueHostsManager)?.onValueHostValidationStateChanged?.(this,
{
issuesFound: this.getIssuesFound(),
isValid: this.isValid,
doNotSave: this.doNotSave,
asyncProcessing: this.asyncProcessing,
status: this.validationStatus,
corrected: this.corrected
});
toIValidationManagerCallbacks(this.valueHostsManager)?.onValueHostValidationStateChanged?.(this, this.currentValidationState);
}

/**
* Exposes the current validation state for the ValueHost.
* It combines other properties and issuesFound.
* The same value is delivered to the onValueHostValidationStateChanged callback.
*/
public get currentValidationState(): ValueHostValidationState {
return {
issuesFound: this.getIssuesFound(),
isValid: this.isValid,
doNotSave: this.doNotSave,
asyncProcessing: this.asyncProcessing,
status: this.validationStatus,
corrected: this.corrected
}
}

/**
Expand Down
7 changes: 5 additions & 2 deletions packages/jivs-engine/tests/TestSupport/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { DataTypeFormatterService } from "../../src/Services/DataTypeFormatterSe
import { InputValueHost } from "../../src/ValueHosts/InputValueHost";
import { IMessageTokenResolverService } from "../../src/Interfaces/MessageTokenResolverService";
import { registerAllConditions, registerDataTypeConverters, registerDataTypeFormatters } from "../../src/Support/createValidationServicesForTesting";
import { ValueHostValidationStateChangedHandler } from "../../src/Interfaces/ValidatableValueHostBase";
import { ValueHostValidationState, ValueHostValidationStateChangedHandler } from "../../src/Interfaces/ValidatableValueHostBase";
import { populateServicesWithManyCultures } from "./utilities";
import { registerTestingOnlyConditions } from "../../src/Support/conditionsForTesting";
import { ValueHostName } from "../../src/DataTypes/BasicTypes";
Expand Down Expand Up @@ -205,7 +205,10 @@ export class MockInputValueHost extends MockValueHost
}

validationStatus: ValidationStatus = ValidationStatus.NotAttempted;

get currentValidationState(): ValueHostValidationState {
throw new Error("Method not implemented.");
}

setBusinessLogicError(error: BusinessLogicError): boolean {
throw new Error("Method not implemented.");
}
Expand Down
5 changes: 5 additions & 0 deletions packages/jivs-engine/tests/ValueHosts/InputValueHost.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1362,6 +1362,11 @@ describe('toIInputValueHost function', () => {
get doNotSave(): boolean {
throw new Error("Method not implemented.");
}

get currentValidationState(): ValueHostValidationState {
throw new Error("Method not implemented.");
}

getIssueFound(errorCode: string): IssueFound | null {
throw new Error("Method not implemented.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { FluentValidatorBuilder } from "../../src/ValueHosts/Fluent";
import { InputValueHost } from "../../src/ValueHosts/InputValueHost";
import { CalcValueHost } from "../../src/ValueHosts/CalcValueHost";
import { IValueHostsManager } from "../../src/Interfaces/ValueHostsManager";
import { ValueHostValidationState } from "../../src/Interfaces/ValidatableValueHostBase";

interface ITestSetupConfig {
services: MockValidationServices,
Expand Down Expand Up @@ -352,6 +353,10 @@ describe('toIPropertyValueHost function', () => {
isValid: boolean = true;
validationStatus: ValidationStatus = ValidationStatus.NotAttempted;
asyncProcessing: boolean = false;
get currentValidationState(): ValueHostValidationState {
throw new Error("Method not implemented.");
}

setBusinessLogicError(error: BusinessLogicError, options?: ValidateOptions | undefined): boolean {
throw new Error("Method not implemented.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,8 @@ describe('toIValidatableValueHostBase', () => {
validationStatus: ValidationStatus.NotAttempted,
asyncProcessing: false,
corrected: false,
currentValidationState: {} as any,

setBusinessLogicError: function (error: BusinessLogicError): boolean {
throw new Error('Function not implemented.');
},
Expand Down Expand Up @@ -1193,6 +1195,10 @@ describe('toIValidatableValueHostBase function', () => {
validationStatus: ValidationStatus = ValidationStatus.NotAttempted;
asyncProcessing: boolean = false;
corrected: boolean = false;
get currentValidationState(): ValueHostValidationState {
throw new Error("Method not implemented.");
}

setBusinessLogicError(error: BusinessLogicError): boolean {
throw new Error("Method not implemented.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3065,6 +3065,10 @@ describe('toIValidatorsValueHostBase function', () => {
validationStatus: ValidationStatus = ValidationStatus.NotAttempted;
asyncProcessing: boolean = false;
corrected: boolean = false;
get currentValidationState(): ValueHostValidationState {
throw new Error("Method not implemented.");
}

setBusinessLogicError(error: BusinessLogicError): boolean {
throw new Error("Method not implemented.");
}
Expand Down

0 comments on commit c1a9c15

Please sign in to comment.