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 @@ ...@@ -2,7 +2,7 @@
<div class="card-body"> <div class="card-body">
<!-- title --> <!-- title -->
<h3 class="card-title">{{ aggregation.name }}</h3> <h3 class="card-title">{{ aggregation.name | aggregationName }}</h3>
<!-- values --> <!-- values -->
<form [formGroup]="aggregationForm"> <form [formGroup]="aggregationForm">
......
...@@ -5,6 +5,7 @@ import { ComponentTester, speculoosMatchers } from 'ngx-speculoos'; ...@@ -5,6 +5,7 @@ import { ComponentTester, speculoosMatchers } from 'ngx-speculoos';
import { AggregationComponent } from './aggregation.component'; import { AggregationComponent } from './aggregation.component';
import { toAggregation } from '../models/test-model-generators'; import { toAggregation } from '../models/test-model-generators';
import { AggregationCriterion } from '../models/aggregation-criterion'; import { AggregationCriterion } from '../models/aggregation-criterion';
import { AggregationNamePipe } from '../aggregation-name.pipe';
describe('AggregationsComponent', () => { describe('AggregationsComponent', () => {
...@@ -30,7 +31,7 @@ describe('AggregationsComponent', () => { ...@@ -30,7 +31,7 @@ describe('AggregationsComponent', () => {
beforeEach(() => TestBed.configureTestingModule({ beforeEach(() => TestBed.configureTestingModule({
imports: [ReactiveFormsModule], imports: [ReactiveFormsModule],
declarations: [AggregationComponent] declarations: [AggregationComponent, AggregationNamePipe]
})); }));
beforeEach(() => jasmine.addMatchers(speculoosMatchers)); beforeEach(() => jasmine.addMatchers(speculoosMatchers));
...@@ -43,7 +44,7 @@ describe('AggregationsComponent', () => { ...@@ -43,7 +44,7 @@ describe('AggregationsComponent', () => {
tester.detectChanges(); tester.detectChanges();
// then it should display a title // 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 // and the buckets with their name and count
expect(tester.labels.length).toBe(3); expect(tester.labels.length).toBe(3);
expect(tester.labels[0]).toContainText('France'); expect(tester.labels[0]).toContainText('France');
......
...@@ -7,6 +7,7 @@ import { AggregationsComponent } from './aggregations.component'; ...@@ -7,6 +7,7 @@ import { AggregationsComponent } from './aggregations.component';
import { AggregationComponent } from '../aggregation/aggregation.component'; import { AggregationComponent } from '../aggregation/aggregation.component';
import { toAggregation } from '../models/test-model-generators'; import { toAggregation } from '../models/test-model-generators';
import { AggregationCriterion } from '../models/aggregation-criterion'; import { AggregationCriterion } from '../models/aggregation-criterion';
import { AggregationNamePipe } from '../aggregation-name.pipe';
describe('AggregationsComponent', () => { describe('AggregationsComponent', () => {
...@@ -22,7 +23,7 @@ describe('AggregationsComponent', () => { ...@@ -22,7 +23,7 @@ describe('AggregationsComponent', () => {
beforeEach(() => TestBed.configureTestingModule({ beforeEach(() => TestBed.configureTestingModule({
imports: [ReactiveFormsModule], imports: [ReactiveFormsModule],
declarations: [AggregationsComponent, AggregationComponent] declarations: [AggregationsComponent, AggregationComponent, AggregationNamePipe]
})); }));
it('should display no aggregations if null', () => { it('should display no aggregations if null', () => {
......
...@@ -17,6 +17,7 @@ import { GeneticResourceComponent } from './genetic-resource/genetic-resource.co ...@@ -17,6 +17,7 @@ import { GeneticResourceComponent } from './genetic-resource/genetic-resource.co
import { AggregationsComponent } from './aggregations/aggregations.component'; import { AggregationsComponent } from './aggregations/aggregations.component';
import { AggregationComponent } from './aggregation/aggregation.component'; import { AggregationComponent } from './aggregation/aggregation.component';
import { PillarsComponent } from './pillars/pillars.component'; import { PillarsComponent } from './pillars/pillars.component';
import { AggregationNamePipe } from './aggregation-name.pipe';
registerLocaleData(localeFr); registerLocaleData(localeFr);
...@@ -29,7 +30,8 @@ registerLocaleData(localeFr); ...@@ -29,7 +30,8 @@ registerLocaleData(localeFr);
GeneticResourceComponent, GeneticResourceComponent,
AggregationsComponent, AggregationsComponent,
AggregationComponent, AggregationComponent,
PillarsComponent PillarsComponent,
AggregationNamePipe
], ],
imports: [ imports: [
BrowserAnimationsModule, 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'; ...@@ -17,6 +17,7 @@ import { GeneticResourceModel } from '../models/genetic-resource.model';
import { toAggregation, toGeneticResource, toSecondPage, toSinglePage } from '../models/test-model-generators'; import { toAggregation, toGeneticResource, toSecondPage, toSinglePage } from '../models/test-model-generators';
import { AggregationsComponent } from '../aggregations/aggregations.component'; import { AggregationsComponent } from '../aggregations/aggregations.component';
import { AggregationComponent } from '../aggregation/aggregation.component'; import { AggregationComponent } from '../aggregation/aggregation.component';
import { AggregationNamePipe } from '../aggregation-name.pipe';
class SearchComponentTester extends ComponentTester<SearchComponent> { class SearchComponentTester extends ComponentTester<SearchComponent> {
constructor() { constructor() {
...@@ -54,7 +55,14 @@ describe('SearchComponent', () => { ...@@ -54,7 +55,14 @@ describe('SearchComponent', () => {
NgbTypeaheadModule.forRoot(), NgbTypeaheadModule.forRoot(),
NoopAnimationsModule NoopAnimationsModule
], ],
declarations: [SearchComponent, GeneticResourcesComponent, GeneticResourceComponent, AggregationsComponent, AggregationComponent] declarations: [
SearchComponent,
GeneticResourcesComponent,
GeneticResourceComponent,
AggregationsComponent,
AggregationComponent,
AggregationNamePipe
]
})); }));
beforeEach(() => jasmine.addMatchers(speculoosMatchers)); 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