test: increase ui test coverage

This commit is contained in:
2022-06-02 14:03:29 +02:00
committed by Rainer Killinger
parent 9e71efca9f
commit 8710ba43ff
35 changed files with 7201 additions and 209 deletions

View File

@@ -88,6 +88,7 @@ import {EventRoutePathComponent} from './types/event/event-route-path.component'
import {UtilModule} from '../../util/util.module';
import {TreeListComponent} from './list/tree-list.component';
import {TreeListFragmentComponent} from './list/tree-list-fragment.component';
import {SettingsProvider} from '../settings/settings.provider';
/**
* Module for handling data
@@ -179,6 +180,7 @@ import {TreeListFragmentComponent} from './list/tree-list-fragment.component';
StAppsWebHttpClient,
CalendarService,
RoutingStackService,
SettingsProvider,
],
exports: [
DataDetailComponent,

View File

@@ -1,22 +1,23 @@
/*
* Copyright (C) 2019 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
* Copyright (C) 2022 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
import {Component, Input} from '@angular/core';
import {
SCAcademicPriceGroup,
SCThingThatCanBeOfferedOffer,
} from '@openstapps/core';
import {SettingsProvider} from '../../settings/settings.provider';
/**
* TODO
@@ -29,5 +30,22 @@ export class OffersInListComponent {
/**
* TODO
*/
@Input() offers: Array<SCThingThatCanBeOfferedOffer<SCAcademicPriceGroup>>;
@Input() set offers(
it: Array<SCThingThatCanBeOfferedOffer<SCAcademicPriceGroup>>,
) {
this._offers = it;
this.price = it[0].prices?.default;
this.settingsProvider.getSetting('profile', 'group').then(group => {
this.price =
it[0].prices?.[(group.value as string).replace(/s$/, '') as never];
console.log(group.value);
});
}
price?: number;
_offers: Array<SCThingThatCanBeOfferedOffer<SCAcademicPriceGroup>>;
constructor(readonly settingsProvider: SettingsProvider) {}
}

View File

@@ -1,9 +1,24 @@
<!--
~ Copyright (C) 2022 StApps
~ This program is free software: you can redistribute it and/or modify it
~ under the terms of the GNU General Public License as published by the Free
~ Software Foundation, version 3.
~
~ This program is distributed in the hope that it will be useful, but WITHOUT
~ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
~ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
~ more details.
~
~ You should have received a copy of the GNU General Public License along with
~ this program. If not, see <https://www.gnu.org/licenses/>.
-->
<div>
<h2 *ngIf="offers[0].prices">
{{ offers[0].prices.default | currency: 'EUR':'symbol':undefined:'de' }}
<h2 *ngIf="price">
{{ price | currency: 'EUR':'symbol':undefined:'de' }}
</h2>
<p *ngIf="offers[0].inPlace">
<ion-icon name="location"></ion-icon>{{ offers[0].inPlace.name
}}<span *ngIf="offers.length > 1">...</span>
<p *ngIf="_offers[0].inPlace">
<ion-icon name="location"></ion-icon>{{ _offers[0].inPlace.name
}}<span *ngIf="_offers.length > 1">...</span>
</p>
</div>

View File

@@ -0,0 +1,81 @@
/*
* Copyright (C) 2022 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* eslint-disable @typescript-eslint/no-explicit-any,jsdoc/require-jsdoc,@typescript-eslint/no-non-null-assertion */
import english from '../../assets/i18n/en.json';
import german from '../../assets/i18n/de.json';
const exceptions = new Set([
'login',
'ok',
'protein',
'feedback',
'name',
'status',
'issn',
'ejournal',
'backup',
'export',
]);
const languages = [
['english', english],
['german', german],
] as [string, any][];
describe('i18n', function () {
for (const [name, language] of languages) {
const [targetName, target] = languages.find(([target]) => target !== name)!;
describe(`${name} (compare to ${targetName})`, function () {
it('should have translations for all languages', function () {
traverseCompare(target, language, (a, b, path) => {
expect(typeof b).toBe(
typeof a,
`Missing translation for ${path.join('.')}`,
);
});
});
it('should have unique translations for each language', function () {
traverseCompare(target, language, (a, b, path) => {
if (!exceptions.has(a.toLowerCase())) {
expect(b).not.toBe(
a,
`Do not copy translations (${path.join(
'.',
)}). If this is a mistake, add an exception in 'src/app/translation/i18n.spec.ts'`,
);
}
});
});
});
}
});
function traverseCompare(
a: any,
b: any,
compare: (a: any, b: any, path: string[]) => void,
path: string[] = [],
) {
for (const key of Object.keys(a)) {
if (typeof a[key] === 'object') {
traverseCompare(a[key], b[key], compare, [...path, key]);
} else {
compare(a[key], b[key], [...path, key]);
}
}
}