|
| 1 | +import { ComponentFixture, TestBed } from '@angular/core/testing'; |
| 2 | +import { OpenstreetmapGroupComponent } from './openstreetmap-group.component'; |
| 3 | +import { Item } from '../../../../../../../../core/shared/item.model'; |
| 4 | +import { of } from 'rxjs'; |
| 5 | +import { LayoutField } from '../../../../../../../../core/layout/models/box.model'; |
| 6 | +import { TranslateLoader, TranslateModule } from '@ngx-translate/core'; |
| 7 | +import { TranslateLoaderMock } from '../../../../../../../../shared/mocks/translate-loader.mock'; |
| 8 | +import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; |
| 9 | +import { LoadMoreService } from '../../../../../../../services/load-more.service'; |
| 10 | +import { OpenStreetMapComponent } from '../../../../../../../../shared/open-street-map/open-street-map.component'; |
| 11 | +import { NO_ERRORS_SCHEMA } from '@angular/core'; |
| 12 | +import { LocationPlace, LocationService } from '../../../../../../../../core/services/location.service'; |
| 13 | + |
| 14 | +describe('OpenstreetmapGroupComponent', () => { |
| 15 | + let component: OpenstreetmapGroupComponent; |
| 16 | + |
| 17 | + let fixture: ComponentFixture<OpenstreetmapGroupComponent>; |
| 18 | + |
| 19 | + const locationService = jasmine.createSpyObj('locationService', { |
| 20 | + searchPlace: jasmine.createSpy('searchPlace'), |
| 21 | + searchCoordinates: jasmine.createSpy('searchCoordinates'), |
| 22 | + isValidCoordinateString: jasmine.createSpy('isValidCoordinateString'), |
| 23 | + parseCoordinates: jasmine.createSpy('parseCoordinates'), |
| 24 | + isCoordinateString: jasmine.createSpy('isCoordinateString'), |
| 25 | + }); |
| 26 | + |
| 27 | + const place: LocationPlace = { |
| 28 | + coordinates: { |
| 29 | + latitude: 52.520008, |
| 30 | + longitude: 13.404954, |
| 31 | + }, |
| 32 | + displayName: '10178 Berlin, Germania' |
| 33 | + }; |
| 34 | + |
| 35 | + const testItem = Object.assign(new Item(), { |
| 36 | + bundles: of({}), |
| 37 | + metadata: { |
| 38 | + 'dc.coverage.spatialgpdpy': [ |
| 39 | + { |
| 40 | + value: '45.4899793' |
| 41 | + }, |
| 42 | + ], |
| 43 | + 'dc.coverage.spatialgpdpx': [ |
| 44 | + { |
| 45 | + value: '9.138292' |
| 46 | + }, |
| 47 | + ] |
| 48 | + } |
| 49 | + }); |
| 50 | + |
| 51 | + const mockField = Object.assign({ |
| 52 | + id: 1, |
| 53 | + fieldType: 'METADATAGROUP', |
| 54 | + metadata: 'dc.coverage.spatialgpdpy', |
| 55 | + label: 'Coordinates', |
| 56 | + rendering: 'googlemaps-group', |
| 57 | + style: 'container row', |
| 58 | + styleLabel: 'font-weight-bold col-4', |
| 59 | + styleValue: 'col', |
| 60 | + metadataGroup: { |
| 61 | + leading: 'dc.coverage.spatialgpdpy', |
| 62 | + elements: [ |
| 63 | + { |
| 64 | + metadata: 'dc.coverage.spatialgpdpy', |
| 65 | + label: 'Latitude', |
| 66 | + rendering: 'TEXT', |
| 67 | + fieldType: 'METADATA', |
| 68 | + style: null, |
| 69 | + styleLabel: 'font-weight-bold col-0', |
| 70 | + styleValue: 'col' |
| 71 | + }, |
| 72 | + { |
| 73 | + metadata: 'dc.coverage.spatialgpdpx', |
| 74 | + label: 'Longitude', |
| 75 | + rendering: 'TEXT', |
| 76 | + fieldType: 'METADATA', |
| 77 | + style: null, |
| 78 | + styleLabel: 'font-weight-bold col-0', |
| 79 | + styleValue: 'col' |
| 80 | + } |
| 81 | + ] |
| 82 | + } |
| 83 | + }) as LayoutField; |
| 84 | + |
| 85 | + beforeEach(async () => { |
| 86 | + await TestBed.configureTestingModule({ |
| 87 | + imports: [TranslateModule.forRoot({ |
| 88 | + loader: { |
| 89 | + provide: TranslateLoader, |
| 90 | + useClass: TranslateLoaderMock |
| 91 | + } |
| 92 | + }), BrowserAnimationsModule], |
| 93 | + providers: [ |
| 94 | + { provide: 'fieldProvider', useValue: mockField }, |
| 95 | + { provide: 'itemProvider', useValue: testItem }, |
| 96 | + { provide: 'renderingSubTypeProvider', useValue: '' }, |
| 97 | + { provide: 'tabNameProvider', useValue: '' }, |
| 98 | + { provide: LocationService, useValue: locationService }, |
| 99 | + LoadMoreService, |
| 100 | + ], |
| 101 | + schemas: [NO_ERRORS_SCHEMA], |
| 102 | + declarations: [ |
| 103 | + OpenstreetmapGroupComponent, |
| 104 | + OpenStreetMapComponent] |
| 105 | + }) |
| 106 | + .compileComponents(); |
| 107 | + |
| 108 | + fixture = TestBed.createComponent(OpenstreetmapGroupComponent); |
| 109 | + component = fixture.componentInstance; |
| 110 | + locationService.isCoordinateString.and.returnValue(true); |
| 111 | + locationService.isValidCoordinateString.and.returnValue(true); |
| 112 | + locationService.parseCoordinates.and.returnValue(place.coordinates); |
| 113 | + locationService.searchCoordinates.and.returnValue(of(place.displayName)); |
| 114 | + fixture.detectChanges(); |
| 115 | + }); |
| 116 | + |
| 117 | + it('should create', () => { |
| 118 | + expect(component).toBeTruthy(); |
| 119 | + }); |
| 120 | + |
| 121 | + it('should populate coordinates', () => { |
| 122 | + expect(component.coordinates).not.toBeUndefined(); |
| 123 | + const latitude = testItem.metadata['dc.coverage.spatialgpdpy'][0].value; |
| 124 | + const longitude = testItem.metadata['dc.coverage.spatialgpdpx'][0].value; |
| 125 | + expect(component.coordinates).toBe(`${latitude},${longitude}`); |
| 126 | + }); |
| 127 | +}); |
0 commit comments