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 12b0e3c
Show file tree
Hide file tree
Showing 38 changed files with 523 additions and 570 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
@@ -1,23 +1,28 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { SearchFacade, SearchService } from '@geonetwork-ui/feature/search'
import { SearchRecordsComponent } from './search-records-list.component'
import {
FieldsService,
SearchFacade,
SearchService,
} from '@geonetwork-ui/feature/search'
import {
ChangeDetectionStrategy,
Component,
CUSTOM_ELEMENTS_SCHEMA,
EventEmitter,
importProvidersFrom,
Input,
Output,
} from '@angular/core'
import { TranslateModule } from '@ngx-translate/core'
import { BehaviorSubject } from 'rxjs'
import { BehaviorSubject, of } from 'rxjs'
import { CatalogRecord } from '@geonetwork-ui/common/domain/model/record'
import { CommonModule } from '@angular/common'
import { MatIconModule } from '@angular/material/icon'
import { UiInputsModule } from '@geonetwork-ui/ui/inputs'
import { By } from '@angular/platform-browser'
import { datasetRecordsFixture } from '@geonetwork-ui/common/fixtures'
import { Router } from '@angular/router'
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, MockProviders } from 'ng-mocks'
import { EditorRouterService } from '../../router.service'
import { Overlay } from '@angular/cdk/overlay'
import { RecordsListComponent } from '../records-list.component'

const results = [{ md: true }]
const currentPage = 5
Expand Down Expand Up @@ -77,50 +82,107 @@ class RouterMock {
navigate = jest.fn(() => Promise.resolve(true))
}

describe('SearchRecordsComponent', () => {
let component: SearchRecordsComponent
let fixture: ComponentFixture<SearchRecordsComponent>
describe('AllRecordsComponent', () => {
MockInstance.scope()

const searchFilters = new BehaviorSubject({
any: 'hello world',
})

let component: AllRecordsComponent
let fixture: ComponentFixture<AllRecordsComponent>

let router: Router
let searchService: SearchService
let searchFacade: SearchFacade
let platformService: PlatformServiceInterface
let fieldsService: FieldsService

beforeEach(() => {
return MockBuilder(AllRecordsComponent)
})

beforeEach(() => {
TestBed.configureTestingModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [TranslateModule.forRoot()],
providers: [
importProvidersFrom(TranslateModule.forRoot()),
{
provide: SearchFacade,
useClass: SearchFacadeMock,
},
{
provide: Router,
useClass: RouterMock,
},
{
provide: SearchService,
useClass: SearchServiceMock,
},
MockProviders(
FieldsService,
SearchFacade,
PlatformServiceInterface,
EditorRouterService,
Overlay,
ActivatedRoute,
SearchService
),
],
}).overrideComponent(SearchRecordsComponent, {
}).overrideComponent(AllRecordsComponent, {
set: {
imports: [
CommonModule,
TranslateModule,
MatIconModule,
ResultsTableContainerComponent,
PaginationButtonsComponent,
UiInputsModule,
RecordsCountComponent,
],
changeDetection: ChangeDetectionStrategy.Default,
},
})
fixture = TestBed.createComponent(SearchRecordsComponent)

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']]),
})

// const flexibleConnectedPositionStrategyMock = MockInstance(
// FlexibleConnectedPositionStrategy,
// 'withPositions',
// jest.fn(),
// 'get'
// ).mockReturnValue({})
// const overlayPositionMock = MockInstance(
// OverlayPositionBuilder,
// 'flexibleConnectedTo',
// jest.fn(),
// 'get'
// ).mockReturnValue(flexibleConnectedPositionStrategyMock)
// MockInstance(Overlay, 'position', jest.fn(), 'get').mockReturnValue(
// overlayPositionMock
// )

fixture = TestBed.createComponent(AllRecordsComponent)

router = TestBed.inject(Router)
searchService = TestBed.inject(SearchService)
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()
})

Expand Down Expand Up @@ -177,59 +239,26 @@ describe('SearchRecordsComponent', () => {
})

describe('when search results', () => {
let table, pagination
let results: any
beforeEach(() => {
table = fixture.debugElement.query(
By.directive(ResultsTableContainerComponent)
).componentInstance
pagination = fixture.debugElement.query(
By.directive(PaginationButtonsComponent)
results = fixture.debugElement.query(
By.directive(RecordsListComponent)
).componentInstance
})
it('displays record table', () => {
expect(table).toBeTruthy()
})
it('displays pagination', () => {
expect(pagination).toBeTruthy()
expect(pagination.currentPage).toEqual(currentPage)
expect(pagination.totalPages).toEqual(totalPages)
it('displays record list', () => {
expect(results).toBeTruthy()
})

describe('when click on a record', () => {
const uniqueIdentifier = 123
const singleRecord = {
...datasetRecordsFixture()[0],
uniqueIdentifier,
}
beforeEach(() => {
table.recordClick.emit(singleRecord)
})
it('routes to record edition', () => {
expect(router.navigate).toHaveBeenCalledWith(['/edit', 123])
})
})

describe('when asking for record duplication', () => {
const uniqueIdentifier = 123
const singleRecord = {
...datasetRecordsFixture()[0],
uniqueIdentifier,
}
beforeEach(() => {
table.duplicateRecord.emit(singleRecord)
})
it('routes to record duplication', () => {
expect(router.navigate).toHaveBeenCalledWith(['/duplicate', 123])
})
})

describe('when click on pagination', () => {
beforeEach(() => {
pagination.newCurrentPageEvent.emit(3)
})
it('paginates', () => {
expect(searchService.setPage).toHaveBeenCalledWith(3)
})
})
})
})
Loading

0 comments on commit 12b0e3c

Please sign in to comment.