Commit 1ad29766 authored by kevin's avatar kevin

add ci

parent 11513954
Pipeline #48732189 failed
......@@ -69,3 +69,6 @@ build/
!**/ios/**/default.pbxuser
!**/ios/**/default.perspectivev3
!/packages/flutter_tools/test/data/dart_dependencies_test/**/.packages
# coverage
coverage
\ No newline at end of file
image: cirrusci/flutter:1.0.0
stages:
- test
- coverage
test:stable:
stage: test
script:
- flutter test --coverage
artifact:
- coverage
test:beta:
stage: test
script:
- flutter channel beta && flutter upgrade
- flutter test
test:dev:
stage: test
script:
- flutter channel dev && flutter upgrade
- flutter test
test:master:
stage: test
script:
- flutter channel master && flutter upgrade
- flutter test
coverage:
image: registry.gitlab.com/santetis/open_source/santetis_image:latest
stage: coverage
coverage: '^\s+lines.+: (\d+.\d*%)'
dependencies:
- test:stable
script:
- genhtml -o coverage coverage/lcov.info
......@@ -76,7 +76,7 @@ class _MyHomePageState extends State<MyHomePage> {
}
}
class MyStreamWidget extends StatelessWidget with StreamHelperWidget {
class MyStreamWidget extends StatelessWidget with StreamHelperMixin {
final Stream<int> periodicStream;
MyStreamWidget(this.periodicStream);
......@@ -90,7 +90,7 @@ class MyStreamWidget extends StatelessWidget with StreamHelperWidget {
Widget get defaultWidget => Text('Waiting stream');
}
class MyFutureWidget extends StatelessWidget with FutureHelperWidget {
class MyFutureWidget extends StatelessWidget with FutureHelperMixin {
final Future<int> future;
MyFutureWidget({@required this.future});
......
import 'package:flutter/widgets.dart';
mixin FutureHelperWidget {
Widget get defaultWidget => null;
mixin FutureHelperMixin {
Widget get defaultWidget => Container();
Future<Widget> buildFuture(BuildContext context);
Widget build(BuildContext context) {
return FutureBuilder(
initialData: defaultWidget ?? Container(),
return FutureBuilder<Widget>(
initialData: defaultWidget,
future: buildFuture(context),
builder: (c, snapshot) {
return snapshot.data;
......
import 'package:flutter/widgets.dart';
mixin StreamHelperWidget {
Widget get defaultWidget => null;
mixin StreamHelperMixin {
Widget get defaultWidget => Container();
Stream<Widget> buildStream(BuildContext context);
Widget build(BuildContext context) {
return StreamBuilder(
initialData: defaultWidget ?? Container(),
return StreamBuilder<Widget>(
initialData: defaultWidget,
stream: buildStream(context),
builder: (c, snapshot) {
return snapshot.data;
......
// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility that Flutter provides. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.
import 'dart:async';
// import 'package:flutter/material.dart';
// import 'package:flutter_test/flutter_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
// import 'package:async_widget_helper/async_widget_helper.dart';
import 'package:async_mixin_helper/async_mixin_helper.dart';
// void main() {
// testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// await tester.pumpWidget(MyApp());
class _FutureTestWidget extends StatelessWidget with FutureHelperMixin {
final Future<int> future;
// expect(find.text('0'), findsOneWidget);
// expect(find.text('1'), findsNothing);
_FutureTestWidget({@required this.future});
// await tester.tap(find.byIcon(Icons.add));
// await tester.pump();
@override
Future<Widget> buildFuture(BuildContext context) async {
final result = await future;
return Text('Future result is $result');
}
}
// expect(find.text('0'), findsNothing);
// expect(find.text('1'), findsOneWidget);
// });
// }
class _StreamTestWidget extends StatelessWidget with StreamHelperMixin {
final Stream<int> stream;
_StreamTestWidget({@required this.stream});
@override
Stream<Widget> buildStream(BuildContext context) =>
stream.map((result) => Text('Stream result is $result'));
}
class _FutureTestWidgetWithCustomDefaultWidget extends StatelessWidget
with FutureHelperMixin {
final Future<int> future;
_FutureTestWidgetWithCustomDefaultWidget({@required this.future});
@override
Widget get defaultWidget => Text('Future doesn\'t completed yet');
@override
Future<Widget> buildFuture(BuildContext context) async {
final result = await future;
return Text('Future result is $result');
}
}
class _StreamTestWidgetWithCustomDefaultWidget extends StatelessWidget
with StreamHelperMixin {
final Stream<int> stream;
_StreamTestWidgetWithCustomDefaultWidget({@required this.stream});
@override
Widget get defaultWidget => Text('Stream doesn\'t completed yet');
@override
Stream<Widget> buildStream(BuildContext context) =>
stream.map((result) => Text('Stream result is $result'));
}
void main() {
testWidgets('FutureHelperMixin', (WidgetTester tester) async {
final completer = Completer<int>();
final app = MaterialApp(
home: Scaffold(
body: _FutureTestWidget(
future: completer.future,
),
),
);
await tester.pumpWidget(app);
expect(find.byType(Container), findsOneWidget);
completer.complete(1);
await tester.pumpAndSettle();
expect(find.text('Future result is 1'), findsOneWidget);
});
testWidgets('StreamHelperMixin ', (WidgetTester tester) async {
final controller = StreamController<int>();
final app = MaterialApp(
home: Scaffold(
body: _StreamTestWidget(
stream: controller.stream,
),
),
);
await tester.pumpWidget(app);
expect(find.byType(Container), findsOneWidget);
controller.add(1);
await tester.pumpAndSettle();
expect(find.text('Stream result is 1'), findsOneWidget);
controller.add(2);
await tester.pumpAndSettle();
expect(find.text('Stream result is 2'), findsOneWidget);
await controller.close();
});
testWidgets('FutureHelperMixin with custom defaultWidget',
(WidgetTester tester) async {
final completer = Completer<int>();
final app = MaterialApp(
home: Scaffold(
body: _FutureTestWidgetWithCustomDefaultWidget(
future: completer.future,
),
),
);
await tester.pumpWidget(app);
expect(find.text('Future doesn\'t completed yet'), findsOneWidget);
completer.complete(1);
await tester.pumpAndSettle();
expect(find.text('Future result is 1'), findsOneWidget);
});
testWidgets('StreamHelperMixin with custom defaultWidget',
(WidgetTester tester) async {
final controller = StreamController<int>();
final app = MaterialApp(
home: Scaffold(
body: _StreamTestWidgetWithCustomDefaultWidget(
stream: controller.stream,
),
),
);
await tester.pumpWidget(app);
expect(find.text('Stream doesn\'t completed yet'), findsOneWidget);
controller.add(1);
await tester.pumpAndSettle();
expect(find.text('Stream result is 1'), findsOneWidget);
controller.add(2);
await tester.pumpAndSettle();
expect(find.text('Stream result is 2'), findsOneWidget);
await controller.close();
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment