Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
when(this.browser.extension).thenReturn(instance(this.extension));
when(this.extension.getURL).thenReturn(s => s);
this.tabs = mock();
when(this.browser.tabs).thenReturn(instance(this.tabs));
this.storage = mock();
when(this.browser.storage).thenReturn(instance(this.storage));
this.localStorage = mock();
when(this.storage.local).thenReturn(instance(this.localStorage));
this.runtime = mock();
when(this.browser.runtime).thenReturn(instance(this.runtime));
this.onMessage = mock();
this.listeners = [];
when(this.runtime.onMessage).thenReturn(instance(this.onMessage));
when(this.onMessage.addListener).thenReturn(toAdd => this.listeners.push(toAdd));
when(this.onMessage.removeListener).thenReturn(toRemove =>
snip(this.listeners, l => l == toRemove),
);
when(this.runtime.sendMessage).thenReturn((message: any) => {
this.listeners.map(l => l(message));
return Promise.resolve();
});
this.setTabs([]);
this.setTabGroups([]);
this.setOptions({ tabLimit: 100, archiveDupes: false, homeGroup: [] });
}
class TestProject extends SFProject {
static readonly TYPE = 'project';
constructor(init?: Partial) {
super(init);
this.projectName = 'project01';
}
}
class TestEnvironment {
component: SettingsComponent;
fixture: ComponentFixture;
overlayContainer: OverlayContainer;
isLoading: boolean = false;
mockedActivatedRoute: ActivatedRoute = mock(ActivatedRoute);
mockedAuthService: AuthService = mock(AuthService);
mockedNoticeService: NoticeService = mock(NoticeService);
mockedParatextService: ParatextService = mock(ParatextService);
mockedSFProjectService: SFProjectService = mock(SFProjectService);
mockedUserService: UserService = mock(UserService);
private readonly project$: BehaviorSubject>;
private readonly paratectProjects$: BehaviorSubject;
constructor() {
when(this.mockedActivatedRoute.params).thenReturn(of({ projectId: 'project01' }));
when(this.mockedNoticeService.isLoading).thenCall(() => this.isLoading);
this.paratectProjects$ = new BehaviorSubject([
{
paratextId: 'paratextId01',
name: 'ParatextP1',
sortKeys: [],
products: [{ sku: 'P1' }, { sku: 'P2' }] as Product[],
total: 2,
})
);
when(productsServiceMock.searchProducts('something', anyNumber(), anything())).thenReturn(
of({ products: [{ sku: 'P2' } as Product], sortKeys: [], total: 1 })
);
promotionsServiceMock = mock(PromotionsService);
when(promotionsServiceMock.getPromotion(anything())).thenReturn(of(promotion));
suggestServiceMock = mock(SuggestService);
when(suggestServiceMock.search('some')).thenReturn(of([{ term: 'something' }]));
filterServiceMock = mock(FilterService);
when(filterServiceMock.getFilterForSearch(anything())).thenReturn(of({} as FilterNavigation));
when(filterServiceMock.getFilterForCategory(anything())).thenReturn(of({} as FilterNavigation));
TestBed.configureTestingModule({
declarations: [DummyComponent],
imports: [
RouterTestingModule.withRoutes([
{
path: 'home',
component: DummyComponent,
},
{
path: 'compare',
component: DummyComponent,
},
{
});
});
@NgModule({
imports: [FormsModule, MdcDialogModule, ReactiveFormsModule, NoopAnimationsModule, UICommonModule],
exports: [QuestionDialogComponent],
declarations: [QuestionDialogComponent],
entryComponents: [QuestionDialogComponent]
})
class DialogTestModule {}
class TestEnvironment {
component: CheckingOverviewComponent;
fixture: ComponentFixture;
mockedActivatedRoute: ActivatedRoute = mock(ActivatedRoute);
mockedSFAdminAuthGuard: SFAdminAuthGuard = mock(SFAdminAuthGuard);
mockedMdcDialog: MdcDialog = mock(MdcDialog);
mockedQuestionDialogRef: MdcDialogRef = mock(MdcDialogRef);
mockedNoticeService = mock(NoticeService);
mockedProjectService: SFProjectService = mock(SFProjectService);
mockedTextService: TextService = mock(TextService);
mockedUserService: UserService = mock(UserService);
mockedAuthService: AuthService = mock(AuthService);
mockedRealtimeOfflineStore: RealtimeOfflineStore = mock(RealtimeOfflineStore);
overlayContainer: OverlayContainer;
constructor() {
when(this.mockedActivatedRoute.params).thenReturn(of({}));
when(this.mockedMdcDialog.open(anything(), anything())).thenReturn(instance(this.mockedQuestionDialogRef));
when(this.mockedSFAdminAuthGuard.allowTransition(anything())).thenReturn(of(true));
when(this.mockedProjectService.getTexts(anything())).thenReturn(
constructor() {
this.mockedIdentityService = mock(IdentityService);
this.mockedActivatedRoute = mock(ActivatedRoute);
this.mockedLocationService = mock(LocationService);
this.mockedAuthService = mock(AuthService);
this.mockedNoticeService = mock(NoticeService);
when(this.mockedActivatedRoute.queryParams).thenReturn(of({}));
when(this.mockedNoticeService.show(anything())).thenResolve();
TestBed.configureTestingModule({
imports: [NoopAnimationsModule, UICommonModule],
declarations: [LogInComponent],
providers: [
{ provide: IdentityService, useFactory: () => instance(this.mockedIdentityService) },
{ provide: ActivatedRoute, useFactory: () => instance(this.mockedActivatedRoute) },
{ provide: LocationService, useFactory: () => instance(this.mockedLocationService) },
{ provide: AuthService, useFactory: () => instance(this.mockedAuthService) },
{ provide: NoticeService, useFactory: () => instance(this.mockedNoticeService) }
]
describe('AcEllipseComponent', () => {
let component: AcEllipseComponent;
let fixture: ComponentFixture;
const cesiumService = mock(CesiumService);
const primitiveCollection = mock(Cesium.PrimitiveCollection);
when(cesiumService.getScene()).thenReturn({primitives: instance(primitiveCollection)});
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AcEllipseComponent],
providers: [EllipseDrawerService, MapLayersService,
providerFromMock(CesiumService, cesiumService)]
})
.compileComponents();
fixture = TestBed.createComponent(AcEllipseComponent);
component = fixture.componentInstance;
}));
describe('AcCircleComponent', () => {
let component: AcCircleComponent;
let fixture: ComponentFixture;
const cesiumService = mock(CesiumService);
const primitiveCollection = mock(Cesium.PrimitiveCollection);
when(cesiumService.getScene()).thenReturn({primitives: instance(primitiveCollection)});
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [AcCircleComponent],
providers: [EllipseDrawerService, MapLayersService,
providerFromMock(CesiumService, cesiumService)]
})
.compileComponents();
fixture = TestBed.createComponent(AcCircleComponent);
component = fixture.componentInstance;
}));
constructor() {
this.mockedUserService = mock(UserService);
TestBed.configureTestingModule({
imports: [NoopAnimationsModule, UICommonModule],
declarations: [SaDeleteDialogComponent],
schemas: [CUSTOM_ELEMENTS_SCHEMA, NO_ERRORS_SCHEMA],
providers: [
{ provide: UserService, useFactory: () => instance(this.mockedUserService) },
{ provide: MAT_DIALOG_DATA },
{ provide: MatDialogRef, useValue: {} }
]
});
this.fixture = TestBed.createComponent(SaDeleteDialogComponent);
this.component = this.fixture.componentInstance;
}
constructor(isVerified = true) {
this.mockedAuthService = mock(AuthService);
this.mockedActivatedRoute = mock(ActivatedRoute);
this.mockedIdentityService = mock(IdentityService);
this.mockedNoticeService = mock(NoticeService);
const params: Params = { ['key']: 'test_verification_key' };
when(this.mockedAuthService.isLoggedIn).thenResolve(true);
when(this.mockedActivatedRoute.queryParams).thenReturn(of(params));
when(this.mockedIdentityService.verifyEmail(anything())).thenResolve(isVerified);
when(this.mockedIdentityService.resendLink(anything())).thenResolve('success');
TestBed.configureTestingModule({
imports: [UICommonModule],
declarations: [VerifyEmailComponent],
providers: [
{ provide: AuthService, useFactory: () => instance(this.mockedAuthService) },
{ provide: ActivatedRoute, useFactory: () => instance(this.mockedActivatedRoute) },
{ provide: IdentityService, useFactory: () => instance(this.mockedIdentityService) },
beforeEach(async(() => {
const mockCesiumService = mock(CesiumService);
const mockStaticCircleDrawerService = mock(StaticCircleDrawerService);
const mockLayerService = mock(LayerService);
const mockComputationCache = mock(ComputationCache);
const mockCesiumProperties = mock(CesiumProperties);
TestBed.configureTestingModule({
declarations: [AcStaticCircleDescComponent],
providers: [
{
provide: CesiumService,
useValue: mockCesiumService
},
{
provide: StaticCircleDrawerService,
useValue: mockStaticCircleDrawerService
},
{
provide: LayerService,
useValue: mockLayerService