Skip to content

Commit

Permalink
Fix new unit test failure #2
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-cox committed Apr 23, 2019
1 parent 2bd840f commit faf5337
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
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;
let fixture: ComponentFixture<KubernetesConfigAuthFormComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ KubernetesConfigAuthFormComponent ],
declarations: [KubernetesConfigAuthFormComponent],
imports: [
SharedModule,
NoopAnimationsModule
]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
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;
let fixture: ComponentFixture<KubernetesGKEAuthFormComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ KubernetesGKEAuthFormComponent ],
declarations: [KubernetesGKEAuthFormComponent],
imports: [
SharedModule,
NoopAnimationsModule
]
})
.compileComponents();
.compileComponents();
}));

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>(true);
Expand All @@ -41,6 +51,9 @@ export class KubernetesDashboardTabComponent implements OnInit {

href = '';

private haveSetupEventLister = false;
private hasIframeLoaded = false;

public breadcrumbs$: Observable<IHeaderBreadcrumb[]>;

constructor(public kubeEndpointService: KubernetesEndpointService, private sanitizer: DomSanitizer, public renderer: Renderer2) { }
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -100,7 +123,6 @@ export class KubernetesDashboardTabComponent implements OnInit {
this.href = '';
}
});

}

toggle(val: boolean) {
Expand All @@ -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];
Expand Down

0 comments on commit faf5337

Please sign in to comment.