-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #942 from geonetwork/ME/duplicate-local-record
ME: duplicate local record
- Loading branch information
Showing
31 changed files
with
418 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
apps/metadata-editor/src/app/duplicate-record.resolver.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import { TestBed } from '@angular/core/testing' | ||
import { DuplicateRecordResolver } from './duplicate-record.resolver' | ||
import { HttpClientTestingModule } from '@angular/common/http/testing' | ||
import { NotificationsService } from '@geonetwork-ui/feature/notifications' | ||
import { of, throwError } from 'rxjs' | ||
import { DATASET_RECORDS } from '@geonetwork-ui/common/fixtures' | ||
import { ActivatedRouteSnapshot, convertToParamMap } from '@angular/router' | ||
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record' | ||
import { TranslateModule } from '@ngx-translate/core' | ||
import { RecordsRepositoryInterface } from '@geonetwork-ui/common/domain/repository/records-repository.interface' | ||
|
||
class NotificationsServiceMock { | ||
showNotification = jest.fn() | ||
} | ||
class RecordsRepositoryMock { | ||
openRecordForDuplication = jest.fn(() => | ||
of([DATASET_RECORDS[0], '<xml>blabla</xml>', false]) | ||
) | ||
} | ||
|
||
const activatedRoute = { | ||
paramMap: convertToParamMap({ id: DATASET_RECORDS[0].uniqueIdentifier }), | ||
} as ActivatedRouteSnapshot | ||
|
||
describe('DuplicateRecordResolver', () => { | ||
let resolver: DuplicateRecordResolver | ||
let recordsRepository: RecordsRepositoryInterface | ||
let notificationsService: NotificationsService | ||
let resolvedData: [CatalogRecord, string, boolean] | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule, TranslateModule.forRoot()], | ||
providers: [ | ||
{ provide: NotificationsService, useClass: NotificationsServiceMock }, | ||
{ | ||
provide: RecordsRepositoryInterface, | ||
useClass: RecordsRepositoryMock, | ||
}, | ||
], | ||
}) | ||
resolver = TestBed.inject(DuplicateRecordResolver) | ||
recordsRepository = TestBed.inject(RecordsRepositoryInterface) | ||
notificationsService = TestBed.inject(NotificationsService) | ||
}) | ||
|
||
it('should be created', () => { | ||
expect(resolver).toBeTruthy() | ||
}) | ||
|
||
describe('load record success', () => { | ||
beforeEach(() => { | ||
resolvedData = undefined | ||
resolver.resolve(activatedRoute).subscribe((r) => (resolvedData = r)) | ||
}) | ||
it('should load record by uuid', () => { | ||
expect(resolvedData).toEqual([ | ||
DATASET_RECORDS[0], | ||
'<xml>blabla</xml>', | ||
false, | ||
]) | ||
}) | ||
}) | ||
|
||
describe('load record failure', () => { | ||
beforeEach(() => { | ||
recordsRepository.openRecordForDuplication = () => | ||
throwError(() => new Error('oopsie')) | ||
resolvedData = undefined | ||
resolver.resolve(activatedRoute).subscribe((r) => (resolvedData = r)) | ||
}) | ||
it('should not emit anything', () => { | ||
expect(resolvedData).toBeUndefined() | ||
}) | ||
it('should show error notification', () => { | ||
expect(notificationsService.showNotification).toHaveBeenCalledWith({ | ||
type: 'error', | ||
title: 'editor.record.loadError.title', | ||
text: 'editor.record.loadError.body oopsie', | ||
closeMessage: 'editor.record.loadError.closeMessage', | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { Injectable } from '@angular/core' | ||
import { ActivatedRouteSnapshot } from '@angular/router' | ||
import { catchError, EMPTY, Observable } from 'rxjs' | ||
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record' | ||
import { NotificationsService } from '@geonetwork-ui/feature/notifications' | ||
import { TranslateService } from '@ngx-translate/core' | ||
import { RecordsRepositoryInterface } from '@geonetwork-ui/common/domain/repository/records-repository.interface' | ||
|
||
@Injectable({ | ||
providedIn: 'root', | ||
}) | ||
export class DuplicateRecordResolver { | ||
constructor( | ||
private recordsRepository: RecordsRepositoryInterface, | ||
private notificationsService: NotificationsService, | ||
private translateService: TranslateService | ||
) {} | ||
|
||
resolve( | ||
route: ActivatedRouteSnapshot | ||
): Observable<[CatalogRecord, string, boolean]> { | ||
return this.recordsRepository | ||
.openRecordForDuplication(route.paramMap.get('uuid')) | ||
.pipe( | ||
catchError((error) => { | ||
this.notificationsService.showNotification({ | ||
type: 'error', | ||
title: this.translateService.instant( | ||
'editor.record.loadError.title' | ||
), | ||
text: `${this.translateService.instant( | ||
'editor.record.loadError.body' | ||
)} ${error.message}`, | ||
closeMessage: this.translateService.instant( | ||
'editor.record.loadError.closeMessage' | ||
), | ||
}) | ||
return EMPTY | ||
}) | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.