-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #279 from akhelouat/fix-links-rendering
Fix links rendering
- Loading branch information
Showing
10 changed files
with
142 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 96 additions & 6 deletions
102
libs/ui/elements/src/lib/downloads-list/downloads-list.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,127 @@ | ||
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 { | ||
LINK_FIXTURES, | ||
LinkHelperService, | ||
MetadataLinkValid, | ||
} from '@geonetwork-ui/util/shared' | ||
import { TranslateModule } from '@ngx-translate/core' | ||
|
||
import { DownloadsListComponent } from './downloads-list.component' | ||
|
||
const linkHelperServiceMock = {} | ||
const linkHelperServiceMock = { | ||
isWfsLink: jest.fn(() => true), | ||
} | ||
|
||
@Component({ | ||
selector: 'gn-ui-download-item', | ||
template: ``, | ||
}) | ||
class MockDownloadItemComponent { | ||
@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, MockDownloadItemComponent], | ||
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 a list of downloads', () => { | ||
let items: DebugElement[] | ||
|
||
beforeEach(() => { | ||
component.links = [ | ||
LINK_FIXTURES.dataCsv, | ||
LINK_FIXTURES.dataPdf, | ||
LINK_FIXTURES.dataPdf, | ||
] | ||
fixture.detectChanges() | ||
items = de.queryAll(By.directive(MockDownloadItemComponent)) | ||
}) | ||
it('contains one link', () => { | ||
expect(items.length).toBe(3) | ||
}) | ||
}) | ||
describe('when link format is unknown', () => { | ||
let items: DebugElement[] | ||
|
||
beforeEach(() => { | ||
component.links = [LINK_FIXTURES.unknownFormat] | ||
fixture.detectChanges() | ||
items = de.queryAll(By.directive(MockDownloadItemComponent)) | ||
}) | ||
it('contains one link', () => { | ||
expect(items.length).toBe(1) | ||
}) | ||
}) | ||
describe('hydrates link with color and format', () => { | ||
let items: DebugElement[] | ||
|
||
beforeEach(() => { | ||
component.links = [LINK_FIXTURES.geodataShpWithMimeType] | ||
fixture.detectChanges() | ||
items = de.queryAll(By.directive(MockDownloadItemComponent)) | ||
}) | ||
it('contains color, isWfs & format', () => { | ||
expect(items.length).toBe(1) | ||
expect(items[0].componentInstance.link).toEqual({ | ||
...LINK_FIXTURES.geodataShpWithMimeType, | ||
color: 'var(--color-gray-700)', | ||
format: '', | ||
isWfs: true, | ||
}) | ||
}) | ||
}) | ||
describe('filtering', () => { | ||
let items: DebugElement[] | ||
|
||
beforeEach(() => { | ||
component.links = [{ ...LINK_FIXTURES.dataCsv, format: 'csv' }] | ||
component.activeFilterFormats = ['csv', 'json'] | ||
fixture.detectChanges() | ||
}) | ||
it('csv link is displayed', () => { | ||
expect(component.filteredLinks.length).toBe(1) | ||
component.toggleFilterFormat('csv') | ||
expect(component.filteredLinks.length).toBe(0) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './geojson.fixtures' | ||
export * from './ol-feature.fixture' | ||
export * from './record-link.fixtures' | ||
export * from './link.fixtures' | ||
export * from './records' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters