-
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.
- Loading branch information
Romuald Caplier
committed
Sep 19, 2024
1 parent
575f30f
commit 98c584d
Showing
39 changed files
with
609 additions
and
727 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
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
4 changes: 2 additions & 2 deletions
4
apps/metadata-editor/src/app/dashboard/search-header/search-header.component.css
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
4 changes: 3 additions & 1 deletion
4
apps/metadata-editor/src/app/dashboard/search-header/search-header.component.html
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
File renamed without changes.
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
181 changes: 181 additions & 0 deletions
181
apps/metadata-editor/src/app/records/all-records/all-records.component.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,181 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing' | ||
import { | ||
FieldsService, | ||
SearchFacade, | ||
SearchService, | ||
} from '@geonetwork-ui/feature/search' | ||
import { ChangeDetectionStrategy } from '@angular/core' | ||
import { TranslateModule } from '@ngx-translate/core' | ||
import { BehaviorSubject, of } from 'rxjs' | ||
import { barbieUserFixture } from '@geonetwork-ui/common/fixtures' | ||
import { ActivatedRoute, Router } from '@angular/router' | ||
import { AllRecordsComponent } from './all-records.component' | ||
import { PlatformServiceInterface } from '@geonetwork-ui/common/domain/platform.service.interface' | ||
import { | ||
MockBuilder, | ||
MockInstance, | ||
MockProvider, | ||
MockProviders, | ||
} from 'ng-mocks' | ||
import { EditorRouterService } from '../../router.service' | ||
import { Overlay } from '@angular/cdk/overlay' | ||
|
||
describe('AllRecordsComponent', () => { | ||
MockInstance.scope() | ||
|
||
const searchFilters = new BehaviorSubject({ | ||
any: 'hello world', | ||
}) | ||
|
||
let component: AllRecordsComponent | ||
let fixture: ComponentFixture<AllRecordsComponent> | ||
|
||
let router: Router | ||
let searchFacade: SearchFacade | ||
let platformService: PlatformServiceInterface | ||
let fieldsService: FieldsService | ||
|
||
const overlayRefMock = { | ||
attach: jest.fn(), | ||
backdropClick: jest.fn().mockReturnValue(of()), | ||
dispose: jest.fn(), | ||
} | ||
|
||
const positionStrategyMock = { | ||
flexibleConnectedTo: jest.fn().mockReturnThis(), | ||
withPositions: jest.fn().mockReturnThis(), | ||
} | ||
|
||
const overlayMock = { | ||
position: jest.fn().mockReturnValue(positionStrategyMock), | ||
create: jest.fn().mockReturnValue(overlayRefMock), | ||
scrollStrategies: { | ||
reposition: jest.fn(), | ||
}, | ||
} | ||
|
||
beforeEach(() => { | ||
return MockBuilder(AllRecordsComponent) | ||
}) | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [TranslateModule.forRoot()], | ||
providers: [ | ||
MockProviders( | ||
FieldsService, | ||
SearchFacade, | ||
PlatformServiceInterface, | ||
EditorRouterService, | ||
ActivatedRoute, | ||
SearchService | ||
), | ||
MockProvider(Overlay, overlayMock, 'useValue'), | ||
], | ||
}).overrideComponent(AllRecordsComponent, { | ||
set: { | ||
changeDetection: ChangeDetectionStrategy.Default, | ||
}, | ||
}) | ||
|
||
MockInstance( | ||
SearchFacade, | ||
'searchFilters$', | ||
jest.fn(), | ||
'get' | ||
).mockReturnValue(searchFilters) | ||
|
||
MockInstance(ActivatedRoute, 'snapshot', jest.fn(), 'get').mockReturnValue({ | ||
paramMap: new Map([['paramId', 'paramValue']]), | ||
queryParams: new Map([['paramId', 'paramValue']]), | ||
}) | ||
|
||
fixture = TestBed.createComponent(AllRecordsComponent) | ||
|
||
router = TestBed.inject(Router) | ||
searchFacade = TestBed.inject(SearchFacade) | ||
platformService = TestBed.inject(PlatformServiceInterface) | ||
fieldsService = TestBed.inject(FieldsService) | ||
|
||
router.navigate = jest.fn().mockReturnValue(Promise.resolve(true)) | ||
|
||
platformService.getMe = jest.fn( | ||
() => new BehaviorSubject(barbieUserFixture()) | ||
) | ||
|
||
fieldsService.buildFiltersFromFieldValues = jest.fn((fieldValues) => | ||
of( | ||
Object.keys(fieldValues).reduce( | ||
(_, curr) => ({ | ||
[curr]: fieldValues[curr], | ||
}), | ||
{} | ||
) | ||
) | ||
) | ||
|
||
// searchFacade.searchFilters$ = new BehaviorSubject({ any: 'scot' }) | ||
searchFacade.resetSearch = jest.fn(() => this) | ||
searchFacade.updateFilters = jest.fn(() => this) | ||
searchFacade.setFilters = jest.fn(() => this) | ||
searchFacade.setSortBy = jest.fn(() => this) | ||
searchFacade.setPageSize = jest.fn(() => this) | ||
searchFacade.setConfigRequestFields = jest.fn(() => this) | ||
|
||
component = fixture.componentInstance | ||
|
||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy() | ||
}) | ||
|
||
it('should map search filters to searchText$', (done) => { | ||
component.searchText$.subscribe((text) => { | ||
expect(text).toBe('hello world') | ||
done() | ||
}) | ||
}) | ||
|
||
describe('when clicking createRecord', () => { | ||
beforeEach(() => { | ||
component.createRecord() | ||
}) | ||
|
||
it('navigates to the create record page', () => { | ||
expect(router.navigate).toHaveBeenCalledWith(['/create']) | ||
}) | ||
}) | ||
|
||
describe('when importing a record', () => { | ||
beforeEach(() => { | ||
component.duplicateExternalRecord() | ||
}) | ||
|
||
it('sets isImportMenuOpen to true', () => { | ||
expect(component.isImportMenuOpen).toBe(true) | ||
}) | ||
}) | ||
|
||
describe('when closing the import menu', () => { | ||
let overlaySpy: any | ||
|
||
beforeEach(() => { | ||
overlaySpy = { | ||
dispose: jest.fn(), | ||
} | ||
component['overlayRef'] = overlaySpy | ||
|
||
component.closeImportMenu() | ||
}) | ||
|
||
it('sets isImportMenuOpen to false', () => { | ||
expect(component.isImportMenuOpen).toBe(false) | ||
}) | ||
|
||
it('disposes the overlay', () => { | ||
expect(overlaySpy.dispose).toHaveBeenCalled() | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.