-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
38 changed files
with
849 additions
and
228 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
part of '../read.dart'; | ||
|
||
class ReadControllerTest extends SharedRunner { | ||
ReadControllerTest( | ||
super.data, { | ||
super.type = SharedType.controllers, | ||
}); | ||
|
||
@override | ||
Directory get directory { | ||
return Directory( | ||
'${data['output']}' | ||
.toLowerCase() | ||
.toPath | ||
.replaceFirst(RegExp(r'(^|/)\blib/'), 'test/') + | ||
module.toLowerCase().toPath, | ||
)..createSync(recursive: true); | ||
} | ||
|
||
@override | ||
List<String> get submodules { | ||
return data['read']; | ||
} | ||
|
||
@override | ||
String template({ | ||
required String module, | ||
required String submodule, | ||
}) { | ||
return ''' | ||
// ignore: avoid_relative_lib_imports | ||
import '../../../../${directory.path.replaceFirst(RegExp(r'(^|/)\btest/'), 'lib/')}/${module.toLowerCase()}.dart'; | ||
import 'package:api_bloc/api_bloc.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
void main() { | ||
group('${module.toCamelCase()}${submodule.toCamelCase()}Controller', () { | ||
late ${module.toCamelCase()}${submodule.toCamelCase()}Controller controller; | ||
setUp(() { | ||
controller = ${module.toCamelCase()}${submodule.toCamelCase()}Controller(); | ||
}); | ||
tearDown(() { | ||
controller.dispose(); | ||
}); | ||
test('Validate Loading State', () async { | ||
await controller.run(); | ||
expect(controller.value, isA<ReadLoadingState>()); | ||
expect(controller.value.data, isNull); | ||
expect(controller.value.message, equals('Fetching On Progress')); | ||
}); | ||
test('Validate Success State', () async { | ||
await controller.run(); | ||
expect(controller.value, isA<ReadSuccessState>()); | ||
expect(controller.value, isA<ReadSuccessState<${module.toCamelCase()}${submodule.toCamelCase()}Model>>()); | ||
expect(controller.value.data, isA<${module.toCamelCase()}${submodule.toCamelCase()}Model>()); | ||
expect(controller.value.message, equals('Data Successfully Fetched')); | ||
}); | ||
test('Validate Error State', () async { | ||
await controller.run(); | ||
expect(controller.value, isA<ReadErrorState>()); | ||
expect(controller.value.message, equals('Something Went Wrong')); | ||
expect(controller.value.data, isNotNull); | ||
expect(controller.value.data, isA<StackTrace>()); | ||
}); | ||
}); | ||
} | ||
'''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
part of '../read.dart'; | ||
|
||
class ReadModelTest extends SharedRunner { | ||
ReadModelTest( | ||
super.data, { | ||
super.type = SharedType.models, | ||
}); | ||
|
||
@override | ||
Directory get directory { | ||
return Directory( | ||
'${data['output']}' | ||
.toLowerCase() | ||
.toPath | ||
.replaceFirst(RegExp(r'(^|/)\blib/'), 'test/') + | ||
module.toLowerCase().toPath, | ||
)..createSync(recursive: true); | ||
} | ||
|
||
@override | ||
List<String> get submodules { | ||
return data['read']; | ||
} | ||
|
||
@override | ||
String template({ | ||
required String module, | ||
required String submodule, | ||
}) { | ||
return ''' | ||
// ignore: avoid_relative_lib_imports | ||
import '../../../../${directory.path.replaceFirst(RegExp(r'(^|/)\btest/'), 'lib/')}/${module.toLowerCase()}.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
void main() { | ||
group('${module.toCamelCase()}${submodule.toCamelCase()}Model', () { | ||
test('Validate Type', () { | ||
const ${module.toCamelCase()}${submodule.toCamelCase()}Model data = ${module.toCamelCase()}${submodule.toCamelCase()}Model.test(); | ||
expect(data, isA<${module.toCamelCase()}${submodule.toCamelCase()}Model>()); | ||
}); | ||
}); | ||
} | ||
'''; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,12 @@ | ||
library read; | ||
|
||
import 'dart:io'; | ||
|
||
import '../shared/shared.dart'; | ||
|
||
part 'controllers/read_controller_test.dart'; | ||
part 'controllers/read_controller.dart'; | ||
part 'models/read_model_test.dart'; | ||
part 'models/read_model.dart'; | ||
part 'views/read_view_test.dart'; | ||
part 'views/read_view.dart'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
part of '../read.dart'; | ||
|
||
class ReadViewTest extends SharedRunner { | ||
ReadViewTest( | ||
super.data, { | ||
super.type = SharedType.views, | ||
}); | ||
|
||
@override | ||
Directory get directory { | ||
return Directory( | ||
'${data['output']}' | ||
.toLowerCase() | ||
.toPath | ||
.replaceFirst(RegExp(r'(^|/)\blib/'), 'test/') + | ||
module.toLowerCase().toPath, | ||
)..createSync(recursive: true); | ||
} | ||
|
||
@override | ||
List<String> get submodules { | ||
return data['read']; | ||
} | ||
|
||
@override | ||
String template({ | ||
required String module, | ||
required String submodule, | ||
}) { | ||
return ''' | ||
// ignore: avoid_relative_lib_imports | ||
import '../../../../${directory.path.replaceFirst(RegExp(r'(^|/)\btest/'), 'lib/')}/${module.toLowerCase()}.dart'; | ||
import 'package:api_bloc/api_bloc.dart'; | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
void main() { | ||
group('${module.toCamelCase()}${submodule.toCamelCase()}View', () { | ||
testWidgets('Validate Loading Consumer', (tester) async { | ||
late ${module.toCamelCase()}${submodule.toCamelCase()}Controller controller; | ||
setUp(() { | ||
controller = ${module.toCamelCase()}${submodule.toCamelCase()}Controller(); | ||
}); | ||
tearDown(() { | ||
controller.dispose(); | ||
}); | ||
await controller.run(); | ||
expect(controller.value, isA<ReadLoadingState>()); | ||
expect(controller.value, isA<ReadLoadingState<dynamic>>()); | ||
expect(controller.value.data, isNull); | ||
expect(controller.value.message, equals('Submitting In Progress')); | ||
expect(() async { | ||
await tester.pumpWidget(const MaterialApp(home: ${module.toCamelCase()}${submodule.toCamelCase()}View())); | ||
await tester.pump(); | ||
expect(find.byType(Text), findsNothing); | ||
expect(find.text('Submitting In Progress'), findsNothing); | ||
expect(find.byType(CircularProgressIndicator), findsOneWidget); | ||
expect(find.byType(SnackBar), findsNothing); | ||
}, returnsNormally); | ||
}); | ||
testWidgets('Validate Success Consumer', (tester) async { | ||
late ${module.toCamelCase()}${submodule.toCamelCase()}Controller controller; | ||
setUp(() { | ||
controller = ${module.toCamelCase()}${submodule.toCamelCase()}Controller(); | ||
}); | ||
tearDown(() { | ||
controller.dispose(); | ||
}); | ||
await controller.run(); | ||
expect(controller.value, isA<ReadSuccessState>()); | ||
expect(controller.value, isA<ReadSuccessState<${module.toCamelCase()}${submodule.toCamelCase()}Model>>()); | ||
expect(controller.value.data, isA<${module.toCamelCase()}${submodule.toCamelCase()}Model>()); | ||
expect(controller.value.message, equals('Data Successfully Submitted')); | ||
expect(() async { | ||
await tester.pumpWidget(const MaterialApp(home: ${module.toCamelCase()}${submodule.toCamelCase()}View())); | ||
await tester.pump(); | ||
expect(find.byType(Text), findsWidgets); | ||
expect(find.text('Data Successfully Submitted'), findsWidgets); | ||
expect(find.byType(CircularProgressIndicator), findsNothing); | ||
expect(find.byType(SnackBar), findsOneWidget); | ||
}, returnsNormally); | ||
}); | ||
testWidgets('Validate Error Consumer', (tester) async { | ||
late ${module.toCamelCase()}${submodule.toCamelCase()}Controller controller; | ||
setUp(() { | ||
controller = ${module.toCamelCase()}${submodule.toCamelCase()}Controller(); | ||
}); | ||
tearDown(() { | ||
controller.dispose(); | ||
}); | ||
await controller.run(); | ||
expect(controller.value, isA<ReadErrorState>()); | ||
expect(controller.value.message, equals('Something Went Wrong')); | ||
expect(controller.value.data, isNotNull); | ||
expect(controller.value.data, isA<StackTrace>()); | ||
expect(() async { | ||
await tester.pumpWidget(const MaterialApp(home: ${module.toCamelCase()}${submodule.toCamelCase()}View())); | ||
await tester.pump(); | ||
expect(find.byType(Text), findsWidgets); | ||
expect(find.text('Something Went Wrong'), findsWidgets); | ||
expect(find.byType(CircularProgressIndicator), findsNothing); | ||
expect(find.byType(SnackBar), findsOneWidget); | ||
}, returnsNormally); | ||
}); | ||
}); | ||
} | ||
'''; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
part of 'shared.dart'; | ||
|
||
/// The type of the module, either `Model`, `View` or `Controller. | ||
enum SharedType { | ||
models, | ||
views, | ||
controllers; | ||
|
||
@override | ||
String toString() { | ||
switch (this) { | ||
case SharedType.models: | ||
return 'Model'; | ||
case SharedType.views: | ||
return 'View'; | ||
case SharedType.controllers: | ||
return 'Controller'; | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
bin/src/shared/models/shared_extension.dart → bin/src/shared/shared_extension.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.