mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 01:54:15 +00:00
90252: Fix flaky tests
This commit is contained in:
@@ -2,10 +2,10 @@ import { CommonModule } from '@angular/common';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { NO_ERRORS_SCHEMA } from '@angular/core';
|
||||
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
||||
import { FormsModule, ReactiveFormsModule, FormArray, FormControl, FormGroup,Validators, NG_VALIDATORS, NG_ASYNC_VALIDATORS } from '@angular/forms';
|
||||
import { FormControl, FormGroup, FormsModule, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { BrowserModule, By } from '@angular/platform-browser';
|
||||
import { ActivatedRoute, Router } from '@angular/router';
|
||||
import { NgbModal, NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { NgbModule } from '@ng-bootstrap/ng-bootstrap';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { TranslateLoader, TranslateModule, TranslateService } from '@ngx-translate/core';
|
||||
import { Observable, of as observableOf } from 'rxjs';
|
||||
@@ -27,7 +27,7 @@ import { FormBuilderService } from '../../../shared/form/builder/form-builder.se
|
||||
import { NotificationsService } from '../../../shared/notifications/notifications.service';
|
||||
import { GroupMock, GroupMock2 } from '../../../shared/testing/group-mock';
|
||||
import { GroupFormComponent } from './group-form.component';
|
||||
import { createFailedRemoteDataObject$, createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
|
||||
import { getMockFormBuilderService } from '../../../shared/mocks/form-builder-service.mock';
|
||||
import { getMockTranslateService } from '../../../shared/mocks/translate.service.mock';
|
||||
import { TranslateLoaderMock } from '../../../shared/testing/translate-loader.mock';
|
||||
@@ -354,8 +354,6 @@ describe('GroupFormComponent', () => {
|
||||
|
||||
describe('delete', () => {
|
||||
let deleteButton;
|
||||
let confirmButton;
|
||||
let cancelButton;
|
||||
|
||||
beforeEach(() => {
|
||||
component.initialisePage();
|
||||
@@ -373,31 +371,25 @@ describe('GroupFormComponent', () => {
|
||||
});
|
||||
|
||||
describe('if confirmed via modal', () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
deleteButton.click();
|
||||
fixture.detectChanges();
|
||||
confirmButton = (document as any).querySelector('.modal-footer .confirm');
|
||||
});
|
||||
(document as any).querySelector('.modal-footer .confirm').click();
|
||||
}));
|
||||
|
||||
it('should call GroupDataService.delete', () => {
|
||||
confirmButton.click();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(groupsDataServiceStub.delete).toHaveBeenCalledWith('active-group');
|
||||
});
|
||||
});
|
||||
|
||||
describe('if canceled via modal', () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
deleteButton.click();
|
||||
fixture.detectChanges();
|
||||
cancelButton = (document as any).querySelector('.modal-footer .cancel');
|
||||
});
|
||||
(document as any).querySelector('.modal-footer .cancel').click();
|
||||
}));
|
||||
|
||||
it('should not call GroupDataService.delete', () => {
|
||||
cancelButton.click();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(groupsDataServiceStub.delete).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
@@ -2,7 +2,7 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { VersionedItemComponent } from './versioned-item.component';
|
||||
import { VersionHistoryDataService } from '../../../../core/data/version-history-data.service';
|
||||
import { TranslateService } from '@ngx-translate/core';
|
||||
import { TranslateLoader, TranslateModule } from '@ngx-translate/core';
|
||||
import { VersionDataService } from '../../../../core/data/version-data.service';
|
||||
import { NotificationsService } from '../../../../shared/notifications/notifications.service';
|
||||
import { ItemVersionsSharedService } from '../../../../shared/item/item-versions/item-versions-shared.service';
|
||||
@@ -19,6 +19,7 @@ import { SearchService } from '../../../../core/shared/search/search.service';
|
||||
import { ItemDataService } from '../../../../core/data/item-data.service';
|
||||
import { Version } from '../../../../core/shared/version.model';
|
||||
import { RouteService } from '../../../../core/services/route.service';
|
||||
import { TranslateLoaderMock } from '../../../../shared/testing/translate-loader.mock';
|
||||
|
||||
const mockItem: Item = Object.assign(new Item(), {
|
||||
bundles: createSuccessfulRemoteDataObject$(buildPaginatedList(new PageInfo(), [])),
|
||||
@@ -57,10 +58,17 @@ describe('VersionedItemComponent', () => {
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
declarations: [VersionedItemComponent, DummyComponent],
|
||||
imports: [RouterTestingModule],
|
||||
imports: [
|
||||
RouterTestingModule,
|
||||
TranslateModule.forRoot({
|
||||
loader: {
|
||||
provide: TranslateLoader,
|
||||
useClass: TranslateLoaderMock,
|
||||
}
|
||||
}),
|
||||
],
|
||||
providers: [
|
||||
{ provide: VersionHistoryDataService, useValue: versionHistoryServiceSpy },
|
||||
{ provide: TranslateService, useValue: {} },
|
||||
{ provide: VersionDataService, useValue: versionServiceSpy },
|
||||
{ provide: NotificationsService, useValue: {} },
|
||||
{ provide: ItemVersionsSharedService, useValue: {} },
|
||||
|
@@ -297,8 +297,6 @@ describe('ItemVersionsComponent', () => {
|
||||
|
||||
describe('when deleting a version', () => {
|
||||
let deleteButton;
|
||||
let confirmButton;
|
||||
let cancelButton;
|
||||
|
||||
beforeEach(() => {
|
||||
const canDelete = (featureID: FeatureID, url: string ) => of(featureID === FeatureID.CanDeleteVersion);
|
||||
@@ -313,31 +311,25 @@ describe('ItemVersionsComponent', () => {
|
||||
});
|
||||
|
||||
describe('if confirmed via modal', () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
deleteButton.click();
|
||||
fixture.detectChanges();
|
||||
confirmButton = (document as any).querySelector('.modal-footer .confirm');
|
||||
});
|
||||
(document as any).querySelector('.modal-footer .confirm').click();
|
||||
}));
|
||||
|
||||
it('should call ItemService.delete', () => {
|
||||
confirmButton.click();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(itemDataServiceSpy.delete).toHaveBeenCalledWith(item2.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe('if canceled via modal', () => {
|
||||
beforeEach(() => {
|
||||
beforeEach(waitForAsync(() => {
|
||||
deleteButton.click();
|
||||
fixture.detectChanges();
|
||||
cancelButton = (document as any).querySelector('.modal-footer .cancel');
|
||||
});
|
||||
(document as any).querySelector('.modal-footer .cancel').click();
|
||||
}));
|
||||
|
||||
it('should not call ItemService.delete', () => {
|
||||
cancelButton.click();
|
||||
fixture.detectChanges();
|
||||
|
||||
expect(itemDataServiceSpy.delete).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
@@ -84,7 +84,7 @@ describe('SearchSwitchConfigurationComponent', () => {
|
||||
expect(childElements.length).toEqual(comp.configurationList.length);
|
||||
});
|
||||
|
||||
it('should call onSelect method when selecting an option', () => {
|
||||
it('should call onSelect method when selecting an option', waitForAsync(() => {
|
||||
fixture.whenStable().then(() => {
|
||||
spyOn(comp, 'onSelect');
|
||||
select = fixture.debugElement.query(By.css('select'));
|
||||
@@ -94,8 +94,7 @@ describe('SearchSwitchConfigurationComponent', () => {
|
||||
fixture.detectChanges();
|
||||
expect(comp.onSelect).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
});
|
||||
}));
|
||||
|
||||
it('should navigate to the route when selecting an option', () => {
|
||||
spyOn((comp as any), 'getSearchLinkParts').and.returnValue([MYDSPACE_ROUTE]);
|
||||
|
Reference in New Issue
Block a user