fixed more tests

This commit is contained in:
lotte
2020-02-04 12:36:17 +01:00
parent d1b7f07c68
commit 34c5d93a98
7 changed files with 22 additions and 26 deletions

View File

@@ -32,9 +32,4 @@ export class ProtractorPage {
submitByPressingEnter() { submitByPressingEnter() {
element(by.css('#search-navbar-container form input[name="query"]')).sendKeys(protractor.Key.ENTER); element(by.css('#search-navbar-container form input[name="query"]')).sendKeys(protractor.Key.ENTER);
} }
submitByPressingEnter() {
element(by.css('#search-navbar-container form input[name="query"]')).sendKeys(protractor.Key.ENTER);
}
} }

View File

@@ -15,6 +15,7 @@ import { DeleteRequest } from './request.models';
import { ObjectCacheService } from '../cache/object-cache.service'; import { ObjectCacheService } from '../cache/object-cache.service';
import { Observable } from 'rxjs/internal/Observable'; import { Observable } from 'rxjs/internal/Observable';
import { createSuccessfulRemoteDataObject$ } from '../../shared/testing/utils'; import { createSuccessfulRemoteDataObject$ } from '../../shared/testing/utils';
import { fakeAsync, tick } from '@angular/core/testing';
describe('RelationshipService', () => { describe('RelationshipService', () => {
let service: RelationshipService; let service: RelationshipService;
@@ -104,6 +105,9 @@ describe('RelationshipService', () => {
}; };
beforeEach(() => { beforeEach(() => {
jasmine.clock().uninstall();
jasmine.clock().install();
requestService = getMockRequestService(getRequestEntry$(true)); requestService = getMockRequestService(getRequestEntry$(true));
service = initTestService(); service = initTestService();
}); });

View File

@@ -147,20 +147,16 @@ export class RelationshipService extends DataService<Relationship> {
* @param item The item to remove from the cache * @param item The item to remove from the cache
*/ */
private refreshRelationshipItemsInCache(item) { private refreshRelationshipItemsInCache(item) {
setTimeout(() => { this.objectCache.remove(item.self);
this.requestService.removeByHrefSubstring(item.uuid);
this.objectCache.remove(item.self); combineLatest(
this.requestService.removeByHrefSubstring(item.uuid); this.objectCache.hasBySelfLinkObservable(item.self),
combineLatest( this.requestService.hasByHrefObservable(item.self)
this.objectCache.hasBySelfLinkObservable(item.self), ).pipe(
this.requestService.hasByHrefObservable(item.self) filter(([existsInOC, existsInRC]) => !existsInOC && !existsInRC),
).pipe( take(1),
filter(([existsInOC, existsInRC]) => !existsInOC && !existsInRC), switchMap(() => this.itemService.findByHref(item.self).pipe(take(1)))
take(1), ).subscribe();
switchMap(() => this.itemService.findByHref(item.self).pipe(take(1)))
).subscribe();
}, 1000)
} }
/** /**

View File

@@ -222,7 +222,6 @@ describe('DsDynamicFormControlContainerComponent test suite', () => {
expect(component.group instanceof FormGroup).toBe(true); expect(component.group instanceof FormGroup).toBe(true);
expect(component.model instanceof DynamicFormControlModel).toBe(true); expect(component.model instanceof DynamicFormControlModel).toBe(true);
expect(component.hasErrorMessaging).toBe(false); expect(component.hasErrorMessaging).toBe(false);
expect(component.asBootstrapFormGroup).toBe(true);
expect(component.onControlValueChanges).toBeDefined(); expect(component.onControlValueChanges).toBeDefined();
expect(component.onModelDisabledUpdates).toBeDefined(); expect(component.onModelDisabledUpdates).toBeDefined();

View File

@@ -18,6 +18,8 @@ import { RestResponse } from '../../../../../core/cache/response.models';
import { Store } from '@ngrx/store'; import { Store } from '@ngrx/store';
import { SubmissionObjectDataService } from '../../../../../core/submission/submission-object-data.service'; import { SubmissionObjectDataService } from '../../../../../core/submission/submission-object-data.service';
import { WorkspaceItem } from '../../../../../core/submission/models/workspaceitem.model'; import { WorkspaceItem } from '../../../../../core/submission/models/workspaceitem.model';
import { ObjectCacheService } from '../../../../../core/cache/object-cache.service';
import { RequestService } from '../../../../../core/data/request.service';
describe('RelationshipEffects', () => { describe('RelationshipEffects', () => {
let relationEffects: RelationshipEffects; let relationEffects: RelationshipEffects;
@@ -102,7 +104,9 @@ describe('RelationshipEffects', () => {
{ provide: RelationshipTypeService, useValue: mockRelationshipTypeService }, { provide: RelationshipTypeService, useValue: mockRelationshipTypeService },
{ provide: RelationshipService, useValue: mockRelationshipService }, { provide: RelationshipService, useValue: mockRelationshipService },
{ provide: SubmissionObjectDataService, useValue: {findById: () => createSuccessfulRemoteDataObject$(new WorkspaceItem())}}, { provide: SubmissionObjectDataService, useValue: {findById: () => createSuccessfulRemoteDataObject$(new WorkspaceItem())}},
{ provide: Store, useValue: jasmine.createSpyObj('store', ['dispatch']) } { provide: Store, useValue: jasmine.createSpyObj('store', ['dispatch']) },
{ provide: ObjectCacheService, useValue: {}},
{ provide: RequestService, useValue: {}},
], ],
}); });
})); }));

View File

@@ -92,7 +92,6 @@ function init() {
groupFactory: () => { groupFactory: () => {
return [ return [
new DynamicInputModel({ new DynamicInputModel({
id: 'bootstrapArrayGroupInput', id: 'bootstrapArrayGroupInput',
placeholder: 'example array group input', placeholder: 'example array group input',
readOnly: false readOnly: false
@@ -363,7 +362,7 @@ describe('FormComponent test suite', () => {
spyOn((formComp as any).formService, 'validateAllFormFields'); spyOn((formComp as any).formService, 'validateAllFormFields');
form.next(formState.testForm) form.next(formState.testForm);
formFixture.detectChanges(); formFixture.detectChanges();
formComp.onSubmit(); formComp.onSubmit();
@@ -419,7 +418,7 @@ describe('FormComponent test suite', () => {
})); }));
it('should dispatch FormChangeAction when an item has been removed from an array', inject([FormBuilderService], (service: FormBuilderService) => { it('should dispatch FormChangeAction when an item has been removed from an array', inject([FormBuilderService], (service: FormBuilderService) => {
formComp.removeItem(new Event('click'), formComp.formModel[0] as DynamicFormArrayModel, 0); formComp.removeItem(new Event('click'), formComp.formModel[0] as DynamicFormArrayModel, 1);
expect(store.dispatch).toHaveBeenCalledWith(new FormChangeAction('testFormArray', service.getValueFromModel(formComp.formModel))); expect(store.dispatch).toHaveBeenCalledWith(new FormChangeAction('testFormArray', service.getValueFromModel(formComp.formModel)));
})); }));
@@ -427,7 +426,7 @@ describe('FormComponent test suite', () => {
it('should emit removeArrayItem Event when an item has been removed from an array', inject([FormBuilderService], (service: FormBuilderService) => { it('should emit removeArrayItem Event when an item has been removed from an array', inject([FormBuilderService], (service: FormBuilderService) => {
spyOn(formComp.removeArrayItem, 'emit'); spyOn(formComp.removeArrayItem, 'emit');
formComp.removeItem(new Event('click'), formComp.formModel[0] as DynamicFormArrayModel, 0); formComp.removeItem(new Event('click'), formComp.formModel[0] as DynamicFormArrayModel, 1);
expect(formComp.removeArrayItem.emit).toHaveBeenCalled(); expect(formComp.removeArrayItem.emit).toHaveBeenCalled();
})); }));

View File

@@ -304,7 +304,6 @@ export class FormComponent implements OnDestroy, OnInit {
this.formBuilderService.addFormArrayGroup(formArrayControl, arrayContext); this.formBuilderService.addFormArrayGroup(formArrayControl, arrayContext);
const value = formArrayControl.controls[index].value; const value = formArrayControl.controls[index].value;
formArrayControl.controls[formArrayControl.length - 1].setValue(value); formArrayControl.controls[formArrayControl.length - 1].setValue(value);
formArrayControl.controls[index].setValue(undefined);
formArrayControl.controls[index].reset(); formArrayControl.controls[index].reset();
this.addArrayItem.emit(this.getEvent($event, arrayContext, index, 'add')); this.addArrayItem.emit(this.getEvent($event, arrayContext, index, 'add'));
this.formService.changeForm(this.formId, this.formModel); this.formService.changeForm(this.formId, this.formModel);