Skip to content

Commit

Permalink
feat(dashboard-menu): reset main search when navigating to my records…
Browse files Browse the repository at this point in the history
… and my drafts
  • Loading branch information
tkohr committed Sep 20, 2024
1 parent 36d2282 commit 01c602e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<div class="menu-title" translate="">dashboard.labels.mySpace</div>
<a
class="menu-item"
(click)="resetMainSearch()"
routerLink="/my-space/my-records"
routerLinkActive="btn-active"
#rlaMyRecords="routerLinkActive"
Expand All @@ -65,6 +66,7 @@
</a>
<a
class="menu-item"
(click)="resetMainSearch()"
routerLink="/my-space/my-draft"
routerLinkActive="btn-active"
#rlaMyDraft="routerLinkActive"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ import { TranslateModule } from '@ngx-translate/core'
import { cold, hot } from 'jasmine-marbles'
import { MockBuilder, MockProviders } from 'ng-mocks'
import { DashboardMenuComponent } from './dashboard-menu.component'
import { SearchFacade } from '@geonetwork-ui/feature/search'

describe('DashboardMenuComponent', () => {
let component: DashboardMenuComponent
let fixture: ComponentFixture<DashboardMenuComponent>
let recordsRepository: RecordsRepositoryInterface
let searchFacade: SearchFacade

beforeEach(() => {
return MockBuilder(DashboardMenuComponent)
Expand All @@ -18,9 +20,12 @@ describe('DashboardMenuComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DashboardMenuComponent, TranslateModule.forRoot()],
providers: [MockProviders(ActivatedRoute, RecordsRepositoryInterface)],
providers: [
MockProviders(ActivatedRoute, RecordsRepositoryInterface, SearchFacade),
],
}).compileComponents()
recordsRepository = TestBed.inject(RecordsRepositoryInterface)
searchFacade = TestBed.inject(SearchFacade)
fixture = TestBed.createComponent(DashboardMenuComponent)
component = fixture.componentInstance
fixture.detectChanges()
Expand All @@ -45,4 +50,10 @@ describe('DashboardMenuComponent', () => {
// Assert that draftsCount$ behaves as expected
expect(component.draftsCount$).toBeObservable(expected)
})

it('should reset filters in main search', () => {
searchFacade.setFilters = jest.fn()
component.resetMainSearch()
expect(searchFacade.setFilters).toHaveBeenCalledWith({})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { TranslateModule } from '@ngx-translate/core'
import { RecordsRepositoryInterface } from '@geonetwork-ui/common/domain/repository/records-repository.interface'
import { map, startWith, switchMap } from 'rxjs/operators'
import { BadgeComponent } from '@geonetwork-ui/ui/inputs'
import { SearchFacade } from '@geonetwork-ui/feature/search'

@Component({
selector: 'md-editor-dashboard-menu',
Expand All @@ -29,5 +30,12 @@ export class DashboardMenuComponent {
)
activeLink = false

constructor(private recordsRepository: RecordsRepositoryInterface) {}
constructor(
private recordsRepository: RecordsRepositoryInterface,
private searchFacade: SearchFacade
) {}

resetMainSearch() {
this.searchFacade.setFilters({})
}
}

0 comments on commit 01c602e

Please sign in to comment.