diff --git a/src/ILICheck.Web/ClientApp/src/logHierarchy.test.js b/src/ILICheck.Web/ClientApp/src/logHierarchy.test.js new file mode 100644 index 0000000..5ea2f66 --- /dev/null +++ b/src/ILICheck.Web/ClientApp/src/logHierarchy.test.js @@ -0,0 +1,143 @@ +import { describe, expect, test } from "@jest/globals"; +import { createLogHierarchy } from "./logHierarchy"; + +describe("transform log data to hierarchy", () => { + test("constraint pass", () => { + const data = [ + { + tid: "o1", + message: "validate set constraint ModelA.TopicA.ClassA.ConstraintName...", + type: "Info", + }, + ]; + + const expected = [ + { + message: "ModelA", + type: "Info", + values: [ + { + message: "TopicA.ClassA", + type: "Info", + values: [{ message: "Set Constraint ConstraintName", type: "Info" }], + }, + ], + }, + ]; + + const hierarchy = createLogHierarchy(data); + + expect(hierarchy).toStrictEqual(expected); + }); + + test("constraint fail", () => { + const data = [ + { + tid: "o1", + message: "validate existence constraint ModelA.TopicA.ClassA.ConstraintName...", + type: "Info", + }, + { + tid: "o2", + message: "Some other message", + type: "Info", + }, + { + tid: "o3", + message: + "Existence constraint ModelA.TopicA.ClassA.ConstraintName is violated! The value of the attribute Test of t1 was not found in the condition class.", + type: "Error", + }, + ]; + + const expected = [ + { + message: "ModelA", + type: "Error", + values: [ + { + message: "TopicA.ClassA", + type: "Error", + values: [ + { + message: + "Existence constraint ConstraintName is violated! The value of the attribute Test of t1 was not found in the condition class.", + type: "Error", + }, + ], + }, + ], + }, + ]; + + const hierarchy = createLogHierarchy(data); + + expect(hierarchy).toStrictEqual(expected); + }); + + test("mixed log types", () => { + const data = [ + { + tid: "o1", + message: "validate data...", + type: "Info", + }, + { + tid: "o2", + message: "lookup model 2.3 in repository ", + type: "Info", + }, + { + tid: "o3", + message: "validate mandatory constraint ModelA.TopicA.ClassA.ConstraintName...", + type: "Info", + }, + { + tid: "o4", + message: + "MandatoryConstraint ModelA.TopicA.ClassA.ConstraintName of ModelA.TopicA.ClassA is not yet implemented.", + type: "Warning", + }, + { + tid: "o5", + message: "validate mandatory constraint ModelA.TopicA.ClassA.Constraint1...", + type: "Info", + }, + { + tid: "o6", + message: "validate mandatory constraint ModelA.TopicA.ClassA.Constraint2...", + type: "Info", + }, + { + tid: "o7", + message: "Custom message for constraint. ModelA.TopicA.ClassA.Constraint1 (MANDATORY CONSTRAINT DEFINED(Abc);)", + type: "Error", + }, + ]; + + const expected = [ + { + message: "ModelA", + type: "Error", + values: [ + { + message: "TopicA.ClassA", + type: "Error", + values: [ + { + message: "MandatoryConstraint ConstraintName of ModelA.TopicA.ClassA is not yet implemented.", + type: "Warning", + }, + { message: "Custom message for constraint.", type: "Error" }, + { message: "Mandatory Constraint Constraint2", type: "Info" }, + ], + }, + ], + }, + ]; + + const hierarchy = createLogHierarchy(data); + + expect(hierarchy).toStrictEqual(expected); + }); +});