Commit 41d63035 authored by Adam Barth's avatar Adam Barth Committed by GitHub

Improve test coverage for material.dart (#4776)

Previously these widget had zero test coverage. Also, improve the
coverage tooling Mac.
parent 14f42a6a
// 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);
});
}
// 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);
});
}
// 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);
});
}
// 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);
});
}
// 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 { ...@@ -30,7 +30,7 @@ class TestCommand extends FlutterCommand {
defaultsTo: false, defaultsTo: false,
negatable: false, negatable: false,
help: 'Whether to merge converage data with "coverage/lcov.base.info". ' 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', argParser.addOption('coverage-path',
defaultsTo: 'coverage/lcov.info', defaultsTo: 'coverage/lcov.info',
...@@ -95,6 +95,8 @@ class TestCommand extends FlutterCommand { ...@@ -95,6 +95,8 @@ class TestCommand extends FlutterCommand {
Status status = logger.startProgress('Collecting coverage information...'); Status status = logger.startProgress('Collecting coverage information...');
String coverageData = await collector.finalizeCoverage(); String coverageData = await collector.finalizeCoverage();
status.stop(showElapsedTime: true); status.stop(showElapsedTime: true);
if (coverageData == null)
return false;
String coveragePath = argResults['coverage-path']; String coveragePath = argResults['coverage-path'];
File coverageFile = new File(coveragePath) File coverageFile = new File(coveragePath)
...@@ -118,10 +120,12 @@ class TestCommand extends FlutterCommand { ...@@ -118,10 +120,12 @@ class TestCommand extends FlutterCommand {
} }
if (os.which('lcov') == null) { if (os.which('lcov') == null) {
printError( String installMessage = 'Please install lcov.';
'Missing "lcov" tool. Unable to merge coverage data.\n' if (os.isLinux)
'Consider running "sudo apt-get install lcov".' 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; return false;
} }
......
...@@ -62,6 +62,8 @@ class CoverageCollector { ...@@ -62,6 +62,8 @@ class CoverageCollector {
assert(enabled); assert(enabled);
await finishPendingJobs(); await finishPendingJobs();
printTrace('formating coverage data'); printTrace('formating coverage data');
if (_globalHitmap == null)
return null;
Resolver resolver = new Resolver(packagesPath: PackageMap.globalPackagesPath); Resolver resolver = new Resolver(packagesPath: PackageMap.globalPackagesPath);
LcovFormatter formater = new LcovFormatter(resolver); LcovFormatter formater = new LcovFormatter(resolver);
String packagePath = Directory.current.path; String packagePath = Directory.current.path;
......
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