Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata-editor: sorting url #616

Merged
merged 1 commit into from
Sep 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ describe('dashboard', () => {
.then((list) => {
newFirstItem = list.trim()
expect(newFirstItem).not.to.equal(originalFirstItem)
cy.url().should(
'include',
'sort=resourceTitleObject.default.keyword'
)
})
})
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,44 @@
import { ComponentFixture, TestBed } from '@angular/core/testing'
import { DashboardPageComponent } from './dashboard-page.component'
import { CommonModule } from '@angular/common'
import { SearchService } from '@geonetwork-ui/feature/search'

class SearchServiceMock {
setSortBy = jest.fn()
}

describe('DashboardPageComponent', () => {
let component: DashboardPageComponent
let fixture: ComponentFixture<DashboardPageComponent>
let searchService: SearchService

beforeEach(async () => {
await TestBed.overrideComponent(DashboardPageComponent, {
set: {
imports: [CommonModule],
providers: [],
},
}).compileComponents()
await TestBed.configureTestingModule({
providers: [
{
provide: SearchService,
useClass: SearchServiceMock,
},
],
})
.overrideComponent(DashboardPageComponent, {
set: {
imports: [CommonModule],
providers: [],
},
})
.compileComponents()

fixture = TestBed.createComponent(DashboardPageComponent)
searchService = TestBed.inject(SearchService)
component = fixture.componentInstance
fixture.detectChanges()
})

it('should create', () => {
expect(component).toBeTruthy()
})
it('orders the completion column', () => {
expect(searchService.setSortBy).toHaveBeenCalledWith(['desc', 'changeDate'])
})
})
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { ChangeDetectionStrategy, Component } from '@angular/core'
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'
import { RouterOutlet } from '@angular/router'
import { SidebarComponent } from './sidebar/sidebar.component'
import { SearchHeaderComponent } from './search-header/search-header.component'
import { SearchService } from '@geonetwork-ui/feature/search'

@Component({
selector: 'md-editor-dashboard',
Expand All @@ -11,4 +12,10 @@ import { SearchHeaderComponent } from './search-header/search-header.component'
imports: [RouterOutlet, SidebarComponent, SearchHeaderComponent],
standalone: true,
})
export class DashboardPageComponent {}
export class DashboardPageComponent implements OnInit {
constructor(public searchService: SearchService) {}

ngOnInit(): void {
this.searchService.setSortBy(['desc', 'changeDate'])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,6 @@ describe('RecordsListComponent', () => {
expect(pagination.currentPage).toEqual(currentPage)
expect(pagination.totalPages).toEqual(totalPages)
})
it('orders the completion column', () => {
expect(searchFacade.setSortBy).toHaveBeenCalledWith([
'desc',
'changeDate',
])
})
describe('when click on a record', () => {
beforeEach(() => {
table.recordSelect.emit({ uniqueIdentifier: 123 })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CommonModule } from '@angular/common'
import { Component, Input } from '@angular/core'
import { Component, Input, OnInit } from '@angular/core'
import { MatIconModule } from '@angular/material/icon'
import { Router } from '@angular/router'
import { CatalogRecord } from '@geonetwork-ui/common/domain/record'
Expand Down Expand Up @@ -34,10 +34,7 @@ export class RecordsListComponent {
public searchFacade: SearchFacade,
public searchService: SearchService
) {
this.searchFacade
.setPageSize(15)
.setConfigRequestFields(includes)
.setSortBy(['desc', 'changeDate'])
this.searchFacade.setPageSize(15).setConfigRequestFields(includes)
}

paginate(page: number) {
Expand All @@ -52,6 +49,6 @@ export class RecordsListComponent {
}

setSortBy(newSortBy: SortByField) {
this.searchFacade.setSortBy(newSortBy)
this.searchService.setSortBy(newSortBy)
}
}
1 change: 1 addition & 0 deletions libs/feature/search/src/lib/state/search.facade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ export class SearchFacade {
resetSearch() {
this.store.dispatch(new Paginate(1, this.searchId))
this.store.dispatch(new SetFilters({}, this.searchId))
this.store.dispatch(new SetSortBy([], this.searchId))
this.store.dispatch(new SetFavoritesOnly(false, this.searchId))
}
}
Loading