diff --git a/lib/extensions/string_extensions.dart b/lib/extensions/string_extensions.dart index 824c47d5..37632a2f 100644 --- a/lib/extensions/string_extensions.dart +++ b/lib/extensions/string_extensions.dart @@ -1,5 +1,11 @@ extension StringExtension on String { String capitalize() { + if (isEmpty) { + return this; + } + if (length == 1) { + return toUpperCase(); + } return "${this[0].toUpperCase()}${substring(1).toLowerCase()}"; } diff --git a/lib/utils/convert_utils.dart b/lib/utils/convert_utils.dart index c772134e..d0b2ac26 100644 --- a/lib/utils/convert_utils.dart +++ b/lib/utils/convert_utils.dart @@ -1,5 +1,6 @@ import 'dart:typed_data'; import 'dart:convert'; +import 'package:apidash/extensions/extensions.dart'; import 'package:collection/collection.dart'; import 'package:intl/intl.dart'; import '../models/models.dart'; @@ -49,21 +50,9 @@ String audioPosition(Duration? duration) { return "$min:$secondsPadding$secs"; } -String capitalizeFirstLetter(String? text) { - if (text == null || text == "") { - return ""; - } else if (text.length == 1) { - return text.toUpperCase(); - } else { - var first = text[0]; - var rest = text.substring(1); - return first.toUpperCase() + rest; - } -} - String formatHeaderCase(String text) { var sp = text.split("-"); - sp = sp.map((e) => capitalizeFirstLetter(e)).toList(); + sp = sp.map((e) => e.capitalize()).toList(); return sp.join("-"); } diff --git a/pubspec.lock b/pubspec.lock index b04f6a8e..12247062 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -1383,6 +1383,14 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.0" + test_cov_console: + dependency: "direct dev" + description: + name: test_cov_console + sha256: "73519e8be3689d73f5cffb652c12c310acacf48379396d834da937094836e65e" + url: "https://pub.dev" + source: hosted + version: "0.2.2" textwrap: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 515fc0c9..93053652 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -89,6 +89,7 @@ dev_dependencies: freezed: ^2.5.2 json_serializable: ^6.7.1 spot: ^0.13.0 + test_cov_console: ^0.2.2 flutter: uses-material-design: true diff --git a/test/extensions/widget_tester_extensions.dart b/test/extensions/widget_tester_extensions.dart index e9c5adbd..d17c26e5 100644 --- a/test/extensions/widget_tester_extensions.dart +++ b/test/extensions/widget_tester_extensions.dart @@ -1,15 +1,6 @@ import 'dart:ui'; import 'package:flutter_test/flutter_test.dart'; - -class ScreenSize { - const ScreenSize(this.name, this.width, this.height, this.pixelDensity); - final String name; - final double width, height, pixelDensity; -} - -const compactWidthDevice = ScreenSize('compact__width_device', 500, 600, 1); -const mediumWidthDevice = ScreenSize('medium__width_device', 800, 800, 1); -const largeWidthDevice = ScreenSize('large_width_device', 1300, 800, 1); +import '../test_consts.dart'; extension ScreenSizeManager on WidgetTester { Future setScreenSize(ScreenSize screenSize) async { diff --git a/test/test_consts.dart b/test/test_consts.dart index 6ef47887..cbd951d0 100644 --- a/test/test_consts.dart +++ b/test/test_consts.dart @@ -1,6 +1,16 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +class ScreenSize { + const ScreenSize(this.name, this.width, this.height, this.pixelDensity); + final String name; + final double width, height, pixelDensity; +} + +const compactWidthDevice = ScreenSize('compact__width_device', 500, 600, 1); +const mediumWidthDevice = ScreenSize('medium__width_device', 800, 800, 1); +const largeWidthDevice = ScreenSize('large_width_device', 1300, 800, 1); + final kThemeDataDark = ThemeData( useMaterial3: true, colorSchemeSeed: Colors.blue, diff --git a/test/utils/convert_utils_test.dart b/test/utils/convert_utils_test.dart index e996c319..ab853bfe 100644 --- a/test/utils/convert_utils_test.dart +++ b/test/utils/convert_utils_test.dart @@ -5,6 +5,58 @@ import 'package:apidash/models/name_value_model.dart'; import 'package:apidash/models/form_data_model.dart'; void main() { + group("Testing humanizeDate function", () { + test('Testing using date1', () { + DateTime date1 = DateTime(2024, 12, 31); + String date1Expected = "December 31, 2024"; + expect(humanizeDate(date1), date1Expected); + }); + + test('Testing using date2', () { + DateTime date2 = DateTime(2024, 1, 1); + String date2Expected = "January 1, 2024"; + expect(humanizeDate(date2), date2Expected); + }); + + test('Testing using date3', () { + DateTime date3 = DateTime(2024, 6, 15); + String date3Expected = "June 15, 2024"; + expect(humanizeDate(date3), date3Expected); + }); + + test('Testing using date4', () { + DateTime date4 = DateTime(2024, 9, 30); + String date4Expected = "September 30, 2024"; + expect(humanizeDate(date4), date4Expected); + }); + }); + + group("Testing humanizeTime function", () { + test('Testing using time1', () { + DateTime time1 = DateTime(2024, 12, 31, 23, 59, 59); + String time1Expected = "11:59:59 PM"; + expect(humanizeTime(time1), time1Expected); + }); + + test('Testing using time2', () { + DateTime time2 = DateTime(2024, 1, 1, 0, 0, 0); + String time2Expected = "12:00:00 AM"; + expect(humanizeTime(time2), time2Expected); + }); + + test('Testing using time3', () { + DateTime time3 = DateTime(2024, 6, 15, 12, 0, 0); + String time3Expected = "12:00:00 PM"; + expect(humanizeTime(time3), time3Expected); + }); + + test('Testing using time4', () { + DateTime time4 = DateTime(2024, 9, 30, 15, 30, 45); + String time4Expected = "03:30:45 PM"; + expect(humanizeTime(time4), time4Expected); + }); + }); + group("Testing humanizeDuration function", () { test('Testing using dur1', () { Duration dur1 = const Duration(minutes: 1, seconds: 3); @@ -31,32 +83,6 @@ void main() { }); }); - group("Testing capitalizeFirstLetter function", () { - test('Testing using text1', () { - String text1 = ""; - String text1Expected = ""; - expect(capitalizeFirstLetter(text1), text1Expected); - }); - - test('Testing using text2', () { - String text2 = "a"; - String text2Expected = "A"; - expect(capitalizeFirstLetter(text2), text2Expected); - }); - - test('Testing using text3', () { - String text3 = "world"; - String text3Expected = "World"; - expect(capitalizeFirstLetter(text3), text3Expected); - }); - - test('Testing using text4', () { - String text4 = "worldly affairs"; - String text4Expected = "Worldly affairs"; - expect(capitalizeFirstLetter(text4), text4Expected); - }); - }); - group("Testing formatHeaderCase function", () { test('Testing using headerText1', () { String headerText1 = "content-type";