|
| 1 | +import { ComponentFixture, TestBed } from '@angular/core/testing'; |
| 2 | + |
| 3 | +import { BrowseByTaxonomyPageComponent } from './browse-by-taxonomy-page.component'; |
| 4 | +import { VocabularyEntryDetail } from '../../core/submission/vocabularies/models/vocabulary-entry-detail.model'; |
| 5 | +import { TranslateModule } from '@ngx-translate/core'; |
| 6 | +import { NO_ERRORS_SCHEMA } from '@angular/core'; |
| 7 | +import { ActivatedRoute } from '@angular/router'; |
| 8 | +import { BehaviorSubject } from 'rxjs'; |
| 9 | +import { createDataWithBrowseDefinition } from '../browse-by-switcher/browse-by-switcher.component.spec'; |
| 10 | +import { HierarchicalBrowseDefinition } from '../../core/shared/hierarchical-browse-definition.model'; |
| 11 | +import { ThemeService } from '../../shared/theme-support/theme.service'; |
| 12 | + |
| 13 | +describe('BrowseByTaxonomyPageComponent', () => { |
| 14 | + let component: BrowseByTaxonomyPageComponent; |
| 15 | + let fixture: ComponentFixture<BrowseByTaxonomyPageComponent>; |
| 16 | + let themeService: ThemeService; |
| 17 | + let detail1: VocabularyEntryDetail; |
| 18 | + let detail2: VocabularyEntryDetail; |
| 19 | + |
| 20 | + const data = new BehaviorSubject(createDataWithBrowseDefinition(new HierarchicalBrowseDefinition())); |
| 21 | + const activatedRouteStub = { |
| 22 | + data |
| 23 | + }; |
| 24 | + |
| 25 | + beforeEach(async () => { |
| 26 | + themeService = jasmine.createSpyObj('themeService', { |
| 27 | + getThemeName: 'dspace', |
| 28 | + }); |
| 29 | + |
| 30 | + await TestBed.configureTestingModule({ |
| 31 | + imports: [ TranslateModule.forRoot() ], |
| 32 | + declarations: [ BrowseByTaxonomyPageComponent ], |
| 33 | + providers: [ |
| 34 | + { provide: ActivatedRoute, useValue: activatedRouteStub }, |
| 35 | + { provide: ThemeService, useValue: themeService }, |
| 36 | + ], |
| 37 | + schemas: [NO_ERRORS_SCHEMA] |
| 38 | + }) |
| 39 | + .compileComponents(); |
| 40 | + }); |
| 41 | + |
| 42 | + beforeEach(() => { |
| 43 | + fixture = TestBed.createComponent(BrowseByTaxonomyPageComponent); |
| 44 | + component = fixture.componentInstance; |
| 45 | + fixture.detectChanges(); |
| 46 | + detail1 = new VocabularyEntryDetail(); |
| 47 | + detail2 = new VocabularyEntryDetail(); |
| 48 | + detail1.value = 'HUMANITIES and RELIGION'; |
| 49 | + detail2.value = 'TECHNOLOGY'; |
| 50 | + detail1.id = 'id-1'; |
| 51 | + detail2.id = 'id-2'; |
| 52 | + }); |
| 53 | + |
| 54 | + it('should create', () => { |
| 55 | + expect(component).toBeTruthy(); |
| 56 | + }); |
| 57 | + |
| 58 | + it('should handle select event', () => { |
| 59 | + component.onSelect(detail1); |
| 60 | + expect(component.selectedItems.length).toBe(1); |
| 61 | + expect(component.selectedItems).toContain(detail1); |
| 62 | + expect(component.selectedItems.length).toBe(1); |
| 63 | + expect(component.filterValues).toEqual(['HUMANITIES and RELIGION,equals'] ); |
| 64 | + }); |
| 65 | + |
| 66 | + it('should handle select event with multiple selected items', () => { |
| 67 | + component.onSelect(detail1); |
| 68 | + component.onSelect(detail2); |
| 69 | + expect(component.selectedItems.length).toBe(2); |
| 70 | + expect(component.selectedItems).toContain(detail1, detail2); |
| 71 | + expect(component.selectedItems.length).toBe(2); |
| 72 | + expect(component.filterValues).toEqual(['HUMANITIES and RELIGION,equals', 'TECHNOLOGY,equals'] ); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should handle deselect event', () => { |
| 76 | + component.onSelect(detail1); |
| 77 | + component.onSelect(detail2); |
| 78 | + expect(component.selectedItems.length).toBe(2); |
| 79 | + expect(component.selectedItems.length).toBe(2); |
| 80 | + component.onDeselect(detail1); |
| 81 | + expect(component.selectedItems.length).toBe(1); |
| 82 | + expect(component.selectedItems).toContain(detail2); |
| 83 | + expect(component.selectedItems.length).toBe(1); |
| 84 | + expect(component.filterValues).toEqual(['TECHNOLOGY,equals'] ); |
| 85 | + }); |
| 86 | + |
| 87 | + afterEach(() => { |
| 88 | + fixture.destroy(); |
| 89 | + component = null; |
| 90 | + }); |
| 91 | +}); |
0 commit comments