mirror of
https://github.com/foss42/apidash.git
synced 2025-06-03 08:16:25 +08:00
test: history models
This commit is contained in:
@ -6,7 +6,42 @@ class FilledButtonGroup extends StatelessWidget {
|
||||
|
||||
final List<ButtonData> buttons;
|
||||
|
||||
Widget buildButton(ButtonData buttonData, {bool showLabel = true}) {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(builder: (context, constraints) {
|
||||
final showLabel = constraints.maxWidth > buttons.length * 110;
|
||||
List<Widget> buttonWidgets = buttons
|
||||
.map((button) =>
|
||||
FilledButtonWidget(buttonData: button, showLabel: showLabel))
|
||||
.toList();
|
||||
|
||||
List<Widget> buttonsWithSpacers = [];
|
||||
for (int i = 0; i < buttonWidgets.length; i++) {
|
||||
buttonsWithSpacers.add(buttonWidgets[i]);
|
||||
if (i < buttonWidgets.length - 1) {
|
||||
buttonsWithSpacers.add(kHSpacer2);
|
||||
}
|
||||
}
|
||||
return ClipRRect(
|
||||
borderRadius: kBorderRadius20,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: buttonsWithSpacers,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
class FilledButtonWidget extends StatelessWidget {
|
||||
const FilledButtonWidget(
|
||||
{super.key, required this.buttonData, this.showLabel = true});
|
||||
|
||||
final ButtonData buttonData;
|
||||
final bool showLabel;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final icon = Icon(buttonData.icon, size: 20);
|
||||
final label = Text(
|
||||
buttonData.label,
|
||||
@ -32,29 +67,4 @@ class FilledButtonGroup extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return LayoutBuilder(builder: (context, constraints) {
|
||||
final showLabel = constraints.maxWidth > buttons.length * 110;
|
||||
List<Widget> buttonWidgets = buttons
|
||||
.map((button) => buildButton(button, showLabel: showLabel))
|
||||
.toList();
|
||||
|
||||
List<Widget> buttonsWithSpacers = [];
|
||||
for (int i = 0; i < buttonWidgets.length; i++) {
|
||||
buttonsWithSpacers.add(buttonWidgets[i]);
|
||||
if (i < buttonWidgets.length - 1) {
|
||||
buttonsWithSpacers.add(kHSpacer2);
|
||||
}
|
||||
}
|
||||
return ClipRRect(
|
||||
borderRadius: kBorderRadius20,
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: buttonsWithSpacers,
|
||||
),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
75
test/models/history_models.dart
Normal file
75
test/models/history_models.dart
Normal file
@ -0,0 +1,75 @@
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/models/models.dart'
|
||||
show HistoryMetaModel, HistoryRequestModel;
|
||||
|
||||
import 'http_request_models.dart';
|
||||
import 'http_response_models.dart';
|
||||
|
||||
/// Basic History Meta model 1
|
||||
final historyMetaModel1 = HistoryMetaModel(
|
||||
historyId: 'historyId1',
|
||||
requestId: 'requestId1',
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
method: HTTPVerb.get,
|
||||
timeStamp: DateTime(2024, 1, 1),
|
||||
responseStatus: 200,
|
||||
);
|
||||
|
||||
/// Basic History Request model 1
|
||||
final historyRequestModel1 = HistoryRequestModel(
|
||||
historyId: 'historyId1',
|
||||
metaData: historyMetaModel1,
|
||||
httpRequestModel: httpRequestModelGet4,
|
||||
httpResponseModel: responseModel,
|
||||
);
|
||||
|
||||
final historyMetaModel2 = HistoryMetaModel(
|
||||
historyId: 'historyId2',
|
||||
requestId: 'requestId2',
|
||||
url: 'https://api.apidash.dev/case/lower',
|
||||
method: HTTPVerb.post,
|
||||
timeStamp: DateTime(2024, 1, 1),
|
||||
responseStatus: 200,
|
||||
);
|
||||
|
||||
final historyRequestModel2 = HistoryRequestModel(
|
||||
historyId: 'historyId2',
|
||||
metaData: historyMetaModel2,
|
||||
httpRequestModel: httpRequestModelPost10,
|
||||
httpResponseModel: responseModel,
|
||||
);
|
||||
|
||||
/// JSONs
|
||||
final Map<String, dynamic> historyMetaModelJson1 = {
|
||||
"historyId": "historyId1",
|
||||
"requestId": "requestId1",
|
||||
"name": "",
|
||||
"url": "https://api.apidash.dev/humanize/social",
|
||||
"method": "get",
|
||||
"timeStamp": '2024-01-01T00:00:00.000',
|
||||
"responseStatus": 200,
|
||||
};
|
||||
|
||||
final Map<String, dynamic> historyRequestModelJson1 = {
|
||||
"historyId": "historyId1",
|
||||
"metaData": historyMetaModelJson1,
|
||||
"httpRequestModel": httpRequestModelGet4Json,
|
||||
"httpResponseModel": responseModelJson,
|
||||
};
|
||||
|
||||
final Map<String, dynamic> historyMetaModelJson2 = {
|
||||
"historyId": "historyId2",
|
||||
"requestId": "requestId2",
|
||||
"name": "",
|
||||
"url": "https://api.apidash.dev/case/lower",
|
||||
"method": "post",
|
||||
"timeStamp": '2024-01-01T00:00:00.000',
|
||||
"responseStatus": 200,
|
||||
};
|
||||
|
||||
final Map<String, dynamic> historyRequestModelJson2 = {
|
||||
"historyId": "historyId2",
|
||||
"metaData": historyMetaModelJson2,
|
||||
"httpRequestModel": httpRequestModelPost10Json,
|
||||
"httpResponseModel": responseModelJson,
|
||||
};
|
80
test/models/history_models_test.dart
Normal file
80
test/models/history_models_test.dart
Normal file
@ -0,0 +1,80 @@
|
||||
import 'package:test/test.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
|
||||
import 'history_models.dart';
|
||||
import 'http_request_models.dart';
|
||||
import 'http_response_models.dart';
|
||||
|
||||
void main() {
|
||||
group('Testing History Meta Models', () {
|
||||
test("Testing HistoryMetaModel copyWith", () {
|
||||
var historyMetaModel = historyMetaModel1;
|
||||
final historyMetaModelcopyWith = historyMetaModel.copyWith(
|
||||
url: 'https://api.apidash.dev/humanize/social',
|
||||
);
|
||||
expect(historyMetaModelcopyWith.url,
|
||||
'https://api.apidash.dev/humanize/social');
|
||||
// original model unchanged
|
||||
expect(historyMetaModel.url, 'https://api.apidash.dev/humanize/social');
|
||||
});
|
||||
|
||||
test("Testing HistoryMetaModel toJson", () {
|
||||
var historyMetaModel = historyMetaModel1;
|
||||
expect(historyMetaModel.toJson(), historyMetaModelJson1);
|
||||
});
|
||||
|
||||
test("Testing HistoryMetaModel fromJson", () {
|
||||
var historyMetaModel = historyMetaModel1;
|
||||
final modelFromJson = HistoryMetaModel.fromJson(historyMetaModelJson1);
|
||||
expect(modelFromJson, historyMetaModel);
|
||||
expect(modelFromJson.timeStamp, DateTime(2024, 1, 1));
|
||||
expect(modelFromJson.responseStatus, 200);
|
||||
});
|
||||
|
||||
test("Testing HistoryMetaModel getters", () {
|
||||
var historyMetaModel = historyMetaModel1;
|
||||
expect(historyMetaModel.historyId, 'historyId1');
|
||||
expect(historyMetaModel.requestId, 'requestId1');
|
||||
expect(historyMetaModel.url, 'https://api.apidash.dev/humanize/social');
|
||||
expect(historyMetaModel.method, HTTPVerb.get);
|
||||
expect(historyMetaModel.timeStamp, DateTime(2024, 1, 1));
|
||||
expect(historyMetaModel.responseStatus, 200);
|
||||
});
|
||||
});
|
||||
|
||||
group('Testing History Request Models', () {
|
||||
test("Testing HistoryRequestModel copyWith", () {
|
||||
var historyRequestModel = historyRequestModel1;
|
||||
final historyRequestModelcopyWith = historyRequestModel.copyWith(
|
||||
metaData: historyMetaModel2,
|
||||
);
|
||||
expect(historyRequestModelcopyWith.metaData, historyMetaModel2);
|
||||
// original model unchanged
|
||||
expect(historyRequestModel.metaData, historyMetaModel1);
|
||||
});
|
||||
|
||||
test("Testing HistoryRequestModel toJson", () {
|
||||
var historyRequestModel = historyRequestModel1;
|
||||
expect(historyRequestModel.toJson(), historyRequestModelJson1);
|
||||
});
|
||||
|
||||
test("Testing HistoryRequestModel fromJson", () {
|
||||
var historyRequestModel = historyRequestModel1;
|
||||
final modelFromJson =
|
||||
HistoryRequestModel.fromJson(historyRequestModelJson1);
|
||||
expect(modelFromJson, historyRequestModel);
|
||||
expect(modelFromJson.metaData, historyMetaModel1);
|
||||
expect(modelFromJson.httpRequestModel, httpRequestModelGet4);
|
||||
expect(modelFromJson.httpResponseModel, responseModel);
|
||||
});
|
||||
|
||||
test("Testing HistoryRequestModel getters", () {
|
||||
var historyRequestModel = historyRequestModel1;
|
||||
expect(historyRequestModel.historyId, 'historyId1');
|
||||
expect(historyRequestModel.metaData, historyMetaModel1);
|
||||
expect(historyRequestModel.httpRequestModel, httpRequestModelGet4);
|
||||
expect(historyRequestModel.httpResponseModel, responseModel);
|
||||
});
|
||||
});
|
||||
}
|
@ -374,6 +374,25 @@ const httpRequestModelDelete2 = HttpRequestModel(
|
||||
);
|
||||
|
||||
// JSONs
|
||||
|
||||
const httpRequestModelGet4Json = <String, dynamic>{
|
||||
"method": 'get',
|
||||
"url": 'https://api.apidash.dev/humanize/social',
|
||||
"headers": null,
|
||||
"params": [
|
||||
{'name': 'num', 'value': '8700000'},
|
||||
{'name': 'digits', 'value': '3'},
|
||||
{'name': 'system', 'value': 'SS'},
|
||||
{'name': 'add_space', 'value': 'true'},
|
||||
{'name': 'trailing_zeros', 'value': 'true'}
|
||||
],
|
||||
"isHeaderEnabledList": null,
|
||||
"isParamEnabledList": null,
|
||||
"bodyContentType": "json",
|
||||
"body": null,
|
||||
"formData": null
|
||||
};
|
||||
|
||||
const httpRequestModelPost10Json = <String, dynamic>{
|
||||
"method": 'post',
|
||||
"url": 'https://api.apidash.dev/case/lower',
|
||||
|
Reference in New Issue
Block a user