Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should not translate routes if not NavigationStart', () => {
localizeRouterService = new LocalizeRouterService(loader, router);
loader.currentLang = 'de';
loader.locales = ['de', 'en'];
spyOn(loader, 'translateRoutes').and.stub();
(router as FakeRouter).fakeRouterEvents.next(new NavigationEnd(1, '/en/new/path', '/en/new/path'));
expect(loader.translateRoutes).not.toHaveBeenCalled();
});
it('should skip non-home routes', () => {
let testEvent: NavigationEnd;
testEvent = new NavigationEnd(1, '/test', '/test');
mockRouter.fakeEvent(testEvent);
expect(component.axFocus01Fix.skipRoute).toBe(true);
testEvent = new NavigationEnd(1, '/', '/');
mockRouter.fakeEvent(testEvent);
expect(component.axFocus01Fix.skipRoute).toBe(false);
});
set eventParams(event) {
let nav;
if (event.nav === 'end') {
console.log('MY ONLY FRIEND THE END');
nav = new NavigationEnd(0, event.url, event.urlAfterRedirects);
} else {
nav = new NavigationStart(0, event.url);
}
this._eventParams = nav;
this.subject.next(nav);
}
it('should reinit page when archiveUnitDetail is called', (done) => {
spyOn(component, 'pageOnInit').and.callFake(() => {
done();
});
spyOn(component.router, 'events').and.returnValues(
Observable.of(new NavigationEnd(1, 'search/archiveUnit/myId', 'urlAfterRedirect'))
);
component.router.navigateByUrl('search/archiveUnit/myId');
});
import { TestBed, async, ComponentFixture, fakeAsync, tick } from '@angular/core/testing';
import { mockData } from './app.component.spec.data';
import { AppComponent } from './app.component';
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { RouterTestingModule } from '@angular/router/testing';
import * as _ from 'lodash-es';
import { ProfileService } from '@sunbird/profile';
import { CacheService } from 'ng2-cache-service';
import { animate, AnimationBuilder, AnimationMetadata, AnimationPlayer, style } from '@angular/animations';
import { Router, NavigationEnd, ActivatedRoute } from '@angular/router';
import { OnboardingService } from './modules/offline';
class RouterStub {
public navigationEnd = new NavigationEnd(0, '/explore', '/explore');
public navigate = jasmine.createSpy('navigate');
public url = '';
public events = new Observable(observer => {
observer.next(this.navigationEnd);
observer.complete();
});
}
const fakeActivatedRoute = {
snapshot: {
root: { firstChild: { params: { slug: 'sunbird' } } }
},
queryParams: of({})
};
describe('AppComponent', () => {
and event receiver callback has been called with loaded`, () => {
let timesCalled = 0;
const subscription = profileTagEventTracker
.profileTagLoaded()
.pipe(tap(_ => timesCalled++))
.subscribe();
getActiveBehavior.next('electronics-test');
eventListener(new CustomEvent(ProfileTagEventNames.LOADED));
routerEventsBehavior.next(new NavigationEnd(0, 'test', 'test'));
subscription.unsubscribe();
expect(timesCalled).toEqual(1);
});
triggerOnNavigationEnd(url?: string) {
return this._routeEvents.next(new NavigationEnd(0, url || '/url/789', url || '/url/789'));
}
events = Observable.create(observer => {
observer.next(new NavigationEnd(123, '', ''));
observer.complete();
});
}
const profileTagLoaded$ = profileTagInjector.track();
const subscription = profileTagLoaded$.subscribe();
getActiveBehavior.next('electronics-test');
nativeWindow.Y_TRACKING.q[0][0].profileTagEventReceiver({
name: 'Loaded',
});
isConsentGivenValue = true;
getConsentBehavior.next({ consent: 'test' });
isConsentGivenValue = false;
getConsentBehavior.next({ consent: 'test' });
isConsentGivenValue = true;
getConsentBehavior.next({ consent: 'test' });
routerEventsBehavior.next(new NavigationEnd(0, 'test', 'test'));
routerEventsBehavior.next(new NavigationEnd(0, 'test', 'test'));
routerEventsBehavior.next(new NavigationEnd(0, 'test', 'test2'));
routerEventsBehavior.next(new NavigationEnd(0, 'test', 'test3'));
routerEventsBehavior.next(new NavigationEnd(0, 'test', 'test1'));
subscription.unsubscribe();
expect(nativeWindow.Y_TRACKING.push).toHaveBeenCalledTimes(6);
expect(nativeWindow.Y_TRACKING.push).toHaveBeenCalledWith({
event: 'Navigated',
});
});
const subscription = profileTagLoaded$.subscribe();
getActiveBehavior.next('electronics-test');
nativeWindow.Y_TRACKING.q[0][0].profileTagEventReceiver({
name: 'Loaded',
});
isConsentGivenValue = true;
getConsentBehavior.next({ consent: 'test' });
isConsentGivenValue = false;
getConsentBehavior.next({ consent: 'test' });
isConsentGivenValue = true;
getConsentBehavior.next({ consent: 'test' });
routerEventsBehavior.next(new NavigationEnd(0, 'test', 'test'));
routerEventsBehavior.next(new NavigationEnd(0, 'test', 'test'));
routerEventsBehavior.next(new NavigationEnd(0, 'test', 'test2'));
routerEventsBehavior.next(new NavigationEnd(0, 'test', 'test3'));
routerEventsBehavior.next(new NavigationEnd(0, 'test', 'test1'));
subscription.unsubscribe();
expect(nativeWindow.Y_TRACKING.push).toHaveBeenCalledTimes(6);
expect(nativeWindow.Y_TRACKING.push).toHaveBeenCalledWith({
event: 'Navigated',
});
});