Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
f-necas committed Nov 22, 2023
2 parents 36a3f6c + eb6728e commit 6653144
Show file tree
Hide file tree
Showing 70 changed files with 1,910 additions and 237 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
push:
branches:
- main
- develop
release:
types: [published]
issue_comment:
Expand All @@ -20,7 +21,7 @@ concurrency:
env:
NODE_VERSION: 18.16.1
# a list of apps to build and publish on releases
APP_NAMES: datafeeder,datahub
APP_NAMES: datafeeder,datahub,metadata-editor

jobs:
checks:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
push:
branches:
- main
- develop
pull_request:
types: [opened, synchronize, ready_for_review]

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/cleanup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ run-name: 🧹 Cleanup operations for 🌱 ${{github.event.ref}}

env:
# a list of apps to build and publish on releases
APP_NAMES: datafeeder,datahub
APP_NAMES: datafeeder,datahub,metadata-editor

on:
delete:
Expand Down
25 changes: 25 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: End-to-end tests
on:
push:
branches:
- main
- develop
pull_request:
types: [opened, synchronize, ready_for_review]

jobs:
cypress-run:
name: Cypress test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build the backend
run: sudo docker-compose -f support-services/docker-compose.yml up -d init

- name: install dependencies
run: |
npm ci
- name: E2E tests
run: npx nx run-many --target=e2e
3 changes: 2 additions & 1 deletion apps/datahub-e2e/src/e2e/datasets.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ describe('datasets', () => {
cy.get('@optionsLabel').should('eql', [
'Agence wallonne du Patrimoine (SPW - Territoire, Logement, Patrimoine, Énergie - Agence wallonne du Patrimoine) (1)',
'atmo Hauts-de-France (1)',
'Barbie Inc. (1)',
'Bundesamt für Raumentwicklung (1)',
"Canton du Valais - Service de l'environnement (SEN) - Protection des sols (1)",
'Cellule informatique et géomatique (SPW - Intérieur et Action sociale - Direction fonctionnelle et d’appui) (1)',
Expand All @@ -279,7 +280,7 @@ describe('datasets', () => {
'Géo2France (1)',
"Helpdesk carto du SPW (SPW - Secrétariat général - SPW Digital - Département de la Géomatique - Direction de l'Intégration des géodonnées) (2)",
'Métropole Européenne de Lille (1)',
'Région Hauts-de-France (2)',
'Région Hauts-de-France (1)',
'Service public de Wallonie (SPW) (2)',
"Société Publique de Gestion de l'Eau (SPGE) (1)",
])
Expand Down
10 changes: 5 additions & 5 deletions apps/datahub-e2e/src/e2e/organizations.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ describe('organizations', () => {
})
it('should display organization information', () => {
cy.get('@organizationsName')
.eq(2)
.eq(3)
.invoke('text')
.should('contain', 'Bundesamt für Raumentwicklung')
cy.get('@organizationsDesc')
.eq(2)
.eq(3)
.invoke('text')
.should('contain', 'Bundesamt für Raumentwicklung')
cy.get('@organizationsRecordsCount')
.eq(2)
.eq(3)
.invoke('text')
.should('contain', '1')
})
it('should display an actual logo', () => {
cy.get('@organizations')
.eq(8)
.eq(9)
.find('img')
.should('have.attr', 'src')
.and('contain', 'G%C3%A9o2France-4-3_decoupe.png')
Expand Down Expand Up @@ -124,7 +124,7 @@ describe('organizations', () => {
it('should go to next page with arrow', () => {
cy.then(() => {
cy.get('@pagination').find('[data-cy=next-page]').click()
cy.get('@organizations').should('have.length', 2)
cy.get('@organizations').should('have.length', 3)
})
})
it('should go back to the first page with arrow', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ <h2 class="text-xl mr-4 font-title" translate>
></gn-ui-filter-dropdown>
<div
class="spatial-filter-toggle sm:col-span-2"
*ngIf="isOpen && searchFacade.hasSpatialFilter$ | async"
*ngIf="isOpen && (searchFacade.hasSpatialFilter$ | async)"
>
<gn-ui-check-toggle
[title]="'search.filters.useSpatialFilterHelp' | translate"
Expand All @@ -63,6 +63,30 @@ <h2 class="text-xl mr-4 font-title" translate>
(toggled)="toggleSpatialFilter($event)"
></gn-ui-check-toggle>
</div>
<div class="sm:col-span-2" *ngIf="userId && isOpen">
<gn-ui-check-toggle
[title]="'search.filters.myRecordsHelp' | translate"
[label]="'search.filters.myRecords' | translate"
[color]="'secondary'"
[value]="myRecordsFilterEnabled$ | async"
(toggled)="toggleMyRecordsFilter($event)"
></gn-ui-check-toggle>
</div>
<div
class="sm:col-span-2"
*ngIf="!userId && (myRecordsFilterEnabled$ | async) && isOpen"
>
<gn-ui-button
type="light"
extraClass="text-sm align-middle"
(buttonClick)="toggleMyRecordsFilter(false)"
>
<span>{{ 'search.filters.otherRecords' | translate }}</span>
<mat-icon class="material-symbols-outlined ml-3 opacity-40"
>close</mat-icon
>
</gn-ui-button>
</div>
</div>
<div
class="col-span-2 flex flex-col justify-between"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import { TranslateModule } from '@ngx-translate/core'
import { By } from '@angular/platform-browser'
import { FormsModule } from '@angular/forms'
import { FieldFilters } from '@geonetwork-ui/common/domain/search'
import { USER_FIXTURE } from '@geonetwork-ui/common/fixtures'
import { AuthService } from '@geonetwork-ui/api/repository/gn4'

jest.mock('@geonetwork-ui/util/app-config', () => ({
getOptionalSearchConfig: () => ({
Expand Down Expand Up @@ -64,6 +66,7 @@ export class MockFilterDropdownComponent {
@Input() title: string
}
const state = { OrgForResource: { mel: true } } as FieldFilters
const user = USER_FIXTURE()
class SearchFacadeMock {
searchFilters$ = new BehaviorSubject(state)
hasSpatialFilter$ = new BehaviorSubject(false)
Expand Down Expand Up @@ -100,6 +103,12 @@ class FieldsServiceMock {
}
}

class AuthServiceMock {
user$ = new BehaviorSubject(user)
authReady = jest.fn(() => this._authSubject$)
_authSubject$ = new BehaviorSubject({})
}

describe('SearchFiltersComponent', () => {
let component: SearchFiltersComponent
let fixture: ComponentFixture<SearchFiltersComponent>
Expand Down Expand Up @@ -128,6 +137,10 @@ describe('SearchFiltersComponent', () => {
provide: FieldsService,
useClass: FieldsServiceMock,
},
{
provide: AuthService,
useClass: AuthServiceMock,
},
],
})
.overrideComponent(SearchFiltersComponent, {
Expand All @@ -152,7 +165,9 @@ describe('SearchFiltersComponent', () => {

describe('spatial filter button', () => {
function getCheckToggleDebugElement() {
return fixture.debugElement.query(By.directive(MockCheckToggleComponent))
return fixture.debugElement.queryAll(
By.directive(MockCheckToggleComponent)
)
}

describe('when panel is closed', () => {
Expand All @@ -161,7 +176,7 @@ describe('SearchFiltersComponent', () => {
fixture.detectChanges()
})
it('does not show up', () => {
expect(getCheckToggleDebugElement()).toBeFalsy()
expect(getCheckToggleDebugElement().length).toBeFalsy()
})
})
describe('when panel is opened & a spatial filter is unavailable', () => {
Expand All @@ -171,7 +186,7 @@ describe('SearchFiltersComponent', () => {
fixture.detectChanges()
})
it('does not show up', () => {
expect(getCheckToggleDebugElement()).toBeFalsy()
expect(getCheckToggleDebugElement().length).toBe(1)
})
})
describe('when panel is opened & a spatial filter is available', () => {
Expand All @@ -182,11 +197,11 @@ describe('SearchFiltersComponent', () => {
fixture.detectChanges()
})
it('does show up', () => {
expect(getCheckToggleDebugElement()).toBeTruthy()
expect(getCheckToggleDebugElement().length).toBe(2)
})
it('has the value set in the state', () => {
expect(
getCheckToggleDebugElement().componentInstance.value
getCheckToggleDebugElement()[0].componentInstance.value
).toBeTruthy()
})
})
Expand All @@ -198,7 +213,7 @@ describe('SearchFiltersComponent', () => {
})
it('emits a SetSpatialFilterEnabled action', () => {
const checkToggleComponent =
getCheckToggleDebugElement().componentInstance
getCheckToggleDebugElement()[0].componentInstance
checkToggleComponent.toggled.emit(false)
expect(searchFacade.setSpatialFilterEnabled).toHaveBeenCalledWith(false)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ import {
QueryList,
ViewChildren,
} from '@angular/core'
import { AuthService } from '@geonetwork-ui/api/repository/gn4'
import {
FieldsService,
FilterDropdownComponent,
SearchFacade,
SearchService,
} from '@geonetwork-ui/feature/search'
import { getOptionalSearchConfig } from '@geonetwork-ui/util/app-config'
import { Observable, switchMap } from 'rxjs'
import { map } from 'rxjs/operators'

@Component({
selector: 'datahub-search-filters',
Expand All @@ -26,14 +29,28 @@ export class SearchFiltersComponent implements OnInit {
searchConfig: { fieldName: string; title: string }[]
isOpen = false
@Input() isQualitySortable = false
userId: string
myRecordsFilterEnabled$: Observable<boolean> =
this.searchFacade.searchFilters$.pipe(
switchMap((filters) => {
return this.fieldsService.readFieldValuesFromFilters(filters)
}),
map((fieldValues) =>
fieldValues['owner'] && Array.isArray(fieldValues['owner'])
? fieldValues['owner'].length > 0
: !!fieldValues['owner']
)
)

constructor(
public searchFacade: SearchFacade,
private searchService: SearchService,
private fieldsService: FieldsService
private fieldsService: FieldsService,
private authService: AuthService
) {}

ngOnInit(): void {
this.authService.user$.subscribe((user) => (this.userId = user?.id))
this.searchConfig = (
getOptionalSearchConfig().ADVANCED_FILTERS || [
'publisher',
Expand Down Expand Up @@ -72,6 +89,12 @@ export class SearchFiltersComponent implements OnInit {
this.searchFacade.setSpatialFilterEnabled(enabled)
}

toggleMyRecordsFilter(enabled: boolean) {
this.fieldsService
.buildFiltersFromFieldValues({ owner: enabled ? this.userId : [] })
.subscribe((filters) => this.searchService.updateFilters(filters))
}

clearFilters() {
const fieldNames = this.filters.map((component) => component.fieldName)
const fieldValues = fieldNames.reduce(
Expand Down
56 changes: 47 additions & 9 deletions apps/metadata-editor-e2e/src/e2e/dashboard.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,27 @@ describe('dashboard', () => {
.then((text) => {
pageOne = text
})
cy.get('gn-ui-pagination-buttons').find('gn-ui-button').last().click()
})
//TODO remove skip when dump contains more than 15 records
it.skip('should display different results on click on specific page and change url', () => {
cy.visit('/records/search?_page=2')
cy.get('gn-ui-pagination-buttons').find('gn-ui-button').eq(1).click()
cy.get('gn-ui-record-table')
.find('.record-table-col')
.first()
.invoke('text')
.then((text) => {
expect(text).not.to.equal(pageOne)
cy.url().should('include', 'page=2')
expect(text).to.equal(pageOne)
cy.url().should('include', 'page=1')
})
})
it('should display different results on click on specific page and change url', () => {
cy.visit('/records/search?_page=2')
cy.get('gn-ui-pagination-buttons').find('gn-ui-button').eq(1).click()
cy.get('gn-ui-pagination-buttons').find('gn-ui-button').last().click()
cy.get('gn-ui-record-table')
.find('.record-table-col')
.first()
.invoke('text')
.then((text) => {
expect(text).to.equal(pageOne)
cy.url().should('include', 'page=1')
expect(text).not.to.equal(pageOne)
cy.url().should('include', 'page=2')
})
})
})
Expand All @@ -46,6 +47,9 @@ describe('dashboard', () => {
.then((list) => {
originalFirstItem = list.trim()
cy.get('.record-table-header').first().click()
// Takes time to refresh results
// eslint-disable-next-line cypress/no-unnecessary-waiting
// cy.wait(500)
cy.get('gn-ui-record-table')
.find('.record-table-col')
.first()
Expand All @@ -61,4 +65,38 @@ describe('dashboard', () => {
})
})
})

describe('checkboxes', () => {
it('should show the correct amount of selected records when they are selected', () => {
cy.visit('/records/all')
cy.get('gn-ui-record-table')
.find('.record-table-col')
.get('[type="checkbox"]')
.eq(2)
.click()
cy.get('.selected-records').contains('1 selected')
})

it('should show nothing when none are selected', () => {
cy.visit('/records/all')
cy.get('gn-ui-record-table')
.find('.record-table-col')
.get('mat-checkbox.mat-primary')
.each(($checkbox) => cy.wrap($checkbox).click())
cy.get('.records-information').should(
'not.have.descendants',
'.selected-records'
)
})

it('should select all records when the "select all" checkbox is checked', () => {
cy.visit('/records/all')
cy.get('gn-ui-record-table')
.find('.record-table-col')
.get('mat-checkbox.mat-primary')
.first()
.click()
cy.get('.selected-records').contains('12 selected')
})
})
})
Loading

0 comments on commit 6653144

Please sign in to comment.