Skip to content

Commit

Permalink
test(search): add and adapt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tkohr committed Sep 25, 2024
1 parent 197304c commit 54cc287
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 38 deletions.
82 changes: 58 additions & 24 deletions apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,35 +213,17 @@ describe('dashboard', () => {
cy.clearRecordDrafts()
})
})

describe('navigation', () => {
function checkDashboardFiltered() {
cy.get('gn-ui-autocomplete').type('Mat')
cy.get('mat-option').first().click()
cy.get('gn-ui-interactive-table')
.find('[data-cy="table-row"]')
.should('have.length', '1')
}
beforeEach(() => {
cy.login('admin', 'admin', false)
cy.visit('/catalog/search')
})
describe('search input', () => {
it('should filter the dashboard based on the search input', () => {
checkDashboardFiltered()
})
it('should navigate to list of all records and filter the dashboard based on the search input when on different page', () => {
cy.visit('/my-space/my-records')
checkDashboardFiltered()
})
it('should clear the search input when navigating to my records', () => {
cy.get('gn-ui-autocomplete').type('Mat')
cy.get('md-editor-dashboard-menu').find('a').eq(5).click()
cy.get('gn-ui-autocomplete').should('have.value', '')
})
it('should clear the search input when navigating to my drafts', () => {
cy.get('gn-ui-autocomplete').type('Mat')
cy.get('md-editor-dashboard-menu').find('a').eq(6).click()
cy.get('gn-ui-autocomplete').should('have.value', '')
describe('all records', () => {
it('should display the correct amount of records', () => {
cy.get('gn-ui-results-table')
.find('[data-cy="table-row"]')
.should('have.length', '15')
})
})
describe('my records', () => {
Expand Down Expand Up @@ -280,4 +262,56 @@ describe('dashboard', () => {
})
})
})

describe('search', () => {
function checkDashboardFiltered() {
cy.get('gn-ui-autocomplete').type('velo{enter}')
cy.get('gn-ui-interactive-table')
.find('[data-cy="table-row"]')
.should('have.length', '1')
}
function checkAutocompleteSelected() {
cy.get('gn-ui-autocomplete').type('velo')
cy.get('mat-option').first().click()
cy.url().should('include', '/edit/accroche_velos')
}
describe('allRecords search input', () => {
beforeEach(() => {
cy.login('admin', 'admin', false)
cy.visit('/catalog/search')
})
it('should filter the dashboard based on the search input', () => {
checkDashboardFiltered()
})
it('should navigate to the record selected in the autocomplete', () => {
checkAutocompleteSelected()
})
it('should clear the search input when navigating to my records', () => {
cy.get('gn-ui-autocomplete').type('velo')
cy.get('md-editor-dashboard-menu').find('a').eq(5).click()
cy.get('gn-ui-autocomplete').should('have.value', '')
})
it('should hide the search input when navigating to my drafts', () => {
cy.get('md-editor-dashboard-menu').find('a').eq(6).click()
cy.get('gn-ui-autocomplete').should('not.exist')
})
})
describe('myRecords search input', () => {
beforeEach(() => {
cy.login('admin', 'admin', false)
cy.visit('/my-space/my-records')
})
it('should filter the dashboard based on the search input', () => {
checkDashboardFiltered()
})
it('should navigate to the record selected in the autocomplete', () => {
checkAutocompleteSelected()
})
it('should clear the search input when navigating to all records', () => {
cy.get('gn-ui-autocomplete').type('velo')
cy.get('md-editor-dashboard-menu').find('a').first().click()
cy.get('gn-ui-autocomplete').should('have.value', '')
})
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ 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 @@ -20,12 +18,9 @@ describe('DashboardMenuComponent', () => {
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [DashboardMenuComponent, TranslateModule.forRoot()],
providers: [
MockProviders(ActivatedRoute, RecordsRepositoryInterface, SearchFacade),
],
providers: [MockProviders(ActivatedRoute, RecordsRepositoryInterface)],
}).compileComponents()
recordsRepository = TestBed.inject(RecordsRepositoryInterface)
searchFacade = TestBed.inject(SearchFacade)
fixture = TestBed.createComponent(DashboardMenuComponent)
component = fixture.componentInstance
fixture.detectChanges()
Expand All @@ -50,10 +45,4 @@ 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
@@ -1,7 +1,5 @@
<div class="py-3 px-12 w-full">
<!-- FIXME: (itemSelected) should not be required -->
<gn-ui-fuzzy-search
#fuzzySearch
(itemSelected)="handleItemSelection($event)"
style="--gn-ui-text-input-border-size: 0px"
></gn-ui-fuzzy-search>
Expand Down

0 comments on commit 54cc287

Please sign in to comment.