Skip to content

Commit

Permalink
Added flag to conditionally display unit list in metadata editing tab…
Browse files Browse the repository at this point in the history
…le. (#1373)

* Added flag to conditionally display unit list in metadata editing table.

* added unit test for metadataEditingUnitListDisabled feature
  • Loading branch information
Junjiequan authored Jan 19, 2024
1 parent ac30e67 commit ca2aa1d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/app/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export interface AppConfig {
helpMessages?: HelpMessages;
notificationInterceptorEnabled: boolean;
pidSearchMethod?: string;
metadataEditingUnitListDisabled?: boolean;
}

@Injectable()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import { NO_ERRORS_SCHEMA } from "@angular/core";

import { FormBuilder } from "@angular/forms";
import { ScientificMetadataModule } from "../scientific-metadata.module";
import { AppConfigService } from "app-config.service";

const getConfig = () => ({
metadataEditingUnitListDisabled: true,
});

describe("MetadataEditComponent", () => {
let component: MetadataEditComponent;
Expand All @@ -17,6 +22,16 @@ describe("MetadataEditComponent", () => {
imports: [ScientificMetadataModule],
providers: [FormBuilder],
}).compileComponents();
TestBed.overrideComponent(MetadataEditComponent, {
set: {
providers: [
{
provide: AppConfigService,
useValue: { getConfig },
},
],
},
});
}));

beforeEach(() => {
Expand Down Expand Up @@ -256,14 +271,27 @@ describe("MetadataEditComponent", () => {
});

describe("#getUnits()", () => {
it("should get an array of units based on the value of fieldName", () => {
it("should get an array of units based on the value of fieldName if metadataEditingUnitListDisabled is false", () => {
component.appConfig.metadataEditingUnitListDisabled = false;

component.addMetadata();
component.items.at(0).get("fieldName").setValue("elapsed_time");

component.getUnits(0);

expect(component.units.includes("seconds")).toEqual(true);
});

it("should not get an array of units based on the value of fieldName if metadataEditingUnitListDisabled is true", () => {
component.appConfig.metadataEditingUnitListDisabled = true;

component.addMetadata();
component.items.at(0).get("fieldName").setValue("elapsed_time");

component.getUnits(0);

expect(component.units).toEqual([]);
});
});

describe("#setValueInputType()", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { UnitsService } from "shared/services/units.service";
import { startWith, map } from "rxjs/operators";
import { Observable } from "rxjs";
import { ScientificMetadata } from "../scientific-metadata.module";
import { AppConfigService } from "app-config.service";

@Component({
selector: "metadata-edit",
Expand All @@ -34,6 +35,8 @@ export class MetadataEditComponent implements OnInit, OnChanges {
});
typeValues: string[] = ["quantity", "number", "string"];
units: string[] = [];
appConfig = this.appConfigService.getConfig();

filteredUnits$: Observable<string[]> | undefined = new Observable<string[]>();
invalidUnitWarning: string[] = [];
@Input() metadata: Record<string, any> | undefined;
Expand All @@ -42,6 +45,7 @@ export class MetadataEditComponent implements OnInit, OnChanges {
constructor(
private formBuilder: FormBuilder,
private unitsService: UnitsService,
private appConfigService: AppConfigService,
) {}

addMetadata() {
Expand Down Expand Up @@ -180,8 +184,9 @@ export class MetadataEditComponent implements OnInit, OnChanges {

getUnits(index: number): void {
const name = this.items.at(index).get("fieldName")?.value;

this.units = this.unitsService.getUnits(name);
this.units = this.appConfig.metadataEditingUnitListDisabled
? []
: this.unitsService.getUnits(name);

this.filteredUnits$ = this.items
.at(index)
Expand Down

0 comments on commit ca2aa1d

Please sign in to comment.