2017-03-02 13:28:28 +00:00
|
|
|
import { async, inject, ComponentFixture, TestBed } from '@angular/core/testing';
|
|
|
|
import { APP_BASE_HREF } from '@angular/common';
|
2017-02-02 23:02:23 -08:00
|
|
|
import { AppComponent } from './app.component';
|
|
|
|
import { AppModule } from './app.module';
|
2017-03-13 18:08:23 -07:00
|
|
|
import { GaService } from 'app/shared/ga.service';
|
2017-03-02 13:28:28 +00:00
|
|
|
import { SearchService } from 'app/search/search.service';
|
2017-03-13 19:58:31 +00:00
|
|
|
import { MockSearchService } from 'testing/search.service';
|
2017-03-13 21:06:15 +00:00
|
|
|
import { LocationService } from 'app/shared/location.service';
|
|
|
|
import { MockLocationService } from 'testing/location.service';
|
2017-02-02 23:02:23 -08:00
|
|
|
|
2017-01-27 00:20:51 -08:00
|
|
|
describe('AppComponent', () => {
|
2017-02-02 23:02:23 -08:00
|
|
|
let component: AppComponent;
|
|
|
|
let fixture: ComponentFixture<AppComponent>;
|
2017-03-13 21:06:15 +00:00
|
|
|
const initialUrl = 'a/b';
|
2017-01-27 00:20:51 -08:00
|
|
|
|
2017-02-02 23:02:23 -08:00
|
|
|
beforeEach(async(() => {
|
|
|
|
TestBed.configureTestingModule({
|
|
|
|
imports: [ AppModule ],
|
|
|
|
providers: [
|
2017-03-13 19:58:31 +00:00
|
|
|
{ provide: APP_BASE_HREF, useValue: '/' },
|
2017-03-13 18:08:23 -07:00
|
|
|
{ provide: SearchService, useClass: MockSearchService },
|
2017-03-13 21:06:15 +00:00
|
|
|
{ provide: GaService, useClass: TestGaService },
|
|
|
|
{ provide: LocationService, useFactory: () => new MockLocationService(initialUrl) }
|
2017-02-02 23:02:23 -08:00
|
|
|
]
|
|
|
|
});
|
|
|
|
TestBed.compileComponents();
|
|
|
|
}));
|
2017-01-27 00:20:51 -08:00
|
|
|
|
2017-02-02 23:02:23 -08:00
|
|
|
beforeEach(() => {
|
|
|
|
fixture = TestBed.createComponent(AppComponent);
|
|
|
|
component = fixture.componentInstance;
|
|
|
|
});
|
2017-01-27 00:20:51 -08:00
|
|
|
|
2017-02-02 23:02:23 -08:00
|
|
|
it('should create', () => {
|
|
|
|
expect(component).toBeDefined();
|
|
|
|
});
|
2017-03-02 13:28:28 +00:00
|
|
|
|
2017-03-13 18:08:23 -07:00
|
|
|
describe('google analytics', () => {
|
|
|
|
it('should call gaService.locationChanged with initial URL', () => {
|
|
|
|
const { locationChanged } = TestBed.get(GaService) as TestGaService;
|
|
|
|
expect(locationChanged.calls.count()).toBe(1, 'gaService.locationChanged');
|
|
|
|
const args = locationChanged.calls.first().args;
|
2017-03-13 21:06:15 +00:00
|
|
|
expect(args[0]).toBe(initialUrl);
|
2017-03-13 18:08:23 -07:00
|
|
|
});
|
|
|
|
|
|
|
|
// Todo: add test to confirm tracking URL when navigate.
|
|
|
|
});
|
|
|
|
|
2017-03-02 13:28:28 +00:00
|
|
|
describe('isHamburgerVisible', () => {
|
2017-03-13 17:58:25 -07:00
|
|
|
console.log('PENDING: AppComponent isHamburgerVisible');
|
2017-03-02 13:28:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('onResize', () => {
|
|
|
|
it('should update `isSideBySide` accordingly', () => {
|
|
|
|
component.onResize(1000);
|
|
|
|
expect(component.isSideBySide).toBe(true);
|
|
|
|
component.onResize(500);
|
|
|
|
expect(component.isSideBySide).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('currentDocument', () => {
|
2017-03-13 19:58:31 +00:00
|
|
|
console.log('PENDING: AppComponent currentDocument');
|
2017-03-02 13:28:28 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('navigationViews', () => {
|
2017-03-13 19:58:31 +00:00
|
|
|
console.log('PENDING: AppComponent navigationViews');
|
2017-03-02 13:28:28 +00:00
|
|
|
});
|
|
|
|
|
2017-03-13 19:58:31 +00:00
|
|
|
describe('initialisation', () => {
|
|
|
|
it('should initialize the search worker', inject([SearchService], (searchService: SearchService) => {
|
|
|
|
fixture.detectChanges(); // triggers ngOnInit
|
|
|
|
expect(searchService.initWorker).toHaveBeenCalled();
|
|
|
|
expect(searchService.loadIndex).toHaveBeenCalled();
|
|
|
|
}));
|
2017-03-02 13:28:28 +00:00
|
|
|
});
|
2017-03-13 21:06:15 +00:00
|
|
|
|
|
|
|
describe('click intercepting', () => {
|
|
|
|
it('should intercept clicks on anchors and call `location.handleAnchorClick()`',
|
|
|
|
inject([LocationService], (location: LocationService) => {
|
|
|
|
const anchorElement: HTMLAnchorElement = document.createElement('a');
|
|
|
|
anchorElement.href = 'some/local/url';
|
|
|
|
fixture.nativeElement.append(anchorElement);
|
|
|
|
anchorElement.click();
|
|
|
|
expect(location.handleAnchorClick).toHaveBeenCalledWith(anchorElement, 0, false, false);
|
|
|
|
}));
|
|
|
|
});
|
2017-02-02 23:02:23 -08:00
|
|
|
});
|
2017-03-13 18:08:23 -07:00
|
|
|
|
|
|
|
class TestGaService {
|
|
|
|
locationChanged = jasmine.createSpy('locationChanged');
|
|
|
|
}
|