Skip to content

Commit

Permalink
Merge pull request #195 from europeana/feat/MET-6063-Switch-to-Countr…
Browse files Browse the repository at this point in the history
…y-Codes

MET-6063 Use Country Codes In API
  • Loading branch information
andyjmaclean authored Aug 22, 2024
2 parents 0a0453d + cc33df8 commit 8133b3f
Show file tree
Hide file tree
Showing 28 changed files with 311 additions and 233 deletions.
32 changes: 27 additions & 5 deletions cypress/e2e/ct-zero.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ context('Statistics Dashboard', () => {
'View by provider'
];

const targetLinkTexts = [
'View (3D data) by content tier',
'View (HQ data) by type'
];

it('should (conditionally) show the control zero control', () => {
cy.visit(urlDefault);
cy.wait(100);
Expand Down Expand Up @@ -123,18 +128,35 @@ context('Statistics Dashboard', () => {
});
});

it('Should maintain the content tier zero control setting', () => {
const country = 'Belgium';
const url = `/country/${country}`;

cy.visit(url);
cy.wait(1000);
cy.get(selCtrlCTZero).click(force);
cy.wait(1000);
cy.contains(targetLinkTexts[1]).click(force);

cy.wait(1000);
confirmCTZeroSetting(false);
cy.go('back');
cy.wait(1000);
confirmCTZeroSetting(true);

cy.contains(linkTexts[0]).click(force);
confirmCTZeroSetting(true);
cy.go('back');
confirmCTZeroSetting(true);
});

it('Should (conditionally) reset the content tier zero control', () => {
const country = 'Belgium';
const url = `/country/${country}`;
const valPercent = '44.1%';
const valPercentCTZero = '11.6%';
const selPercent = '.total.percent-value';

const targetLinkTexts = [
'View (3D data) by content tier',
'View (HQ data) by type'
];

// go to Belgium
cy.visit(url);
cy.wait(1000);
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/filters.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ context('Statistics Dashboard', () => {
cy.get(selFilterValueLabel).contains('Cyprus').should('have.length', 1);

cy.get(selSearch).type('a');
cy.get(selCheckbox).should('have.length', 20);
cy.get(selCheckbox).should('have.length', 21);
cy.get(selFilterValueLabel).contains('Cyprus').should('have.length', 0);
cy.get(selFilterValueLabel).contains('Croatia').should('have.length', 1);

Expand Down
10 changes: 5 additions & 5 deletions cypress/e2e/grid.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ context('Statistics Dashboard', () => {
// assumes page of 10 entries
const pageOneCountries = ['Belgium', 'Holy See (Vatican City State)'];
const pageTwoCountries = ['Ireland', 'Netherlands'];
const pageThreeCountries = ['Iceland', 'Czech Republic'];
const pageThreeCountries = ['Iceland', 'Czechia'];

assertRowLength(pageOneCountries, 1);
assertRowLength(pageTwoCountries, 0);
Expand Down Expand Up @@ -108,12 +108,12 @@ context('Statistics Dashboard', () => {
cy.visit(`/data/${DimensionName.country}`);

assertRowLength(['Belgium'], 1);
assertRowLength(['Czech Republic'], 0);
assertRowLength(['Czechia'], 0);

cy.get(selColSortCount).click(force);
cy.get(selColSortCount).click(force);
assertRowLength(['Belgium'], 0);
assertRowLength(['Czech Republic'], 1);
assertRowLength(['Czechia'], 1);

cy.get(selFacetSelect).select('Data Provider', force);

Expand All @@ -123,12 +123,12 @@ context('Statistics Dashboard', () => {
cy.get(selFacetSelect).select('Country', force);

assertRowLength(['Belgium'], 0);
assertRowLength(['Czech Republic'], 1);
assertRowLength(['Czechia'], 1);

cy.get(selColSortCount).click(force);

assertRowLength(['Belgium'], 1);
assertRowLength(['Czech Republic'], 0);
assertRowLength(['Czechia'], 0);

cy.get(selFacetSelect).select('Data Provider', force);

Expand Down
6 changes: 3 additions & 3 deletions src/app/_data/static-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,20 @@ export const isoCountryCodes = {
Norway: 'NO',
Kosovo: 'XK',
Switzerland: 'CH',
'Czech Republic': 'CZ',
Czechia: 'CZ',
Cyprus: 'CY',
Slovakia: 'SK',
Slovenia: 'SI',
Sweden: 'SE',
Denmark: 'DK',
Germany: 'DE',
'United States of America': 'USA',
'United States of America': 'US',
Turkey: 'TR',
Liechtenstein: 'LI',
Latvia: 'LV',
Lithuania: 'LT',
Luxembourg: 'LU',
Vatican: 'VA',
'Holy See (Vatican City State)': 'VA',
Andorra: 'AD',
Iceland: 'IS',
Israel: 'IL',
Expand Down
22 changes: 2 additions & 20 deletions src/app/_mocked/mock-api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const MockGeneralResults = {
{
count: 15,
percentage: 1.5,
value: 'Czech Republic'
value: 'Czechia'
},
{
count: 52,
Expand Down Expand Up @@ -303,19 +303,7 @@ export const MockGeneralResults = {
export const MockBreakdowns = {
filteringOptions: {
contentTier: ['0', '1', '2', '3'],
country: [
'Denmark',
'Ireland',
'Norway',
'Finland',
'Germany',
'Portugal',
'Poland',
'Italy',
'Holy See (Vatican City State)',
'Croatia',
'Iceland'
],
country: ['IT', 'IE', 'NO', 'FI', 'DE', 'PT', 'PL', 'IT', 'VA', 'HR', 'IS'],
dataProvider: [
'The Danish Agency for Culture',
'University College Cork',
Expand Down Expand Up @@ -633,12 +621,6 @@ export const MockBreakdowns = {
export class MockAPIService {
errorMode = false;

loadIsoCountryCodes(): IHash<string> {
return {
Belgium: 'BE'
};
}

getBreakdowns(br: BreakdownRequest): Observable<BreakdownResults> {
if (this.errorMode) {
return of({ filteringOptions: {}, results: {} } as BreakdownResults).pipe(
Expand Down
4 changes: 0 additions & 4 deletions src/app/_services/api.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,6 @@ describe('API Service', () => {
sub.unsubscribe();
});

it('should load the ISO country codes', () => {
expect(service.loadIsoCountryCodes()).toBeTruthy();
});

it('should load the rightsCategory urls', () => {
expect(service.getRightsCategoryUrls(['CC0'])).toBeTruthy();
});
Expand Down
6 changes: 1 addition & 5 deletions src/app/_services/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ export class APIService {

constructor(private readonly http: HttpClient) {}

loadIsoCountryCodes(): IHash<string> {
return isoCountryCodes;
}

replaceDoubleSlashes(s: string): string {
return s.replace(/([^:]\/)\/+/g, '$1');
}
Expand Down Expand Up @@ -90,7 +86,6 @@ export class APIService {
map((targetData: Array<TargetMetaDataRaw>) => {
return targetData.map((tmd: TargetMetaDataRaw) => {
tmd.isInterim = tmd.targetYear !== 2030;
tmd.country = isoCountryCodes[tmd.country];
return tmd;
});
})
Expand All @@ -112,6 +107,7 @@ export class APIService {
return rows.reduce(
(res: IHash<IHashArray<TargetMetaData>>, item: TargetMetaDataRaw) => {
const country = item.country;

if (!res[country]) {
res[country] = {};
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class AppComponent extends SubscriptionManager implements OnInit {
*
* @param { boolean } value - the value to set
**/
setContentTierZeroValue(value: boolean) {
setContentTierZeroValue(value: boolean): void {
const ctrlCTZero = this.getCtrlCTZero();

this.lastSetContentTierZeroValue = value;
Expand Down
3 changes: 2 additions & 1 deletion src/app/chart/map/map.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as am4maps from '@amcharts/amcharts4/maps';
import am4themes_animated from '@amcharts/amcharts4/themes/animated';
import am4geodata_worldHigh from '@amcharts/amcharts4-geodata/worldHigh';

import { isoCountryCodes } from '../../_data';
import { APIService } from '../../_services';
import { IHash, NameValue } from '../../_models';

Expand Down Expand Up @@ -39,7 +40,7 @@ export class MapComponent {
private readonly zone: NgZone,
private readonly api: APIService
) {
this.countryCodes = api.loadIsoCountryCodes();
this.countryCodes = isoCountryCodes;
am4core.options.autoDispose = true;
}

Expand Down
39 changes: 18 additions & 21 deletions src/app/country/country.component.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<main class="fit-to-page">
<h1 class="page-title">
<span class="flag-orb" [ngClass]="isoCountryCodes[country]"></span>
<span class="flag-orb" [ngClass]="country"></span>
<ng-container
*ngIf="
headerRef &&
Expand All @@ -9,7 +9,7 @@ <h1 class="page-title">
headerRef['countryTotalMap'][country]['percentage'] !== undefined
"
>
<span *ngIf="country">{{ country }}</span>
<span *ngIf="country">{{ country | renameCountry }}</span>
<span *ngIf="country" i18n="@@countryPageTitle">Data</span>
<span class="page-subtitle">
{{ headerRef["countryTotalMap"][country]["percentage"] }}% of the
Expand Down Expand Up @@ -294,7 +294,7 @@ <h1 class="page-title">
<div
class="entry-card-content"
*ngIf="
targetMetaData[countryCodes[country]][TargetFieldName.THREE_D];
targetMetaData[country][TargetFieldName.THREE_D];
let targets3D
"
>
Expand Down Expand Up @@ -342,7 +342,7 @@ <h1 class="page-title">
class="data-link"
routerLink="/data/{{ DimensionName.contentTier }}"
[queryParams]="{
country: country,
country: country | renameCountry,
type: '3D'
}"
(click)="resetAppCTZeroParam()"
Expand All @@ -368,10 +368,7 @@ <h1 class="page-title">

<div
class="entry-card-content"
*ngIf="
targetMetaData[countryCodes[country]][TargetFieldName.HQ];
let targetsHQ
"
*ngIf="targetMetaData[country][TargetFieldName.HQ]; let targetsHQ"
>
<ng-content
*ngTemplateOutlet="
Expand Down Expand Up @@ -418,7 +415,7 @@ <h1 class="page-title">
class="data-link"
routerLink="/data/{{ DimensionName.type }}"
[queryParams]="{
country: country,
country: country | renameCountry,
contentTier: [2, 3, 4],
metadataTier: ['A', 'B', 'C']
}"
Expand All @@ -444,7 +441,7 @@ <h1 class="page-title">
<div
class="entry-card-content entry-card-totals"
*ngIf="
targetMetaData[countryCodes[country]][TargetFieldName.TOTAL];
targetMetaData[country][TargetFieldName.TOTAL];
let targetsTOTAL
"
>
Expand Down Expand Up @@ -493,11 +490,11 @@ <h1 class="page-title">
class="data-link"
routerLink="/data/{{ DimensionName.contentTier }}"
[queryParams]="{
country: country
country: country | renameCountry
}"
(click)="resetAppCTZeroParam()"
><span i18n="@@countrySectionLinkCountry">View all data for</span
>&nbsp;{{ country }}</a
>&nbsp;{{ country | renameCountry }}</a
>
</div>

Expand All @@ -521,7 +518,7 @@ <h1 class="page-title">
<app-legend-grid
#legendGrid
[countryData]="countryData"
[countryCode]="countryCode"
[countryCode]="country"
[targetMetaData]="targetMetaData"
[lineChart]="lineChart"
[columnEnabled3D]="columnsEnabled[TargetFieldName.THREE_D]"
Expand Down Expand Up @@ -570,7 +567,7 @@ <h1 class="page-title">
<div class="entry-card-pair">
<div class="entry-card">
<span class="entry-card-header">
<span class="pad-word-right">{{ country }}</span>
<span class="pad-word-right">{{ country | renameCountry }}</span>
<span i18n="@@countryEntryType">data by content type</span>
</span>

Expand Down Expand Up @@ -600,7 +597,7 @@ <h1 class="page-title">
routerLink="/data/{{ DimensionName.type }}"
[queryParams]="{
'content-tier-zero': includeCTZero ? true : undefined,
country: country
country: country | renameCountry
}"
data-e2e="link-entry-type"
i18n="@@countrySectionLinkType"
Expand All @@ -610,7 +607,7 @@ <h1 class="page-title">
</div>
<div class="entry-card">
<span class="entry-card-header">
<span class="pad-word-right">{{ country }}</span>
<span class="pad-word-right">{{ country | renameCountry }}</span>
<span i18n="@@countryEntryRights">data by rights category</span>
<a
class="info-icon"
Expand All @@ -636,7 +633,7 @@ <h1 class="page-title">
routerLink="/data/{{ DimensionName.rightsCategory }}"
[queryParams]="{
'content-tier-zero': includeCTZero ? true : undefined,
country: country
country: country | renameCountry
}"
data-e2e="link-entry-rights"
i18n="@@countrySectionLinkRights"
Expand All @@ -649,7 +646,7 @@ <h1 class="page-title">
<div class="entry-card-pair">
<div class="entry-card">
<span class="entry-card-header">
<span class="pad-word-right">{{ country }}</span>
<span class="pad-word-right">{{ country | renameCountry }}</span>
<span i18n="@@countryEntryDataProvider">data by data provider</span>
</span>
<div class="entry-card-content">
Expand All @@ -669,7 +666,7 @@ <h1 class="page-title">
routerLink="/data/{{ DimensionName.dataProvider }}"
[queryParams]="{
'content-tier-zero': includeCTZero ? true : undefined,
country: country
country: country | renameCountry
}"
data-e2e="link-entry-data-provider"
i18n="@@countrySectionLinkDataProvider"
Expand All @@ -679,7 +676,7 @@ <h1 class="page-title">
</div>
<div class="entry-card">
<span class="entry-card-header">
<span class="pad-word-right">{{ country }}</span>
<span class="pad-word-right">{{ country | renameCountry }}</span>
<span i18n="@@countryEntryProvider">data by provider</span>
<a
class="info-icon"
Expand All @@ -705,7 +702,7 @@ <h1 class="page-title">
routerLink="/data/{{ DimensionName.provider }}"
[queryParams]="{
'content-tier-zero': includeCTZero ? true : undefined,
country: country
country: country | renameCountry
}"
data-e2e="link-entry-provider"
i18n="@@countrySectionLinkProvider"
Expand Down
Loading

0 comments on commit 8133b3f

Please sign in to comment.