diff --git a/custom-src/frontend/app/custom/kubernetes/auth-forms/kubernetes-config-auth-form/kubernetes-config-auth-form.component.spec.ts b/custom-src/frontend/app/custom/kubernetes/auth-forms/kubernetes-config-auth-form/kubernetes-config-auth-form.component.spec.ts index f9cd740fc5..0fd0b060d0 100644 --- a/custom-src/frontend/app/custom/kubernetes/auth-forms/kubernetes-config-auth-form/kubernetes-config-auth-form.component.spec.ts +++ b/custom-src/frontend/app/custom/kubernetes/auth-forms/kubernetes-config-auth-form/kubernetes-config-auth-form.component.spec.ts @@ -1,9 +1,9 @@ -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { SharedModule } from '../../../../shared/shared.module'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { FormBuilder } from '@angular/forms'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { SharedModule } from '../../../../shared/shared.module'; import { KubernetesConfigAuthFormComponent } from './kubernetes-config-auth-form.component'; -import { FormBuilder } from '@angular/forms'; describe('KubernetesConfigAuthFormComponent', () => { let component: KubernetesConfigAuthFormComponent; @@ -11,13 +11,13 @@ describe('KubernetesConfigAuthFormComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ KubernetesConfigAuthFormComponent ], + declarations: [KubernetesConfigAuthFormComponent], imports: [ SharedModule, NoopAnimationsModule ] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/custom-src/frontend/app/custom/kubernetes/auth-forms/kubernetes-gke-auth-form/kubernetes-gke-auth-form.component.spec.ts b/custom-src/frontend/app/custom/kubernetes/auth-forms/kubernetes-gke-auth-form/kubernetes-gke-auth-form.component.spec.ts index 67dbff717f..1327730757 100644 --- a/custom-src/frontend/app/custom/kubernetes/auth-forms/kubernetes-gke-auth-form/kubernetes-gke-auth-form.component.spec.ts +++ b/custom-src/frontend/app/custom/kubernetes/auth-forms/kubernetes-gke-auth-form/kubernetes-gke-auth-form.component.spec.ts @@ -1,9 +1,9 @@ -import { NoopAnimationsModule } from '@angular/platform-browser/animations'; -import { SharedModule } from '../../../../shared/shared.module'; import { async, ComponentFixture, TestBed } from '@angular/core/testing'; +import { FormBuilder } from '@angular/forms'; +import { NoopAnimationsModule } from '@angular/platform-browser/animations'; +import { SharedModule } from '../../../../shared/shared.module'; import { KubernetesGKEAuthFormComponent } from './kubernetes-gke-auth-form.component'; -import { FormBuilder } from '@angular/forms'; describe('KubernetesGKEAuthFormComponent', () => { let component: KubernetesGKEAuthFormComponent; @@ -11,13 +11,13 @@ describe('KubernetesGKEAuthFormComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ - declarations: [ KubernetesGKEAuthFormComponent ], + declarations: [KubernetesGKEAuthFormComponent], imports: [ SharedModule, NoopAnimationsModule ] }) - .compileComponents(); + .compileComponents(); })); beforeEach(() => { diff --git a/custom-src/frontend/app/custom/kubernetes/kubernetes-dashboard/kubernetes-dashboard.component.ts b/custom-src/frontend/app/custom/kubernetes/kubernetes-dashboard/kubernetes-dashboard.component.ts index 50941b9b97..c6a9049a49 100644 --- a/custom-src/frontend/app/custom/kubernetes/kubernetes-dashboard/kubernetes-dashboard.component.ts +++ b/custom-src/frontend/app/custom/kubernetes/kubernetes-dashboard/kubernetes-dashboard.component.ts @@ -31,7 +31,17 @@ import { KubernetesService } from '../services/kubernetes.service'; }) export class KubernetesDashboardTabComponent implements OnInit { - @ViewChild('kubeDash', { read: ElementRef }) kubeDash: ElementRef; + private pKubeDash: ElementRef; + @ViewChild('kubeDash', { read: ElementRef }) set kubeDash(kubeDash: ElementRef) { + if (!this.pKubeDash) { + this.pKubeDash = kubeDash; + // Need to look at this process again. In tests this is never hit, leading to null references to kubeDash + this.setupEventListener(); + } + } + get kubeDash(): ElementRef { + return this.pKubeDash; + } source: SafeResourceUrl; isLoading$ = new BehaviorSubject(true); @@ -41,6 +51,9 @@ export class KubernetesDashboardTabComponent implements OnInit { href = ''; + private haveSetupEventLister = false; + private hasIframeLoaded = false; + public breadcrumbs$: Observable; constructor(public kubeEndpointService: KubernetesEndpointService, private sanitizer: DomSanitizer, public renderer: Renderer2) { } @@ -72,6 +85,16 @@ export class KubernetesDashboardTabComponent implements OnInit { this.isLoading$.next(false); this.toggle(false); } + this.hasIframeLoaded = true; + this.setupEventListener(); + } + + setupEventListener() { + if (this.haveSetupEventLister || !this.kubeDash || !this.hasIframeLoaded) { + return; + } + + this.haveSetupEventLister = true; const iframeWindow = this.kubeDash.nativeElement.contentWindow; // console.log('iframe loaded'); @@ -100,7 +123,6 @@ export class KubernetesDashboardTabComponent implements OnInit { this.href = ''; } }); - } toggle(val: boolean) { @@ -119,7 +141,8 @@ export class KubernetesDashboardTabComponent implements OnInit { } private getKubeDashToolbar() { - if (this.kubeDash.nativeElement && + if (this.kubeDash && + this.kubeDash.nativeElement && this.kubeDash.nativeElement.contentDocument && this.kubeDash.nativeElement.contentDocument.getElementsByTagName) { const kdChrome = this.kubeDash.nativeElement.contentDocument.getElementsByTagName('kd-chrome')[0];