test(aio): reimplemented all the commented-out unit tests
This commit is contained in:
parent
2ebfa2ff31
commit
01ff427685
@ -1,6 +1,8 @@
|
|||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, inject, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { APP_BASE_HREF } from '@angular/common';
|
||||||
import { AppComponent } from './app.component';
|
import { AppComponent } from './app.component';
|
||||||
import { AppModule } from './app.module';
|
import { AppModule } from './app.module';
|
||||||
|
import { SearchService } from 'app/search/search.service';
|
||||||
|
|
||||||
describe('AppComponent', () => {
|
describe('AppComponent', () => {
|
||||||
let component: AppComponent;
|
let component: AppComponent;
|
||||||
@ -10,6 +12,7 @@ describe('AppComponent', () => {
|
|||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [ AppModule ],
|
imports: [ AppModule ],
|
||||||
providers: [
|
providers: [
|
||||||
|
{ provide: APP_BASE_HREF, useValue: '/' }
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
TestBed.compileComponents();
|
TestBed.compileComponents();
|
||||||
@ -23,4 +26,38 @@ describe('AppComponent', () => {
|
|||||||
it('should create', () => {
|
it('should create', () => {
|
||||||
expect(component).toBeDefined();
|
expect(component).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('isHamburgerVisible', () => {
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onResize', () => {
|
||||||
|
it('should update `isSideBySide` accordingly', () => {
|
||||||
|
component.onResize(1000);
|
||||||
|
expect(component.isSideBySide).toBe(true);
|
||||||
|
component.onResize(500);
|
||||||
|
expect(component.isSideBySide).toBe(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onSearch', () => {
|
||||||
|
it('should call the search service', inject([SearchService], (search: SearchService) => {
|
||||||
|
spyOn(search, 'search');
|
||||||
|
component.onSearch('some query');
|
||||||
|
expect(search.search).toHaveBeenCalledWith('some query');
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('currentDocument', () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('navigationViews', () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('searchResults', () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
@ -11,7 +11,7 @@ import { SearchService, QueryResults } from 'app/search/search.service';
|
|||||||
<button *ngIf="isHamburgerVisible" class="hamburger" md-button (click)="sidenav.toggle()"><md-icon>menu</md-icon></button>
|
<button *ngIf="isHamburgerVisible" class="hamburger" md-button (click)="sidenav.toggle()"><md-icon>menu</md-icon></button>
|
||||||
<aio-top-menu [nodes]="(navigationViews | async)?.TopBar"></aio-top-menu>
|
<aio-top-menu [nodes]="(navigationViews | async)?.TopBar"></aio-top-menu>
|
||||||
<md-input-container >
|
<md-input-container >
|
||||||
<input mdInput placeholder="Search" (keyup)="onSearch($event)">
|
<input mdInput placeholder="Search" (keyup)="onSearch($event.target.value)">
|
||||||
</md-input-container>
|
</md-input-container>
|
||||||
<span class="fill-remaining-space"></span>
|
<span class="fill-remaining-space"></span>
|
||||||
</md-toolbar>
|
</md-toolbar>
|
||||||
@ -86,9 +86,10 @@ import { SearchService, QueryResults } from 'app/search/search.service';
|
|||||||
]
|
]
|
||||||
})
|
})
|
||||||
export class AppComponent implements OnInit {
|
export class AppComponent implements OnInit {
|
||||||
|
readonly sideBySideWidth = 600;
|
||||||
|
|
||||||
isHamburgerVisible = true; // always ... for now
|
isHamburgerVisible = true; // always ... for now
|
||||||
isSideBySide = false;
|
isSideBySide = false;
|
||||||
sideBySideWidth = 600;
|
|
||||||
|
|
||||||
currentDocument: Observable<DocumentContents>;
|
currentDocument: Observable<DocumentContents>;
|
||||||
navigationViews: Observable<NavigationViews>;
|
navigationViews: Observable<NavigationViews>;
|
||||||
@ -111,9 +112,7 @@ export class AppComponent implements OnInit {
|
|||||||
this.isSideBySide = width > this.sideBySideWidth;
|
this.isSideBySide = width > this.sideBySideWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
onSearch(event: KeyboardEvent) {
|
onSearch(query: string) {
|
||||||
const query = (event.target as HTMLInputElement).value;
|
|
||||||
console.log(query);
|
|
||||||
this.searchService.search(query);
|
this.searchService.search(query);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,31 @@
|
|||||||
import { TestBed, inject } from '@angular/core/testing';
|
import { ReflectiveInjector } from '@angular/core';
|
||||||
|
import { Location, LocationStrategy } from '@angular/common';
|
||||||
|
import { MockLocationStrategy } from '@angular/common/testing';
|
||||||
|
import { Http, ConnectionBackend, RequestOptions, BaseRequestOptions } from '@angular/http';
|
||||||
|
import { MockBackend } from '@angular/http/testing';
|
||||||
|
import { LocationService } from 'app/shared/location.service';
|
||||||
|
import { Logger } from 'app/shared/logger.service';
|
||||||
import { DocumentService } from './document.service';
|
import { DocumentService } from './document.service';
|
||||||
|
|
||||||
describe('DocumentService', () => {
|
describe('DocumentService', () => {
|
||||||
|
|
||||||
|
let injector: ReflectiveInjector;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
injector = ReflectiveInjector.resolveAndCreate([
|
||||||
providers: [DocumentService]
|
DocumentService,
|
||||||
});
|
LocationService,
|
||||||
|
Location,
|
||||||
|
{ provide: LocationStrategy, useClass: MockLocationStrategy },
|
||||||
|
{ provide: ConnectionBackend, useClass: MockBackend },
|
||||||
|
{ provide: RequestOptions, useClass: BaseRequestOptions },
|
||||||
|
Http,
|
||||||
|
Logger
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ...', inject([DocumentService], (service: DocumentService) => {
|
it('should be creatable', () => {
|
||||||
|
const service: DocumentService = injector.get(DocumentService);
|
||||||
expect(service).toBeTruthy();
|
expect(service).toBeTruthy();
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
|
@ -1,305 +1,300 @@
|
|||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { ComponentFactoryResolver, ElementRef, Injector, NgModule, OnInit, ViewChild, Component, DebugElement } from '@angular/core';
|
||||||
import { By } from '@angular/platform-browser';
|
import { By } from '@angular/platform-browser';
|
||||||
import { Component, DebugElement } from '@angular/core';
|
|
||||||
|
|
||||||
import { ComponentFactoryResolver, ElementRef, Injector, NgModule, OnInit, ViewChild } from '@angular/core';
|
|
||||||
|
|
||||||
import { DocViewerComponent } from './doc-viewer.component';
|
import { DocViewerComponent } from './doc-viewer.component';
|
||||||
|
import { DocumentContents } from 'app/documents/document.service';
|
||||||
import { embeddedComponents, EmbeddedComponents } from 'app/embedded';
|
import { embeddedComponents, EmbeddedComponents } from 'app/embedded';
|
||||||
|
|
||||||
|
|
||||||
// /// Embedded Test Components ///
|
/// Embedded Test Components ///
|
||||||
|
|
||||||
// ///// FooComponent /////
|
///// FooComponent /////
|
||||||
|
|
||||||
// @Component({
|
@Component({
|
||||||
// selector: 'aio-foo',
|
selector: 'aio-foo',
|
||||||
// template: `Foo Component`
|
template: `Foo Component`
|
||||||
// })
|
})
|
||||||
// class FooComponent { }
|
class FooComponent { }
|
||||||
|
|
||||||
// ///// BarComponent /////
|
///// BarComponent /////
|
||||||
|
|
||||||
// @Component({
|
@Component({
|
||||||
// selector: 'aio-bar',
|
selector: 'aio-bar',
|
||||||
// template: `
|
template: `
|
||||||
// <hr>
|
<hr>
|
||||||
// <h2>Bar Component</h2>
|
<h2>Bar Component</h2>
|
||||||
// <p #barContent></p>
|
<p #barContent></p>
|
||||||
// <hr>
|
<hr>
|
||||||
// `
|
`
|
||||||
// })
|
})
|
||||||
// class BarComponent implements OnInit {
|
class BarComponent implements OnInit {
|
||||||
|
|
||||||
// @ViewChild('barContent') barContentRef: ElementRef;
|
@ViewChild('barContent') barContentRef: ElementRef;
|
||||||
|
|
||||||
// constructor(public elementRef: ElementRef) { }
|
constructor(public elementRef: ElementRef) { }
|
||||||
|
|
||||||
// // Project content in ngOnInit just like CodeExampleComponent
|
// Project content in ngOnInit just like CodeExampleComponent
|
||||||
// ngOnInit() {
|
ngOnInit() {
|
||||||
// // Security: this is a test component; never deployed
|
// Security: this is a test component; never deployed
|
||||||
// this.barContentRef.nativeElement.innerHTML = this.elementRef.nativeElement.aioBarContent;
|
this.barContentRef.nativeElement.innerHTML = this.elementRef.nativeElement.aioBarContent;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
|
|
||||||
// ///// BazComponent /////
|
///// BazComponent /////
|
||||||
|
|
||||||
// @Component({
|
@Component({
|
||||||
// selector: 'aio-baz',
|
selector: 'aio-baz',
|
||||||
// template: `
|
template: `
|
||||||
// <div>++++++++++++++</div>
|
<div>++++++++++++++</div>
|
||||||
// <h2>Baz Component</h2>
|
<h2>Baz Component</h2>
|
||||||
// <p #bazContent></p>
|
<p #bazContent></p>
|
||||||
// <div>++++++++++++++</div>
|
<div>++++++++++++++</div>
|
||||||
// `
|
`
|
||||||
// })
|
})
|
||||||
// class BazComponent implements OnInit {
|
class BazComponent implements OnInit {
|
||||||
|
|
||||||
// @ViewChild('bazContent') bazContentRef: ElementRef;
|
@ViewChild('bazContent') bazContentRef: ElementRef;
|
||||||
|
|
||||||
// constructor(public elementRef: ElementRef) { }
|
constructor(public elementRef: ElementRef) { }
|
||||||
|
|
||||||
// // Project content in ngOnInit just like CodeExampleComponent
|
// Project content in ngOnInit just like CodeExampleComponent
|
||||||
// ngOnInit() {
|
ngOnInit() {
|
||||||
// // Security: this is a test component; never deployed
|
// Security: this is a test component; never deployed
|
||||||
// this.bazContentRef.nativeElement.innerHTML = this.elementRef.nativeElement.aioBazContent;
|
this.bazContentRef.nativeElement.innerHTML = this.elementRef.nativeElement.aioBazContent;
|
||||||
// }
|
}
|
||||||
// }
|
}
|
||||||
// ///// Test Module //////
|
///// Test Module //////
|
||||||
|
|
||||||
// const embeddedTestComponents = [FooComponent, BarComponent, BazComponent, ...embeddedComponents];
|
const embeddedTestComponents = [FooComponent, BarComponent, BazComponent, ...embeddedComponents];
|
||||||
|
|
||||||
// @NgModule({
|
@NgModule({
|
||||||
// entryComponents: embeddedTestComponents
|
entryComponents: embeddedTestComponents
|
||||||
// })
|
})
|
||||||
// class TestModule { }
|
class TestModule { }
|
||||||
|
|
||||||
// //// Test Component //////
|
//// Test Component //////
|
||||||
|
|
||||||
// @Component({
|
@Component({
|
||||||
// selector: 'aio-test',
|
selector: 'aio-test',
|
||||||
// template: `
|
template: `
|
||||||
// <aio-doc-viewer>Test Component</aio-doc-viewer>
|
<aio-doc-viewer [doc]="currentDoc">Test Component</aio-doc-viewer>
|
||||||
// `
|
`
|
||||||
// })
|
})
|
||||||
// class TestComponent {
|
class TestComponent {
|
||||||
// private currentDoc: Doc;
|
currentDoc: DocumentContents;
|
||||||
|
@ViewChild(DocViewerComponent) docViewer: DocViewerComponent;
|
||||||
|
}
|
||||||
|
|
||||||
// @ViewChild(DocViewerComponent) docViewer: DocViewerComponent;
|
//////// Tests //////////////
|
||||||
|
|
||||||
// setDoc(doc: Doc) {
|
describe('DocViewerComponent', () => {
|
||||||
// if (this.docViewer) {
|
let component: TestComponent;
|
||||||
// this.docViewer.doc = doc;
|
let docViewerDE: DebugElement;
|
||||||
// }
|
let docViewerEl: HTMLElement;
|
||||||
// }
|
let fixture: ComponentFixture<TestComponent>;
|
||||||
// }
|
|
||||||
|
|
||||||
// //////// Tests //////////////
|
beforeEach(async(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [ TestModule ],
|
||||||
|
declarations: [
|
||||||
|
TestComponent,
|
||||||
|
DocViewerComponent,
|
||||||
|
embeddedTestComponents
|
||||||
|
],
|
||||||
|
providers: [
|
||||||
|
{provide: EmbeddedComponents, useValue: {components: embeddedTestComponents}}
|
||||||
|
]
|
||||||
|
})
|
||||||
|
.compileComponents();
|
||||||
|
}));
|
||||||
|
|
||||||
// describe('DocViewerComponent', () => {
|
beforeEach(() => {
|
||||||
// const fakeDocMetadata: DocMetadata = { docId: 'fake', title: 'fake Doc' };
|
fixture = TestBed.createComponent(TestComponent);
|
||||||
// let component: TestComponent;
|
component = fixture.componentInstance;
|
||||||
// let docViewerDE: DebugElement;
|
fixture.detectChanges();
|
||||||
// let docViewerEl: HTMLElement;
|
docViewerDE = fixture.debugElement.children[0];
|
||||||
// let fixture: ComponentFixture<TestComponent>;
|
docViewerEl = docViewerDE.nativeElement;
|
||||||
|
});
|
||||||
|
|
||||||
// beforeEach(async(() => {
|
it('should create a DocViewer', () => {
|
||||||
// TestBed.configureTestingModule({
|
expect(component.docViewer).toBeTruthy();
|
||||||
// imports: [ TestModule ],
|
});
|
||||||
// declarations: [
|
|
||||||
// TestComponent,
|
|
||||||
// DocViewerComponent,
|
|
||||||
// embeddedTestComponents
|
|
||||||
// ],
|
|
||||||
// providers: [
|
|
||||||
// {provide: EmbeddedComponents, useValue: {components: embeddedTestComponents}}
|
|
||||||
// ]
|
|
||||||
// })
|
|
||||||
// .compileComponents();
|
|
||||||
// }));
|
|
||||||
|
|
||||||
// beforeEach(() => {
|
it(('should display nothing when set currentDoc has no content'), () => {
|
||||||
// fixture = TestBed.createComponent(TestComponent);
|
component.currentDoc = { title: 'fake title', contents: '' };
|
||||||
// component = fixture.componentInstance;
|
fixture.detectChanges();
|
||||||
// fixture.detectChanges();
|
expect(docViewerEl.innerHTML).toBe('');
|
||||||
// docViewerDE = fixture.debugElement.children[0];
|
});
|
||||||
// docViewerEl = docViewerDE.nativeElement;
|
|
||||||
// });
|
|
||||||
|
|
||||||
// it('should create a DocViewer', () => {
|
it(('should display simple static content doc'), () => {
|
||||||
// expect(component.docViewer).toBeTruthy();
|
const contents = '<p>Howdy, doc viewer</p>';
|
||||||
// });
|
component.currentDoc = { title: 'fake title', contents };
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(docViewerEl.innerHTML).toEqual(contents);
|
||||||
|
});
|
||||||
|
|
||||||
// it(('should display nothing when set DocViewer.doc to doc w/o content'), () => {
|
it(('should display nothing after reset static content doc'), () => {
|
||||||
// component.docViewer.doc = { metadata: fakeDocMetadata, content: '' };
|
const contents = '<p>Howdy, doc viewer</p>';
|
||||||
// expect(docViewerEl.innerHTML).toBe('');
|
component.currentDoc = { title: 'fake title', contents };
|
||||||
// });
|
fixture.detectChanges();
|
||||||
|
component.currentDoc = { title: 'fake title', contents: '' };
|
||||||
|
fixture.detectChanges();
|
||||||
|
expect(docViewerEl.innerHTML).toEqual('');
|
||||||
|
});
|
||||||
|
|
||||||
// it(('should display simple static content doc'), () => {
|
it(('should apply FooComponent'), () => {
|
||||||
// const content = '<p>Howdy, doc viewer</p>';
|
const contents = `
|
||||||
// component.docViewer.doc = { metadata: fakeDocMetadata, content };
|
<p>Above Foo</p>
|
||||||
// expect(docViewerEl.innerHTML).toEqual(content);
|
<p><aio-foo></aio-foo></p>
|
||||||
// });
|
<p>Below Foo</p>
|
||||||
|
`;
|
||||||
|
component.currentDoc = { title: 'fake title', contents };
|
||||||
|
fixture.detectChanges();
|
||||||
|
const fooHtml = docViewerEl.querySelector('aio-foo').innerHTML;
|
||||||
|
expect(fooHtml).toContain('Foo Component');
|
||||||
|
});
|
||||||
|
|
||||||
// it(('should display nothing after reset static content doc'), () => {
|
it(('should apply multiple FooComponents'), () => {
|
||||||
// const content = '<p>Howdy, doc viewer</p>';
|
const contents = `
|
||||||
// component.docViewer.doc = { metadata: fakeDocMetadata, content };
|
<p>Above Foo</p>
|
||||||
// fixture.detectChanges();
|
<p><aio-foo></aio-foo></p>
|
||||||
// component.docViewer.doc = { metadata: fakeDocMetadata, content: '' };
|
<div style="margin-left: 2em;">
|
||||||
// expect(docViewerEl.innerHTML).toEqual('');
|
Holds a
|
||||||
// });
|
<aio-foo>Ignored text</aio-foo>
|
||||||
|
</div>
|
||||||
|
<p>Below Foo</p>
|
||||||
|
`;
|
||||||
|
component.currentDoc = { title: 'fake title', contents };
|
||||||
|
fixture.detectChanges();
|
||||||
|
const foos = docViewerEl.querySelectorAll('aio-foo');
|
||||||
|
expect(foos.length).toBe(2);
|
||||||
|
});
|
||||||
|
|
||||||
// it(('should apply FooComponent'), () => {
|
it(('should apply BarComponent'), () => {
|
||||||
// const content = `
|
const contents = `
|
||||||
// <p>Above Foo</p>
|
<p>Above Bar</p>
|
||||||
// <p><aio-foo></aio-foo></p>
|
<aio-bar></aio-bar>
|
||||||
// <p>Below Foo</p>
|
<p>Below Bar</p>
|
||||||
// `;
|
`;
|
||||||
// component.docViewer.doc = { metadata: fakeDocMetadata, content };
|
component.currentDoc = { title: 'fake title', contents };
|
||||||
// const fooHtml = docViewerEl.querySelector('aio-foo').innerHTML;
|
fixture.detectChanges();
|
||||||
// expect(fooHtml).toContain('Foo Component');
|
const barHtml = docViewerEl.querySelector('aio-bar').innerHTML;
|
||||||
// });
|
expect(barHtml).toContain('Bar Component');
|
||||||
|
});
|
||||||
|
|
||||||
// it(('should apply multiple FooComponents'), () => {
|
it(('should project bar content into BarComponent'), () => {
|
||||||
// const content = `
|
const contents = `
|
||||||
// <p>Above Foo</p>
|
<p>Above Bar</p>
|
||||||
// <p><aio-foo></aio-foo></p>
|
<aio-bar>###bar content###</aio-bar>
|
||||||
// <div style="margin-left: 2em;">
|
<p>Below Bar</p>
|
||||||
// Holds a
|
`;
|
||||||
// <aio-foo>Ignored text</aio-foo>
|
component.currentDoc = { title: 'fake title', contents };
|
||||||
// </div>
|
|
||||||
// <p>Below Foo</p>
|
|
||||||
// `;
|
|
||||||
// component.docViewer.doc = { metadata: fakeDocMetadata, content };
|
|
||||||
// const foos = docViewerEl.querySelectorAll('aio-foo');
|
|
||||||
// expect(foos.length).toBe(2);
|
|
||||||
// });
|
|
||||||
|
|
||||||
// it(('should apply BarComponent'), () => {
|
// necessary to trigger projection within ngOnInit
|
||||||
// const content = `
|
fixture.detectChanges();
|
||||||
// <p>Above Bar</p>
|
|
||||||
// <aio-bar></aio-bar>
|
|
||||||
// <p>Below Bar</p>
|
|
||||||
// `;
|
|
||||||
// component.docViewer.doc = { metadata: fakeDocMetadata, content };
|
|
||||||
// const barHtml = docViewerEl.querySelector('aio-bar').innerHTML;
|
|
||||||
// expect(barHtml).toContain('Bar Component');
|
|
||||||
// });
|
|
||||||
|
|
||||||
// it(('should project bar content into BarComponent'), () => {
|
const barHtml = docViewerEl.querySelector('aio-bar').innerHTML;
|
||||||
// const content = `
|
expect(barHtml).toContain('###bar content###');
|
||||||
// <p>Above Bar</p>
|
});
|
||||||
// <aio-bar>###bar content###</aio-bar>
|
|
||||||
// <p>Below Bar</p>
|
|
||||||
// `;
|
|
||||||
// component.docViewer.doc = { metadata: fakeDocMetadata, content };
|
|
||||||
|
|
||||||
// // necessary to trigger projection within ngOnInit
|
|
||||||
// fixture.detectChanges();
|
|
||||||
|
|
||||||
// const barHtml = docViewerEl.querySelector('aio-bar').innerHTML;
|
|
||||||
// expect(barHtml).toContain('###bar content###');
|
|
||||||
// });
|
|
||||||
|
|
||||||
|
|
||||||
// it(('should include Foo and Bar'), () => {
|
it(('should include Foo and Bar'), () => {
|
||||||
// const content = `
|
const contents = `
|
||||||
// <p>Top</p>
|
<p>Top</p>
|
||||||
// <p><aio-foo>ignored</aio-foo></p>
|
<p><aio-foo>ignored</aio-foo></p>
|
||||||
// <aio-bar>###bar content###</aio-bar>
|
<aio-bar>###bar content###</aio-bar>
|
||||||
// <p><aio-foo></aio-foo></p>
|
<p><aio-foo></aio-foo></p>
|
||||||
// <p>Bottom</p>
|
<p>Bottom</p>
|
||||||
// `;
|
`;
|
||||||
// component.docViewer.doc = { metadata: fakeDocMetadata, content };
|
component.currentDoc = { title: 'fake title', contents };
|
||||||
|
|
||||||
// // necessary to trigger Bar's projection within ngOnInit
|
// necessary to trigger Bar's projection within ngOnInit
|
||||||
// fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
// const foos = docViewerEl.querySelectorAll('aio-foo');
|
const foos = docViewerEl.querySelectorAll('aio-foo');
|
||||||
// expect(foos.length).toBe(2, 'should have 2 foos');
|
expect(foos.length).toBe(2, 'should have 2 foos');
|
||||||
|
|
||||||
// const barHtml = docViewerEl.querySelector('aio-bar').innerHTML;
|
const barHtml = docViewerEl.querySelector('aio-bar').innerHTML;
|
||||||
// expect(barHtml).toContain('###bar content###', 'should have bar with projected content');
|
expect(barHtml).toContain('###bar content###', 'should have bar with projected content');
|
||||||
// });
|
});
|
||||||
|
|
||||||
// it(('should not include Bar within Foo'), () => {
|
it(('should not include Bar within Foo'), () => {
|
||||||
// const content = `
|
const contents = `
|
||||||
// <p>Top</p>
|
<p>Top</p>
|
||||||
// <div>
|
<div>
|
||||||
// <aio-foo>
|
<aio-foo>
|
||||||
// <aio-bar>###bar content###</aio-bar>
|
<aio-bar>###bar content###</aio-bar>
|
||||||
// </aio-foo>
|
</aio-foo>
|
||||||
// </div>
|
</div>
|
||||||
// <p><aio-foo></aio-foo><p>
|
<p><aio-foo></aio-foo><p>
|
||||||
// <p>Bottom</p>
|
<p>Bottom</p>
|
||||||
// `;
|
`;
|
||||||
// component.docViewer.doc = { metadata: fakeDocMetadata, content };
|
component.currentDoc = { title: 'fake title', contents };
|
||||||
|
|
||||||
// // necessary to trigger Bar's projection within ngOnInit
|
// necessary to trigger Bar's projection within ngOnInit
|
||||||
// fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
// const foos = docViewerEl.querySelectorAll('aio-foo');
|
const foos = docViewerEl.querySelectorAll('aio-foo');
|
||||||
// expect(foos.length).toBe(2, 'should have 2 foos');
|
expect(foos.length).toBe(2, 'should have 2 foos');
|
||||||
|
|
||||||
// const bars = docViewerEl.querySelectorAll('aio-bar');
|
const bars = docViewerEl.querySelectorAll('aio-bar');
|
||||||
// expect(bars.length).toBe(0, 'did not expect Bar inside Foo');
|
expect(bars.length).toBe(0, 'did not expect Bar inside Foo');
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // because FooComponents are processed before BazComponents
|
// because FooComponents are processed before BazComponents
|
||||||
// it(('should include Foo within Bar'), () => {
|
it(('should include Foo within Bar'), () => {
|
||||||
// const content = `
|
const contents = `
|
||||||
// <p>Top</p>
|
<p>Top</p>
|
||||||
// <aio-bar>
|
<aio-bar>
|
||||||
// <div style="margin-left: 2em">
|
<div style="margin-left: 2em">
|
||||||
// Inner <aio-foo></aio-foo>
|
Inner <aio-foo></aio-foo>
|
||||||
// </div>
|
</div>
|
||||||
// </aio-bar>
|
</aio-bar>
|
||||||
// <p><aio-foo></aio-foo></p>
|
<p><aio-foo></aio-foo></p>
|
||||||
// <p>Bottom</p>
|
<p>Bottom</p>
|
||||||
// `;
|
`;
|
||||||
// component.docViewer.doc = { metadata: fakeDocMetadata, content };
|
component.currentDoc = { title: 'fake title', contents };
|
||||||
|
|
||||||
// // necessary to trigger Bar's projection within ngOnInit
|
// necessary to trigger Bar's projection within ngOnInit
|
||||||
// fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
// const foos = docViewerEl.querySelectorAll('aio-foo');
|
const foos = docViewerEl.querySelectorAll('aio-foo');
|
||||||
// expect(foos.length).toBe(2, 'should have 2 foos');
|
expect(foos.length).toBe(2, 'should have 2 foos');
|
||||||
|
|
||||||
// const bars = docViewerEl.querySelectorAll('aio-bar');
|
const bars = docViewerEl.querySelectorAll('aio-bar');
|
||||||
// expect(bars.length).toBe(1, 'should have a bar');
|
expect(bars.length).toBe(1, 'should have a bar');
|
||||||
// expect(bars[0].innerHTML).toContain('Bar Component', 'should have bar template content');
|
expect(bars[0].innerHTML).toContain('Bar Component', 'should have bar template content');
|
||||||
// });
|
});
|
||||||
|
|
||||||
// // The <aio-baz> tag and its inner content is copied
|
// The <aio-baz> tag and its inner content is copied
|
||||||
// // But the BazComponent is not created and therefore its template content is not displayed
|
// But the BazComponent is not created and therefore its template content is not displayed
|
||||||
// // because BarComponents are processed before BazComponents
|
// because BarComponents are processed before BazComponents
|
||||||
// // and no chance for first Baz inside Bar to be processed by builder.
|
// and no chance for first Baz inside Bar to be processed by builder.
|
||||||
// it(('should NOT include Bar within Baz'), () => {
|
it(('should NOT include Bar within Baz'), () => {
|
||||||
// const content = `
|
const contents = `
|
||||||
// <p>Top</p>
|
<p>Top</p>
|
||||||
// <aio-bar>
|
<aio-bar>
|
||||||
// <div style="margin-left: 2em">
|
<div style="margin-left: 2em">
|
||||||
// Inner <aio-baz>---baz stuff---</aio-baz>
|
Inner <aio-baz>---baz stuff---</aio-baz>
|
||||||
// </div>
|
</div>
|
||||||
// </aio-bar>
|
</aio-bar>
|
||||||
// <p><aio-baz>---More baz--</aio-baz></p>
|
<p><aio-baz>---More baz--</aio-baz></p>
|
||||||
// <p>Bottom</p>
|
<p>Bottom</p>
|
||||||
// `;
|
`;
|
||||||
// component.docViewer.doc = { metadata: fakeDocMetadata, content };
|
component.currentDoc = { title: 'fake title', contents };
|
||||||
|
|
||||||
// // necessary to trigger Bar's projection within ngOnInit
|
// necessary to trigger Bar's projection within ngOnInit
|
||||||
// fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
// const bazs = docViewerEl.querySelectorAll('aio-baz');
|
const bazs = docViewerEl.querySelectorAll('aio-baz');
|
||||||
|
|
||||||
// // Both baz tags are there ...
|
// Both baz tags are there ...
|
||||||
// expect(bazs.length).toBe(2, 'should have 2 bazs');
|
expect(bazs.length).toBe(2, 'should have 2 bazs');
|
||||||
|
|
||||||
// expect(bazs[0].innerHTML).not.toContain('Baz Component',
|
expect(bazs[0].innerHTML).not.toContain('Baz Component',
|
||||||
// 'did not expect 1st Baz template content');
|
'did not expect 1st Baz template content');
|
||||||
|
|
||||||
// expect(bazs[1].innerHTML).toContain('Baz Component',
|
expect(bazs[1].innerHTML).toContain('Baz Component',
|
||||||
// 'expected 2nd Baz template content');
|
'expected 2nd Baz template content');
|
||||||
|
|
||||||
// });
|
});
|
||||||
// });
|
});
|
||||||
|
@ -53,7 +53,6 @@ export class DocViewerComponent implements DoCheck, OnDestroy {
|
|||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set doc(newDoc: DocumentContents) {
|
set doc(newDoc: DocumentContents) {
|
||||||
console.log(newDoc);
|
|
||||||
this.ngOnDestroy();
|
this.ngOnDestroy();
|
||||||
if (newDoc) {
|
if (newDoc) {
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
||||||
|
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||||
import { NavMenuComponent } from './nav-menu.component';
|
import { NavMenuComponent } from './nav-menu.component';
|
||||||
|
|
||||||
describe('NavMenuComponent', () => {
|
describe('NavMenuComponent', () => {
|
||||||
@ -8,7 +8,8 @@ describe('NavMenuComponent', () => {
|
|||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [ NavMenuComponent ]
|
declarations: [ NavMenuComponent ],
|
||||||
|
schemas: [NO_ERRORS_SCHEMA]
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
}));
|
}));
|
||||||
|
@ -1,14 +1,34 @@
|
|||||||
import { TestBed, inject } from '@angular/core/testing';
|
import { ReflectiveInjector } from '@angular/core';
|
||||||
import { NavigationService } from './navigation.service';
|
import { Location, LocationStrategy } from '@angular/common';
|
||||||
|
import { MockLocationStrategy } from '@angular/common/testing';
|
||||||
|
import { Http, ConnectionBackend, RequestOptions, BaseRequestOptions } from '@angular/http';
|
||||||
|
import { MockBackend } from '@angular/http/testing';
|
||||||
|
import { NavigationService } from 'app/navigation/navigation.service';
|
||||||
|
import { LocationService } from 'app/shared/location.service';
|
||||||
|
import { Logger } from 'app/shared/logger.service';
|
||||||
|
|
||||||
describe('NavigationService', () => {
|
describe('NavigationService', () => {
|
||||||
|
|
||||||
|
let injector: ReflectiveInjector;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
injector = ReflectiveInjector.resolveAndCreate([
|
||||||
providers: [NavigationService]
|
NavigationService,
|
||||||
});
|
LocationService,
|
||||||
|
Location,
|
||||||
|
{ provide: LocationStrategy, useClass: MockLocationStrategy },
|
||||||
|
{ provide: ConnectionBackend, useClass: MockBackend },
|
||||||
|
{ provide: RequestOptions, useClass: BaseRequestOptions },
|
||||||
|
Http,
|
||||||
|
Logger
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ...', inject([NavigationService], (service: NavigationService) => {
|
it('should be creatable', () => {
|
||||||
|
const service: NavigationService = injector.get(NavigationService);
|
||||||
expect(service).toBeTruthy();
|
expect(service).toBeTruthy();
|
||||||
}));
|
});
|
||||||
|
|
||||||
|
xit('should fetch the navigation views', () => {});
|
||||||
|
xit('should compute the navigation map', () => {});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user