From e6e0a2cd337355506bb7916fd60abb58277b762e Mon Sep 17 00:00:00 2001 From: Schottkyc137 <45085299+Schottkyc137@users.noreply.github.com> Date: Thu, 21 Oct 2021 11:27:00 +0200 Subject: [PATCH] fix: Colors for highest ASER level are correctly displayed closes #993 --- .../child-dev-project/aser/model/aser.spec.ts | 20 ++++++++-- src/app/child-dev-project/aser/model/aser.ts | 37 +++++++++++-------- .../aser/model/mathLevels.ts | 14 ++++--- .../aser/model/readingLevels.ts | 14 ++++--- .../configurable-enum.interface.ts | 5 +++ 5 files changed, 60 insertions(+), 30 deletions(-) diff --git a/src/app/child-dev-project/aser/model/aser.spec.ts b/src/app/child-dev-project/aser/model/aser.spec.ts index 63ed13cebb..b5172ffbf0 100644 --- a/src/app/child-dev-project/aser/model/aser.spec.ts +++ b/src/app/child-dev-project/aser/model/aser.spec.ts @@ -16,7 +16,6 @@ */ import { Aser } from "./aser"; -import { waitForAsync } from "@angular/core/testing"; import { Entity } from "../../../core/entity/model/entity"; import { EntitySchemaService } from "../../../core/entity/schema/entity-schema.service"; import { mathLevels } from "./mathLevels"; @@ -27,8 +26,6 @@ describe("Aser", () => { const ENTITY_TYPE = "Aser"; const entitySchemaService = new EntitySchemaService(); - beforeEach(waitForAsync(() => {})); - it("has correct _id and entityId and type", function () { const id = "test1"; const entity = new Aser(id); @@ -90,4 +87,21 @@ describe("Aser", () => { expect(entity.getWarningLevel()).toBe(WarningLevel.WARNING); }); + + it("has a warning level of OK if english is at it's highest level", () => { + const entity = new Aser(); + entity.english = readingLevels[readingLevels.length - 1]; + + expect(entity.getWarningLevel()).toBe(WarningLevel.OK); + }); + + it("has a warning level of OK if all values are at it's highest level", () => { + const entity = new Aser(); + entity.math = mathLevels[mathLevels.length - 1]; + entity.english = readingLevels[readingLevels.length - 1]; + entity.hindi = readingLevels[readingLevels.length - 1]; + entity.bengali = readingLevels[readingLevels.length - 1]; + + expect(entity.getWarningLevel()).toBe(WarningLevel.OK); + }); }); diff --git a/src/app/child-dev-project/aser/model/aser.ts b/src/app/child-dev-project/aser/model/aser.ts index 41ac3366cd..c672b3593c 100644 --- a/src/app/child-dev-project/aser/model/aser.ts +++ b/src/app/child-dev-project/aser/model/aser.ts @@ -18,27 +18,34 @@ import { Entity } from "../../../core/entity/model/entity"; import { DatabaseField } from "../../../core/entity/database-field.decorator"; import { DatabaseEntity } from "../../../core/entity/database-entity.decorator"; -import { ConfigurableEnumValue } from "../../../core/configurable-enum/configurable-enum.interface"; -import { mathLevels } from "./mathLevels"; -import { readingLevels } from "./readingLevels"; +import { + ConfigurableEnumConfig, + ConfigurableEnumValue, +} from "../../../core/configurable-enum/configurable-enum.interface"; +import { MathLevel, mathLevels } from "./mathLevels"; +import { ReadingLevel, readingLevels } from "./readingLevels"; import { WarningLevel } from "../../../core/entity/model/warning-level"; @DatabaseEntity("Aser") export class Aser extends Entity { - static isReadingPassedOrNA(level: ConfigurableEnumValue) { - if (!level || level.id === "") { - // not applicable - return true; - } - return level === readingLevels.find((it) => it.id === "read_paragraph"); + static isReadingPassedOrNA(level: ConfigurableEnumValue): boolean { + return this.isHighestLevelOrNA(level, readingLevels); + } + + static isMathPassedOrNA(level: ConfigurableEnumValue): boolean { + return this.isHighestLevelOrNA(level, mathLevels); } - static isMathPassedOrNA(level: ConfigurableEnumValue) { + static isHighestLevelOrNA( + level: ConfigurableEnumValue, + source: ConfigurableEnumConfig + ): boolean { if (!level || level.id === "") { // not applicable return true; } - return level === mathLevels.find((it) => it.id === "division"); + const index = source.findIndex((cEnumValue) => cEnumValue.id === level.id); + return index === source.length - 1; } @DatabaseField() child: string; // id of Child entity @@ -51,25 +58,25 @@ export class Aser extends Entity { dataType: "configurable-enum", innerDataType: "reading-levels", }) - hindi: ConfigurableEnumValue; + hindi: ReadingLevel; @DatabaseField({ label: $localize`:Label of the Bengali ASER result:Bengali`, dataType: "configurable-enum", innerDataType: "reading-levels", }) - bengali: ConfigurableEnumValue; + bengali: ReadingLevel; @DatabaseField({ label: $localize`:Label of the English ASER result:English`, dataType: "configurable-enum", innerDataType: "reading-levels", }) - english: ConfigurableEnumValue; + english: ReadingLevel; @DatabaseField({ label: $localize`:Label of the Math ASER result:Math`, dataType: "configurable-enum", innerDataType: "math-levels", }) - math: ConfigurableEnumValue; + math: MathLevel; @DatabaseField({ label: $localize`:Label for the remarks of a ASER result:Remarks`, }) diff --git a/src/app/child-dev-project/aser/model/mathLevels.ts b/src/app/child-dev-project/aser/model/mathLevels.ts index b88fe930a5..00af8d1eb5 100644 --- a/src/app/child-dev-project/aser/model/mathLevels.ts +++ b/src/app/child-dev-project/aser/model/mathLevels.ts @@ -1,10 +1,12 @@ -import { ConfigurableEnumValue } from "../../../core/configurable-enum/configurable-enum.interface"; +import { + ConfigurableEnumConfig, + ConfigurableEnumValue, + EMPTY, +} from "../../../core/configurable-enum/configurable-enum.interface"; -export const mathLevels: ConfigurableEnumValue[] = [ - { - id: "", - label: "", - }, +export type MathLevel = ConfigurableEnumValue; +export const mathLevels: ConfigurableEnumConfig = [ + EMPTY, { id: "Nothing", label: $localize`:Label math level:Nothing`, diff --git a/src/app/child-dev-project/aser/model/readingLevels.ts b/src/app/child-dev-project/aser/model/readingLevels.ts index c594316cfb..577f7a0f44 100644 --- a/src/app/child-dev-project/aser/model/readingLevels.ts +++ b/src/app/child-dev-project/aser/model/readingLevels.ts @@ -1,10 +1,12 @@ -import { ConfigurableEnumValue } from "../../../core/configurable-enum/configurable-enum.interface"; +import { + ConfigurableEnumConfig, + ConfigurableEnumValue, + EMPTY, +} from "../../../core/configurable-enum/configurable-enum.interface"; -export const readingLevels: ConfigurableEnumValue[] = [ - { - id: "", - label: "", - }, +export type ReadingLevel = ConfigurableEnumValue; +export const readingLevels: ConfigurableEnumConfig = [ + EMPTY, { id: "Nothing", label: $localize`:Label reading level:Nothing`, diff --git a/src/app/core/configurable-enum/configurable-enum.interface.ts b/src/app/core/configurable-enum/configurable-enum.interface.ts index 6ca3054b5b..c269d2ac58 100644 --- a/src/app/core/configurable-enum/configurable-enum.interface.ts +++ b/src/app/core/configurable-enum/configurable-enum.interface.ts @@ -32,6 +32,11 @@ export interface ConfigurableEnumValue { [x: string]: any; } +export const EMPTY: ConfigurableEnumValue = { + id: "", + label: "", +}; + /** * The prefix of all enum collection entries in the config database. *