Update convert_utils_test.dart

This commit is contained in:
Ashita Prasad
2024-01-09 08:00:57 +05:30
parent 1d57a9ab7d
commit 064b898019

View File

@ -1,6 +1,8 @@
import 'package:apidash/consts.dart';
import 'package:test/test.dart';
import 'package:apidash/utils/convert_utils.dart';
import 'package:apidash/models/name_value_model.dart';
import 'package:apidash/models/form_data_model.dart';
void main() {
group("Testing humanizeDuration function", () {
@ -106,6 +108,92 @@ void main() {
});
});
group("Testing rowsToFormDataMapList", () {
test('Testing for null', () {
expect(rowsToFormDataMapList(null), null);
});
test('Testing with a map value', () {
const input = <FormDataModel>[
FormDataModel(name: "text", value: "abc", type: FormDataType.file),
FormDataModel(name: "lang", value: "eng", type: FormDataType.file),
FormDataModel(name: "code", value: "1", type: FormDataType.text)
];
const expectedResult = [
{"name": "text", "value": "abc", "type": "file"},
{"name": "lang", "value": "eng", "type": "file"},
{"name": "code", "value": "1", "type": "text"}
];
expect(rowsToFormDataMapList(input), expectedResult);
});
});
group("Testing mapListToFormDataModelRows", () {
test('Testing for null', () {
expect(mapListToFormDataModelRows(null), null);
});
test('Testing with a map value', () {
const input = [
{"name": "text", "value": "abc", "type": "file"},
{"name": "lang", "value": "eng", "type": "file"},
{"name": "code", "value": "1", "type": "text"}
];
const expectedResult = <FormDataModel>[
FormDataModel(name: "text", value: "abc", type: FormDataType.file),
FormDataModel(name: "lang", value: "eng", type: FormDataType.file),
FormDataModel(name: "code", value: "1", type: FormDataType.text)
];
expect(mapListToFormDataModelRows(input), expectedResult);
});
});
group("Testing getFormDataType", () {
test('Testing for null', () {
expect(getFormDataType(null), FormDataType.text);
});
test('Testing with a map value', () {
const input = "file";
const expectedResult = FormDataType.file;
expect(getFormDataType(input), expectedResult);
});
});
group("Testing jsonMapToBytes", () {
test('Testing for null', () {
expect(jsonMapToBytes(null), []);
});
test('Testing with a map value', () {
Map<String, String> value1 = {"a": "1"};
const result1Expected = [
123,
10,
32,
32,
34,
97,
34,
58,
32,
34,
49,
34,
10,
125
];
expect(jsonMapToBytes(value1), result1Expected);
});
});
group("Testing stringToBytes", () {
test('Testing for null', () {
expect(stringToBytes(null), null);
});
test('Testing with a stringToBytes value', () {
String value1 = "ab";
const result1Expected = [97, 98];
expect(stringToBytes(value1), result1Expected);
});
});
group("Testing padMultilineString", () {
String text1 =
'''Using API Dash, you can draft API requests via an easy to use GUI which allows you to: