|
| 1 | +import { AppComponent } from '@trungk18/app.component'; |
| 2 | +import { NavigationEnd } from '@angular/router'; |
| 3 | +import { environment } from '../environments/environment'; |
| 4 | + |
| 5 | +describe('AppComponent', () => { |
| 6 | + let component: AppComponent; |
| 7 | + |
| 8 | + const router: any = { |
| 9 | + events: { |
| 10 | + subscribe: jasmine.createSpy('subscribe') |
| 11 | + } |
| 12 | + }; |
| 13 | + const projectQuery: any = {}; |
| 14 | + const changeDetectorRef: any = { |
| 15 | + detectChanges: jasmine.createSpy('detectChanges') |
| 16 | + }; |
| 17 | + const projectService: any = { |
| 18 | + setLoading: jasmine.createSpy('setLoading').and.callThrough() |
| 19 | + }; |
| 20 | + const googleAnalyticsService: any = { |
| 21 | + sendPageView: jasmine.createSpy('sendPageView').and.callThrough() |
| 22 | + }; |
| 23 | + |
| 24 | + beforeEach(() => { |
| 25 | + environment.production = true; |
| 26 | + component = new AppComponent( |
| 27 | + router, |
| 28 | + projectQuery, |
| 29 | + changeDetectorRef, |
| 30 | + projectService, |
| 31 | + googleAnalyticsService |
| 32 | + ); |
| 33 | + }); |
| 34 | + it('should be able to set Loading', () => { |
| 35 | + expect(router.events.subscribe).toHaveBeenCalled(); |
| 36 | + expect(projectService.setLoading).toHaveBeenCalledWith(true); |
| 37 | + }); |
| 38 | + it('should be able to make ng After View Init', () => { |
| 39 | + component.ngAfterViewInit(); |
| 40 | + expect(changeDetectorRef.detectChanges).toHaveBeenCalled(); |
| 41 | + }); |
| 42 | + it('should be able to handle Google Analytics', () => { |
| 43 | + component.handleGoogleAnalytics( new NavigationEnd(1, '/', '/')); |
| 44 | + |
| 45 | + expect(googleAnalyticsService.sendPageView).toHaveBeenCalled(); |
| 46 | + }); |
| 47 | + it('should not be able to handle Google Analytics', () => { |
| 48 | + googleAnalyticsService.sendPageView.calls.reset(); |
| 49 | + component.handleGoogleAnalytics({ }); |
| 50 | + |
| 51 | + expect(googleAnalyticsService.sendPageView).not.toHaveBeenCalled(); |
| 52 | + }); |
| 53 | + |
| 54 | +}); |
0 commit comments