|
| 1 | +import { |
| 2 | + ChangeDetectionStrategy, |
| 3 | + NO_ERRORS_SCHEMA, |
| 4 | +} from '@angular/core'; |
| 5 | +import { |
| 6 | + ComponentFixture, |
| 7 | + TestBed, |
| 8 | + waitForAsync, |
| 9 | +} from '@angular/core/testing'; |
| 10 | +import { LayoutField } from '@dspace/core/layout/models/box.model'; |
| 11 | +import { Item } from '@dspace/core/shared/item.model'; |
| 12 | +import { TranslateLoaderMock } from '@dspace/core/testing/translate-loader.mock'; |
| 13 | +import { |
| 14 | + TranslateLoader, |
| 15 | + TranslateModule, |
| 16 | +} from '@ngx-translate/core'; |
| 17 | + |
| 18 | +import { OpenstreetmapComponent } from './openstreetmap.component'; |
| 19 | + |
| 20 | +describe('OpenstreetmapComponent', () => { |
| 21 | + let component: OpenstreetmapComponent; |
| 22 | + let fixture: ComponentFixture<OpenstreetmapComponent>; |
| 23 | + const testItem = Object.assign(new Item(), { |
| 24 | + uuid: 'itemUUID', |
| 25 | + id: 'itemUUID', |
| 26 | + metadata: { |
| 27 | + 'dcterms.spatial': [ |
| 28 | + { |
| 29 | + value: 'POINT(12.4924 41.8902)', |
| 30 | + }, |
| 31 | + { |
| 32 | + value: 'POINT(2.3522 48.8566)', |
| 33 | + }, |
| 34 | + ], |
| 35 | + 'dc.coverage.spatial': [ |
| 36 | + { |
| 37 | + value: 'POINT(-0.1278 51.5074)', |
| 38 | + }, |
| 39 | + { |
| 40 | + value: '{westlimit=12.23, southlimit=41.65, eastlimit=12.85, northlimit=42.02}', |
| 41 | + }, |
| 42 | + ], |
| 43 | + }, |
| 44 | + _links: { |
| 45 | + self: { href: 'item-selflink' }, |
| 46 | + }, |
| 47 | + }); |
| 48 | + |
| 49 | + const mockField = Object.assign({ |
| 50 | + id: 1, |
| 51 | + metadata: 'dcterms.spatial', |
| 52 | + fieldType: 'METADATAGROUP', |
| 53 | + label: 'Location(s)', |
| 54 | + rendering: 'OPENSTREETMAP', |
| 55 | + style: 'container row', |
| 56 | + styleLabel: 'fw-bold col-4', |
| 57 | + styleValue: 'col', |
| 58 | + metadataGroup: { |
| 59 | + leading: 'dcterms.spatial', |
| 60 | + elements: [ |
| 61 | + { |
| 62 | + metadata: 'dcterms.spatial', |
| 63 | + label: 'Spatial', |
| 64 | + rendering: 'TEXT', |
| 65 | + fieldType: 'METADATA', |
| 66 | + style: null, |
| 67 | + styleLabel: 'fw-bold col-0', |
| 68 | + styleValue: 'col', |
| 69 | + }, |
| 70 | + { |
| 71 | + metadata: 'dc.coverage.spatial', |
| 72 | + label: 'Coverage', |
| 73 | + rendering: 'TEXT', |
| 74 | + fieldType: 'METADATA', |
| 75 | + style: null, |
| 76 | + styleLabel: 'fw-bold col-0', |
| 77 | + styleValue: 'col', |
| 78 | + }, |
| 79 | + ], |
| 80 | + }, |
| 81 | + }) as LayoutField; |
| 82 | + |
| 83 | + beforeEach(waitForAsync(() => { |
| 84 | + TestBed.configureTestingModule({ |
| 85 | + imports: [ |
| 86 | + TranslateModule.forRoot({ |
| 87 | + loader: { |
| 88 | + provide: TranslateLoader, |
| 89 | + useClass: TranslateLoaderMock, |
| 90 | + }, |
| 91 | + }), |
| 92 | + OpenstreetmapComponent, |
| 93 | + ], |
| 94 | + providers: [ |
| 95 | + { provide: 'fieldProvider', useValue: mockField }, |
| 96 | + { provide: 'itemProvider', useValue: testItem }, |
| 97 | + { provide: 'renderingSubTypeProvider', useValue: '' }, |
| 98 | + { provide: 'tabNameProvider', useValue: '' }, |
| 99 | + ], |
| 100 | + schemas: [NO_ERRORS_SCHEMA], |
| 101 | + }).overrideComponent(OpenstreetmapComponent, { |
| 102 | + set: { changeDetection: ChangeDetectionStrategy.OnPush }, |
| 103 | + }).compileComponents(); |
| 104 | + })); |
| 105 | + |
| 106 | + beforeEach(() => { |
| 107 | + fixture = TestBed.createComponent(OpenstreetmapComponent); |
| 108 | + component = fixture.componentInstance; |
| 109 | + fixture.detectChanges(); |
| 110 | + }); |
| 111 | + |
| 112 | + it('should create', () => { |
| 113 | + expect(component).toBeTruthy(); |
| 114 | + }); |
| 115 | + |
| 116 | + it('should extract coordinates from multiple metadata fields', () => { |
| 117 | + expect(component.points.length).toBe(3); |
| 118 | + expect(component.points).toContain('POINT(12.4924 41.8902)'); |
| 119 | + expect(component.points).toContain('POINT(2.3522 48.8566)'); |
| 120 | + expect(component.points).toContain('POINT(-0.1278 51.5074)'); |
| 121 | + }); |
| 122 | + |
| 123 | + it('should extract bboxes from multiple metadata fields', () => { |
| 124 | + expect(component.bboxes.length).toBe(1); |
| 125 | + expect(component.bboxes).toContain('{westlimit=12.23, southlimit=41.65, eastlimit=12.85, northlimit=42.02}'); |
| 126 | + }); |
| 127 | + |
| 128 | + it('should have clustering enabled by default', () => { |
| 129 | + expect(component.cluster).toBeTrue(); |
| 130 | + }); |
| 131 | +}); |
0 commit comments