wip: convert_utils_tests

This commit is contained in:
DenserMeerkat
2024-07-29 00:23:58 +05:30
parent 289c7c73ea
commit cfcf448664
7 changed files with 80 additions and 49 deletions

View File

@ -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()}";
}

View File

@ -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("-");
}

View File

@ -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:

View File

@ -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

View File

@ -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<void> setScreenSize(ScreenSize screenSize) async {

View File

@ -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,

View File

@ -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";