Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/integration_test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.9.3

* Set TestBindingEventSource to test for web integration_tests.

## 0.9.2+2

* Broaden the constraint on vm_service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
// tree, read text, and verify that the values of widget properties are correct.

import 'dart:html' as html;
import 'dart:js_util' as js_util;
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';

Expand All @@ -21,15 +23,74 @@ void main() {
// Trigger a frame.
await tester.pumpAndSettle();

final Finder finder = find.byKey(const Key('platform'));
final Text platformText = tester.widget(finder);

// Verify that platform is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) =>
widget is Text &&
widget.data
.startsWith('Platform: ${html.window.navigator.platform}\n'),
),
findsOneWidget,
);
expect(finder, findsOneWidget);
expect(platformText.data, 'Platform: ${html.window.navigator.platform}\n');
});

testWidgets('verify event dispatching works', (WidgetTester tester) async {
// Build our app and trigger a frame.
app.main();

// Trigger a frame.
await tester.pumpAndSettle();

final Finder finderButton = find.byKey(const Key('button'));
expect(finderButton, findsOneWidget);

final Offset offset = tester.getCenter(finderButton);

dispatchEventToMouseLocation((offset.dx).toInt(), (offset.dy).toInt());
await tester.pumpAndSettle();

final Finder finder = find.byKey(const Key('counter'));
final Text counter = tester.widget(finder);

// Verify that counter is clicked.
expect(finder, findsOneWidget);
expect(counter.data, '1');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, can we assert earlier that this is '0'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! I'll make the change thanks :)

});
}

void dispatchEventToMouseLocation(int mouseX, int mouseY) {
final html.EventTarget target =
html.document.elementFromPoint(mouseX, mouseY);

dispatchPointerEvent(target, 'pointerdown', <String, dynamic>{
'bubbles': true,
'cancelable': true,
'screenX': mouseX,
'screenY': mouseY,
'clientX': mouseX,
'clientY': mouseY,
});

dispatchPointerEvent(target, 'pointerup', <String, dynamic>{
'bubbles': true,
'cancelable': true,
'screenX': mouseX,
'screenY': mouseY,
'clientX': mouseX,
'clientY': mouseY,
});
}

html.PointerEvent dispatchPointerEvent(
html.EventTarget target, String type, Map<String, dynamic> args) {
final dynamic jsPointerEvent =
js_util.getProperty(html.window, 'PointerEvent');
final List<dynamic> eventArgs = <dynamic>[
type,
args,
];

final html.PointerEvent event = js_util.callConstructor(
jsPointerEvent, js_util.jsify(eventArgs) as List<dynamic>)
as html.PointerEvent;
target.dispatchEvent(event);

return event;
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,12 @@ void main() {
// Take a screenshot.
await binding.takeScreenshot('platform_name');

final Finder finder = find.byKey(const Key('platform'));
final Text platformText = tester.widget(finder);

// Verify that platform is retrieved.
expect(
find.byWidgetPredicate(
(Widget widget) =>
widget is Text &&
widget.data
.startsWith('Platform: ${html.window.navigator.platform}\n'),
),
findsOneWidget,
);
expect(finder, findsOneWidget);
expect(platformText, 'Platform: ${html.window.navigator.platform}\n');
});

testWidgets('verify screenshot', (WidgetTester tester) async {
Expand Down
37 changes: 35 additions & 2 deletions packages/integration_test/example/lib/my_web_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ class MyWebApp extends StatefulWidget {
}

class _MyWebAppState extends State<MyWebApp> {
int _counter = 0;

void _increment() {
setState(() {
_counter++;
});
}

@override
Widget build(BuildContext context) {
return MaterialApp(
Expand All @@ -19,8 +27,33 @@ class _MyWebAppState extends State<MyWebApp> {
title: const Text('Plugin example app'),
),
body: Center(
key: Key('mainapp'),
child: Text('Platform: ${html.window.navigator.platform}\n'),
child: Column(
children: [
Text(
'Platform: ${html.window.navigator.platform}\n',
key: Key('platform'),
),
Text(
'$_counter',
key: Key('counter'),
),
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
RaisedButton(
padding: const EdgeInsets.all(10.0),
onPressed: _increment,
key: Key('button'),
child:
const Text('Button!', style: TextStyle(fontSize: 20)),
),
],
),
)
],
),
),
),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/integration_test/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ publish_to: 'none'

environment:
sdk: ">=2.1.0 <3.0.0"
flutter: ">=1.6.7 <2.0.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"

dependencies:
flutter:
Expand Down
12 changes: 12 additions & 0 deletions packages/integration_test/lib/integration_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ class IntegrationTestWidgetsFlutterBinding extends LiveTestWidgetsFlutterBinding
};
}

@override
void handlePointerEvent(
PointerEvent pointerEvent, {
TestBindingEventSource source = TestBindingEventSource.device,
}) {
// TestBindingEventSource.device uses WidgerTester.dispatchEvent method
// vs TestBindingEventSource.test. Test uses RenderBindind.dispatch
// event. The former does not deliver the gesture but only compare
// matchers.
super.handlePointerEvent(pointerEvent, source: TestBindingEventSource.test);
}

// TODO(dnfield): Remove the ignore once we bump the minimum Flutter version
// ignore: override_on_non_overriding_member
@override
Expand Down
2 changes: 1 addition & 1 deletion packages/integration_test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: integration_test
description: Runs tests that use the flutter_test API as integration tests.
version: 0.9.2+2
version: 0.9.3
homepage: https://github.com/flutter/plugins/tree/master/packages/integration_test

environment:
Expand Down