diff --git a/src/app/admin/admin-search-page/admin-search-results/admin-search-result-grid-element/collection-search-result/collection-admin-search-result-grid-element.component.spec.ts b/src/app/admin/admin-search-page/admin-search-results/admin-search-result-grid-element/collection-search-result/collection-admin-search-result-grid-element.component.spec.ts index 2cb0413bbc..9a28fd745f 100644 --- a/src/app/admin/admin-search-page/admin-search-results/admin-search-result-grid-element/collection-search-result/collection-admin-search-result-grid-element.component.spec.ts +++ b/src/app/admin/admin-search-page/admin-search-results/admin-search-result-grid-element/collection-search-result/collection-admin-search-result-grid-element.component.spec.ts @@ -14,6 +14,8 @@ import { By } from '@angular/platform-browser'; import { RouterTestingModule } from '@angular/router/testing'; import { getCollectionEditRoute } from '../../../../../collection-page/collection-page-routing-paths'; 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', () => { let component: CollectionAdminSearchResultGridElementComponent; @@ -45,7 +47,8 @@ describe('CollectionAdminSearchResultGridElementComponent', () => { providers: [ { provide: TruncatableService, useValue: mockTruncatableService }, { provide: BitstreamDataService, useValue: {} }, - { provide: LinkService, useValue: linkService } + { provide: LinkService, useValue: linkService }, + { provide: ThemeService, useValue: getMockThemeService() }, ] }) .compileComponents(); diff --git a/src/app/home-page/top-level-community-list/top-level-community-list.component.spec.ts b/src/app/home-page/top-level-community-list/top-level-community-list.component.spec.ts index 00408e4696..c9e8f37ee9 100644 --- a/src/app/home-page/top-level-community-list/top-level-community-list.component.spec.ts +++ b/src/app/home-page/top-level-community-list/top-level-community-list.component.spec.ts @@ -26,7 +26,7 @@ import { getMockThemeService } from '../../shared/mocks/theme-service.mock'; import { ThemeService } from '../../shared/theme-support/theme.service'; import { PaginationServiceStub } from '../../shared/testing/pagination-service.stub'; -describe('TopLevelCommunityList Component', () => { +fdescribe('TopLevelCommunityList Component', () => { let comp: TopLevelCommunityListComponent; let fixture: ComponentFixture; let communityDataServiceStub: any; @@ -131,7 +131,6 @@ describe('TopLevelCommunityList Component', () => { { provide: SelectableListService, useValue: {} }, { provide: ThemeService, useValue: themeService }, ], - schemas: [NO_ERRORS_SCHEMA] }).compileComponents(); })); diff --git a/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.spec.ts b/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.spec.ts index edf0b3ea7c..4a63a256b6 100644 --- a/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.spec.ts +++ b/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.spec.ts @@ -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', () => { let listableComponent; let reloadedObject: any; diff --git a/src/app/shared/object-list/badges/badges.component.html b/src/app/shared/object-list/badges/badges.component.html index 2a5704970c..1e59ca3660 100644 --- a/src/app/shared/object-list/badges/badges.component.html +++ b/src/app/shared/object-list/badges/badges.component.html @@ -1,6 +1,2 @@ -
- -
-
- -
+ + diff --git a/src/app/shared/object-list/badges/status-badge/status-badge.component.html b/src/app/shared/object-list/badges/status-badge/status-badge.component.html index 1f28aedf34..c864f22afa 100644 --- a/src/app/shared/object-list/badges/status-badge/status-badge.component.html +++ b/src/app/shared/object-list/badges/status-badge/status-badge.component.html @@ -1,6 +1,6 @@ - +
{{ "item.badge.private" | translate }} - - +
+
{{ "item.badge.withdrawn" | translate }} - +
diff --git a/src/app/shared/object-list/badges/status-badge/status-badge.component.spec.ts b/src/app/shared/object-list/badges/status-badge/status-badge.component.spec.ts index 09bc7ea585..4cfa0e2341 100644 --- a/src/app/shared/object-list/badges/status-badge/status-badge.component.spec.ts +++ b/src/app/shared/object-list/badges/status-badge/status-badge.component.spec.ts @@ -6,37 +6,17 @@ import { TruncatePipe } from '../../../utils/truncate.pipe'; import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; import { By } from '@angular/platform-browser'; import { StatusBadgeComponent } from './status-badge.component'; +import { ViewMode } from '../../../../core/shared/view-mode.model'; let comp: StatusBadgeComponent; let fixture: ComponentFixture; -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(), { - 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', () => { +describe('ItemStatusBadgeComponent', () => { beforeEach(waitForAsync(() => { TestBed.configureTestingModule({ imports: [TranslateModule.forRoot()], @@ -45,34 +25,69 @@ describe('ItemTypeBadgeComponent', () => { }).overrideComponent(StatusBadgeComponent, { set: { changeDetection: ChangeDetectionStrategy.Default } }).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(() => { fixture = TestBed.createComponent(StatusBadgeComponent); comp = fixture.componentInstance; })); - describe('When the item has an entity type', () => { + + describe('when the item is not withdrawn', () => { beforeEach(() => { - comp.object = mockItemWithEntityType; + comp.object = notWithdrawnItem; + comp.ngOnInit(); fixture.detectChanges(); }); - it('should show the entity type badge', () => { - const badge = fixture.debugElement.query(By.css('span.badge')); - expect(badge.nativeElement.textContent).toContain(type.toLowerCase()); + it('should not show the withdrawn badge', () => { + const badge = fixture.debugElement.query(By.css('div.withdrawn-badge')); + expect(badge).toBeNull(); }); }); - describe('When the item has no entity type', () => { + describe('when the item is withdrawn', () => { beforeEach(() => { - comp.object = mockItemWithoutEntityType; + comp.object = withdrawnItem; + comp.ngOnInit(); fixture.detectChanges(); }); - it('should show an item badge', () => { - const badge = fixture.debugElement.query(By.css('span.badge')); - expect(badge.nativeElement.textContent).toContain('item'); + 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 = 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(); }); }); }); diff --git a/src/app/shared/object-list/badges/type-badge/type-badge.component.html b/src/app/shared/object-list/badges/type-badge/type-badge.component.html index 119702c375..0c2bd7544e 100644 --- a/src/app/shared/object-list/badges/type-badge/type-badge.component.html +++ b/src/app/shared/object-list/badges/type-badge/type-badge.component.html @@ -1,3 +1,3 @@ - +
{{ typeMessage | translate }} - +
diff --git a/src/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.spec.ts b/src/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.spec.ts index 023b51a8dd..65147f17d4 100644 --- a/src/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.spec.ts +++ b/src/app/shared/object-list/my-dspace-result-list-element/item-list-preview/item-list-preview.component.spec.ts @@ -154,8 +154,8 @@ describe('ItemListPreviewComponent', () => { fixture.detectChanges(); }); - it('should show the entity type span', () => { - const entityField = fixture.debugElement.query(By.css('ds-type-badge')); + it('should show the badges', () => { + const entityField = fixture.debugElement.query(By.css('ds-themed-badges')); expect(entityField).not.toBeNull(); }); }); diff --git a/src/app/shared/search-form/search-form.component.spec.ts b/src/app/shared/search-form/search-form.component.spec.ts index 20c9435eb4..f1c05d47df 100644 --- a/src/app/shared/search-form/search-form.component.spec.ts +++ b/src/app/shared/search-form/search-form.component.spec.ts @@ -36,7 +36,9 @@ describe('SearchFormComponent', () => { { provide: SearchConfigurationService, useValue: searchConfigService }, { provide: DSpaceObjectDataService, useValue: { findById: () => createSuccessfulRemoteDataObject$(undefined)} } ], - declarations: [SearchFormComponent] + declarations: [ + SearchFormComponent, + ] }).compileComponents(); })); @@ -47,21 +49,23 @@ describe('SearchFormComponent', () => { el = de.nativeElement; }); - it('should not display scopes when empty', () => { - fixture.detectChanges(); - 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; + it('should not display scopes when showScopeSelector is false', fakeAsync(() => { + comp.showScopeSelector = false; fixture.detectChanges(); - const select = de.query(By.css('select')); - expect(select).toBeNull(); - }); + tick(); + + 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(() => { const testString = 'This is a test query';