mirror of
https://github.com/foss42/apidash.git
synced 2025-06-05 10:20:44 +08:00
Merge pull request #434 from DenserMeerkat/add-test-environment
test: environment manager tests
This commit is contained in:
@ -355,7 +355,7 @@ enum FormDataType { text, file }
|
||||
|
||||
enum EnvironmentVariableType { variable, secret }
|
||||
|
||||
final kEnvVarRegEx = RegExp(r'{{(.*?)}}');
|
||||
final kEnvVarRegEx = RegExp(r'{{([^{}]*)}}');
|
||||
|
||||
const kSupportedUriSchemes = ["https", "http"];
|
||||
const kDefaultUriScheme = "https";
|
||||
|
@ -1,9 +1,18 @@
|
||||
extension StringExtension on String {
|
||||
String capitalize() {
|
||||
if (isEmpty) {
|
||||
return this;
|
||||
}
|
||||
if (length == 1) {
|
||||
return toUpperCase();
|
||||
}
|
||||
return "${this[0].toUpperCase()}${substring(1).toLowerCase()}";
|
||||
}
|
||||
|
||||
String clip(int limit) {
|
||||
if (limit < 0) {
|
||||
return '...';
|
||||
}
|
||||
if (length <= limit) {
|
||||
return this;
|
||||
}
|
||||
|
@ -65,4 +65,18 @@ class EnvironmentVariableSuggestion {
|
||||
isUnknown: isUnknown ?? this.isUnknown,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(this, other)) return true;
|
||||
|
||||
return other is EnvironmentVariableSuggestion &&
|
||||
other.environmentId == environmentId &&
|
||||
other.variable == variable &&
|
||||
other.isUnknown == isUnknown;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
environmentId.hashCode ^ variable.hashCode ^ isUnknown.hashCode;
|
||||
}
|
||||
|
@ -26,10 +26,10 @@ class EnvironmentTriggerField extends StatefulWidget {
|
||||
|
||||
@override
|
||||
State<EnvironmentTriggerField> createState() =>
|
||||
_EnvironmentTriggerFieldState();
|
||||
EnvironmentTriggerFieldState();
|
||||
}
|
||||
|
||||
class _EnvironmentTriggerFieldState extends State<EnvironmentTriggerField> {
|
||||
class EnvironmentTriggerFieldState extends State<EnvironmentTriggerField> {
|
||||
final TextEditingController controller = TextEditingController();
|
||||
final FocusNode focusNode = FocusNode();
|
||||
|
||||
@ -71,7 +71,7 @@ class _EnvironmentTriggerFieldState extends State<EnvironmentTriggerField> {
|
||||
triggerEnd: "}}",
|
||||
triggerOnlyAfterSpace: false,
|
||||
optionsViewBuilder: (context, autocompleteQuery, controller) {
|
||||
return EnvironmentAutocompleteOptions(
|
||||
return EnvironmentTriggerOptions(
|
||||
query: autocompleteQuery.query,
|
||||
onSuggestionTap: (suggestion) {
|
||||
final autocomplete = MultiTriggerAutocomplete.of(context);
|
||||
@ -86,7 +86,7 @@ class _EnvironmentTriggerFieldState extends State<EnvironmentTriggerField> {
|
||||
triggerEnd: "}}",
|
||||
triggerOnlyAfterSpace: false,
|
||||
optionsViewBuilder: (context, autocompleteQuery, controller) {
|
||||
return EnvironmentAutocompleteOptions(
|
||||
return EnvironmentTriggerOptions(
|
||||
query: autocompleteQuery.query,
|
||||
onSuggestionTap: (suggestion) {
|
||||
final autocomplete = MultiTriggerAutocomplete.of(context);
|
||||
|
@ -7,8 +7,8 @@ import 'package:apidash/utils/utils.dart';
|
||||
|
||||
import 'envvar_indicator.dart';
|
||||
|
||||
class EnvironmentAutocompleteOptions extends ConsumerWidget {
|
||||
const EnvironmentAutocompleteOptions({
|
||||
class EnvironmentTriggerOptions extends ConsumerWidget {
|
||||
const EnvironmentTriggerOptions({
|
||||
super.key,
|
||||
required this.query,
|
||||
required this.onSuggestionTap,
|
||||
|
@ -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("-");
|
||||
}
|
||||
|
||||
|
@ -91,7 +91,7 @@ HttpRequestModel substituteHttpRequestModel(
|
||||
}
|
||||
|
||||
List<EnvironmentVariableSuggestion>? getEnvironmentTriggerSuggestions(
|
||||
String? query,
|
||||
String query,
|
||||
Map<String, List<EnvironmentVariableModel>> envMap,
|
||||
String? activeEnvironmentId) {
|
||||
final suggestions = <EnvironmentVariableSuggestion>[];
|
||||
@ -99,7 +99,7 @@ List<EnvironmentVariableSuggestion>? getEnvironmentTriggerSuggestions(
|
||||
|
||||
if (activeEnvironmentId != null && envMap[activeEnvironmentId] != null) {
|
||||
for (final variable in envMap[activeEnvironmentId]!) {
|
||||
if ((query!.isEmpty || variable.key.contains(query)) &&
|
||||
if ((query.isEmpty || variable.key.contains(query)) &&
|
||||
!addedVariableKeys.contains(variable.key)) {
|
||||
suggestions.add(EnvironmentVariableSuggestion(
|
||||
environmentId: activeEnvironmentId, variable: variable));
|
||||
@ -109,7 +109,7 @@ List<EnvironmentVariableSuggestion>? getEnvironmentTriggerSuggestions(
|
||||
}
|
||||
|
||||
envMap[kGlobalEnvironmentId]?.forEach((variable) {
|
||||
if ((query!.isEmpty || variable.key.contains(query)) &&
|
||||
if ((query.isEmpty || variable.key.contains(query)) &&
|
||||
!addedVariableKeys.contains(variable.key)) {
|
||||
suggestions.add(EnvironmentVariableSuggestion(
|
||||
environmentId: kGlobalEnvironmentId, variable: variable));
|
||||
|
@ -15,7 +15,6 @@ class CodegenPopupMenu extends StatelessWidget {
|
||||
final List<CodegenLanguage>? items;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final textClipLength = context.isCompactWindow ? 12 : 22;
|
||||
final double boxLength = context.isCompactWindow ? 150 : 220;
|
||||
return PopupMenuButton<CodegenLanguage>(
|
||||
tooltip: "Select Code Generation Language",
|
||||
@ -37,9 +36,13 @@ class CodegenPopupMenu extends StatelessWidget {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
value.label.clip(textClipLength),
|
||||
style: kTextStylePopupMenuItem,
|
||||
Expanded(
|
||||
child: Text(
|
||||
value.label,
|
||||
style: kTextStylePopupMenuItem,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.unfold_more,
|
||||
|
@ -19,7 +19,6 @@ class EnvironmentPopupMenu extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final valueName = getEnvironmentTitle(value?.name);
|
||||
final textClipLength = context.isCompactWindow ? 6 : 10;
|
||||
final double boxLength = context.isCompactWindow ? 100 : 130;
|
||||
return PopupMenuButton(
|
||||
tooltip: "Select Environment",
|
||||
@ -54,9 +53,12 @@ class EnvironmentPopupMenu extends StatelessWidget {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
value == null ? "None" : valueName.clip(textClipLength),
|
||||
softWrap: false,
|
||||
Expanded(
|
||||
child: Text(
|
||||
value == null ? "None" : valueName,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.unfold_more,
|
||||
|
@ -40,10 +40,13 @@ class HistoryRetentionPopupMenu extends StatelessWidget {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
value.label,
|
||||
style: kTextStylePopupMenuItem,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
Expanded(
|
||||
child: Text(
|
||||
value.label,
|
||||
style: kTextStylePopupMenuItem,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.unfold_more,
|
||||
|
@ -36,9 +36,13 @@ class URIPopupMenu extends StatelessWidget {
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
value,
|
||||
style: kTextStylePopupMenuItem,
|
||||
Expanded(
|
||||
child: Text(
|
||||
value,
|
||||
style: kTextStylePopupMenuItem,
|
||||
softWrap: false,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const Icon(
|
||||
Icons.unfold_more,
|
||||
|
@ -671,10 +671,10 @@ packages:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: http
|
||||
sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938"
|
||||
sha256: b9c29a161230ee03d3ccf545097fccd9b87a5264228c5d348202e0f0c28f9010
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
version: "1.2.2"
|
||||
http_multi_server:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
113
test/extensions/context_extensions_test.dart
Normal file
113
test/extensions/context_extensions_test.dart
Normal file
@ -0,0 +1,113 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/extensions/context_extensions.dart';
|
||||
|
||||
void main() {
|
||||
group('Testing MediaQueryExtension', () {
|
||||
testWidgets('isCompactWindow returns true for compact window size',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(size: Size(kCompactWindowWidth - 1, 800)),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
expect(context.isCompactWindow, isTrue);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('isMediumWindow returns true for medium window size',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(size: Size(kMediumWindowWidth - 1, 800)),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
expect(context.isMediumWindow, isTrue);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('isExpandedWindow returns true for expanded window size',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(size: Size(kExpandedWindowWidth - 1, 800)),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
expect(context.isExpandedWindow, isTrue);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('isLargeWindow returns true for large window size',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(size: Size(kLargeWindowWidth - 1, 800)),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
expect(context.isLargeWindow, isTrue);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('isExtraLargeWindow returns true for extra large window size',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(size: Size(kLargeWindowWidth + 1, 800)),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
expect(context.isExtraLargeWindow, isTrue);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('width returns correct width', (tester) async {
|
||||
const double testWidth = 1024;
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(size: Size(testWidth, 800)),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
expect(context.width, testWidth);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
testWidgets('height returns correct height', (tester) async {
|
||||
const double testHeight = 768;
|
||||
await tester.pumpWidget(
|
||||
MediaQuery(
|
||||
data: const MediaQueryData(size: Size(1024, testHeight)),
|
||||
child: Builder(
|
||||
builder: (context) {
|
||||
expect(context.height, testHeight);
|
||||
return Container();
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
62
test/extensions/string_extensions_test.dart
Normal file
62
test/extensions/string_extensions_test.dart
Normal file
@ -0,0 +1,62 @@
|
||||
import 'package:test/test.dart';
|
||||
import 'package:apidash/extensions/string_extensions.dart';
|
||||
|
||||
void main() {
|
||||
group('Testing StringExtensions', () {
|
||||
group('Testing capitalize', () {
|
||||
test('should capitalize the first letter of a lowercase word', () {
|
||||
expect('hello'.capitalize(), 'Hello');
|
||||
});
|
||||
|
||||
test(
|
||||
'should capitalize the first letter and lowercase the rest of an uppercase word',
|
||||
() {
|
||||
expect('HELLO'.capitalize(), 'Hello');
|
||||
});
|
||||
|
||||
test('should return the same string if it is already capitalized', () {
|
||||
expect('Hello'.capitalize(), 'Hello');
|
||||
});
|
||||
|
||||
test('should return an empty string if the input is empty', () {
|
||||
expect(''.capitalize(), '');
|
||||
});
|
||||
|
||||
test('should capitalize a single lowercase letter', () {
|
||||
expect('h'.capitalize(), 'H');
|
||||
});
|
||||
|
||||
test('should return the same single uppercase letter', () {
|
||||
expect('H'.capitalize(), 'H');
|
||||
});
|
||||
});
|
||||
|
||||
group('Testing clip', () {
|
||||
test(
|
||||
'should return the same string if its length is less than or equal to the limit',
|
||||
() {
|
||||
expect('hello'.clip(5), 'hello');
|
||||
expect('hello'.clip(10), 'hello');
|
||||
});
|
||||
|
||||
test(
|
||||
'should clip the string and add ellipsis if its length is greater than the limit',
|
||||
() {
|
||||
expect('hello world'.clip(5), 'hello...');
|
||||
expect('hello world'.clip(8), 'hello wo...');
|
||||
});
|
||||
|
||||
test('should return an empty string if the input is empty', () {
|
||||
expect(''.clip(5), '');
|
||||
});
|
||||
|
||||
test('should handle limit of 0 correctly', () {
|
||||
expect('hello'.clip(0), '...');
|
||||
});
|
||||
|
||||
test('should handle negative limit correctly', () {
|
||||
expect('hello'.clip(-1), '...');
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
@ -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 {
|
||||
|
145
test/models/environment_models.dart
Normal file
145
test/models/environment_models.dart
Normal file
@ -0,0 +1,145 @@
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/models/models.dart'
|
||||
show
|
||||
EnvironmentModel,
|
||||
EnvironmentVariableModel,
|
||||
EnvironmentVariableSuggestion;
|
||||
|
||||
/// Global environment model
|
||||
const globalEnvironment = EnvironmentModel(
|
||||
id: kGlobalEnvironmentId,
|
||||
name: 'Global',
|
||||
values: [
|
||||
EnvironmentVariableModel(
|
||||
key: 'key1',
|
||||
value: 'value1',
|
||||
enabled: true,
|
||||
),
|
||||
EnvironmentVariableModel(
|
||||
key: 'key2',
|
||||
value: 'value2',
|
||||
enabled: false,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
/// Basic Environment model with 2 variables
|
||||
const environmentModel1 = EnvironmentModel(
|
||||
id: 'environmentId',
|
||||
name: 'Development',
|
||||
values: [
|
||||
EnvironmentVariableModel(
|
||||
key: 'key1',
|
||||
value: 'value1',
|
||||
type: EnvironmentVariableType.variable,
|
||||
enabled: true,
|
||||
),
|
||||
EnvironmentVariableModel(
|
||||
key: 'key2',
|
||||
value: 'value2',
|
||||
type: EnvironmentVariableType.variable,
|
||||
enabled: false,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
/// Basic Environment model with 2 secrets
|
||||
const environmentModel2 = EnvironmentModel(
|
||||
id: 'environmentId',
|
||||
name: 'Development',
|
||||
values: [
|
||||
EnvironmentVariableModel(
|
||||
key: 'key1',
|
||||
value: 'value1',
|
||||
type: EnvironmentVariableType.secret,
|
||||
enabled: true,
|
||||
),
|
||||
EnvironmentVariableModel(
|
||||
key: 'key2',
|
||||
value: 'value2',
|
||||
type: EnvironmentVariableType.secret,
|
||||
enabled: false,
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
/// Basic Environment Variable
|
||||
const environmentVariableModel1 = EnvironmentVariableModel(
|
||||
key: 'key1',
|
||||
value: 'value1',
|
||||
type: EnvironmentVariableType.variable,
|
||||
enabled: true,
|
||||
);
|
||||
|
||||
/// Secret Environment Variable
|
||||
const environmentVariableModel2 = EnvironmentVariableModel(
|
||||
key: 'key1',
|
||||
value: 'value1',
|
||||
type: EnvironmentVariableType.secret,
|
||||
enabled: true,
|
||||
);
|
||||
|
||||
/// Basic Environment Variable Suggestion
|
||||
const environmentVariableSuggestion1 = EnvironmentVariableSuggestion(
|
||||
environmentId: 'environmentId',
|
||||
variable: environmentVariableModel1,
|
||||
);
|
||||
|
||||
/// Secret Environment Variable Suggestion
|
||||
const environmentVariableSuggestion2 = EnvironmentVariableSuggestion(
|
||||
environmentId: 'environmentId',
|
||||
variable: environmentVariableModel2,
|
||||
);
|
||||
|
||||
/// JSONs
|
||||
const environmentModel1Json = {
|
||||
'id': 'environmentId',
|
||||
'name': 'Development',
|
||||
'values': [
|
||||
{
|
||||
'key': 'key1',
|
||||
'value': 'value1',
|
||||
'type': 'variable',
|
||||
'enabled': true,
|
||||
},
|
||||
{
|
||||
'key': 'key2',
|
||||
'value': 'value2',
|
||||
'type': 'variable',
|
||||
'enabled': false,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const environmentModel2Json = {
|
||||
'id': 'environmentId',
|
||||
'name': 'Development',
|
||||
'values': [
|
||||
{
|
||||
'key': 'key',
|
||||
'value': 'value1',
|
||||
'type': 'secret',
|
||||
'enabled': true,
|
||||
},
|
||||
{
|
||||
'key': 'key2',
|
||||
'value': 'value2',
|
||||
'type': 'secret',
|
||||
'enabled': false,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const environmentVariableModel1Json = {
|
||||
'key': 'key1',
|
||||
'value': 'value1',
|
||||
'type': 'variable',
|
||||
'enabled': true,
|
||||
};
|
||||
|
||||
const environmentVariableModel2Json = {
|
||||
'key': 'key1',
|
||||
'value': 'value1',
|
||||
'type': 'secret',
|
||||
'enabled': true,
|
||||
};
|
220
test/models/environment_models_test.dart
Normal file
220
test/models/environment_models_test.dart
Normal file
@ -0,0 +1,220 @@
|
||||
import 'package:test/test.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
|
||||
import 'environment_models.dart';
|
||||
|
||||
void main() {
|
||||
group("Testing EnvironmentModel", () {
|
||||
test("Testing EnvironmentModel copyWith", () {
|
||||
var environmentModel = environmentModel1;
|
||||
final environmentModelcopyWith =
|
||||
environmentModel.copyWith(name: 'Production');
|
||||
expect(environmentModelcopyWith.name, 'Production');
|
||||
// original model unchanged
|
||||
expect(environmentModel.name, 'Development');
|
||||
});
|
||||
|
||||
test("Testing EnvironmentModel toJson", () {
|
||||
var environmentModel = environmentModel1;
|
||||
expect(environmentModel.toJson(), environmentModel1Json);
|
||||
});
|
||||
|
||||
test("Testing EnvironmentModel fromJson", () {
|
||||
var environmentModel = environmentModel1;
|
||||
final modelFromJson = EnvironmentModel.fromJson(environmentModel1Json);
|
||||
expect(modelFromJson, environmentModel);
|
||||
expect(modelFromJson.values, const [
|
||||
EnvironmentVariableModel(
|
||||
key: 'key1',
|
||||
value: 'value1',
|
||||
type: EnvironmentVariableType.variable,
|
||||
enabled: true,
|
||||
),
|
||||
EnvironmentVariableModel(
|
||||
key: 'key2',
|
||||
value: 'value2',
|
||||
type: EnvironmentVariableType.variable,
|
||||
enabled: false,
|
||||
),
|
||||
]);
|
||||
});
|
||||
|
||||
test("Testing EnvironmentModel getters", () {
|
||||
var environmentModel = environmentModel1;
|
||||
expect(environmentModel.values, const [
|
||||
EnvironmentVariableModel(
|
||||
key: 'key1',
|
||||
value: 'value1',
|
||||
type: EnvironmentVariableType.variable,
|
||||
enabled: true,
|
||||
),
|
||||
EnvironmentVariableModel(
|
||||
key: 'key2',
|
||||
value: 'value2',
|
||||
type: EnvironmentVariableType.variable,
|
||||
enabled: false,
|
||||
),
|
||||
]);
|
||||
expect(environmentModel.name, 'Development');
|
||||
expect(environmentModel.id, 'environmentId');
|
||||
});
|
||||
|
||||
test("Testing EnvironmentModel immutability", () {
|
||||
var testEnvironmentModel = environmentModel1;
|
||||
final testEnvironmentModel2 =
|
||||
testEnvironmentModel.copyWith(values: testEnvironmentModel.values);
|
||||
expect(testEnvironmentModel2.values, testEnvironmentModel.values);
|
||||
|
||||
expect(
|
||||
identical(testEnvironmentModel.values, testEnvironmentModel2.values),
|
||||
false);
|
||||
var testEnvironmentModel3 = testEnvironmentModel.copyWith(values: []);
|
||||
expect(testEnvironmentModel3.values, []);
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing EnvironmentVariableModel", () {
|
||||
test("Testing EnvironmentVariableModel copyWith", () {
|
||||
var environmentVariableModel = environmentVariableModel1;
|
||||
final environmentVariableModelcopyWith = environmentVariableModel
|
||||
.copyWith(key: 'key3', value: 'value3', enabled: false);
|
||||
expect(environmentVariableModelcopyWith.key, 'key3');
|
||||
expect(environmentVariableModelcopyWith.value, 'value3');
|
||||
expect(environmentVariableModelcopyWith.enabled, false);
|
||||
// original model unchanged
|
||||
expect(environmentVariableModel.key, 'key1');
|
||||
expect(environmentVariableModel.value, 'value1');
|
||||
expect(environmentVariableModel.enabled, true);
|
||||
});
|
||||
|
||||
test("Testing EnvironmentVariableModel toJson", () {
|
||||
var environmentVariable = environmentVariableModel1;
|
||||
expect(environmentVariable.toJson(), environmentVariableModel1Json);
|
||||
|
||||
var environmentSecret = environmentVariableModel2;
|
||||
expect(environmentSecret.toJson(), environmentVariableModel2Json);
|
||||
});
|
||||
|
||||
test("Testing EnvironmentVariableModel fromJson", () {
|
||||
var environmentVariableModel = environmentVariableModel1;
|
||||
final modelFromJson =
|
||||
EnvironmentVariableModel.fromJson(environmentVariableModel1Json);
|
||||
expect(modelFromJson, environmentVariableModel);
|
||||
});
|
||||
|
||||
test("Testing EnvironmentVariableModel getters", () {
|
||||
var environmentVariableModel = environmentVariableModel1;
|
||||
expect(environmentVariableModel.key, 'key1');
|
||||
expect(environmentVariableModel.value, 'value1');
|
||||
expect(environmentVariableModel.enabled, true);
|
||||
});
|
||||
|
||||
test("Testing EnvironmentVariableModel immutability", () {
|
||||
var testEnvironmentVariableModel = environmentVariableModel1;
|
||||
final testEnvironmentVariableModel2 =
|
||||
testEnvironmentVariableModel.copyWith(key: 'key2');
|
||||
expect(testEnvironmentVariableModel2.key, 'key2');
|
||||
expect(testEnvironmentVariableModel2.value, 'value1');
|
||||
expect(testEnvironmentVariableModel2.enabled, true);
|
||||
|
||||
expect(
|
||||
identical(
|
||||
testEnvironmentVariableModel, testEnvironmentVariableModel2),
|
||||
false);
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing EnvironmentVariableSuggestionModel", () {
|
||||
test("Testing EnvironmentVariableSuggestionModel copyWith", () {
|
||||
var environmentVariableSuggestionModel = environmentVariableSuggestion1;
|
||||
|
||||
// Test case where all fields are provided
|
||||
final environmentVariableSuggestionModelCopyWithAllFields =
|
||||
environmentVariableSuggestionModel.copyWith(
|
||||
environmentId: 'environmentId2',
|
||||
variable: environmentVariableModel2,
|
||||
isUnknown: true);
|
||||
expect(environmentVariableSuggestionModelCopyWithAllFields.environmentId,
|
||||
'environmentId2');
|
||||
expect(environmentVariableSuggestionModelCopyWithAllFields.variable,
|
||||
environmentVariableModel2);
|
||||
expect(
|
||||
environmentVariableSuggestionModelCopyWithAllFields.isUnknown, true);
|
||||
|
||||
// Test case where no fields are provided (should return the same object)
|
||||
final environmentVariableSuggestionModelCopyWithNoFields =
|
||||
environmentVariableSuggestionModel.copyWith();
|
||||
expect(environmentVariableSuggestionModelCopyWithNoFields.environmentId,
|
||||
environmentVariableSuggestionModel.environmentId);
|
||||
expect(environmentVariableSuggestionModelCopyWithNoFields.variable,
|
||||
environmentVariableSuggestionModel.variable);
|
||||
expect(environmentVariableSuggestionModelCopyWithNoFields.isUnknown,
|
||||
environmentVariableSuggestionModel.isUnknown);
|
||||
|
||||
// Test case where only environmentId is provided
|
||||
final environmentVariableSuggestionModelCopyWithEnvironmentId =
|
||||
environmentVariableSuggestionModel.copyWith(
|
||||
environmentId: 'environmentId2');
|
||||
expect(
|
||||
environmentVariableSuggestionModelCopyWithEnvironmentId.environmentId,
|
||||
'environmentId2');
|
||||
expect(environmentVariableSuggestionModelCopyWithEnvironmentId.variable,
|
||||
environmentVariableSuggestionModel.variable);
|
||||
expect(environmentVariableSuggestionModelCopyWithEnvironmentId.isUnknown,
|
||||
environmentVariableSuggestionModel.isUnknown);
|
||||
|
||||
// Test case where only variable is provided
|
||||
final environmentVariableSuggestionModelCopyWithVariable =
|
||||
environmentVariableSuggestionModel.copyWith(
|
||||
variable: environmentVariableModel2);
|
||||
expect(environmentVariableSuggestionModelCopyWithVariable.environmentId,
|
||||
environmentVariableSuggestionModel.environmentId);
|
||||
expect(environmentVariableSuggestionModelCopyWithVariable.variable,
|
||||
environmentVariableModel2);
|
||||
expect(environmentVariableSuggestionModelCopyWithVariable.isUnknown,
|
||||
environmentVariableSuggestionModel.isUnknown);
|
||||
|
||||
// Test case where only isUnknown is provided
|
||||
final environmentVariableSuggestionModelCopyWithIsUnknown =
|
||||
environmentVariableSuggestionModel.copyWith(isUnknown: true);
|
||||
expect(environmentVariableSuggestionModelCopyWithIsUnknown.environmentId,
|
||||
environmentVariableSuggestionModel.environmentId);
|
||||
expect(environmentVariableSuggestionModelCopyWithIsUnknown.variable,
|
||||
environmentVariableSuggestionModel.variable);
|
||||
expect(
|
||||
environmentVariableSuggestionModelCopyWithIsUnknown.isUnknown, true);
|
||||
|
||||
// Ensure the original model remains unchanged
|
||||
expect(environmentVariableSuggestionModel.environmentId, 'environmentId');
|
||||
expect(environmentVariableSuggestionModel.variable,
|
||||
environmentVariableModel1);
|
||||
expect(environmentVariableSuggestionModel.isUnknown, false);
|
||||
});
|
||||
|
||||
test("Testing EnvironmentVariableSuggestionModel immutability", () {
|
||||
var testEnvironmentVariableSuggestionModel =
|
||||
environmentVariableSuggestion1;
|
||||
final testEnvironmentVariableSuggestionModel2 =
|
||||
testEnvironmentVariableSuggestionModel.copyWith(
|
||||
environmentId: 'environmentId2',
|
||||
variable: environmentVariableModel2,
|
||||
isUnknown: true);
|
||||
expect(testEnvironmentVariableSuggestionModel2.environmentId,
|
||||
'environmentId2');
|
||||
expect(testEnvironmentVariableSuggestionModel2.variable,
|
||||
environmentVariableModel2);
|
||||
expect(testEnvironmentVariableSuggestionModel2.isUnknown, true);
|
||||
|
||||
expect(
|
||||
identical(testEnvironmentVariableSuggestionModel,
|
||||
testEnvironmentVariableSuggestionModel2),
|
||||
false);
|
||||
});
|
||||
|
||||
test("Testing EnvironmentVariableSuggestionModel hashCode", () {
|
||||
var environmentVariableSuggestionModel = environmentVariableSuggestion1;
|
||||
expect(environmentVariableSuggestionModel.hashCode, greaterThan(0));
|
||||
});
|
||||
});
|
||||
}
|
121
test/screens/common_widgets/button_navbar_test.dart
Normal file
121
test/screens/common_widgets/button_navbar_test.dart
Normal file
@ -0,0 +1,121 @@
|
||||
import 'package:apidash/providers/ui_providers.dart';
|
||||
import 'package:apidash/screens/common_widgets/button_navbar.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing NavbarButton shows label when showLabel is true',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
mobileScaffoldKeyStateProvider
|
||||
.overrideWith((ref) => GlobalKey<ScaffoldState>())
|
||||
],
|
||||
child: const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: NavbarButton(
|
||||
railIdx: 0,
|
||||
buttonIdx: 1,
|
||||
selectedIcon: Icons.check,
|
||||
icon: Icons.add,
|
||||
label: 'Test Label',
|
||||
showLabel: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('Test Label'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Testing NavbarButton hides label when showLabel is false',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
mobileScaffoldKeyStateProvider
|
||||
.overrideWith((ref) => GlobalKey<ScaffoldState>())
|
||||
],
|
||||
child: const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: NavbarButton(
|
||||
railIdx: 0,
|
||||
buttonIdx: 1,
|
||||
selectedIcon: Icons.check,
|
||||
icon: Icons.add,
|
||||
label: 'Test Label',
|
||||
showLabel: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('Test Label'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Testing NavbarButton label style with isSelected',
|
||||
(WidgetTester tester) async {
|
||||
const testKey = Key('navbar_button');
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
mobileScaffoldKeyStateProvider
|
||||
.overrideWith((ref) => GlobalKey<ScaffoldState>())
|
||||
],
|
||||
child: const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: NavbarButton(
|
||||
key: testKey,
|
||||
railIdx: 1,
|
||||
buttonIdx: 1,
|
||||
selectedIcon: Icons.check,
|
||||
icon: Icons.check_box_outline_blank,
|
||||
label: 'Test Label',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Text label = tester.widget(find.text('Test Label'));
|
||||
expect(
|
||||
label.style?.color,
|
||||
equals(Theme.of(tester.element(find.byKey(testKey)))
|
||||
.colorScheme
|
||||
.onSecondaryContainer));
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
mobileScaffoldKeyStateProvider
|
||||
.overrideWith((ref) => GlobalKey<ScaffoldState>())
|
||||
],
|
||||
child: const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: NavbarButton(
|
||||
key: testKey,
|
||||
railIdx: 1,
|
||||
buttonIdx: 2,
|
||||
selectedIcon: Icons.check,
|
||||
icon: Icons.check_box_outline_blank,
|
||||
label: 'Test Label',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
label = tester.widget(find.text('Test Label'));
|
||||
expect(
|
||||
label.style?.color,
|
||||
equals(Theme.of(tester.element(find.byKey(testKey)))
|
||||
.colorScheme
|
||||
.onSurface
|
||||
.withOpacity(0.65)));
|
||||
});
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
import 'package:apidash/screens/common_widgets/env_regexp_span_builder.dart';
|
||||
import 'package:apidash/screens/common_widgets/envvar_span.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:extended_text_field/extended_text_field.dart';
|
||||
import 'package:flutter/widgets.dart';
|
||||
|
||||
void main() {
|
||||
test('Testing RegExpSpanBuilder returns correct ExtendedWidgetSpan', () {
|
||||
final regExpEnvText = RegExpEnvText();
|
||||
final match = RegExp(r'\{\{.*?\}\}').firstMatch('{{variable}}')!;
|
||||
const start = 0;
|
||||
|
||||
final span = regExpEnvText.finishText(start, match);
|
||||
|
||||
expect(span, isA<ExtendedWidgetSpan>());
|
||||
final extendedWidgetSpan = span as ExtendedWidgetSpan;
|
||||
expect(extendedWidgetSpan.actualText, '{{variable}}');
|
||||
expect(extendedWidgetSpan.start, start);
|
||||
expect(extendedWidgetSpan.alignment, PlaceholderAlignment.middle);
|
||||
expect(extendedWidgetSpan.child, isA<EnvVarSpan>());
|
||||
|
||||
final envVarSpan = extendedWidgetSpan.child as EnvVarSpan;
|
||||
expect(envVarSpan.variableKey, 'variable');
|
||||
});
|
||||
}
|
48
test/screens/common_widgets/env_trigger_field_test.dart
Normal file
48
test/screens/common_widgets/env_trigger_field_test.dart
Normal file
@ -0,0 +1,48 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_portal/flutter_portal.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:extended_text_field/extended_text_field.dart';
|
||||
import 'package:apidash/screens/common_widgets/env_trigger_field.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing EnvironmentTriggerField updates the controller text',
|
||||
(WidgetTester tester) async {
|
||||
final fieldKey = GlobalKey<EnvironmentTriggerFieldState>();
|
||||
const initialValue = 'initial';
|
||||
const updatedValue = 'updated';
|
||||
|
||||
await tester.pumpWidget(
|
||||
Portal(
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvironmentTriggerField(
|
||||
key: fieldKey,
|
||||
keyId: 'testKey',
|
||||
initialValue: initialValue,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
Finder field = find.byType(ExtendedTextField);
|
||||
expect(field, findsOneWidget);
|
||||
expect(fieldKey.currentState!.controller.text, initialValue);
|
||||
|
||||
await tester.pumpWidget(
|
||||
Portal(
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvironmentTriggerField(
|
||||
key: fieldKey,
|
||||
keyId: 'testKey',
|
||||
initialValue: updatedValue,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(fieldKey.currentState!.controller.text, updatedValue);
|
||||
});
|
||||
}
|
120
test/screens/common_widgets/env_trigger_options_test.dart
Normal file
120
test/screens/common_widgets/env_trigger_options_test.dart
Normal file
@ -0,0 +1,120 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/providers/providers.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/screens/common_widgets/env_trigger_options.dart';
|
||||
|
||||
void main() {
|
||||
const envMap = {
|
||||
kGlobalEnvironmentId: [
|
||||
EnvironmentVariableModel(key: 'key1', value: 'value1'),
|
||||
EnvironmentVariableModel(key: 'key2', value: 'value2'),
|
||||
],
|
||||
'activeEnvId': [
|
||||
EnvironmentVariableModel(key: 'key2', value: 'value1'),
|
||||
EnvironmentVariableModel(key: 'key3', value: 'value2'),
|
||||
],
|
||||
};
|
||||
|
||||
const suggestions = [
|
||||
EnvironmentVariableSuggestion(
|
||||
environmentId: 'activeEnvId',
|
||||
variable: EnvironmentVariableModel(key: 'key2', value: 'value1'),
|
||||
),
|
||||
EnvironmentVariableSuggestion(
|
||||
environmentId: 'activeEnvId',
|
||||
variable: EnvironmentVariableModel(key: 'key3', value: 'value2'),
|
||||
),
|
||||
EnvironmentVariableSuggestion(
|
||||
environmentId: kGlobalEnvironmentId,
|
||||
variable: EnvironmentVariableModel(key: 'key1', value: 'value1'),
|
||||
),
|
||||
EnvironmentVariableSuggestion(
|
||||
environmentId: kGlobalEnvironmentId,
|
||||
variable: EnvironmentVariableModel(key: 'key2', value: 'value2'),
|
||||
),
|
||||
];
|
||||
testWidgets(
|
||||
'EnvironmentTriggerOptions shows no suggestions when suggestions are empty',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
availableEnvironmentVariablesStateProvider.overrideWith((ref) => {}),
|
||||
activeEnvironmentIdStateProvider.overrideWith((ref) => null),
|
||||
],
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvironmentTriggerOptions(
|
||||
query: 'test',
|
||||
onSuggestionTap: (suggestion) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(SizedBox), findsOneWidget);
|
||||
expect(find.byType(ClipRRect), findsNothing);
|
||||
expect(find.byType(ListView), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('EnvironmentTriggerOptions shows suggestions when available',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
availableEnvironmentVariablesStateProvider
|
||||
.overrideWith((ref) => envMap),
|
||||
activeEnvironmentIdStateProvider.overrideWith((ref) => 'activeEnvId'),
|
||||
],
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvironmentTriggerOptions(
|
||||
query: 'key',
|
||||
onSuggestionTap: (suggestion) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(ClipRRect), findsOneWidget);
|
||||
expect(find.byType(ListView), findsOneWidget);
|
||||
expect(find.byType(ListTile), findsNWidgets(3));
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'EnvironmentTriggerOptions calls onSuggestionTap when a suggestion is tapped',
|
||||
(WidgetTester tester) async {
|
||||
EnvironmentVariableSuggestion? tappedSuggestion;
|
||||
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
availableEnvironmentVariablesStateProvider
|
||||
.overrideWith((ref) => envMap),
|
||||
activeEnvironmentIdStateProvider.overrideWith((ref) => 'activeEnvId'),
|
||||
],
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvironmentTriggerOptions(
|
||||
query: 'key',
|
||||
onSuggestionTap: (suggestion) {
|
||||
tappedSuggestion = suggestion;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byType(ListTile).first);
|
||||
await tester.pump();
|
||||
|
||||
expect(tappedSuggestion, isNotNull);
|
||||
expect(tappedSuggestion, equals(suggestions.first));
|
||||
});
|
||||
}
|
94
test/screens/common_widgets/envvar_indicator_test.dart
Normal file
94
test/screens/common_widgets/envvar_indicator_test.dart
Normal file
@ -0,0 +1,94 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/screens/common_widgets/envvar_indicator.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'EnvVarIndicator displays correct icon and color for unknown suggestion',
|
||||
(WidgetTester tester) async {
|
||||
const suggestion = EnvironmentVariableSuggestion(
|
||||
isUnknown: true,
|
||||
environmentId: 'someId',
|
||||
variable: EnvironmentVariableModel(key: 'key', value: 'value'));
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvVarIndicator(suggestion: suggestion),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final container = tester.widget<Container>(find.byType(Container));
|
||||
final icon = tester.widget<Icon>(find.byType(Icon));
|
||||
|
||||
expect(container.decoration, isA<BoxDecoration>());
|
||||
final decoration = container.decoration as BoxDecoration;
|
||||
expect(
|
||||
decoration.color,
|
||||
Theme.of(tester.element(find.byType(Container)))
|
||||
.colorScheme
|
||||
.errorContainer);
|
||||
expect(icon.icon, Icons.block);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'EnvVarIndicator displays correct icon and color for global suggestion',
|
||||
(WidgetTester tester) async {
|
||||
const suggestion = EnvironmentVariableSuggestion(
|
||||
isUnknown: false,
|
||||
environmentId: kGlobalEnvironmentId,
|
||||
variable: EnvironmentVariableModel(key: 'key', value: 'value'));
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvVarIndicator(suggestion: suggestion),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final container = tester.widget<Container>(find.byType(Container));
|
||||
final icon = tester.widget<Icon>(find.byType(Icon));
|
||||
|
||||
expect(container.decoration, isA<BoxDecoration>());
|
||||
final decoration = container.decoration as BoxDecoration;
|
||||
expect(
|
||||
decoration.color,
|
||||
Theme.of(tester.element(find.byType(Container)))
|
||||
.colorScheme
|
||||
.secondaryContainer);
|
||||
expect(icon.icon, Icons.public);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'EnvVarIndicator displays correct icon and color for non-global suggestion',
|
||||
(WidgetTester tester) async {
|
||||
const suggestion = EnvironmentVariableSuggestion(
|
||||
isUnknown: false,
|
||||
environmentId: 'someOtherId',
|
||||
variable: EnvironmentVariableModel(key: 'key', value: 'value'));
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvVarIndicator(suggestion: suggestion),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final container = tester.widget<Container>(find.byType(Container));
|
||||
final icon = tester.widget<Icon>(find.byType(Icon));
|
||||
|
||||
expect(container.decoration, isA<BoxDecoration>());
|
||||
final decoration = container.decoration as BoxDecoration;
|
||||
expect(
|
||||
decoration.color,
|
||||
Theme.of(tester.element(find.byType(Container)))
|
||||
.colorScheme
|
||||
.primaryContainer);
|
||||
expect(icon.icon, Icons.computer);
|
||||
});
|
||||
}
|
35
test/screens/common_widgets/envvar_popover_test.dart
Normal file
35
test/screens/common_widgets/envvar_popover_test.dart
Normal file
@ -0,0 +1,35 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/screens/common_widgets/envvar_indicator.dart';
|
||||
import 'package:apidash/screens/common_widgets/envvar_popover.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('EnvVarPopover displays correct information',
|
||||
(WidgetTester tester) async {
|
||||
const suggestion = EnvironmentVariableSuggestion(
|
||||
isUnknown: false,
|
||||
environmentId: 'someId',
|
||||
variable: EnvironmentVariableModel(key: 'API_KEY', value: '12345'),
|
||||
);
|
||||
const scope = 'Global';
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvVarPopover(suggestion: suggestion, scope: scope),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(EnvVarIndicator), findsOneWidget);
|
||||
|
||||
expect(find.text('API_KEY'), findsOneWidget);
|
||||
|
||||
expect(find.text('VALUE'), findsOneWidget);
|
||||
expect(find.text('12345'), findsOneWidget);
|
||||
|
||||
expect(find.text('SCOPE'), findsOneWidget);
|
||||
expect(find.text('Global'), findsOneWidget);
|
||||
});
|
||||
}
|
67
test/screens/common_widgets/sidebar_save_button_test.dart
Normal file
67
test/screens/common_widgets/sidebar_save_button_test.dart
Normal file
@ -0,0 +1,67 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/providers/ui_providers.dart';
|
||||
import 'package:apidash/screens/common_widgets/sidebar_save_button.dart';
|
||||
import '../../test_consts.dart';
|
||||
|
||||
void main() {
|
||||
group("Testing Save Button", () {
|
||||
testWidgets('Testing for Save button enabled', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
saveDataStateProvider.overrideWith((ref) => false),
|
||||
hasUnsavedChangesProvider.overrideWith((ref) => true),
|
||||
],
|
||||
child: MaterialApp(
|
||||
title: 'Save button',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: SaveButton(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
final icon = find.byIcon(Icons.save);
|
||||
expect(icon, findsOneWidget);
|
||||
|
||||
final saveButton = find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton));
|
||||
expect(saveButton, findsOneWidget);
|
||||
|
||||
final saveButtonWidget = tester.widget<TextButton>(saveButton);
|
||||
expect(saveButtonWidget.enabled, true);
|
||||
});
|
||||
|
||||
testWidgets('Testing for Save button disabled', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
overrides: [
|
||||
saveDataStateProvider.overrideWith((ref) => false),
|
||||
hasUnsavedChangesProvider.overrideWith((ref) => false),
|
||||
],
|
||||
child: MaterialApp(
|
||||
title: 'Save button',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: SaveButton(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final icon = find.byIcon(Icons.save);
|
||||
expect(icon, findsOneWidget);
|
||||
|
||||
final saveButton = find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton));
|
||||
expect(saveButton, findsOneWidget);
|
||||
|
||||
final saveButtonWidget = tester.widget<TextButton>(saveButton);
|
||||
expect(saveButtonWidget.enabled, false);
|
||||
});
|
||||
});
|
||||
}
|
@ -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,
|
||||
|
@ -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";
|
||||
|
340
test/utils/envvar_utils_test.dart
Normal file
340
test/utils/envvar_utils_test.dart
Normal file
@ -0,0 +1,340 @@
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/utils/envvar_utils.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
const envVars = [
|
||||
EnvironmentVariableModel(
|
||||
key: "var1",
|
||||
value: "var1-value",
|
||||
type: EnvironmentVariableType.variable,
|
||||
),
|
||||
EnvironmentVariableModel(
|
||||
key: "var2",
|
||||
value: "var2-value",
|
||||
type: EnvironmentVariableType.variable,
|
||||
),
|
||||
];
|
||||
const envSecrets = [
|
||||
EnvironmentVariableModel(
|
||||
key: "secret1",
|
||||
value: "secret1-value",
|
||||
type: EnvironmentVariableType.secret,
|
||||
),
|
||||
EnvironmentVariableModel(
|
||||
key: "secret2",
|
||||
value: "secret2-value",
|
||||
type: EnvironmentVariableType.secret,
|
||||
),
|
||||
];
|
||||
const emptyEnvVar = EnvironmentVariableModel(
|
||||
key: "",
|
||||
value: "",
|
||||
type: EnvironmentVariableType.variable,
|
||||
);
|
||||
const emptyEnvSecret = EnvironmentVariableModel(
|
||||
key: "",
|
||||
value: "",
|
||||
type: EnvironmentVariableType.secret,
|
||||
);
|
||||
const environmentModel = EnvironmentModel(
|
||||
id: "id",
|
||||
name: "Testing",
|
||||
values: [...envVars, emptyEnvVar, ...envSecrets, emptyEnvSecret]);
|
||||
const emptyEnvironmentModel =
|
||||
EnvironmentModel(id: "id", name: "Testing", values: []);
|
||||
const globalVars = [
|
||||
EnvironmentVariableModel(key: "url", value: "api.foss42.com"),
|
||||
EnvironmentVariableModel(key: "num", value: "5670000"),
|
||||
EnvironmentVariableModel(key: "token", value: "token"),
|
||||
];
|
||||
const activeEnvVars = [
|
||||
EnvironmentVariableModel(key: "url", value: "api.apidash.dev"),
|
||||
EnvironmentVariableModel(key: "num", value: "8940000"),
|
||||
];
|
||||
|
||||
void main() {
|
||||
group("Testing getEnvironmentTitle function", () {
|
||||
String titleUntitled = "untitled";
|
||||
test("Testing getEnvironmentTitle with null", () {
|
||||
String? envName1;
|
||||
expect(getEnvironmentTitle(envName1), titleUntitled);
|
||||
});
|
||||
|
||||
test("Testing getEnvironmentTitle with empty string", () {
|
||||
String envName2 = "";
|
||||
expect(getEnvironmentTitle(envName2), titleUntitled);
|
||||
});
|
||||
|
||||
test("Testing getEnvironmentTitle with trimmable string", () {
|
||||
String envName3 = " ";
|
||||
expect(getEnvironmentTitle(envName3), titleUntitled);
|
||||
});
|
||||
|
||||
test("Testing getEnvironmentTitle with non-empty string", () {
|
||||
String envName4 = "test";
|
||||
expect(getEnvironmentTitle(envName4), "test");
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing getEnvironmentVariables function", () {
|
||||
test("Testing getEnvironmentVariables with null", () {
|
||||
EnvironmentModel? environment;
|
||||
expect(getEnvironmentVariables(environment), []);
|
||||
});
|
||||
|
||||
test("Testing getEnvironmentVariables with empty", () {
|
||||
expect(getEnvironmentVariables(emptyEnvironmentModel), []);
|
||||
});
|
||||
|
||||
test("Testing getEnvironmentVariables with non-empty environmentModel", () {
|
||||
expect(
|
||||
getEnvironmentVariables(environmentModel), [...envVars, emptyEnvVar]);
|
||||
});
|
||||
|
||||
test(
|
||||
"Testing getEnvironmentVariables with non-empty environmentModel and removeEmptyModels",
|
||||
() {
|
||||
expect(getEnvironmentVariables(environmentModel, removeEmptyModels: true),
|
||||
envVars);
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing getEnvironmentSecrets function", () {
|
||||
test("Testing getEnvironmentSecrets with null", () {
|
||||
EnvironmentModel? environment;
|
||||
expect(getEnvironmentSecrets(environment), []);
|
||||
});
|
||||
|
||||
test("Testing getEnvironmentSecrets with empty", () {
|
||||
expect(getEnvironmentSecrets(emptyEnvironmentModel), []);
|
||||
});
|
||||
|
||||
test("Testing getEnvironmentSecrets with non-empty environmentModel", () {
|
||||
expect(getEnvironmentSecrets(environmentModel),
|
||||
[...envSecrets, emptyEnvSecret]);
|
||||
});
|
||||
|
||||
test(
|
||||
"Testing getEnvironmentSecrets with non-empty environmentModel and removeEmptyModels",
|
||||
() {
|
||||
expect(getEnvironmentSecrets(environmentModel, removeEmptyModels: true),
|
||||
envSecrets);
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing substituteVariables function", () {
|
||||
test("Testing substituteVariables with null", () {
|
||||
String? input;
|
||||
Map<String?, List<EnvironmentVariableModel>> envMap = {};
|
||||
String? activeEnvironmentId;
|
||||
expect(substituteVariables(input, envMap, activeEnvironmentId), null);
|
||||
});
|
||||
|
||||
test("Testing substituteVariables with empty input", () {
|
||||
String input = "";
|
||||
Map<String?, List<EnvironmentVariableModel>> envMap = {};
|
||||
String? activeEnvironmentId;
|
||||
expect(substituteVariables(input, envMap, activeEnvironmentId), "");
|
||||
});
|
||||
|
||||
test("Testing substituteVariables with empty envMap", () {
|
||||
String input = "{{url}}/humanize/social?num={{num}}";
|
||||
Map<String?, List<EnvironmentVariableModel>> envMap = {};
|
||||
String? activeEnvironmentId;
|
||||
String expected = "/humanize/social?num=";
|
||||
expect(substituteVariables(input, envMap, activeEnvironmentId), expected);
|
||||
});
|
||||
|
||||
test("Testing substituteVariables with empty activeEnvironmentId", () {
|
||||
String input = "{{url}}/humanize/social?num={{num}}";
|
||||
Map<String?, List<EnvironmentVariableModel>> envMap = {
|
||||
kGlobalEnvironmentId: globalVars,
|
||||
};
|
||||
String expected = "api.foss42.com/humanize/social?num=5670000";
|
||||
expect(substituteVariables(input, envMap, null), expected);
|
||||
});
|
||||
|
||||
test("Testing substituteVariables with non-empty activeEnvironmentId", () {
|
||||
String input = "{{url}}/humanize/social?num={{num}}";
|
||||
Map<String?, List<EnvironmentVariableModel>> envMap = {
|
||||
kGlobalEnvironmentId: globalVars,
|
||||
"activeEnvId": activeEnvVars,
|
||||
};
|
||||
String? activeEnvId = "activeEnvId";
|
||||
String expected = "api.apidash.dev/humanize/social?num=8940000";
|
||||
expect(substituteVariables(input, envMap, activeEnvId), expected);
|
||||
});
|
||||
|
||||
test("Testing substituteVariables with incorrect paranthesis", () {
|
||||
String input = "{{url}}}/humanize/social?num={{num}}";
|
||||
Map<String?, List<EnvironmentVariableModel>> envMap = {
|
||||
kGlobalEnvironmentId: globalVars,
|
||||
"activeEnvId": activeEnvVars,
|
||||
};
|
||||
String? activeEnvId = "activeEnvId";
|
||||
String expected = "api.apidash.dev}/humanize/social?num=8940000";
|
||||
expect(substituteVariables(input, envMap, activeEnvId), expected);
|
||||
});
|
||||
|
||||
test("Testing substituteVariables function with unavailable variables", () {
|
||||
String input = "{{url1}}/humanize/social?num={{num}}";
|
||||
Map<String?, List<EnvironmentVariableModel>> envMap = {
|
||||
kGlobalEnvironmentId: globalVars,
|
||||
"activeEnvId": activeEnvVars,
|
||||
};
|
||||
String? activeEnvironmentId = "activeEnvId";
|
||||
String expected = "/humanize/social?num=8940000";
|
||||
expect(substituteVariables(input, envMap, activeEnvironmentId), expected);
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing substituteHttpRequestModel function", () {
|
||||
test("Testing substituteHttpRequestModel with empty", () {
|
||||
const httpRequestModel = HttpRequestModel();
|
||||
Map<String?, List<EnvironmentVariableModel>> envMap = {};
|
||||
String? activeEnvironmentId;
|
||||
const expected = HttpRequestModel();
|
||||
expect(
|
||||
substituteHttpRequestModel(
|
||||
httpRequestModel, envMap, activeEnvironmentId),
|
||||
expected);
|
||||
});
|
||||
|
||||
test("Testing substituteHttpRequestModel with non-empty", () {
|
||||
const httpRequestModel = HttpRequestModel(
|
||||
url: "{{url}}/humanize/social",
|
||||
headers: [
|
||||
NameValueModel(name: "Authorization", value: "Bearer {{token}}"),
|
||||
],
|
||||
params: [
|
||||
NameValueModel(name: "num", value: "{{num}}"),
|
||||
],
|
||||
);
|
||||
Map<String?, List<EnvironmentVariableModel>> envMap = {
|
||||
kGlobalEnvironmentId: globalVars,
|
||||
"activeEnvId": activeEnvVars,
|
||||
};
|
||||
String? activeEnvironmentId = "activeEnvId";
|
||||
const expected = HttpRequestModel(
|
||||
url: "api.apidash.dev/humanize/social",
|
||||
headers: [
|
||||
NameValueModel(name: "Authorization", value: "Bearer token"),
|
||||
],
|
||||
params: [
|
||||
NameValueModel(name: "num", value: "8940000"),
|
||||
],
|
||||
);
|
||||
expect(
|
||||
substituteHttpRequestModel(
|
||||
httpRequestModel, envMap, activeEnvironmentId),
|
||||
expected);
|
||||
});
|
||||
|
||||
test("Testing substituteHttpRequestModel with unavailable variables", () {
|
||||
const httpRequestModel = HttpRequestModel(
|
||||
url: "{{url1}}/humanize/social",
|
||||
headers: [
|
||||
NameValueModel(name: "Authorization", value: "Bearer {{token1}}"),
|
||||
],
|
||||
params: [
|
||||
NameValueModel(name: "num", value: "{{num}}"),
|
||||
],
|
||||
);
|
||||
Map<String?, List<EnvironmentVariableModel>> envMap = {
|
||||
kGlobalEnvironmentId: globalVars,
|
||||
"activeEnvId": activeEnvVars,
|
||||
};
|
||||
String? activeEnvironmentId = "activeEnvId";
|
||||
const expected = HttpRequestModel(
|
||||
url: "/humanize/social",
|
||||
headers: [
|
||||
NameValueModel(name: "Authorization", value: "Bearer "),
|
||||
],
|
||||
params: [
|
||||
NameValueModel(name: "num", value: "8940000"),
|
||||
],
|
||||
);
|
||||
expect(
|
||||
substituteHttpRequestModel(
|
||||
httpRequestModel, envMap, activeEnvironmentId),
|
||||
expected);
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing getEnvironmentTriggerSuggestions function", () {
|
||||
test("Testing getEnvironmentTriggerSuggestion with empty envMap", () {
|
||||
const query = "u";
|
||||
Map<String, List<EnvironmentVariableModel>> envMap = {};
|
||||
const activeEnvironmentId = "";
|
||||
expect(
|
||||
getEnvironmentTriggerSuggestions(query, envMap, activeEnvironmentId),
|
||||
[]);
|
||||
});
|
||||
|
||||
test("Testing getEnvironmentTriggerSuggestion with empty query", () {
|
||||
const query = "";
|
||||
Map<String, List<EnvironmentVariableModel>> envMap = {
|
||||
kGlobalEnvironmentId: globalVars,
|
||||
"activeEnvId": activeEnvVars,
|
||||
};
|
||||
const activeEnvironmentId = "activeEnvId";
|
||||
expect(
|
||||
getEnvironmentTriggerSuggestions(query, envMap, activeEnvironmentId),
|
||||
const [
|
||||
EnvironmentVariableSuggestion(
|
||||
environmentId: activeEnvironmentId,
|
||||
variable: EnvironmentVariableModel(
|
||||
key: "url", value: "api.apidash.dev")),
|
||||
EnvironmentVariableSuggestion(
|
||||
environmentId: activeEnvironmentId,
|
||||
variable:
|
||||
EnvironmentVariableModel(key: "num", value: "8940000")),
|
||||
EnvironmentVariableSuggestion(
|
||||
environmentId: kGlobalEnvironmentId,
|
||||
variable:
|
||||
EnvironmentVariableModel(key: "token", value: "token")),
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
group("Testing getVariableStatus function", () {
|
||||
test("Testing getVariableStatus with variable available in global", () {
|
||||
const query = "num";
|
||||
Map<String, List<EnvironmentVariableModel>> envMap = {
|
||||
kGlobalEnvironmentId: globalVars,
|
||||
};
|
||||
const expected = EnvironmentVariableSuggestion(
|
||||
environmentId: kGlobalEnvironmentId,
|
||||
variable: EnvironmentVariableModel(key: "num", value: "5670000"));
|
||||
expect(getVariableStatus(query, envMap, null), expected);
|
||||
});
|
||||
|
||||
test("Testing getVariableStatus with variable available in active", () {
|
||||
const query = "num";
|
||||
Map<String, List<EnvironmentVariableModel>> envMap = {
|
||||
kGlobalEnvironmentId: globalVars,
|
||||
"activeEnvId": activeEnvVars,
|
||||
};
|
||||
const activeEnvironmentId = "activeEnvId";
|
||||
const expected = EnvironmentVariableSuggestion(
|
||||
environmentId: activeEnvironmentId,
|
||||
variable: EnvironmentVariableModel(key: "num", value: "8940000"));
|
||||
expect(getVariableStatus(query, envMap, activeEnvironmentId), expected);
|
||||
});
|
||||
|
||||
test("Testing getVariableStatus with unavailable variable", () {
|
||||
const query = "path";
|
||||
Map<String, List<EnvironmentVariableModel>> envMap = {
|
||||
kGlobalEnvironmentId: globalVars,
|
||||
"activeEnvId": activeEnvVars,
|
||||
};
|
||||
const activeEnvironmentId = "activeEnvId";
|
||||
const expected = EnvironmentVariableSuggestion(
|
||||
isUnknown: true,
|
||||
environmentId: "unknown",
|
||||
variable: EnvironmentVariableModel(key: query, value: "unknown"));
|
||||
expect(getVariableStatus(query, envMap, activeEnvironmentId), expected);
|
||||
});
|
||||
});
|
||||
}
|
@ -141,4 +141,19 @@ void main() {
|
||||
colMethodDeleteDarkModeExpected);
|
||||
});
|
||||
});
|
||||
|
||||
group('Testing getScaffoldKey function', () {
|
||||
test('Returns kEnvScaffoldKey for railIdx 1', () {
|
||||
expect(getScaffoldKey(1), kEnvScaffoldKey);
|
||||
});
|
||||
|
||||
test('Returns kHisScaffoldKey for railIdx 2', () {
|
||||
expect(getScaffoldKey(2), kHisScaffoldKey);
|
||||
});
|
||||
|
||||
test('Returns kHomeScaffoldKey for railIdx other than 1 or 2', () {
|
||||
expect(getScaffoldKey(0), kHomeScaffoldKey);
|
||||
expect(getScaffoldKey(3), kHomeScaffoldKey);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
21
test/widgets/button_clear_response_test.dart
Normal file
21
test/widgets/button_clear_response_test.dart
Normal file
@ -0,0 +1,21 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/widgets/button_clear_response.dart';
|
||||
|
||||
import '../test_consts.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing for ClearResponseButton', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'ClearResponseButton',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: ClearResponseButton(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.delete), findsOneWidget);
|
||||
});
|
||||
}
|
53
test/widgets/button_copy_test.dart
Normal file
53
test/widgets/button_copy_test.dart
Normal file
@ -0,0 +1,53 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/widgets/button_copy.dart';
|
||||
|
||||
void main() {
|
||||
String copyText = 'This is a sample response generated by ';
|
||||
|
||||
testWidgets('Testing for copy button with label', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Copy Button',
|
||||
home: Scaffold(
|
||||
body: CopyButton(toCopy: copyText, showLabel: true),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final icon = find.byIcon(Icons.content_copy);
|
||||
expect(icon, findsOneWidget);
|
||||
|
||||
final button = find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton));
|
||||
expect(button, findsOneWidget);
|
||||
|
||||
await tester.tap(button);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
//TODO: The below test works for `flutter run` but not for `flutter test`
|
||||
// var data = await Clipboard.getData('text/plain');
|
||||
// expect(data?.text, copyText);
|
||||
});
|
||||
|
||||
testWidgets('Testing for copy button without label', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Copy Button',
|
||||
home: Scaffold(
|
||||
body: CopyButton(toCopy: copyText, showLabel: false),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final icon = find.byIcon(Icons.content_copy);
|
||||
expect(icon, findsOneWidget);
|
||||
|
||||
final button = find.byType(IconButton);
|
||||
expect(button, findsOneWidget);
|
||||
|
||||
await tester.tap(button);
|
||||
await tester.pump();
|
||||
});
|
||||
}
|
22
test/widgets/button_discord_test.dart
Normal file
22
test/widgets/button_discord_test.dart
Normal file
@ -0,0 +1,22 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/widgets/button_discord.dart';
|
||||
|
||||
import '../test_consts.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing for Discord button', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Discord button',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: DiscordButton(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.discord), findsOneWidget);
|
||||
expect(find.text("Discord Server"), findsOneWidget);
|
||||
});
|
||||
}
|
44
test/widgets/button_repo_test.dart
Normal file
44
test/widgets/button_repo_test.dart
Normal file
@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/widgets/button_repo.dart';
|
||||
|
||||
import '../test_consts.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing for Repo button', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Repo button',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: RepoButton(
|
||||
icon: Icons.code,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.code), findsOneWidget);
|
||||
expect(find.text("GitHub"), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Testing for Repo button icon = null', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Repo button',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: RepoButton(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.code), findsNothing);
|
||||
expect(find.text("GitHub"), findsOneWidget);
|
||||
|
||||
final button1 = find.byType(FilledButton);
|
||||
expect(button1, findsOneWidget);
|
||||
|
||||
expect(tester.widget<FilledButton>(button1).enabled, isTrue);
|
||||
});
|
||||
}
|
79
test/widgets/button_save_download_test.dart
Normal file
79
test/widgets/button_save_download_test.dart
Normal file
@ -0,0 +1,79 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/widgets/button_save_download.dart';
|
||||
|
||||
import '../test_consts.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing for Save in Downloads button', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Save in Downloads button',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: SaveInDownloadsButton(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final icon = find.byIcon(Icons.download);
|
||||
expect(icon, findsOneWidget);
|
||||
|
||||
Finder button;
|
||||
if (tester.any(find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton)))) {
|
||||
expect(find.text(kLabelDownload), findsOneWidget);
|
||||
button = find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton));
|
||||
expect(button, findsOneWidget);
|
||||
expect(tester.widget<TextButton>(button).enabled, isFalse);
|
||||
} else if (tester
|
||||
.any(find.ancestor(of: icon, matching: find.byType(IconButton)))) {
|
||||
button = find.byType(IconButton);
|
||||
expect(button, findsOneWidget);
|
||||
expect(tester.widget<IconButton>(button).onPressed == null, isFalse);
|
||||
} else {
|
||||
fail('No TextButton or IconButton found');
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Testing for Save in Downloads button 2', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Save in Downloads button',
|
||||
theme: kThemeDataLight,
|
||||
home: Scaffold(
|
||||
body: SaveInDownloadsButton(
|
||||
content: Uint8List.fromList([1]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final icon = find.byIcon(Icons.download);
|
||||
expect(icon, findsOneWidget);
|
||||
|
||||
Finder button;
|
||||
if (tester.any(find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton)))) {
|
||||
expect(find.text(kLabelDownload), findsOneWidget);
|
||||
button = find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton));
|
||||
expect(button, findsOneWidget);
|
||||
expect(tester.widget<TextButton>(button).enabled, isTrue);
|
||||
} else if (tester
|
||||
.any(find.ancestor(of: icon, matching: find.byType(IconButton)))) {
|
||||
button = find.byType(IconButton);
|
||||
expect(button, findsOneWidget);
|
||||
expect(tester.widget<IconButton>(button).onPressed == null, isTrue);
|
||||
} else {
|
||||
fail('No TextButton or IconButton found');
|
||||
}
|
||||
});
|
||||
}
|
58
test/widgets/button_send_test.dart
Normal file
58
test/widgets/button_send_test.dart
Normal file
@ -0,0 +1,58 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:apidash/widgets/button_send.dart';
|
||||
|
||||
import '../test_consts.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing for Send Request button', (tester) async {
|
||||
dynamic changedValue;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Send Request button',
|
||||
theme: kThemeDataLight,
|
||||
home: Scaffold(
|
||||
body: SendButton(
|
||||
isWorking: false,
|
||||
onTap: () {
|
||||
changedValue = 'Send';
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.send), findsOneWidget);
|
||||
expect(find.text(kLabelSend), findsOneWidget);
|
||||
final button1 = find.byType(FilledButton);
|
||||
expect(button1, findsOneWidget);
|
||||
|
||||
await tester.tap(button1);
|
||||
expect(changedValue, 'Send');
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Testing for Send Request button when RequestModel is viewed and is waiting for response',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Send Request button',
|
||||
theme: kThemeDataLight,
|
||||
home: Scaffold(
|
||||
body: SendButton(
|
||||
isWorking: true,
|
||||
onTap: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.send), findsNothing);
|
||||
expect(find.text(kLabelSending), findsOneWidget);
|
||||
final button1 = find.byType(FilledButton);
|
||||
expect(button1, findsOneWidget);
|
||||
|
||||
expect(tester.widget<FilledButton>(button1).enabled, isFalse);
|
||||
});
|
||||
}
|
@ -1,250 +0,0 @@
|
||||
import 'dart:typed_data';
|
||||
import 'package:apidash/screens/common_widgets/sidebar_save_button.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
import '../test_consts.dart';
|
||||
|
||||
void main() {
|
||||
String copyText = 'This is a sample response generated by ';
|
||||
testWidgets('Testing for copy button', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Copy Button',
|
||||
home: Scaffold(
|
||||
body: CopyButton(toCopy: copyText),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final icon = find.byIcon(Icons.content_copy);
|
||||
expect(icon, findsOneWidget);
|
||||
|
||||
Finder button;
|
||||
if (tester.any(find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton)))) {
|
||||
expect(find.text(kLabelCopy), findsOneWidget);
|
||||
button = find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton));
|
||||
} else if (tester
|
||||
.any(find.ancestor(of: icon, matching: find.byType(IconButton)))) {
|
||||
button = find.byType(IconButton);
|
||||
} else {
|
||||
fail('No TextButton or IconButton found');
|
||||
}
|
||||
|
||||
expect(button, findsOneWidget);
|
||||
await tester.tap(button);
|
||||
|
||||
//TODO: The below test works for `flutter run` but not for `flutter test`
|
||||
//var data = await Clipboard.getData('text/plain');
|
||||
//expect(data?.text, copyText);
|
||||
});
|
||||
|
||||
testWidgets('Testing for Send Request button', (tester) async {
|
||||
dynamic changedValue;
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Send Request button',
|
||||
theme: kThemeDataLight,
|
||||
home: Scaffold(
|
||||
body: SendButton(
|
||||
isWorking: false,
|
||||
onTap: () {
|
||||
changedValue = 'Send';
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.send), findsOneWidget);
|
||||
expect(find.text(kLabelSend), findsOneWidget);
|
||||
final button1 = find.byType(FilledButton);
|
||||
expect(button1, findsOneWidget);
|
||||
|
||||
await tester.tap(button1);
|
||||
expect(changedValue, 'Send');
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Testing for Send Request button when RequestModel is viewed and is waiting for response',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Send Request button',
|
||||
theme: kThemeDataLight,
|
||||
home: Scaffold(
|
||||
body: SendButton(
|
||||
isWorking: true,
|
||||
onTap: () {},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.send), findsNothing);
|
||||
expect(find.text(kLabelSending), findsOneWidget);
|
||||
final button1 = find.byType(FilledButton);
|
||||
expect(button1, findsOneWidget);
|
||||
|
||||
expect(tester.widget<FilledButton>(button1).enabled, isFalse);
|
||||
});
|
||||
|
||||
testWidgets('Testing for Save in Downloads button', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Save in Downloads button',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: SaveInDownloadsButton(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final icon = find.byIcon(Icons.download);
|
||||
expect(icon, findsOneWidget);
|
||||
|
||||
Finder button;
|
||||
if (tester.any(find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton)))) {
|
||||
expect(find.text(kLabelDownload), findsOneWidget);
|
||||
button = find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton));
|
||||
expect(button, findsOneWidget);
|
||||
expect(tester.widget<TextButton>(button).enabled, isFalse);
|
||||
} else if (tester
|
||||
.any(find.ancestor(of: icon, matching: find.byType(IconButton)))) {
|
||||
button = find.byType(IconButton);
|
||||
expect(button, findsOneWidget);
|
||||
expect(tester.widget<IconButton>(button).onPressed == null, isFalse);
|
||||
} else {
|
||||
fail('No TextButton or IconButton found');
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Testing for Save in Downloads button 2', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Save in Downloads button',
|
||||
theme: kThemeDataLight,
|
||||
home: Scaffold(
|
||||
body: SaveInDownloadsButton(
|
||||
content: Uint8List.fromList([1]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final icon = find.byIcon(Icons.download);
|
||||
expect(icon, findsOneWidget);
|
||||
|
||||
Finder button;
|
||||
if (tester.any(find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton)))) {
|
||||
expect(find.text(kLabelDownload), findsOneWidget);
|
||||
button = find.ancestor(
|
||||
of: icon,
|
||||
matching: find.byWidgetPredicate((widget) => widget is TextButton));
|
||||
expect(button, findsOneWidget);
|
||||
expect(tester.widget<TextButton>(button).enabled, isTrue);
|
||||
} else if (tester
|
||||
.any(find.ancestor(of: icon, matching: find.byType(IconButton)))) {
|
||||
button = find.byType(IconButton);
|
||||
expect(button, findsOneWidget);
|
||||
expect(tester.widget<IconButton>(button).onPressed == null, isTrue);
|
||||
} else {
|
||||
fail('No TextButton or IconButton found');
|
||||
}
|
||||
});
|
||||
|
||||
testWidgets('Testing for Repo button', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Repo button',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: RepoButton(
|
||||
icon: Icons.code,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.code), findsOneWidget);
|
||||
expect(find.text("GitHub"), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Testing for Repo button icon = null', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Repo button',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: RepoButton(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.code), findsNothing);
|
||||
expect(find.text("GitHub"), findsOneWidget);
|
||||
|
||||
final button1 = find.byType(FilledButton);
|
||||
expect(button1, findsOneWidget);
|
||||
|
||||
expect(tester.widget<FilledButton>(button1).enabled, isTrue);
|
||||
});
|
||||
|
||||
testWidgets('Testing for Discord button', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Discord button',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: DiscordButton(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.discord), findsOneWidget);
|
||||
expect(find.text("Discord Server"), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Testing for Save button', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
ProviderScope(
|
||||
child: MaterialApp(
|
||||
title: 'Save button',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: SaveButton(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.save), findsOneWidget);
|
||||
expect(find.text("Save"), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('Testing for ClearResponseButton', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'ClearResponseButton',
|
||||
theme: kThemeDataLight,
|
||||
home: const Scaffold(
|
||||
body: ClearResponseButton(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byIcon(Icons.delete), findsOneWidget);
|
||||
});
|
||||
}
|
18
test/widgets/card_request_details.dart
Normal file
18
test/widgets/card_request_details.dart
Normal file
@ -0,0 +1,18 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing Request Details Card', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
title: 'Request Details Card',
|
||||
home: Scaffold(
|
||||
body: RequestDetailsCard(child: SizedBox(height: 10, width: 10))),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(Card), findsOneWidget);
|
||||
expect(find.byType(SizedBox), findsOneWidget);
|
||||
});
|
||||
}
|
206
test/widgets/card_sidebar_environment_test.dart
Normal file
206
test/widgets/card_sidebar_environment_test.dart
Normal file
@ -0,0 +1,206 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/widgets/widgets.dart'
|
||||
show SidebarEnvironmentCard, ItemCardMenu;
|
||||
|
||||
import '../test_consts.dart';
|
||||
|
||||
Future<void> pumpSidebarEnvironmentCard(
|
||||
WidgetTester tester, {
|
||||
required ThemeData theme,
|
||||
required String id,
|
||||
required String selectedId,
|
||||
String? editRequestId,
|
||||
bool isGlobal = false,
|
||||
required String name,
|
||||
Function()? onTap,
|
||||
Function()? onDoubleTap,
|
||||
Function(String)? onChangedNameEditor,
|
||||
Function()? onTapOutsideNameEditor,
|
||||
Function(dynamic)? onMenuSelected,
|
||||
}) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
title: 'Sidebar Environment Card',
|
||||
theme: theme,
|
||||
home: Scaffold(
|
||||
body: ListView(
|
||||
children: [
|
||||
SidebarEnvironmentCard(
|
||||
id: id,
|
||||
selectedId: selectedId,
|
||||
editRequestId: editRequestId,
|
||||
isGlobal: isGlobal,
|
||||
name: name,
|
||||
onTap: onTap,
|
||||
onDoubleTap: onDoubleTap,
|
||||
onChangedNameEditor: onChangedNameEditor,
|
||||
onTapOutsideNameEditor: onTapOutsideNameEditor,
|
||||
onMenuSelected: onMenuSelected,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing Sidebar Environment Card', (tester) async {
|
||||
dynamic changedValue;
|
||||
|
||||
await pumpSidebarEnvironmentCard(
|
||||
tester,
|
||||
theme: kThemeDataLight,
|
||||
id: '23',
|
||||
selectedId: '2',
|
||||
name: 'Production',
|
||||
onTap: () {
|
||||
changedValue = 'Single Tapped';
|
||||
},
|
||||
onDoubleTap: () {
|
||||
changedValue = 'Double Tapped';
|
||||
},
|
||||
);
|
||||
|
||||
expect(find.byType(InkWell), findsOneWidget);
|
||||
expect(find.text('Production'), findsOneWidget);
|
||||
expect(find.widgetWithText(SizedBox, 'Production'), findsOneWidget);
|
||||
expect(find.widgetWithText(Card, 'Production'), findsOneWidget);
|
||||
|
||||
var tappable = find.widgetWithText(Card, 'Production');
|
||||
await tester.tap(tappable);
|
||||
await tester.pumpAndSettle(const Duration(seconds: 2));
|
||||
expect(changedValue, 'Single Tapped');
|
||||
});
|
||||
|
||||
testWidgets('Testing Sidebar Environment Card dark mode', (tester) async {
|
||||
dynamic changedValue;
|
||||
|
||||
await pumpSidebarEnvironmentCard(
|
||||
tester,
|
||||
theme: kThemeDataDark,
|
||||
id: '23',
|
||||
selectedId: '2',
|
||||
name: 'Production',
|
||||
onTap: () {
|
||||
changedValue = 'Single Tapped';
|
||||
},
|
||||
onDoubleTap: () {
|
||||
changedValue = 'Double Tapped';
|
||||
},
|
||||
);
|
||||
|
||||
expect(find.byType(InkWell), findsOneWidget);
|
||||
expect(find.text('Production'), findsOneWidget);
|
||||
expect(find.widgetWithText(SizedBox, 'Production'), findsOneWidget);
|
||||
expect(find.widgetWithText(Card, 'Production'), findsOneWidget);
|
||||
|
||||
var tappable = find.widgetWithText(Card, 'Production');
|
||||
await tester.tap(tappable);
|
||||
await tester.pumpAndSettle(const Duration(seconds: 2));
|
||||
expect(changedValue, 'Single Tapped');
|
||||
});
|
||||
|
||||
testWidgets('Testing Sidebar Environment Card inEditMode', (tester) async {
|
||||
dynamic changedValue;
|
||||
|
||||
await pumpSidebarEnvironmentCard(
|
||||
tester,
|
||||
theme: kThemeDataLight,
|
||||
id: '23',
|
||||
selectedId: '23',
|
||||
editRequestId: '23',
|
||||
name: 'Production',
|
||||
onChangedNameEditor: (value) {
|
||||
changedValue = value;
|
||||
},
|
||||
onTapOutsideNameEditor: () {
|
||||
changedValue = 'Tapped Outside';
|
||||
},
|
||||
);
|
||||
|
||||
expect(find.byType(InkWell), findsOneWidget);
|
||||
|
||||
var tappable = find.byType(TextFormField);
|
||||
await tester.enterText(tappable, 'entering 123 for testing');
|
||||
await tester.pumpAndSettle();
|
||||
expect(changedValue, 'entering 123 for testing');
|
||||
|
||||
await tester.tapAt(const Offset(100, 100));
|
||||
await tester.pumpAndSettle();
|
||||
expect(changedValue, 'Tapped Outside');
|
||||
|
||||
await tester.enterText(tappable, 'New Name');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
expect(changedValue, "Tapped Outside");
|
||||
});
|
||||
|
||||
group("Testing Sidebar Environment Card Item Card Menu visibility", () {
|
||||
testWidgets(
|
||||
'Environment ItemCardMenu should be visible when not in edit mode',
|
||||
(tester) async {
|
||||
await pumpSidebarEnvironmentCard(
|
||||
tester,
|
||||
theme: kThemeDataLight,
|
||||
id: '23',
|
||||
selectedId: '23',
|
||||
isGlobal: false,
|
||||
name: 'Production',
|
||||
onMenuSelected: (value) {},
|
||||
);
|
||||
|
||||
expect(find.byType(ItemCardMenu), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Environment ItemCardMenu should not be visible when in edit mode',
|
||||
(tester) async {
|
||||
await pumpSidebarEnvironmentCard(
|
||||
tester,
|
||||
theme: kThemeDataLight,
|
||||
id: '23',
|
||||
selectedId: '23',
|
||||
editRequestId: '23',
|
||||
isGlobal: false,
|
||||
name: 'Production',
|
||||
onMenuSelected: (value) {},
|
||||
);
|
||||
|
||||
expect(find.byType(ItemCardMenu), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'Environment ItemCardMenu should not be visible when not selected',
|
||||
(tester) async {
|
||||
await pumpSidebarEnvironmentCard(
|
||||
tester,
|
||||
theme: kThemeDataLight,
|
||||
id: '23',
|
||||
selectedId: '24',
|
||||
editRequestId: '24',
|
||||
isGlobal: false,
|
||||
name: 'Production',
|
||||
onMenuSelected: (value) {},
|
||||
);
|
||||
|
||||
expect(find.byType(ItemCardMenu), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('Environment ItemCardMenu should not be visible if isGlobal',
|
||||
(tester) async {
|
||||
await pumpSidebarEnvironmentCard(
|
||||
tester,
|
||||
theme: kThemeDataLight,
|
||||
id: '23',
|
||||
selectedId: '23',
|
||||
editRequestId: '24',
|
||||
isGlobal: true,
|
||||
name: 'Production',
|
||||
onMenuSelected: (value) {},
|
||||
);
|
||||
|
||||
expect(find.byType(ItemCardMenu), findsNothing);
|
||||
});
|
||||
});
|
||||
}
|
@ -90,17 +90,9 @@ void main() {
|
||||
await tester.tapAt(const Offset(100, 100));
|
||||
await tester.pumpAndSettle();
|
||||
expect(changedValue, 'Tapped Outside');
|
||||
});
|
||||
testWidgets('Testing Request Details Card', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
title: 'Request Details Card',
|
||||
home: Scaffold(
|
||||
body: RequestDetailsCard(child: SizedBox(height: 10, width: 10))),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.byType(Card), findsOneWidget);
|
||||
expect(find.byType(SizedBox), findsOneWidget);
|
||||
await tester.enterText(tappable, 'New Name');
|
||||
await tester.testTextInput.receiveAction(TextInputAction.done);
|
||||
expect(changedValue, "Tapped Outside");
|
||||
});
|
||||
}
|
42
test/widgets/dialog_about_test.dart
Normal file
42
test/widgets/dialog_about_test.dart
Normal file
@ -0,0 +1,42 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'Testing showAboutAppDialog displays the dialog with IntroMessage and Close button',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: ElevatedButton(
|
||||
onPressed: () {
|
||||
showAboutAppDialog(context);
|
||||
},
|
||||
child: const Text('Show About Dialog'),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.text('Show About Dialog'));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(AlertDialog), findsOneWidget);
|
||||
|
||||
expect(find.byType(IntroMessage), findsOneWidget);
|
||||
|
||||
expect(find.text('Close'), findsOneWidget);
|
||||
|
||||
await tester.tap(find.text('Close'));
|
||||
await tester.pump();
|
||||
|
||||
expect(find.byType(AlertDialog), findsNothing);
|
||||
});
|
||||
}
|
64
test/widgets/field_cell_obscurable_test.dart
Normal file
64
test/widgets/field_cell_obscurable_test.dart
Normal file
@ -0,0 +1,64 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/widgets/field_cell_obscurable.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets(
|
||||
'Testing ObscurableCellField toggles obscure text on icon button press',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ObscurableCellField(
|
||||
keyId: 'testKey',
|
||||
initialValue: 'password',
|
||||
hintText: 'Enter password',
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final iconButton = find.byType(IconButton);
|
||||
expect(iconButton, findsOneWidget);
|
||||
|
||||
Icon icon = tester.widget<Icon>(
|
||||
find.descendant(of: iconButton, matching: find.byType(Icon)));
|
||||
expect(icon.icon, Icons.visibility);
|
||||
|
||||
await tester.tap(iconButton);
|
||||
await tester.pump();
|
||||
|
||||
icon = tester.widget<Icon>(
|
||||
find.descendant(of: iconButton, matching: find.byType(Icon)));
|
||||
expect(icon.icon, Icons.visibility_off);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('ObscurableCellField calls onChanged when text is changed',
|
||||
(WidgetTester tester) async {
|
||||
String? changedValue;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ObscurableCellField(
|
||||
keyId: 'testKey',
|
||||
initialValue: 'password',
|
||||
hintText: 'Enter password',
|
||||
onChanged: (value) {
|
||||
changedValue = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
final textField = find.byType(TextFormField);
|
||||
expect(textField, findsOneWidget);
|
||||
|
||||
await tester.enterText(textField, 'newpassword');
|
||||
await tester.pump();
|
||||
|
||||
expect(changedValue, 'newpassword');
|
||||
});
|
||||
}
|
36
test/widgets/field_read_only_test.dart
Normal file
36
test/widgets/field_read_only_test.dart
Normal file
@ -0,0 +1,36 @@
|
||||
import 'package:apidash/widgets/field_read_only.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/consts.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing ReadOnlyTextField displays initial value and decoration',
|
||||
(WidgetTester tester) async {
|
||||
const testInitialValue = 'Test Value';
|
||||
const testDecoration = InputDecoration(
|
||||
hintText: 'Test Hint',
|
||||
isDense: true,
|
||||
border: InputBorder.none,
|
||||
contentPadding: kPv8,
|
||||
);
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: ReadOnlyTextField(
|
||||
initialValue: testInitialValue,
|
||||
decoration: testDecoration,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text(testInitialValue), findsOneWidget);
|
||||
|
||||
final textField = tester.widget<TextField>(find.byType(TextField));
|
||||
expect(textField.decoration?.hintText, testDecoration.hintText);
|
||||
expect(textField.decoration?.isDense, testDecoration.isDense);
|
||||
expect(textField.decoration?.border, testDecoration.border);
|
||||
expect(textField.decoration?.contentPadding, testDecoration.contentPadding);
|
||||
});
|
||||
}
|
76
test/widgets/popup_menu_codegen_test.dart
Normal file
76
test/widgets/popup_menu_codegen_test.dart
Normal file
@ -0,0 +1,76 @@
|
||||
import 'package:apidash/consts.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/widgets/popup_menu_codegen.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('CodegenPopupMenu displays initial value',
|
||||
(WidgetTester tester) async {
|
||||
const codegenLanguage = CodegenLanguage.dartDio;
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: CodegenPopupMenu(
|
||||
value: codegenLanguage,
|
||||
items: [codegenLanguage],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text(codegenLanguage.label), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('CodegenPopupMenu displays popup menu items',
|
||||
(WidgetTester tester) async {
|
||||
const codegenLanguage1 = CodegenLanguage.dartDio;
|
||||
const codegenLanguage2 = CodegenLanguage.pythonRequests;
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: CodegenPopupMenu(
|
||||
items: [codegenLanguage1, codegenLanguage2],
|
||||
value: codegenLanguage1,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.unfold_more));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(codegenLanguage1.label), findsExactly(2));
|
||||
expect(find.text(codegenLanguage2.label), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('CodegenPopupMenu calls onChanged when an item is selected',
|
||||
(WidgetTester tester) async {
|
||||
const codegenLanguage1 = CodegenLanguage.dartDio;
|
||||
const codegenLanguage2 = CodegenLanguage.pythonRequests;
|
||||
CodegenLanguage? selectedLanguage;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: CodegenPopupMenu(
|
||||
value: codegenLanguage1,
|
||||
items: const [codegenLanguage1, codegenLanguage2],
|
||||
onChanged: (value) {
|
||||
selectedLanguage = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.unfold_more));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text(codegenLanguage2.label).last);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(selectedLanguage, codegenLanguage2);
|
||||
});
|
||||
}
|
118
test/widgets/popup_menu_env_test.dart
Normal file
118
test/widgets/popup_menu_env_test.dart
Normal file
@ -0,0 +1,118 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/models/models.dart';
|
||||
import 'package:apidash/widgets/popup_menu_env.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('EnvironmentPopupMenu displays initial value',
|
||||
(WidgetTester tester) async {
|
||||
const environment = EnvironmentModel(name: 'Production', id: 'prod');
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvironmentPopupMenu(
|
||||
value: environment,
|
||||
items: [environment],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('Production'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('EnvironmentPopupMenu displays "None" when no value is provided',
|
||||
(WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvironmentPopupMenu(
|
||||
items: [],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('None'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('EnvironmentPopupMenu displays popup menu items',
|
||||
(WidgetTester tester) async {
|
||||
const environment1 = EnvironmentModel(name: 'Production', id: 'prod');
|
||||
const environment2 = EnvironmentModel(name: 'Development', id: 'dev');
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvironmentPopupMenu(
|
||||
items: [environment1, environment2],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.unfold_more));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text('None'), findsExactly(2));
|
||||
expect(find.text('Production'), findsOneWidget);
|
||||
expect(find.text('Development'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('EnvironmentPopupMenu calls onChanged when an item is selected',
|
||||
(WidgetTester tester) async {
|
||||
const environment1 = EnvironmentModel(name: 'Production', id: 'prod');
|
||||
const environment2 = EnvironmentModel(name: 'Development', id: 'dev');
|
||||
EnvironmentModel? selectedEnvironment;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvironmentPopupMenu(
|
||||
items: const [environment1, environment2],
|
||||
onChanged: (value) {
|
||||
selectedEnvironment = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.unfold_more));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('Development').last);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(selectedEnvironment, environment2);
|
||||
});
|
||||
|
||||
testWidgets(
|
||||
'EnvironmentPopupMenu calls onChanged with null when "None" is selected',
|
||||
(WidgetTester tester) async {
|
||||
const environment = EnvironmentModel(name: 'Production', id: 'prod');
|
||||
EnvironmentModel? selectedEnvironment = environment;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: EnvironmentPopupMenu(
|
||||
items: const [environment],
|
||||
onChanged: (value) {
|
||||
selectedEnvironment = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.unfold_more));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text('None').last);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(selectedEnvironment, isNull);
|
||||
});
|
||||
}
|
75
test/widgets/popup_menu_uri_test.dart
Normal file
75
test/widgets/popup_menu_uri_test.dart
Normal file
@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/widgets/popup_menu_uri.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('URIPopupMenu displays initial value',
|
||||
(WidgetTester tester) async {
|
||||
const uriScheme = 'https';
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: URIPopupMenu(
|
||||
value: uriScheme,
|
||||
items: [uriScheme],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text(uriScheme), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('URIPopupMenu displays popup menu items',
|
||||
(WidgetTester tester) async {
|
||||
const uriScheme1 = 'https';
|
||||
const uriScheme2 = 'http';
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: URIPopupMenu(
|
||||
items: [uriScheme1, uriScheme2],
|
||||
value: uriScheme1,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.unfold_more));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(find.text(uriScheme1), findsExactly(2));
|
||||
expect(find.text(uriScheme2), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('URIPopupMenu calls onChanged when an item is selected',
|
||||
(WidgetTester tester) async {
|
||||
const uriScheme1 = 'https';
|
||||
const uriScheme2 = 'http';
|
||||
String? selectedScheme;
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: URIPopupMenu(
|
||||
value: uriScheme1,
|
||||
items: const [uriScheme1, uriScheme2],
|
||||
onChanged: (value) {
|
||||
selectedScheme = value;
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
await tester.tap(find.byIcon(Icons.unfold_more));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
await tester.tap(find.text(uriScheme2).last);
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
expect(selectedScheme, uriScheme2);
|
||||
});
|
||||
}
|
25
test/widgets/splitview_dashboard_test.dart
Normal file
25
test/widgets/splitview_dashboard_test.dart
Normal file
@ -0,0 +1,25 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:multi_split_view/multi_split_view.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing for Dashboard Splitview', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
title: 'Dashboard Splitview',
|
||||
home: Scaffold(
|
||||
body: DashboardSplitView(
|
||||
sidebarWidget: Column(children: [Text("Hello")]),
|
||||
mainWidget: Column(children: [Text("World")]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text("World"), findsOneWidget);
|
||||
expect(find.text("Hello"), findsOneWidget);
|
||||
expect(find.byType(MultiSplitViewTheme), findsOneWidget);
|
||||
});
|
||||
//TODO: Divider not visible on flutter run. Investigate.
|
||||
}
|
97
test/widgets/splitview_drawer_test.dart
Normal file
97
test/widgets/splitview_drawer_test.dart
Normal file
@ -0,0 +1,97 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/widgets/splitview_drawer.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('DrawerSplitView displays main components', (tester) async {
|
||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DrawerSplitView(
|
||||
scaffoldKey: scaffoldKey,
|
||||
mainContent: const Text('Main Content'),
|
||||
title: const Text('Title'),
|
||||
leftDrawerContent: const Text('Left Drawer Content'),
|
||||
rightDrawerContent: const Text('Right Drawer Content'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Verify the main content is displayed
|
||||
expect(find.text('Main Content'), findsOneWidget);
|
||||
|
||||
// Verify the title is displayed
|
||||
expect(find.text('Title'), findsOneWidget);
|
||||
|
||||
// Verify the left drawer content is not displayed initially
|
||||
expect(find.text('Left Drawer Content'), findsNothing);
|
||||
|
||||
// Verify the right drawer content is not displayed initially
|
||||
expect(find.text('Right Drawer Content'), findsNothing);
|
||||
});
|
||||
|
||||
testWidgets('DrawerSplitView opens left drawer', (tester) async {
|
||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DrawerSplitView(
|
||||
scaffoldKey: scaffoldKey,
|
||||
mainContent: const Text('Main Content'),
|
||||
title: const Text('Title'),
|
||||
leftDrawerContent: const Text('Left Drawer Content'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Tap the leading icon to open the left drawer
|
||||
await tester.tap(find.byIcon(Icons.format_list_bulleted_rounded));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify the left drawer content is displayed
|
||||
expect(find.text('Left Drawer Content'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('DrawerSplitView opens right drawer', (tester) async {
|
||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DrawerSplitView(
|
||||
scaffoldKey: scaffoldKey,
|
||||
mainContent: const Text('Main Content'),
|
||||
title: const Text('Title'),
|
||||
rightDrawerContent: const Text('Right Drawer Content'),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Tap the right drawer icon to open the right drawer
|
||||
await tester.tap(find.byIcon(Icons.arrow_forward));
|
||||
await tester.pumpAndSettle();
|
||||
|
||||
// Verify the right drawer content is displayed
|
||||
expect(find.text('Right Drawer Content'), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('DrawerSplitView displays actions', (tester) async {
|
||||
final scaffoldKey = GlobalKey<ScaffoldState>();
|
||||
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: DrawerSplitView(
|
||||
scaffoldKey: scaffoldKey,
|
||||
mainContent: const Text('Main Content'),
|
||||
title: const Text('Title'),
|
||||
actions: [
|
||||
IconButton(icon: const Icon(Icons.search), onPressed: () {})
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
// Verify the action icon is displayed
|
||||
expect(find.byIcon(Icons.search), findsOneWidget);
|
||||
});
|
||||
}
|
@ -4,23 +4,6 @@ import 'package:multi_split_view/multi_split_view.dart';
|
||||
import 'package:apidash/widgets/widgets.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Testing for Dashboard Splitview', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
title: 'Dashboard Splitview',
|
||||
home: Scaffold(
|
||||
body: DashboardSplitView(
|
||||
sidebarWidget: Column(children: [Text("Hello")]),
|
||||
mainWidget: Column(children: [Text("World")]),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text("World"), findsOneWidget);
|
||||
expect(find.text("Hello"), findsOneWidget);
|
||||
expect(find.byType(MultiSplitViewTheme), findsOneWidget);
|
||||
});
|
||||
testWidgets('Testing for Equal SplitView', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
43
test/widgets/tabs_test.dart
Normal file
43
test/widgets/tabs_test.dart
Normal file
@ -0,0 +1,43 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:apidash/widgets/tabs.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('TabLabel shows indicator when showIndicator is true',
|
||||
(tester) async {
|
||||
const String labelText = 'URL Params';
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: TabLabel(
|
||||
text: labelText,
|
||||
showIndicator: true,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text(labelText), findsOneWidget);
|
||||
expect(find.byIcon(Icons.circle), findsOneWidget);
|
||||
});
|
||||
|
||||
testWidgets('TabLabel does not show indicator when showIndicator is false',
|
||||
(tester) async {
|
||||
const String labelText = 'Request';
|
||||
|
||||
await tester.pumpWidget(
|
||||
const MaterialApp(
|
||||
home: Scaffold(
|
||||
body: TabLabel(
|
||||
text: labelText,
|
||||
showIndicator: false,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text(labelText), findsOneWidget);
|
||||
expect(find.byIcon(Icons.circle), findsNothing);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user