Skip to content
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
14 changes: 8 additions & 6 deletions ui/src/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,34 @@ import {HttpClient} from "@angular/common/http"
export class AppConfig {

static settings: IAppConfig
environment: { production: boolean; baseApiUrl: string; loginUrl: string; dynamicWhitelabel: boolean }

constructor(
private http: HttpClient
) {
this.environment = environment
}

defaultConfig(): IAppConfig {
const settings = new DefaultAppConfig()
settings.baseApiUrl = environment.baseApiUrl
settings.loginUrl = environment.loginUrl
settings.baseApiUrl = this.environment.baseApiUrl
settings.loginUrl = this.environment.loginUrl
return settings
}

load(): Promise<object> {
const baseUrl = environment.baseApiUrl
const baseUrl = this.environment.baseApiUrl

if (environment.dynamicWhitelabel) {
if (this.environment.dynamicWhitelabel) {
return this.http.get(`${baseUrl}/whitelabel/whitelabel.json`)
.toPromise()
.then(value => {
AppConfig.settings = this.defaultConfig()
Object.assign(AppConfig.settings, value as IAppConfig)

// baseApiUrl and loginUrl are not runtime whitelabellable
AppConfig.settings.baseApiUrl = environment.baseApiUrl
AppConfig.settings.loginUrl = environment.loginUrl
AppConfig.settings.baseApiUrl = this.environment.baseApiUrl
AppConfig.settings.loginUrl = this.environment.loginUrl
return value
}).catch(reason => {
AppConfig.settings = this.defaultConfig()
Expand Down
2 changes: 1 addition & 1 deletion ui/src/app/auth/auth-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class AuthService extends Whitelabelled implements IAuthService {

storeToken(accessToken: string): void {
localStorage.setItem(STORAGE_KEY_TOKEN, accessToken)
localStorage.setItem(STORAGE_KEY_ROLE, JSON.parse(atob(accessToken.split(".")[1])).roles)
localStorage.setItem(STORAGE_KEY_ROLE, JSON.parse(atob(accessToken.split(".")[1]))?.roles)
}

storeReturn(returnRoute: string): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Type } from "@angular/core"
import { async, ComponentFixture, TestBed } from "@angular/core/testing"
import { ActivatedRoute, Router } from "@angular/router"
import { ActivatedRouteStubSpec } from "test/util/activated-route-stub.spec"
import { RichSkillServiceStub } from "../../../../../test/resource/mock-stubs"
import { RichSkillService } from "../../../richskill/service/rich-skill.service"
import { ToastService } from "../../../toast/toast.service"
import { PublicCollectionDetailCardComponent } from "./public-collection-detail-card.component"


export function createComponent(T: Type<PublicCollectionDetailCardComponent>): Promise<void> {
fixture = TestBed.createComponent(T)
component = fixture.componentInstance

// 1st change detection triggers ngOnInit which gets a hero
fixture.detectChanges()

return fixture.whenStable().then(() => {
// 2nd change detection displays the async-fetched hero
fixture.detectChanges()
})
}


let activatedRoute: ActivatedRouteStubSpec
let component: PublicCollectionDetailCardComponent
let fixture: ComponentFixture<PublicCollectionDetailCardComponent>


describe("PublicCollectionDetailCardComponent", () => {
beforeEach(() => {
activatedRoute = new ActivatedRouteStubSpec()
})

beforeEach(async(() => {
const routerSpy = ActivatedRouteStubSpec.createRouterSpy()

TestBed.configureTestingModule({
declarations: [
PublicCollectionDetailCardComponent
],
imports: [
],
providers: [
ToastService,
{ provide: RichSkillService, useClass: RichSkillServiceStub },
{ provide: ActivatedRoute, useValue: activatedRoute },
{ provide: Router, useValue: routerSpy },
]
})
.compileComponents()

createComponent(PublicCollectionDetailCardComponent)
}))

it("should be created", () => {
expect(component).toBeTruthy()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { HttpClientTestingModule } from "@angular/common/http/testing"
import { Component, Type } from "@angular/core"
import { async, ComponentFixture, TestBed } from "@angular/core/testing"
import { FormsModule } from "@angular/forms"
import { By } from "@angular/platform-browser"
import { RouterTestingModule } from "@angular/router/testing"
import { AppConfig } from "src/app/app.config"
import { AuthService } from "src/app/auth/auth-service"
import { EnvironmentService } from "src/app/core/environment.service"
import { RichSkillService } from "src/app/richskill/service/rich-skill.service"
import { ToastService } from "src/app/toast/toast.service"
import { AuthServiceStub, RichSkillServiceStub } from "test/resource/mock-stubs"
import { ManageSkillActionBarHorizontalComponent } from "./manage-skill-action-bar-horizontal.component"


@Component({
template: `
<app-manage-skill-action-bar-horizontal
[skillUuid]="mySkillUuid"
[skillName]="mySkillName"
[archived]="myArchived"
[published]="myPublished">
</app-manage-skill-action-bar-horizontal>`
})
class TestHostComponent {
mySkillUuid = "1234"
mySkillName = "my skill name"
myArchived = false
myPublished = false
}


export function createComponent(T: Type<TestHostComponent>): Promise<void> {
hostFixture = TestBed.createComponent(T)
hostComponent = hostFixture.componentInstance

const debugEl = hostFixture.debugElement.query(By.directive(ManageSkillActionBarHorizontalComponent))
childComponent = debugEl.componentInstance

// 1st change detection triggers ngOnInit which gets a hero
hostFixture.detectChanges()

return hostFixture.whenStable().then(() => {
// 2nd change detection displays the async-fetched hero
hostFixture.detectChanges()
})
}


let hostFixture: ComponentFixture<TestHostComponent>
let hostComponent: TestHostComponent
let childComponent: ManageSkillActionBarHorizontalComponent


describe("ManageSkillActionBarHorizontalComponent", () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
ManageSkillActionBarHorizontalComponent,
TestHostComponent
],
imports: [
FormsModule, // Required for ([ngModel])
RouterTestingModule, // Required for routerLink
HttpClientTestingModule, // Needed to avoid the toolName race condition below
],
providers: [
EnvironmentService, // Needed to avoid the toolName race condition below
AppConfig, // Needed to avoid the toolName race condition below
ToastService,
{ provide: RichSkillService, useClass: RichSkillServiceStub },
{ provide: AuthService, useClass: AuthServiceStub },
]
})
.compileComponents()

const appConfig = TestBed.inject(AppConfig)
AppConfig.settings = appConfig.defaultConfig() // This avoids the race condition on reading the config's whitelabel.toolName

createComponent(TestHostComponent)
}))

it("should be created", () => {
expect(hostComponent).toBeTruthy()
})
})
File renamed without changes
File renamed without changes
File renamed without changes