Skip to content

Commit

Permalink
test(downloads-list): add unknown format link
Browse files Browse the repository at this point in the history
  • Loading branch information
fgravin committed Jun 22, 2022
1 parent 51c207e commit c16b90b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,37 +1,78 @@
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<DownloadsListComponent>
let de

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [TranslateModule.forRoot()],
declarations: [DownloadsListComponent],
declarations: [DownloadsListComponent, DownloadItemComponentMock],
schemas: [NO_ERRORS_SCHEMA],
providers: [
{
provide: LinkHelperService,
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)
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions libs/util/shared/src/lib/links/link.fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
}

0 comments on commit c16b90b

Please sign in to comment.