Fixing tests

This commit is contained in:
lotte
2023-01-24 09:30:45 +01:00
parent d7b38b2a78
commit 1f2897664a
9 changed files with 84 additions and 125 deletions

View File

@@ -14,6 +14,8 @@ import { By } from '@angular/platform-browser';
import { RouterTestingModule } from '@angular/router/testing'; import { RouterTestingModule } from '@angular/router/testing';
import { getCollectionEditRoute } from '../../../../../collection-page/collection-page-routing-paths'; import { getCollectionEditRoute } from '../../../../../collection-page/collection-page-routing-paths';
import { LinkService } from '../../../../../core/cache/builders/link.service'; import { LinkService } from '../../../../../core/cache/builders/link.service';
import { ThemeService } from '../../../../../shared/theme-support/theme.service';
import { getMockThemeService } from '../../../../../shared/mocks/theme-service.mock';
describe('CollectionAdminSearchResultGridElementComponent', () => { describe('CollectionAdminSearchResultGridElementComponent', () => {
let component: CollectionAdminSearchResultGridElementComponent; let component: CollectionAdminSearchResultGridElementComponent;
@@ -45,7 +47,8 @@ describe('CollectionAdminSearchResultGridElementComponent', () => {
providers: [ providers: [
{ provide: TruncatableService, useValue: mockTruncatableService }, { provide: TruncatableService, useValue: mockTruncatableService },
{ provide: BitstreamDataService, useValue: {} }, { provide: BitstreamDataService, useValue: {} },
{ provide: LinkService, useValue: linkService } { provide: LinkService, useValue: linkService },
{ provide: ThemeService, useValue: getMockThemeService() },
] ]
}) })
.compileComponents(); .compileComponents();

View File

@@ -26,7 +26,7 @@ import { getMockThemeService } from '../../shared/mocks/theme-service.mock';
import { ThemeService } from '../../shared/theme-support/theme.service'; import { ThemeService } from '../../shared/theme-support/theme.service';
import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub'; import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub';
describe('TopLevelCommunityList Component', () => { fdescribe('TopLevelCommunityList Component', () => {
let comp: TopLevelCommunityListComponent; let comp: TopLevelCommunityListComponent;
let fixture: ComponentFixture<TopLevelCommunityListComponent>; let fixture: ComponentFixture<TopLevelCommunityListComponent>;
let communityDataServiceStub: any; let communityDataServiceStub: any;
@@ -131,7 +131,6 @@ describe('TopLevelCommunityList Component', () => {
{ provide: SelectableListService, useValue: {} }, { provide: SelectableListService, useValue: {} },
{ provide: ThemeService, useValue: themeService }, { provide: ThemeService, useValue: themeService },
], ],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents(); }).compileComponents();
})); }));

View File

@@ -72,64 +72,6 @@ describe('ListableObjectComponentLoaderComponent', () => {
}); });
}); });
describe('when the object is an item and viewMode is a list', () => {
beforeEach(() => {
comp.object = Object.assign(new Item());
comp.viewMode = ViewMode.ListElement;
});
describe('when the item is not withdrawn', () => {
beforeEach(() => {
(comp.object as any).isWithdrawn = false;
comp.initBadges();
fixture.detectChanges();
});
it('should not show the withdrawn badge', () => {
const badge = fixture.debugElement.query(By.css('div.withdrawn-badge'));
expect(badge).toBeNull();
});
});
describe('when the item is withdrawn', () => {
beforeEach(() => {
(comp.object as any).isWithdrawn = true;
comp.initBadges();
fixture.detectChanges();
});
it('should show the withdrawn badge', () => {
const badge = fixture.debugElement.query(By.css('div.withdrawn-badge'));
expect(badge).not.toBeNull();
});
});
describe('when the item is not private', () => {
beforeEach(() => {
(comp.object as any).isDiscoverable = true;
comp.initBadges();
fixture.detectChanges();
});
it('should not show the private badge', () => {
const badge = fixture.debugElement.query(By.css('div.private-badge'));
expect(badge).toBeNull();
});
});
describe('when the item is private', () => {
beforeEach(() => {
(comp.object as any).isDiscoverable = false;
comp.initBadges();
fixture.detectChanges();
});
it('should show the private badge', () => {
const badge = fixture.debugElement.query(By.css('div.private-badge'));
expect(badge).not.toBeNull();
});
});
});
describe('When a reloadedObject is emitted', () => { describe('When a reloadedObject is emitted', () => {
let listableComponent; let listableComponent;
let reloadedObject: any; let reloadedObject: any;

View File

@@ -1,6 +1,2 @@
<div>
<ds-themed-status-badge [object]="object"></ds-themed-status-badge> <ds-themed-status-badge [object]="object"></ds-themed-status-badge>
</div>
<div>
<ds-themed-type-badge [object]="object"></ds-themed-type-badge> <ds-themed-type-badge [object]="object"></ds-themed-type-badge>
</div>

View File

@@ -1,6 +1,6 @@
<span *ngIf="privateBadge" class="private-badge"> <div *ngIf="privateBadge" class="private-badge">
<span class="badge badge-danger">{{ "item.badge.private" | translate }}</span> <span class="badge badge-danger">{{ "item.badge.private" | translate }}</span>
</span> </div>
<span *ngIf="withdrawnBadge" class="withdrawn-badge"> <div *ngIf="withdrawnBadge" class="withdrawn-badge">
<span class="badge badge-warning">{{ "item.badge.withdrawn" | translate }}</span> <span class="badge badge-warning">{{ "item.badge.withdrawn" | translate }}</span>
</span> </div>

View File

@@ -6,37 +6,17 @@ import { TruncatePipe } from '../../../utils/truncate.pipe';
import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core';
import { By } from '@angular/platform-browser'; import { By } from '@angular/platform-browser';
import { StatusBadgeComponent } from './status-badge.component'; import { StatusBadgeComponent } from './status-badge.component';
import { ViewMode } from '../../../../core/shared/view-mode.model';
let comp: StatusBadgeComponent; let comp: StatusBadgeComponent;
let fixture: ComponentFixture<StatusBadgeComponent>; let fixture: ComponentFixture<StatusBadgeComponent>;
const type = 'authorOfPublication'; let withdrawnItem = Object.assign(new Item(), { isWithdrawn: true });
let notWithdrawnItem = Object.assign(new Item(), { isWithdrawn: false });
let privateItem = Object.assign(new Item(), { isDiscoverable: false });
let notPrivateItem = Object.assign(new Item(), { isDiscoverable: true });
const mockItemWithEntityType = Object.assign(new Item(), { describe('ItemStatusBadgeComponent', () => {
bundles: observableOf({}),
metadata: {
'dspace.entity.type': [
{
language: 'en_US',
value: type
}
]
}
});
const mockItemWithoutEntityType = Object.assign(new Item(), {
bundles: observableOf({}),
metadata: {
'dc.title': [
{
language: 'en_US',
value: 'This is just another title'
}
]
}
});
describe('ItemTypeBadgeComponent', () => {
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ TestBed.configureTestingModule({
imports: [TranslateModule.forRoot()], imports: [TranslateModule.forRoot()],
@@ -45,34 +25,69 @@ describe('ItemTypeBadgeComponent', () => {
}).overrideComponent(StatusBadgeComponent, { }).overrideComponent(StatusBadgeComponent, {
set: { changeDetection: ChangeDetectionStrategy.Default } set: { changeDetection: ChangeDetectionStrategy.Default }
}).compileComponents(); }).compileComponents();
init();
})); }));
function init() {
withdrawnItem = Object.assign(new Item(), { isWithdrawn: true });
notWithdrawnItem = Object.assign(new Item(), { isWithdrawn: false });
privateItem = Object.assign(new Item(), { isDiscoverable: false });
notPrivateItem = Object.assign(new Item(), { isDiscoverable: true });
}
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
fixture = TestBed.createComponent(StatusBadgeComponent); fixture = TestBed.createComponent(StatusBadgeComponent);
comp = fixture.componentInstance; comp = fixture.componentInstance;
})); }));
describe('When the item has an entity type', () => {
describe('when the item is not withdrawn', () => {
beforeEach(() => { beforeEach(() => {
comp.object = mockItemWithEntityType; comp.object = notWithdrawnItem;
comp.ngOnInit();
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should show the entity type badge', () => { it('should not show the withdrawn badge', () => {
const badge = fixture.debugElement.query(By.css('span.badge')); const badge = fixture.debugElement.query(By.css('div.withdrawn-badge'));
expect(badge.nativeElement.textContent).toContain(type.toLowerCase()); expect(badge).toBeNull();
}); });
}); });
describe('When the item has no entity type', () => { describe('when the item is withdrawn', () => {
beforeEach(() => { beforeEach(() => {
comp.object = mockItemWithoutEntityType; comp.object = withdrawnItem;
comp.ngOnInit();
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should show an item badge', () => { it('should show the withdrawn badge', () => {
const badge = fixture.debugElement.query(By.css('span.badge')); const badge = fixture.debugElement.query(By.css('div.withdrawn-badge'));
expect(badge.nativeElement.textContent).toContain('item'); expect(badge).not.toBeNull();
});
});
describe('when the item is not private', () => {
beforeEach(() => {
comp.object = notPrivateItem;
comp.ngOnInit();
fixture.detectChanges();
});
it('should not show the private badge', () => {
const badge = fixture.debugElement.query(By.css('div.private-badge'));
expect(badge).toBeNull();
});
});
describe('when the item is private', () => {
beforeEach(() => {
comp.object = privateItem;
comp.ngOnInit();
fixture.detectChanges();
});
it('should show the private badge', () => {
const badge = fixture.debugElement.query(By.css('div.private-badge'));
expect(badge).not.toBeNull();
}); });
}); });
}); });

View File

@@ -1,3 +1,3 @@
<span *ngIf="typeMessage"> <div *ngIf="typeMessage">
<span class="badge badge-info">{{ typeMessage | translate }}</span> <span class="badge badge-info">{{ typeMessage | translate }}</span>
</span> </div>

View File

@@ -154,8 +154,8 @@ describe('ItemListPreviewComponent', () => {
fixture.detectChanges(); fixture.detectChanges();
}); });
it('should show the entity type span', () => { it('should show the badges', () => {
const entityField = fixture.debugElement.query(By.css('ds-type-badge')); const entityField = fixture.debugElement.query(By.css('ds-themed-badges'));
expect(entityField).not.toBeNull(); expect(entityField).not.toBeNull();
}); });
}); });

View File

@@ -36,7 +36,9 @@ describe('SearchFormComponent', () => {
{ provide: SearchConfigurationService, useValue: searchConfigService }, { provide: SearchConfigurationService, useValue: searchConfigService },
{ provide: DSpaceObjectDataService, useValue: { findById: () => createSuccessfulRemoteDataObject$(undefined)} } { provide: DSpaceObjectDataService, useValue: { findById: () => createSuccessfulRemoteDataObject$(undefined)} }
], ],
declarations: [SearchFormComponent] declarations: [
SearchFormComponent,
]
}).compileComponents(); }).compileComponents();
})); }));
@@ -47,21 +49,23 @@ describe('SearchFormComponent', () => {
el = de.nativeElement; el = de.nativeElement;
}); });
it('should not display scopes when empty', () => { it('should not display scopes when showScopeSelector is false', fakeAsync(() => {
fixture.detectChanges(); comp.showScopeSelector = false;
const select = de.query(By.css('select'));
expect(select).toBeNull();
});
it('should not display scopes when scopeSelectable is false', () => {
comp.scopeSelectable = false;
comp.scopes = objects;
comp.scope = objects[1].id;
fixture.detectChanges(); fixture.detectChanges();
const select = de.query(By.css('select')); tick();
expect(select).toBeNull();
}); expect(de.query(By.css('.scope-button'))).toBeFalsy();
}));
it('should display scopes when showScopeSelector is true', fakeAsync(() => {
comp.showScopeSelector = true;
fixture.detectChanges();
tick();
expect(de.query(By.css('.scope-button'))).toBeTruthy();
}));
it('should display set query value in input field', fakeAsync(() => { it('should display set query value in input field', fakeAsync(() => {
const testString = 'This is a test query'; const testString = 'This is a test query';