Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Romuald Caplier committed Sep 19, 2024
1 parent 575f30f commit 98c584d
Show file tree
Hide file tree
Showing 39 changed files with 609 additions and 727 deletions.
22 changes: 8 additions & 14 deletions apps/metadata-editor/src/app/app.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ import { EditPageComponent } from './edit/edit-page.component'
import { EditRecordResolver } from './edit-record.resolver'
import { MyRecordsComponent } from './records/my-records/my-records.component'
import { MyDraftComponent } from './records/my-draft/my-draft.component'
import { MyLibraryComponent } from './records/my-library/my-library.component'
import { SearchRecordsComponent } from './records/search-records/search-records-list.component'
import { TemplatesComponent } from './records/templates/templates.component'
import { MyOrgUsersComponent } from './my-org-users/my-org-users.component'
import { MyOrgRecordsComponent } from './records/my-org-records/my-org-records.component'
import { NewRecordResolver } from './new-record.resolver'
import { DuplicateRecordResolver } from './duplicate-record.resolver'
import { AllRecordsComponent } from './records/all-records/all-records.component'

export const appRoutes: Route[] = [
{ path: '', redirectTo: 'catalog/search', pathMatch: 'prefix' },
Expand All @@ -26,35 +25,30 @@ export const appRoutes: Route[] = [
},
{
path: 'discussion',
component: SearchRecordsComponent,
component: AllRecordsComponent,
pathMatch: 'prefix',
},
{
path: 'calendar',
component: SearchRecordsComponent,
component: AllRecordsComponent,
pathMatch: 'prefix',
},
{
path: 'contacts',
component: SearchRecordsComponent,
component: AllRecordsComponent,
pathMatch: 'prefix',
},
{
path: 'thesaurus',
component: SearchRecordsComponent,
component: AllRecordsComponent,
pathMatch: 'prefix',
},
{
path: 'search',
title: 'Search Records',
component: SearchRecordsComponent,
component: AllRecordsComponent,
pathMatch: 'prefix',
},
{
path: 'my-org',
title: 'My Organisation',
component: MyOrgRecordsComponent,
},
],
},
{
Expand All @@ -78,7 +72,7 @@ export const appRoutes: Route[] = [
{
path: 'templates',
title: 'Templates',
component: MyLibraryComponent,
component: TemplatesComponent,
pathMatch: 'prefix',
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@
>
<mat-icon class="material-symbols-outlined">edit_note</mat-icon>
<span translate="">dashboard.records.myDraft</span>
<gn-ui-badge
[style.--gn-ui-badge-rounded]="'100px'"
data-cy="dashboard-drafts-count"
>{{ draftsCount$ | async }}</gn-ui-badge
>
<ng-container *ngIf="draftsCount$ | async as draftsCount">
<gn-ui-badge *ngIf="draftsCount > 0" data-cy="dashboard-drafts-count">{{
draftsCount
}}</gn-ui-badge>
</ng-container>
</a>
<a
class="menu-item"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<md-editor-sidebar></md-editor-sidebar>
</aside>
<div class="grow flex flex-col">
<header class="shrink-0 border-b border-blue-300">
<header class="shrink-0 border-b border-gray-300">
<md-editor-search-header></md-editor-search-header>
</header>
<div class="relative">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
:host ::ng-deep gn-ui-autocomplete input {
@apply bg-blue-50 rounded-3xl shadow-none !py-2 !px-8 !pl-14 hover:shadow-none focus:outline-4 focus:outline-offset-1 focus:outline-blue-100 focus:outline-dotted;
@apply rounded-3xl shadow-none !py-2 !px-8 !pl-14 hover:shadow-none;
}
:host ::ng-deep gn-ui-autocomplete button {
@apply bg-blue-50 hover:bg-blue-50 border-none shadow-none hover:shadow-none text-gray-500 hover:text-gray-600 left-0 right-auto rounded-3xl;
@apply border-none shadow-none hover:shadow-none text-gray-500 hover:text-gray-600 left-0 right-auto rounded-3xl;
}

::ng-deep .mdc-menu-surface.mat-mdc-autocomplete-panel {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<div class="py-3 px-12 flex justify-between w-full">
<div class="w-2/3">
<gn-ui-fuzzy-search></gn-ui-fuzzy-search>
<gn-ui-fuzzy-search
style="--gn-ui-text-input-border-size: 0px"
></gn-ui-fuzzy-search>
</div>
<div class="flex gap-5 items-center">
<button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,23 +65,5 @@ <h1 class="text-[16px] text-main font-title font-bold" translate>
</gn-ui-button>
</div>

<div
class="shadow-md shadow-gray-300 border-[1px] border-gray-200 overflow-hidden rounded bg-white grow mx-[32px] my-[16px]"
>
<gn-ui-results-table-container
class="text-[14px]"
(recordClick)="editRecord($event)"
(duplicateRecord)="duplicateRecord($event)"
></gn-ui-results-table-container>

<div class="px-5 py-5 flex justify-center gap-8 items-baseline">
<div class="grow">
<gn-ui-pagination-buttons
[currentPage]="searchFacade.currentPage$ | async"
[totalPages]="searchFacade.totalPages$ | async"
(newCurrentPageEvent)="searchService.setPage($event)"
></gn-ui-pagination-buttons>
</div>
</div>
</div>
<md-editor-records-list></md-editor-records-list>
</main>
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()
})
})
})
Loading

0 comments on commit 98c584d

Please sign in to comment.