Improve test coverage for material.dart (#4776)
Previously these widget had zero test coverage. Also, improve the coverage tooling Mac.
This commit is contained in:
33
packages/flutter/test/material/chip_test.dart
Normal file
33
packages/flutter/test/material/chip_test.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Chip control test', (WidgetTester tester) async {
|
||||
bool didDeleteChip = false;
|
||||
await tester.pumpWidget(
|
||||
new MaterialApp(
|
||||
home: new Material(
|
||||
child: new Center(
|
||||
child: new Chip(
|
||||
avatar: new CircleAvatar(
|
||||
child: new Text('C')
|
||||
),
|
||||
label: new Text('Chip'),
|
||||
onDeleted: () {
|
||||
didDeleteChip = true;
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
expect(didDeleteChip, isFalse);
|
||||
await tester.tap(find.byType(Tooltip));
|
||||
expect(didDeleteChip, isTrue);
|
||||
});
|
||||
}
|
||||
14
packages/flutter/test/material/divider_test.dart
Normal file
14
packages/flutter/test/material/divider_test.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Divider control test', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(new Center(child: new Divider()));
|
||||
RenderBox box = tester.firstRenderObject(find.byType(Divider));
|
||||
expect(box.size.height, 15.0);
|
||||
});
|
||||
}
|
||||
35
packages/flutter/test/material/drawer_test.dart
Normal file
35
packages/flutter/test/material/drawer_test.dart
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Drawer control test', (WidgetTester tester) async {
|
||||
await tester.pumpWidget(
|
||||
new Scaffold(
|
||||
drawer: new Drawer(
|
||||
child: new Block(
|
||||
children: <Widget>[
|
||||
new DrawerHeader(
|
||||
content: new Text('header')
|
||||
),
|
||||
new DrawerItem(
|
||||
icon: new Icon(Icons.archive),
|
||||
child: new Text('Archive')
|
||||
)
|
||||
]
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
expect(find.text('Archive'), findsNothing);
|
||||
ScaffoldState state = tester.firstState(find.byType(Scaffold));
|
||||
state.openDrawer();
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(seconds: 1));
|
||||
expect(find.text('Archive'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('Floating Action Button control test', (WidgetTester tester) async {
|
||||
bool didPressButton = false;
|
||||
await tester.pumpWidget(
|
||||
new Center(
|
||||
child: new FloatingActionButton(
|
||||
onPressed: () {
|
||||
didPressButton = true;
|
||||
},
|
||||
child: new Icon(Icons.add)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
expect(didPressButton, isFalse);
|
||||
await tester.tap(find.byType(Icon));
|
||||
expect(didPressButton, isTrue);
|
||||
});
|
||||
}
|
||||
14
packages/flutter/test/material/icon_data_test.dart
Normal file
14
packages/flutter/test/material/icon_data_test.dart
Normal file
@@ -0,0 +1,14 @@
|
||||
// Copyright 2016 The Chromium Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('IconData object test', (WidgetTester tester) async {
|
||||
expect(Icons.account_balance, isNot(equals(Icons.account_box)));
|
||||
expect(Icons.account_balance.hashCode, isNot(equals(Icons.account_box.hashCode)));
|
||||
expect(Icons.account_balance, hasOneLineDescription);
|
||||
});
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class TestCommand extends FlutterCommand {
|
||||
defaultsTo: false,
|
||||
negatable: false,
|
||||
help: 'Whether to merge converage data with "coverage/lcov.base.info". '
|
||||
'Implies collecting coverage data. (Linux only)'
|
||||
'Implies collecting coverage data. (Requires lcov)'
|
||||
);
|
||||
argParser.addOption('coverage-path',
|
||||
defaultsTo: 'coverage/lcov.info',
|
||||
@@ -95,6 +95,8 @@ class TestCommand extends FlutterCommand {
|
||||
Status status = logger.startProgress('Collecting coverage information...');
|
||||
String coverageData = await collector.finalizeCoverage();
|
||||
status.stop(showElapsedTime: true);
|
||||
if (coverageData == null)
|
||||
return false;
|
||||
|
||||
String coveragePath = argResults['coverage-path'];
|
||||
File coverageFile = new File(coveragePath)
|
||||
@@ -118,10 +120,12 @@ class TestCommand extends FlutterCommand {
|
||||
}
|
||||
|
||||
if (os.which('lcov') == null) {
|
||||
printError(
|
||||
'Missing "lcov" tool. Unable to merge coverage data.\n'
|
||||
'Consider running "sudo apt-get install lcov".'
|
||||
);
|
||||
String installMessage = 'Please install lcov.';
|
||||
if (os.isLinux)
|
||||
installMessage = 'Consider running "sudo apt-get install lcov".';
|
||||
else if (os.isMacOS)
|
||||
installMessage = 'Consider running "brew install lcov".';
|
||||
printError('Missing "lcov" tool. Unable to merge coverage data.\n$installMessage');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ class CoverageCollector {
|
||||
assert(enabled);
|
||||
await finishPendingJobs();
|
||||
printTrace('formating coverage data');
|
||||
if (_globalHitmap == null)
|
||||
return null;
|
||||
Resolver resolver = new Resolver(packagesPath: PackageMap.globalPackagesPath);
|
||||
LcovFormatter formater = new LcovFormatter(resolver);
|
||||
String packagePath = Directory.current.path;
|
||||
|
||||
Reference in New Issue
Block a user