Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow help messages configuration from config.json #1000

Merged
merged 1 commit into from
Nov 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/app/app-config.service.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HttpClient } from "@angular/common/http";
import { TestBed } from "@angular/core/testing";
import { AppConfig, AppConfigService } from "app-config.service";
import { AppConfig, AppConfigService, HelpMessages } from "app-config.service";
import { of } from "rxjs";
import { MockHttp } from "shared/MockStubs";

Expand Down Expand Up @@ -120,7 +120,8 @@ const appConfig: AppConfig = {
tableSciDataEnabled: true,
fileserverBaseURL: "",
fileserverButtonLabel: "",
datasetDetailsShowMissingProposalId: true
datasetDetailsShowMissingProposalId: true,
helpMessages: new HelpMessages(),
};

describe("AppConfigService", () => {
Expand Down Expand Up @@ -160,4 +161,5 @@ describe("AppConfigService", () => {
expect(config).toEqual(appConfig);
});
});

});
15 changes: 15 additions & 0 deletions src/app/app-config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@ export class RetrieveDestinations {
option = "";
}

export class HelpMessages {
ingestManual: string;
gettingStarted: string;

constructor(
gettingStarted = "gives a brief description on how to get started using the data catalog.",
ingestManual = `provides detailed information on how to make your data available to the
catalog as well as archiving and retrieval of datasets.`
) {
this.gettingStarted = gettingStarted;
this.ingestManual = ingestManual;
}
}

export interface AppConfig {
accessTokenPrefix: string;
addDatasetEnabled: boolean;
Expand Down Expand Up @@ -58,6 +72,7 @@ export interface AppConfig {
fileserverBaseURL: string;
fileserverButtonLabel: string | undefined;
datasetDetailsShowMissingProposalId: boolean;
helpMessages?: HelpMessages;
}

@Injectable()
Expand Down
5 changes: 2 additions & 3 deletions src/app/help/help/help.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</mat-card-header>
The
<a href="{{ gettingStarted }}" target="blank">Getting Started Guide</a>
gives a brief description on how to get started using the data catalog.
{{ helpMessages.gettingStarted }}
</mat-card>
</p>

Expand Down Expand Up @@ -65,8 +65,7 @@
</mat-card-header>
The
<a href="{{ ingestManual }}" target="blank">Ingest Manual</a>
provides detailed information on how to make your data available to the
catalog as well as archiving and retrieval of datasets.
{{ helpMessages.ingestManual }}
</mat-card>
</p>

Expand Down
47 changes: 46 additions & 1 deletion src/app/help/help/help.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { ComponentFixture, TestBed, waitForAsync } from "@angular/core/testing";
import { HelpComponent } from "./help.component";
import { MatCardModule } from "@angular/material/card";
import { AppConfigService } from "app-config.service";
import { AppConfigService, HelpMessages } from "app-config.service";

const getConfig = () => ({
facility: "ESS",
gettingStarted: true,
ingestManual: true
});

const helpMessages = new HelpMessages();

describe("HelpComponent", () => {
let component: HelpComponent;
let fixture: ComponentFixture<HelpComponent>;
Expand Down Expand Up @@ -42,4 +46,45 @@ describe("HelpComponent", () => {
it("should create", () => {
expect(component).toBeTruthy();
});

it("should have default messages", () => {
const compiled = fixture.debugElement.nativeElement;
expect(compiled.innerHTML).toContain(helpMessages.gettingStarted);
expect(compiled.innerHTML).toContain(helpMessages.ingestManual);
});

describe("should have custom messages", () => {
let customHelpMessages: HelpMessages;
beforeEach(() => {
fixture = TestBed.createComponent(HelpComponent);
component = fixture.componentInstance;
customHelpMessages = { gettingStarted: "someGettingStart", ingestManual: "someOtherIngest" };
component.appConfig.helpMessages = customHelpMessages;
fixture.detectChanges();
});

it("should have custom messages", () => {
const compiled = fixture.debugElement.nativeElement;
expect(compiled.innerHTML).toContain(customHelpMessages.gettingStarted);
expect(compiled.innerHTML).toContain(customHelpMessages.ingestManual);
});
});

describe("should set only one custom message", () => {
let customHelpMessages: HelpMessages;
beforeEach(() => {
fixture = TestBed.createComponent(HelpComponent);
component = fixture.componentInstance;
customHelpMessages = new HelpMessages("someGettingStart");
component.appConfig.helpMessages = customHelpMessages;
fixture.detectChanges();
});

it("should set only one custom message", () => {
const compiled = fixture.debugElement.nativeElement;
expect(compiled.innerHTML).toContain(customHelpMessages.gettingStarted);
expect(compiled.innerHTML).toContain(helpMessages.ingestManual);
});
});

});
7 changes: 6 additions & 1 deletion src/app/help/help/help.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Component, OnInit } from "@angular/core";
import { AppConfigService } from "app-config.service";
import { AppConfigService, HelpMessages } from "app-config.service";

@Component({
selector: "help",
Expand All @@ -12,11 +12,16 @@ export class HelpComponent implements OnInit {
ingestManual: string | null = null;
gettingStarted: string | null = null;
shoppingCartEnabled = false;
helpMessages: HelpMessages;
constructor(public appConfigService: AppConfigService) {}

ngOnInit() {
this.facility = this.appConfig.facility;
this.ingestManual = this.appConfig.ingestManual;
this.helpMessages = new HelpMessages(
this.appConfig.helpMessages?.gettingStarted,
this.appConfig.helpMessages?.ingestManual
);
this.gettingStarted = this.appConfig.gettingStarted;
this.shoppingCartEnabled = this.appConfig.shoppingCartEnabled;
}
Expand Down