diff --git a/libs/ui/elements/src/lib/downloads-list/downloads-list.component.spec.ts b/libs/ui/elements/src/lib/downloads-list/downloads-list.component.spec.ts index 74bfde2f2a..47fa2fe3f7 100644 --- a/libs/ui/elements/src/lib/downloads-list/downloads-list.component.spec.ts +++ b/libs/ui/elements/src/lib/downloads-list/downloads-list.component.spec.ts @@ -1,19 +1,43 @@ -import { NO_ERRORS_SCHEMA } from '@angular/core' +import { + ChangeDetectionStrategy, + Component, + DebugElement, + Input, + NO_ERRORS_SCHEMA, +} from '@angular/core' import { ComponentFixture, TestBed } from '@angular/core/testing' -import { LinkHelperService } from '@geonetwork-ui/util/shared' +import { By } from '@angular/platform-browser' +import { + LinkHelperService, + MetadataLinkValid, +} from '@geonetwork-ui/util/shared' import { TranslateModule } from '@ngx-translate/core' +import { LINK_FIXTURES } from '../../../../../util/shared/src/lib/links/link.fixtures' import { DownloadsListComponent } from './downloads-list.component' -const linkHelperServiceMock = {} +const linkHelperServiceMock = { + isWfsLink: jest.fn(() => true), +} + +@Component({ + selector: 'gn-ui-download-item', + template: ``, +}) +export class DownloadItemComponentMock { + @Input() link: MetadataLinkValid + @Input() color: string +} + describe('DownloadsListComponent', () => { let component: DownloadsListComponent let fixture: ComponentFixture + let de beforeEach(async () => { await TestBed.configureTestingModule({ imports: [TranslateModule.forRoot()], - declarations: [DownloadsListComponent], + declarations: [DownloadsListComponent, DownloadItemComponentMock], schemas: [NO_ERRORS_SCHEMA], providers: [ { @@ -21,17 +45,34 @@ describe('DownloadsListComponent', () => { useValue: linkHelperServiceMock, }, ], - }).compileComponents() + }) + .overrideComponent(DownloadsListComponent, { + set: { changeDetection: ChangeDetectionStrategy.Default }, + }) + .compileComponents() }) beforeEach(() => { fixture = TestBed.createComponent(DownloadsListComponent) component = fixture.componentInstance component.links = [] - fixture.detectChanges() + de = fixture.debugElement }) it('should create', () => { + fixture.detectChanges() expect(component).toBeTruthy() }) + describe('when link format is unknown', () => { + let items: DebugElement[] + + beforeEach(() => { + component.links = [LINK_FIXTURES.unknownFormat] + fixture.detectChanges() + items = de.queryAll(By.directive(DownloadItemComponentMock)) + }) + it('contains one link', () => { + expect(items.length).toBe(1) + }) + }) }) diff --git a/libs/ui/elements/src/lib/downloads-list/downloads-list.component.ts b/libs/ui/elements/src/lib/downloads-list/downloads-list.component.ts index 8a183721be..89cb504f32 100644 --- a/libs/ui/elements/src/lib/downloads-list/downloads-list.component.ts +++ b/libs/ui/elements/src/lib/downloads-list/downloads-list.component.ts @@ -54,7 +54,6 @@ export class DownloadsListComponent implements OnInit { ngOnInit(): void { this.processedLinks = this.formatLinks(this.links) - console.log(this.processedLinks) this.processedLinks = this.assignColor(this.processedLinks) this.processedLinks = this.isGeneratedFromWfs(this.processedLinks) this.filteredLinks = this.filterLinks(this.processedLinks) diff --git a/libs/util/shared/src/lib/links/link.fixtures.ts b/libs/util/shared/src/lib/links/link.fixtures.ts index a4f84a7dba..9846a94839 100644 --- a/libs/util/shared/src/lib/links/link.fixtures.ts +++ b/libs/util/shared/src/lib/links/link.fixtures.ts @@ -156,4 +156,11 @@ export const LINK_FIXTURES = { label: 'landingpage link', url: 'https://landing.page', }, + unknownFormat: { + protocol: 'WWW:DOWNLOAD-1.0-http--download', + format: undefined, + name: 'Vue HTML des métadonnées sur internet', + label: 'Vue HTML des métadonnées sur internet', + url: 'http://catalogue.geo-ide.developpement-durable.gouv.fr/catalogue/srv/fre/catalog.search#/metadata/fr-120066022-jdd-199fd14c-2abb-4c14-b0f8-6c8d92e7b480', + }, }