Skip to content

Commit

Permalink
fix: Colors for highest ASER level are correctly displayed
Browse files Browse the repository at this point in the history
closes #993
  • Loading branch information
Schottkyc137 authored Oct 21, 2021
1 parent c00dbcb commit e6e0a2c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 30 deletions.
20 changes: 17 additions & 3 deletions src/app/child-dev-project/aser/model/aser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);
Expand Down Expand Up @@ -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);
});
});
37 changes: 22 additions & 15 deletions src/app/child-dev-project/aser/model/aser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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`,
})
Expand Down
14 changes: 8 additions & 6 deletions src/app/child-dev-project/aser/model/mathLevels.ts
Original file line number Diff line number Diff line change
@@ -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<MathLevel> = [
EMPTY,
{
id: "Nothing",
label: $localize`:Label math level:Nothing`,
Expand Down
14 changes: 8 additions & 6 deletions src/app/child-dev-project/aser/model/readingLevels.ts
Original file line number Diff line number Diff line change
@@ -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<ReadingLevel> = [
EMPTY,
{
id: "Nothing",
label: $localize`:Label reading level:Nothing`,
Expand Down
5 changes: 5 additions & 0 deletions src/app/core/configurable-enum/configurable-enum.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down

0 comments on commit e6e0a2c

Please sign in to comment.