import 'package:consumer_app/core/content/listing_labels.dart';
import 'package:consumer_app/core/content/navigation_labels.dart';
import 'package:consumer_app/features/discovery/resource_browser_page.dart';
import 'package:consumer_app/l10n/app_localizations_de.dart';
import 'package:consumer_app/models/content_models.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
final l10n = AppLocalizationsDe();
test('unknown listing values remain visible backend data', () {
expect(
listingValueLabel(l10n, 'future_backend_value'),
'Future Backend Value',
);
expect(listingFieldLabel(l10n, 'future_backend_field'), 'Eintrag');
});
test('legacy real-estate transaction values use the current rent label', () {
expect(listingValueLabel(l10n, 'lease'), 'Miete');
expect(listingValueLabel(l10n, 'temporary'), 'Miete');
});
test(
'legacy real-estate transaction aliases do not create duplicate choices',
() {
expect(
canonicalRealEstateTransactionValues([
'sale',
'rent',
'lease',
'temporary',
'rent',
]),
['sale', 'rent'],
);
},
);
test('free remains classifieds-only while event tickets use event copy', () {
expect(listingValueLabel(l10n, 'free'), 'Zu verschenken');
expect(
listingValueLabel(l10n, 'free', fieldKey: 'ticket_mode'),
'Kostenlos',
);
});
test('controlled property counts keep their German labels', () {
expect(
listingValueLabel(l10n, 'more_than_6', fieldKey: 'bathrooms'),
'Mehr als 6',
);
expect(
listingValueLabel(l10n, 'custom', fieldKey: 'property_rooms'),
'Eigene Anzahl',
);
});
test('heating-cost inclusion has a localized field label', () {
expect(
listingFieldLabel(l10n, 'heating_costs_included'),
'Heizkosten in Nebenkosten enthalten',
);
});
test('German job labels do not expose English UI copy', () {
expect(listingValueLabel(l10n, 'remote'), 'Fernarbeit');
expect(listingFieldLabel(l10n, 'benefits'), 'Vorteile');
});
test('place category profiles use localized fallback labels', () {
expect(
localizedCategoryProfileLabel(l10n, 'places', 'gastronomy'),
'Gastronomie',
);
expect(
localizedCategoryProfileLabel(l10n, 'places', 'playgrounds'),
'Spielplätze',
);
});
test('job salary interval uses the canonical price interval', () {
final hourly = ListingData.fromJson({
'salary_min': 14.5,
'salary_max': 16.0,
'price_currency': 'EUR',
'price_interval': 'hour',
});
final monthly = ListingData.fromJson({
'salary_min': 2800,
'salary_max': 3200,
'price_currency': 'EUR',
'price_interval': 'month',
});
final yearly = ListingData.fromJson({
'salary_min': 42000,
'salary_max': 48000,
'price_currency': 'EUR',
'price_interval': 'year',
});
expect(jobSalaryLabel(hourly, 'de-DE'), '14,50\u00a0EUR–16,00\u00a0EUR');
expect(jobSalaryIntervalLabel(l10n, hourly), 'Brutto/Stunde');
expect(jobSalaryIntervalLabel(l10n, monthly), 'Brutto/Monat');
expect(jobSalaryIntervalLabel(l10n, yearly), 'Brutto/Jahr');
});
test('job salary filter converts monthly and yearly values both ways', () {
expect(
convertJobSalaryAmount(2500, fromInterval: 'month', toInterval: 'year'),
30000,
);
expect(
convertJobSalaryAmount(30000, fromInterval: 'year', toInterval: 'month'),
2500,
);
expect(parseJobSalaryFilterAmount('2.500,50'), 2500.5);
expect(parseJobSalaryFilterAmount('30.000', locale: 'de-DE'), 30000);
expect(parseJobSalaryFilterAmount('30,000', locale: 'en-US'), 30000);
});
test('same enum values use the field-specific German label', () {
expect(
listingValueLabel(l10n, 'both', fieldKey: 'commission_payer'),
'Beide Parteien',
);
expect(
listingValueLabel(l10n, 'both', fieldKey: 'delivery_mode'),
'Abholung oder Versand',
);
expect(listingValueLabel(l10n, 'both'), 'Andere');
});
test('technical category labels fall back to localized copy', () {
expect(
localizedCategoryProfileLabel(l10n, 'real-estate', 'wg-room'),
'WG-Zimmer',
);
});
test('technical navigation labels fail closed without hiding real copy', () {
expect(isTechnicalContentLabel('real-estate', 'real-estate'), isTrue);
expect(isTechnicalContentLabel('office_practice', 'real-estate'), isTrue);
expect(isTechnicalContentLabel('wg-room', 'real-estate'), isTrue);
expect(isTechnicalContentLabel('Meine Orte', 'places'), isFalse);
expect(isTechnicalContentLabel(' ', 'jobs'), isTrue);
});
test('canonical resource ids receive localized route labels', () {
expect(localizedResourceIdLabel(l10n, 'classifieds'), 'Kleinanzeigen');
expect(localizedResourceIdLabel(l10n, 'jobs'), 'Jobs');
expect(localizedResourceIdLabel(l10n, 'real-estate'), 'Immobilien');
expect(localizedResourceIdLabel(l10n, 'guides'), 'Ratgeber');
expect(
localizedResourceIdLabel(l10n, 'services'),
'Services und Einrichtungen',
);
});
test('resource label projection rejects raw profile keys', () {
expect(
localizedResourceLabel(
l10n,
const ResourceDefinition(
id: 'places',
label: '',
endpoint: '',
geo: true,
),
),
'Orte',
);
expect(
localizedResourceLabel(
l10n,
const ResourceDefinition(
id: 'events',
label: '',
endpoint: '',
geo: true,
),
),
'Events',
);
expect(
localizedResourceLabel(
l10n,
const ResourceDefinition(
id: 'custom',
label: 'office_practice',
endpoint: '',
geo: false,
),
),
'Eintrag',
);
expect(
localizedResourceLabel(
l10n,
const ResourceDefinition(
id: 'custom',
label: 'Kultur und Freizeit',
endpoint: '',
geo: false,
),
),
'Kultur und Freizeit',
);
});
}
