mirror of
https://github.com/foss42/apidash.git
synced 2025-06-20 05:51:58 +08:00
wip: convert_utils_tests
This commit is contained in:
@ -1,5 +1,11 @@
|
|||||||
extension StringExtension on String {
|
extension StringExtension on String {
|
||||||
String capitalize() {
|
String capitalize() {
|
||||||
|
if (isEmpty) {
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
if (length == 1) {
|
||||||
|
return toUpperCase();
|
||||||
|
}
|
||||||
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
|
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'package:apidash/extensions/extensions.dart';
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:intl/intl.dart';
|
import 'package:intl/intl.dart';
|
||||||
import '../models/models.dart';
|
import '../models/models.dart';
|
||||||
@ -49,21 +50,9 @@ String audioPosition(Duration? duration) {
|
|||||||
return "$min:$secondsPadding$secs";
|
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) {
|
String formatHeaderCase(String text) {
|
||||||
var sp = text.split("-");
|
var sp = text.split("-");
|
||||||
sp = sp.map((e) => capitalizeFirstLetter(e)).toList();
|
sp = sp.map((e) => e.capitalize()).toList();
|
||||||
return sp.join("-");
|
return sp.join("-");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1383,6 +1383,14 @@ packages:
|
|||||||
url: "https://pub.dev"
|
url: "https://pub.dev"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.6.0"
|
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:
|
textwrap:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
@ -89,6 +89,7 @@ dev_dependencies:
|
|||||||
freezed: ^2.5.2
|
freezed: ^2.5.2
|
||||||
json_serializable: ^6.7.1
|
json_serializable: ^6.7.1
|
||||||
spot: ^0.13.0
|
spot: ^0.13.0
|
||||||
|
test_cov_console: ^0.2.2
|
||||||
|
|
||||||
flutter:
|
flutter:
|
||||||
uses-material-design: true
|
uses-material-design: true
|
||||||
|
@ -1,15 +1,6 @@
|
|||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import '../test_consts.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);
|
|
||||||
|
|
||||||
extension ScreenSizeManager on WidgetTester {
|
extension ScreenSizeManager on WidgetTester {
|
||||||
Future<void> setScreenSize(ScreenSize screenSize) async {
|
Future<void> setScreenSize(ScreenSize screenSize) async {
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.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(
|
final kThemeDataDark = ThemeData(
|
||||||
useMaterial3: true,
|
useMaterial3: true,
|
||||||
colorSchemeSeed: Colors.blue,
|
colorSchemeSeed: Colors.blue,
|
||||||
|
@ -5,6 +5,58 @@ import 'package:apidash/models/name_value_model.dart';
|
|||||||
import 'package:apidash/models/form_data_model.dart';
|
import 'package:apidash/models/form_data_model.dart';
|
||||||
|
|
||||||
void main() {
|
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", () {
|
group("Testing humanizeDuration function", () {
|
||||||
test('Testing using dur1', () {
|
test('Testing using dur1', () {
|
||||||
Duration dur1 = const Duration(minutes: 1, seconds: 3);
|
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", () {
|
group("Testing formatHeaderCase function", () {
|
||||||
test('Testing using headerText1', () {
|
test('Testing using headerText1', () {
|
||||||
String headerText1 = "content-type";
|
String headerText1 = "content-type";
|
||||||
|
Reference in New Issue
Block a user