Commits
Paulo Graça authored 1919f976f41
1 1 | import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing'; |
2 2 | import { ChangeDetectionStrategy, NO_ERRORS_SCHEMA } from '@angular/core'; |
3 3 | import { By } from '@angular/platform-browser'; |
4 4 | |
5 5 | import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; |
6 6 | |
7 7 | import { ItemMetadataRepresentation } from '../../../../core/shared/metadata-representation/item/item-metadata-representation.model'; |
8 8 | import { Item } from '../../../../core/shared/item.model'; |
9 9 | import { ProjectItemMetadataListElementComponent } from './project-item-metadata-list-element.component'; |
10 10 | import { MetadataValue } from '../../../../core/shared/metadata.models'; |
11 11 | import { DSONameService } from '../../../../core/breadcrumbs/dso-name.service'; |
12 + | import { DSONameServiceMock } from '../../../../shared/mocks/dso-name.service.mock'; |
12 13 | |
13 14 | const projectTitle = 'Lorem ipsum dolor sit amet'; |
14 15 | const mockItem = Object.assign(new Item(), { metadata: { 'dc.title': [{ value: projectTitle }] } }); |
15 16 | const virtMD = Object.assign(new MetadataValue(), { value: projectTitle }); |
16 17 | |
17 18 | const mockItemMetadataRepresentation = Object.assign(new ItemMetadataRepresentation(virtMD), mockItem); |
18 19 | |
19 20 | describe('ProjectItemMetadataListElementComponent', () => { |
20 21 | let comp: ProjectItemMetadataListElementComponent; |
21 22 | let fixture: ComponentFixture<ProjectItemMetadataListElementComponent>; |
22 23 | |
23 24 | beforeEach(waitForAsync(() => { |
24 25 | TestBed.configureTestingModule({ |
25 26 | imports:[ |
26 27 | NgbModule |
27 28 | ], |
28 29 | declarations: [ProjectItemMetadataListElementComponent], |
29 30 | providers: [ |
30 - | { provide: DSONameService, useValue: dsoNameService } |
31 + | { provide: DSONameService, useValue: new DSONameServiceMock() } |
31 32 | ], |
32 33 | schemas: [NO_ERRORS_SCHEMA] |
33 34 | }).overrideComponent(ProjectItemMetadataListElementComponent, { |
34 35 | set: { changeDetection: ChangeDetectionStrategy.Default } |
35 36 | }).compileComponents(); |
36 37 | })); |
37 38 | |
38 39 | beforeEach(() => { |
39 40 | fixture = TestBed.createComponent(ProjectItemMetadataListElementComponent); |
40 41 | comp = fixture.componentInstance; |
41 42 | comp.mdRepresentation = mockItemMetadataRepresentation; |
42 43 | fixture.detectChanges(); |
43 - | dsoNameService = jasmine.createSpyObj({ |
44 - | getName: projectTitle |
45 - | }); |
46 44 | }); |
47 45 | |
48 46 | it('should show the project\'s name as a link', () => { |
49 47 | const linkText = fixture.debugElement.query(By.css('a')).nativeElement.textContent; |
50 48 | expect(linkText).toBe(projectTitle); |
51 49 | }); |
52 50 | |
53 51 | }); |