Commit 79214043 authored by Exbrayat Cédric's avatar Exbrayat Cédric Committed by Exbrayat Cédric
Browse files

feat: display friendly aggregation name

parent 1e00e9af
import { AggregationNamePipe } from './aggregation-name.pipe';
describe('AggregationNamePipe', () => {
it('should return the displayed name of an aggregation', () => {
const pipe = new AggregationNamePipe();
// for know aggregation names
const cooResult = pipe.transform('coo');
expect(cooResult).toBe('Pays d\'origine');
const domainResult = pipe.transform('domain');
expect(domainResult).toBe('Domaine');
});
it('should return the key for an unknown aggregation', () => {
const pipe = new AggregationNamePipe();
// for an unknow aggregation names
const result = pipe.transform('unknown');
expect(result).toBe('unknown');
});
});
import { Pipe, PipeTransform } from '@angular/core';
import { aggregationNames } from './models/aggregation-names';
/**
* Returns the name of an aggregation, ot the key itself if the aggregation is unknown.
*/
@Pipe({
name: 'aggregationName'
})
export class AggregationNamePipe implements PipeTransform {
transform(value: string, args?: any): string {
return aggregationNames[value] || value;
}
}
......@@ -2,7 +2,7 @@
<div class="card-body">
<!-- title -->
<h3 class="card-title">{{ aggregation.name }}</h3>
<h3 class="card-title">{{ aggregation.name | aggregationName }}</h3>
<!-- values -->
<form [formGroup]="aggregationForm">
......
......@@ -5,6 +5,7 @@ import { ComponentTester, speculoosMatchers } from 'ngx-speculoos';
import { AggregationComponent } from './aggregation.component';
import { toAggregation } from '../models/test-model-generators';
import { AggregationCriterion } from '../models/aggregation-criterion';
import { AggregationNamePipe } from '../aggregation-name.pipe';
describe('AggregationsComponent', () => {
......@@ -30,7 +31,7 @@ describe('AggregationsComponent', () => {
beforeEach(() => TestBed.configureTestingModule({
imports: [ReactiveFormsModule],
declarations: [AggregationComponent]
declarations: [AggregationComponent, AggregationNamePipe]
}));
beforeEach(() => jasmine.addMatchers(speculoosMatchers));
......@@ -43,7 +44,7 @@ describe('AggregationsComponent', () => {
tester.detectChanges();
// then it should display a title
expect(tester.title).toHaveText('coo');
expect(tester.title).toHaveText('Pays d\'origine');
// and the buckets with their name and count
expect(tester.labels.length).toBe(3);
expect(tester.labels[0]).toContainText('France');
......
......@@ -7,6 +7,7 @@ import { AggregationsComponent } from './aggregations.component';
import { AggregationComponent } from '../aggregation/aggregation.component';
import { toAggregation } from '../models/test-model-generators';
import { AggregationCriterion } from '../models/aggregation-criterion';
import { AggregationNamePipe } from '../aggregation-name.pipe';
describe('AggregationsComponent', () => {
......@@ -22,7 +23,7 @@ describe('AggregationsComponent', () => {
beforeEach(() => TestBed.configureTestingModule({
imports: [ReactiveFormsModule],
declarations: [AggregationsComponent, AggregationComponent]
declarations: [AggregationsComponent, AggregationComponent, AggregationNamePipe]
}));
it('should display no aggregations if null', () => {
......
......@@ -17,6 +17,7 @@ import { GeneticResourceComponent } from './genetic-resource/genetic-resource.co
import { AggregationsComponent } from './aggregations/aggregations.component';
import { AggregationComponent } from './aggregation/aggregation.component';
import { PillarsComponent } from './pillars/pillars.component';
import { AggregationNamePipe } from './aggregation-name.pipe';
registerLocaleData(localeFr);
......@@ -29,7 +30,8 @@ registerLocaleData(localeFr);
GeneticResourceComponent,
AggregationsComponent,
AggregationComponent,
PillarsComponent
PillarsComponent,
AggregationNamePipe
],
imports: [
BrowserAnimationsModule,
......
/**
* Map containing the list of the aggregations and their displayed name.
* Should be kept in sync with the `RareAggregation` enum of the backend.
*/
export const aggregationNames: { [key: string]: string } = {
coo: 'Pays d\'origine',
domain: 'Domaine',
material: 'Matériel',
taxon: 'Taxon',
biotope: 'Biotope',
};
......@@ -17,6 +17,7 @@ import { GeneticResourceModel } from '../models/genetic-resource.model';
import { toAggregation, toGeneticResource, toSecondPage, toSinglePage } from '../models/test-model-generators';
import { AggregationsComponent } from '../aggregations/aggregations.component';
import { AggregationComponent } from '../aggregation/aggregation.component';
import { AggregationNamePipe } from '../aggregation-name.pipe';
class SearchComponentTester extends ComponentTester<SearchComponent> {
constructor() {
......@@ -54,7 +55,14 @@ describe('SearchComponent', () => {
NgbTypeaheadModule.forRoot(),
NoopAnimationsModule
],
declarations: [SearchComponent, GeneticResourcesComponent, GeneticResourceComponent, AggregationsComponent, AggregationComponent]
declarations: [
SearchComponent,
GeneticResourcesComponent,
GeneticResourceComponent,
AggregationsComponent,
AggregationComponent,
AggregationNamePipe
]
}));
beforeEach(() => jasmine.addMatchers(speculoosMatchers));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment