From f2f70a6db9e4a0872799f5d9b2ba06f3a259e6b7 Mon Sep 17 00:00:00 2001 From: Tibor Bossanyi Date: Sun, 19 Mar 2023 09:51:05 +0100 Subject: [PATCH] v1.0.15 AppText --- README.md | 3 ++ lib/model/app_text.dart | 30 +++++++++++ pubspec.yaml | 2 +- test/app_text_test.dart | 115 ++++++++++++++++++++++++++++++++++++++++ test/customer_test.dart | 2 - 5 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 lib/model/app_text.dart create mode 100644 test/app_text_test.dart diff --git a/README.md b/README.md index 2de7cbf..81a2c0c 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ Workout Test and Diet 4 You Common Util Functions +Version 1.0.15 +AppText and translations + Version 1.0.14 OpenAI chat completion extension fix diff --git a/lib/model/app_text.dart b/lib/model/app_text.dart new file mode 100644 index 0000000..5e216f9 --- /dev/null +++ b/lib/model/app_text.dart @@ -0,0 +1,30 @@ +import 'dart:collection'; + +class AppText { + late int textId; + late String textKey; + + HashMap translations = HashMap(); + + AppText.fromJson(Map json) { + textId = json['textId']; + textKey = json['textKey']; + + if (json['translations'] != null && json['translations'].length > 0) { + json['translations'].forEach((translation) { + translations[translation['languageCode']] = translation['translation']; + }); + } + } + + Map toJson() => { + "textId": textId, + "textKey": textKey, + "translations": translations.toString(), + }; + + @override + String toString() { + return toJson().toString(); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 4afd104..c990d51 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: workouttest_util description: Workout Test app and web functions. -version: 1.0.14 +version: 1.0.15 environment: sdk: ">=2.18.6 <3.0.0" diff --git a/test/app_text_test.dart b/test/app_text_test.dart new file mode 100644 index 0000000..28739f2 --- /dev/null +++ b/test/app_text_test.dart @@ -0,0 +1,115 @@ +import 'dart:convert'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:workouttest_util/model/app_text.dart'; + +main() { + late String appTextJson; + setUp(() { + appTextJson = ''' +[ + { + "textId": 1, + "textKey": "monday", + "screenshotUrl": null, + "checked": false, + "translations": [ + { + "translationId": 1, + "languageCode": "hu", + "translation": "hétfő" + } + ] + }, + { + "textId": 2, + "textKey": "tuesday", + "screenshotUrl": null, + "checked": false, + "translations": [ + { + "translationId": 2, + "languageCode": "hu", + "translation": "kedd" + } + ] + }, + { + "textId": 3, + "textKey": "wednesday", + "screenshotUrl": null, + "checked": false, + "translations": [ + { + "translationId": 3, + "languageCode": "hu", + "translation": "szerda" + } + ] + }, + { + "textId": 4, + "textKey": "thursday", + "screenshotUrl": null, + "checked": false, + "translations": [ + { + "translationId": 4, + "languageCode": "hu", + "translation": "csütörtök" + } + ] + }, + { + "textId": 5, + "textKey": "friday", + "screenshotUrl": null, + "checked": false, + "translations": [ + { + "translationId": 5, + "languageCode": "hu", + "translation": "péntek" + } + ] + }, + { + "textId": 6, + "textKey": "saturday", + "screenshotUrl": null, + "checked": false, + "translations": [ + { + "translationId": 6, + "languageCode": "hu", + "translation": "szombat" + } + ] + }, + { + "textId": 7, + "textKey": "sunday", + "screenshotUrl": null, + "checked": false, + "translations": [ + { + "translationId": 7, + "languageCode": "hu", + "translation": "vasárnap" + } + ] + } +] +'''; + }); + + group('customer', () { + test('decode from json successful', () async { + Iterable json = jsonDecode(appTextJson); + final List appTexts = json.map((text) => AppText.fromJson(text)).toList(); + + expect(appTexts[0].textKey, "monday"); + expect(appTexts[1].translations['hu'], "kedd"); + print(appTexts[0]); + }); + }); +} diff --git a/test/customer_test.dart b/test/customer_test.dart index 50932be..f23c23c 100644 --- a/test/customer_test.dart +++ b/test/customer_test.dart @@ -5,8 +5,6 @@ import 'package:workouttest_util/model/cache.dart'; import 'package:workouttest_util/model/customer.dart'; import 'package:workouttest_util/model/property.dart'; import 'package:workouttest_util/repository/customer_repository.dart'; -import 'dart:collection'; -import 'package:intl/intl.dart'; main() { setUp(() {