From f7d91c5b4353e00d9b8020fd0a4f6eec07fb4b07 Mon Sep 17 00:00:00 2001 From: DenserMeerkat Date: Sat, 3 Aug 2024 17:33:27 +0530 Subject: [PATCH] test: history models --- lib/widgets/button_group_filled.dart | 62 ++++++++++++--------- test/models/history_models.dart | 75 ++++++++++++++++++++++++++ test/models/history_models_test.dart | 80 ++++++++++++++++++++++++++++ test/models/http_request_models.dart | 19 +++++++ 4 files changed, 210 insertions(+), 26 deletions(-) create mode 100644 test/models/history_models.dart create mode 100644 test/models/history_models_test.dart diff --git a/lib/widgets/button_group_filled.dart b/lib/widgets/button_group_filled.dart index 24ae622d..bfd57759 100644 --- a/lib/widgets/button_group_filled.dart +++ b/lib/widgets/button_group_filled.dart @@ -6,7 +6,42 @@ class FilledButtonGroup extends StatelessWidget { final List 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 buttonWidgets = buttons + .map((button) => + FilledButtonWidget(buttonData: button, showLabel: showLabel)) + .toList(); + + List 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 buttonWidgets = buttons - .map((button) => buildButton(button, showLabel: showLabel)) - .toList(); - - List 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, - ), - ); - }); - } } diff --git a/test/models/history_models.dart b/test/models/history_models.dart new file mode 100644 index 00000000..13d1603f --- /dev/null +++ b/test/models/history_models.dart @@ -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 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 historyRequestModelJson1 = { + "historyId": "historyId1", + "metaData": historyMetaModelJson1, + "httpRequestModel": httpRequestModelGet4Json, + "httpResponseModel": responseModelJson, +}; + +final Map 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 historyRequestModelJson2 = { + "historyId": "historyId2", + "metaData": historyMetaModelJson2, + "httpRequestModel": httpRequestModelPost10Json, + "httpResponseModel": responseModelJson, +}; diff --git a/test/models/history_models_test.dart b/test/models/history_models_test.dart new file mode 100644 index 00000000..7f2ae5aa --- /dev/null +++ b/test/models/history_models_test.dart @@ -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); + }); + }); +} diff --git a/test/models/http_request_models.dart b/test/models/http_request_models.dart index a7dd9ca8..a9eeed3f 100644 --- a/test/models/http_request_models.dart +++ b/test/models/http_request_models.dart @@ -374,6 +374,25 @@ const httpRequestModelDelete2 = HttpRequestModel( ); // JSONs + +const httpRequestModelGet4Json = { + "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 = { "method": 'post', "url": 'https://api.apidash.dev/case/lower',