diff --git a/src/__tests__/environment/Generator.ts b/src/__tests__/environment/Generator.ts index cd71a6fff..60e53f5ae 100644 --- a/src/__tests__/environment/Generator.ts +++ b/src/__tests__/environment/Generator.ts @@ -113,7 +113,7 @@ export default class Generator { Generator.generateUri(), { iri: termIri, label: { cs: "Test term" } }, { iri: VocabularyUtils.SH_VIOLATION }, - [{ language: "cs", value: "Chyba" }], + { cs: "Chyba" }, { iri: "https://example.org/sourceShape" }, { iri: VocabularyUtils.SKOS_PREF_LABEL } ); diff --git a/src/action/__tests__/AsyncActions.test.ts b/src/action/__tests__/AsyncActions.test.ts index a1a071bbd..614faccc8 100644 --- a/src/action/__tests__/AsyncActions.test.ts +++ b/src/action/__tests__/AsyncActions.test.ts @@ -1394,7 +1394,7 @@ describe("Async actions", () => { "@id" ] ); - expect(array[i].message.length).toEqual( + expect(Object.getOwnPropertyNames(array[i].message).length).toEqual( validationResults[i]["http://www.w3.org/ns/shacl#resultMessage"] .length ); @@ -1427,7 +1427,7 @@ describe("Async actions", () => { "@id" ] ); - expect(array[0].message.length).toEqual( + expect(Object.getOwnPropertyNames(array[0].message).length).toEqual( validationResults[0]["http://www.w3.org/ns/shacl#resultMessage"] .length ); diff --git a/src/model/ValidationResult.ts b/src/model/ValidationResult.ts index da0112cd6..c5cde7638 100644 --- a/src/model/ValidationResult.ts +++ b/src/model/ValidationResult.ts @@ -1,32 +1,26 @@ import VocabularyUtils from "../util/VocabularyUtils"; -import { TermData } from "./Term"; -import { CONTEXT as TERM_CONTEXT } from "./Term"; -import { CONTEXT as LANG_STRING_CONTEXT, LangString } from "./LangString"; +import { CONTEXT as TERM_CONTEXT, TermData } from "./Term"; import { Severity } from "./Severity"; import { SourceShape } from "./SourceShape"; import { ResultPath } from "./ResultPath"; +import { context, MultilingualString } from "./MultilingualString"; // @id and @type are merged from ASSET_CONTEXT const ctx = { term: VocabularyUtils.SH_FOCUS_NODE, severity: VocabularyUtils.SH_RESULT_SEVERITY, - message: VocabularyUtils.SH_RESULT_MESSAGE, + message: context(VocabularyUtils.SH_RESULT_MESSAGE), sourceShape: VocabularyUtils.SH_SOURCE_SHAPE, resultPath: VocabularyUtils.SH_RESULT_PATH, }; -export const CONTEXT = Object.assign( - {}, - TERM_CONTEXT, - LANG_STRING_CONTEXT, - ctx -); +export const CONTEXT = Object.assign({}, TERM_CONTEXT, ctx); export default class ValidationResult { public iri: string; public term: TermData; public severity: Severity; - public message: LangString[]; + public message: MultilingualString; public sourceShape: SourceShape; public resultPath: ResultPath; @@ -34,7 +28,7 @@ export default class ValidationResult { iri: string, term: TermData, severity: Severity, - message: LangString[], + message: MultilingualString, sourceShape: SourceShape, resultPath: ResultPath ) { diff --git a/src/model/form/ValidationResult.ts b/src/model/form/ValidationResult.ts index 134b4c3f4..20db11322 100644 --- a/src/model/form/ValidationResult.ts +++ b/src/model/form/ValidationResult.ts @@ -1,7 +1,7 @@ import OntoValidationResult from "../ValidationResult"; -import Utils from "../../util/Utils"; import { getShortLocale } from "../../util/IntlUtil"; import Validation from "../../util/Validation"; +import { getLocalized } from "../MultilingualString"; export enum Severity { BLOCKER, // Blocker severity indicates the form cannot be submitted and the input should have an error boundary @@ -42,10 +42,8 @@ export default class ValidationResult { locale: string ) { return new ValidationResult( - Validation.toSeverity(result.sourceShape.iri), - Utils.sanitizeArray(result.message).find( - (ls) => ls.language === getShortLocale(locale) - )?.value + Validation.toSeverity(result.sourceShape?.iri), + getLocalized(result.message, getShortLocale(locale)) ); } diff --git a/src/model/form/__tests__/ValidationResult.test.ts b/src/model/form/__tests__/ValidationResult.test.ts index 03f872935..a3dd8f5ee 100644 --- a/src/model/form/__tests__/ValidationResult.test.ts +++ b/src/model/form/__tests__/ValidationResult.test.ts @@ -11,7 +11,7 @@ describe("ValidationResult", () => { "en" ); expect(formResult.severity).toBeDefined(); - expect(formResult.message).not.toBeDefined(); + expect(formResult.message).toBeDefined(); }); it("constructs instance with correct severity", () => {