mirror of
https://github.com/flutter/samples.git
synced 2026-03-29 07:41:41 +00:00
Add flutter_web samples (#75)
This commit is contained in:
committed by
Andrew Brogdon
parent
42f2dce01b
commit
3fe927cb29
116
web/charts/flutter/test/behaviors/legend/legend_layout_test.dart
Normal file
116
web/charts/flutter/test/behaviors/legend/legend_layout_test.dart
Normal file
@@ -0,0 +1,116 @@
|
||||
// Copyright 2018 the Charts project authors. Please see the AUTHORS file
|
||||
// for details.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import 'package:flutter_web/material.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:test/test.dart';
|
||||
|
||||
import 'package:charts_flutter/src/behaviors/legend/legend_layout.dart';
|
||||
|
||||
class MockContext extends Mock implements BuildContext {}
|
||||
|
||||
void main() {
|
||||
BuildContext context;
|
||||
|
||||
setUp(() {
|
||||
context = new MockContext();
|
||||
});
|
||||
|
||||
group('TabularLegendLayoutBuilder', () {
|
||||
test('builds horizontally', () {
|
||||
final builder = new TabularLegendLayout.horizontalFirst();
|
||||
final widgets = <Widget>[new Text('1'), new Text('2'), new Text('3')];
|
||||
|
||||
final Table layout = builder.build(context, widgets);
|
||||
expect(layout.children.length, 1);
|
||||
expect(layout.children.first.children.length, 3);
|
||||
});
|
||||
|
||||
test('does not build extra columns if max columns exceed widget count', () {
|
||||
final builder =
|
||||
new TabularLegendLayout.horizontalFirst(desiredMaxColumns: 10);
|
||||
final widgets = <Widget>[new Text('1'), new Text('2'), new Text('3')];
|
||||
|
||||
final Table layout = builder.build(context, widgets);
|
||||
expect(layout.children.length, 1);
|
||||
expect(layout.children.first.children.length, 3);
|
||||
});
|
||||
|
||||
test('builds horizontally until max column exceeded', () {
|
||||
final builder =
|
||||
new TabularLegendLayout.horizontalFirst(desiredMaxColumns: 2);
|
||||
|
||||
final widgets = new List<Widget>.generate(
|
||||
7, (int index) => new Text(index.toString()));
|
||||
|
||||
final Table layout = builder.build(context, widgets);
|
||||
expect(layout.children.length, 4);
|
||||
|
||||
expect(layout.children[0].children[0], equals(widgets[0]));
|
||||
expect(layout.children[0].children[1], equals(widgets[1]));
|
||||
|
||||
expect(layout.children[1].children[0], equals(widgets[2]));
|
||||
expect(layout.children[1].children[1], equals(widgets[3]));
|
||||
|
||||
expect(layout.children[2].children[0], equals(widgets[4]));
|
||||
expect(layout.children[2].children[1], equals(widgets[5]));
|
||||
|
||||
expect(layout.children[3].children[0], equals(widgets[6]));
|
||||
});
|
||||
|
||||
test('builds vertically', () {
|
||||
final builder = new TabularLegendLayout.verticalFirst();
|
||||
final widgets = <Widget>[new Text('1'), new Text('2'), new Text('3')];
|
||||
|
||||
final Table layout = builder.build(context, widgets);
|
||||
expect(layout.children.length, 3);
|
||||
expect(layout.children[0].children.length, 1);
|
||||
expect(layout.children[1].children.length, 1);
|
||||
expect(layout.children[2].children.length, 1);
|
||||
});
|
||||
|
||||
test('does not build extra rows if max rows exceed widget count', () {
|
||||
final builder = new TabularLegendLayout.verticalFirst(desiredMaxRows: 10);
|
||||
final widgets = <Widget>[new Text('1'), new Text('2'), new Text('3')];
|
||||
|
||||
final Table layout = builder.build(context, widgets);
|
||||
expect(layout.children.length, 3);
|
||||
expect(layout.children[0].children.length, 1);
|
||||
expect(layout.children[1].children.length, 1);
|
||||
expect(layout.children[2].children.length, 1);
|
||||
});
|
||||
|
||||
test('builds vertically until max column exceeded', () {
|
||||
final builder = new TabularLegendLayout.verticalFirst(desiredMaxRows: 2);
|
||||
|
||||
final widgets = new List<Widget>.generate(
|
||||
7, (int index) => new Text(index.toString()));
|
||||
|
||||
final Table layout = builder.build(context, widgets);
|
||||
expect(layout.children.length, 2);
|
||||
|
||||
expect(layout.children[0].children[0], equals(widgets[0]));
|
||||
expect(layout.children[1].children[0], equals(widgets[1]));
|
||||
|
||||
expect(layout.children[0].children[1], equals(widgets[2]));
|
||||
expect(layout.children[1].children[1], equals(widgets[3]));
|
||||
|
||||
expect(layout.children[0].children[2], equals(widgets[4]));
|
||||
expect(layout.children[1].children[2], equals(widgets[5]));
|
||||
|
||||
expect(layout.children[0].children[3], equals(widgets[6]));
|
||||
});
|
||||
});
|
||||
}
|
||||
39
web/charts/flutter/test/text_element_test.dart
Normal file
39
web/charts/flutter/test/text_element_test.dart
Normal file
@@ -0,0 +1,39 @@
|
||||
// Copyright 2018 the Charts project authors. Please see the AUTHORS file
|
||||
// for details.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import 'package:flutter_web/material.dart' show BuildContext;
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:charts_flutter/src/graphics_factory.dart';
|
||||
import 'package:charts_flutter/src/text_element.dart';
|
||||
|
||||
class MockContext extends Mock implements BuildContext {}
|
||||
|
||||
class MockGraphicsFactoryHelper extends Mock implements GraphicsFactoryHelper {}
|
||||
|
||||
void main() {
|
||||
test('Text element gets assigned scale factor', () {
|
||||
final helper = new MockGraphicsFactoryHelper();
|
||||
when(helper.getTextScaleFactorOf(any)).thenReturn(3.0);
|
||||
final graphicsFactory =
|
||||
new GraphicsFactory(new MockContext(), helper: helper);
|
||||
|
||||
final textElement =
|
||||
graphicsFactory.createTextElement('test') as TextElement;
|
||||
|
||||
expect(textElement.text, equals('test'));
|
||||
expect(textElement.textScaleFactor, equals(3.0));
|
||||
});
|
||||
}
|
||||
128
web/charts/flutter/test/user_managed_state_test.dart
Normal file
128
web/charts/flutter/test/user_managed_state_test.dart
Normal file
@@ -0,0 +1,128 @@
|
||||
// Copyright 2018 the Charts project authors. Please see the AUTHORS file
|
||||
// for details.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import 'package:flutter_web/widgets.dart';
|
||||
import 'package:flutter_web_test/flutter_web_test.dart';
|
||||
|
||||
import 'package:charts_flutter/flutter.dart' as charts;
|
||||
|
||||
void main() {
|
||||
testWidgets('selection can be set programmatically',
|
||||
(WidgetTester tester) async {
|
||||
final onTapSelection =
|
||||
new charts.UserManagedSelectionModel<String>.fromConfig(
|
||||
selectedDataConfig: [
|
||||
new charts.SeriesDatumConfig<String>('Sales', '2016')
|
||||
]);
|
||||
|
||||
charts.SelectionModel<String> currentSelectionModel;
|
||||
|
||||
void selectionChangedListener(charts.SelectionModel<String> model) {
|
||||
currentSelectionModel = model;
|
||||
}
|
||||
|
||||
final testChart = new TestChart(selectionChangedListener, onTapSelection);
|
||||
|
||||
await tester.pumpWidget(testChart);
|
||||
|
||||
expect(currentSelectionModel, isNull);
|
||||
|
||||
await tester.tap(find.byType(charts.BarChart));
|
||||
|
||||
await tester.pump();
|
||||
|
||||
expect(currentSelectionModel.selectedDatum, hasLength(1));
|
||||
final selectedDatum =
|
||||
currentSelectionModel.selectedDatum.first.datum as OrdinalSales;
|
||||
expect(selectedDatum.year, equals('2016'));
|
||||
expect(selectedDatum.sales, equals(100));
|
||||
expect(currentSelectionModel.selectedSeries, hasLength(1));
|
||||
expect(currentSelectionModel.selectedSeries.first.id, equals('Sales'));
|
||||
});
|
||||
}
|
||||
|
||||
class TestChart extends StatefulWidget {
|
||||
final charts.SelectionModelListener<String> selectionChangedListener;
|
||||
final charts.UserManagedSelectionModel<String> onTapSelection;
|
||||
|
||||
TestChart(this.selectionChangedListener, this.onTapSelection);
|
||||
|
||||
@override
|
||||
TestChartState createState() {
|
||||
return new TestChartState(selectionChangedListener, onTapSelection);
|
||||
}
|
||||
}
|
||||
|
||||
class TestChartState extends State<TestChart> {
|
||||
final charts.SelectionModelListener<String> selectionChangedListener;
|
||||
final charts.UserManagedSelectionModel<String> onTapSelection;
|
||||
|
||||
final seriesList = _createSampleData();
|
||||
final myState = new charts.UserManagedState<String>();
|
||||
|
||||
TestChartState(this.selectionChangedListener, this.onTapSelection);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final chart = new charts.BarChart(
|
||||
seriesList,
|
||||
userManagedState: myState,
|
||||
selectionModels: [
|
||||
new charts.SelectionModelConfig(
|
||||
type: charts.SelectionModelType.info,
|
||||
changedListener: widget.selectionChangedListener)
|
||||
],
|
||||
// Disable animation and gesture for testing.
|
||||
animate: false, //widget.animate,
|
||||
defaultInteractions: false,
|
||||
);
|
||||
|
||||
return new GestureDetector(child: chart, onTap: handleOnTap);
|
||||
}
|
||||
|
||||
void handleOnTap() {
|
||||
setState(() {
|
||||
myState.selectionModels[charts.SelectionModelType.info] = onTapSelection;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Create one series with sample hard coded data.
|
||||
List<charts.Series<OrdinalSales, String>> _createSampleData() {
|
||||
final data = [
|
||||
new OrdinalSales('2014', 5),
|
||||
new OrdinalSales('2015', 25),
|
||||
new OrdinalSales('2016', 100),
|
||||
new OrdinalSales('2017', 75),
|
||||
];
|
||||
|
||||
return [
|
||||
new charts.Series<OrdinalSales, String>(
|
||||
id: 'Sales',
|
||||
colorFn: (_, __) => charts.MaterialPalette.blue.shadeDefault,
|
||||
domainFn: (OrdinalSales sales, _) => sales.year,
|
||||
measureFn: (OrdinalSales sales, _) => sales.sales,
|
||||
data: data,
|
||||
)
|
||||
];
|
||||
}
|
||||
|
||||
/// Sample ordinal data type.
|
||||
class OrdinalSales {
|
||||
final String year;
|
||||
final int sales;
|
||||
|
||||
OrdinalSales(this.year, this.sales);
|
||||
}
|
||||
548
web/charts/flutter/test/widget_layout_delegate_test.dart
Normal file
548
web/charts/flutter/test/widget_layout_delegate_test.dart
Normal file
@@ -0,0 +1,548 @@
|
||||
// Copyright 2018 the Charts project authors. Please see the AUTHORS file
|
||||
// for details.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
import 'dart:math' show Rectangle;
|
||||
import 'package:flutter_web/material.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:flutter_web_test/flutter_web_test.dart';
|
||||
|
||||
import 'package:charts_common/common.dart' as common
|
||||
show BehaviorPosition, InsideJustification, OutsideJustification;
|
||||
import 'package:charts_flutter/src/behaviors/chart_behavior.dart';
|
||||
import 'package:charts_flutter/src/widget_layout_delegate.dart';
|
||||
|
||||
const chartContainerLayoutID = 'chartContainer';
|
||||
|
||||
class MockBuildableBehavior extends Mock implements BuildableBehavior {}
|
||||
|
||||
void main() {
|
||||
group('widget layout test', () {
|
||||
final chartKey = new UniqueKey();
|
||||
final behaviorKey = new UniqueKey();
|
||||
final behaviorID = 'behavior';
|
||||
final totalSize = const Size(200.0, 100.0);
|
||||
final behaviorSize = const Size(50.0, 50.0);
|
||||
|
||||
/// Creates widget for testing.
|
||||
Widget createWidget(
|
||||
Size chartSize, Size behaviorSize, common.BehaviorPosition position,
|
||||
{common.OutsideJustification outsideJustification,
|
||||
common.InsideJustification insideJustification,
|
||||
Rectangle<int> drawAreaBounds,
|
||||
bool isRTL: false}) {
|
||||
// Create a mock buildable behavior that returns information about the
|
||||
// position and justification desired.
|
||||
final behavior = new MockBuildableBehavior();
|
||||
when(behavior.position).thenReturn(position);
|
||||
when(behavior.outsideJustification).thenReturn(outsideJustification);
|
||||
when(behavior.insideJustification).thenReturn(insideJustification);
|
||||
when(behavior.drawAreaBounds).thenReturn(drawAreaBounds);
|
||||
|
||||
// The 'chart' widget that expands to the full size allowed to test that
|
||||
// the behavior widget's size affects the size given to the chart.
|
||||
final chart = new LayoutId(
|
||||
key: chartKey, id: chartContainerLayoutID, child: new Container());
|
||||
|
||||
// A behavior widget
|
||||
final behaviorWidget = new LayoutId(
|
||||
key: behaviorKey,
|
||||
id: behaviorID,
|
||||
child: new SizedBox.fromSize(size: behaviorSize));
|
||||
|
||||
// Create a the widget that uses the layout delegate that is being tested.
|
||||
final layout = new CustomMultiChildLayout(
|
||||
delegate: new WidgetLayoutDelegate(
|
||||
chartContainerLayoutID, {behaviorID: behavior}, isRTL),
|
||||
children: [chart, behaviorWidget]);
|
||||
|
||||
final container = new Align(
|
||||
alignment: Alignment.topLeft,
|
||||
child: new Container(
|
||||
width: chartSize.width, height: chartSize.height, child: layout));
|
||||
|
||||
return container;
|
||||
}
|
||||
|
||||
// Verifies the expected results.
|
||||
void verifyResults(WidgetTester tester, Size expectedChartSize,
|
||||
Offset expectedChartOffset, Offset expectedBehaviorOffset) {
|
||||
final RenderBox chartBox = tester.firstRenderObject(find.byKey(chartKey));
|
||||
expect(chartBox.size, equals(expectedChartSize));
|
||||
|
||||
final chartOffset = chartBox.localToGlobal(Offset.zero);
|
||||
expect(chartOffset, equals(expectedChartOffset));
|
||||
|
||||
final RenderBox behaviorBox =
|
||||
tester.firstRenderObject(find.byKey(behaviorKey));
|
||||
final behaviorOffset = behaviorBox.localToGlobal(Offset.zero);
|
||||
expect(behaviorOffset, equals(expectedBehaviorOffset));
|
||||
}
|
||||
|
||||
testWidgets('Position top - start draw area justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.top;
|
||||
final outsideJustification = common.OutsideJustification.startDrawArea;
|
||||
final drawAreaBounds = const Rectangle<int>(25, 50, 150, 50);
|
||||
|
||||
// Behavior takes up 50 height, so 50 height remains for the chart.
|
||||
final expectedChartSize = const Size(200.0, 50.0);
|
||||
// Behavior is positioned on the top, so the chart is offset by 50.
|
||||
final expectedChartOffset = const Offset(0.0, 50.0);
|
||||
// Behavior is aligned to draw area
|
||||
final expectedBehaviorOffset = const Offset(25.0, 0.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('Position bottom - end draw area justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.bottom;
|
||||
final outsideJustification = common.OutsideJustification.endDrawArea;
|
||||
final drawAreaBounds = const Rectangle<int>(25, 0, 125, 50);
|
||||
|
||||
// Behavior takes up 50 height, so 50 height remains for the chart.
|
||||
final expectedChartSize = const Size(200.0, 50.0);
|
||||
// Behavior is positioned on the bottom, so the chart is offset by 0.
|
||||
final expectedChartOffset = const Offset(0.0, 0.0);
|
||||
// Behavior is aligned to draw area and offset to the bottom.
|
||||
final expectedBehaviorOffset = const Offset(100.0, 50.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('Position start - start draw area justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.start;
|
||||
final outsideJustification = common.OutsideJustification.startDrawArea;
|
||||
final drawAreaBounds = const Rectangle<int>(75, 25, 150, 50);
|
||||
|
||||
// Behavior takes up 50 width, so 150 width remains for the chart.
|
||||
final expectedChartSize = const Size(150.0, 100.0);
|
||||
// Behavior is positioned at the start (left) since this is NOT a RTL
|
||||
// so the chart is offset to the right by the behavior width of 50.
|
||||
final expectedChartOffset = const Offset(50.0, 0.0);
|
||||
// Behavior is aligned to draw area.
|
||||
final expectedBehaviorOffset = const Offset(0.0, 25.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('Position end - end draw area justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.end;
|
||||
final outsideJustification = common.OutsideJustification.endDrawArea;
|
||||
final drawAreaBounds = const Rectangle<int>(25, 25, 150, 50);
|
||||
|
||||
// Behavior takes up 50 width, so 150 width remains for the chart.
|
||||
final expectedChartSize = const Size(150.0, 100.0);
|
||||
// Behavior is positioned at the right (left) since this is NOT a RTL
|
||||
// so no offset for the chart.
|
||||
final expectedChartOffset = const Offset(0.0, 0.0);
|
||||
// Behavior is aligned to draw area and offset to the right of the
|
||||
// chart.
|
||||
final expectedBehaviorOffset = const Offset(150.0, 25.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('Position top - start justified', (WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.top;
|
||||
final outsideJustification = common.OutsideJustification.start;
|
||||
final drawAreaBounds = const Rectangle<int>(25, 50, 150, 50);
|
||||
|
||||
// Behavior takes up 50 height, so 50 height remains for the chart.
|
||||
final expectedChartSize = const Size(200.0, 50.0);
|
||||
// Behavior is positioned on the top, so the chart is offset by 50.
|
||||
final expectedChartOffset = const Offset(0.0, 50.0);
|
||||
// Behavior is aligned to the start, so no offset
|
||||
final expectedBehaviorOffset = const Offset(0.0, 0.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('Position top - end justified', (WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.top;
|
||||
final outsideJustification = common.OutsideJustification.end;
|
||||
final drawAreaBounds = const Rectangle<int>(25, 50, 150, 50);
|
||||
|
||||
// Behavior takes up 50 height, so 50 height remains for the chart.
|
||||
final expectedChartSize = const Size(200.0, 50.0);
|
||||
// Behavior is positioned on the top, so the chart is offset by 50.
|
||||
final expectedChartOffset = const Offset(0.0, 50.0);
|
||||
// Behavior is aligned to the end, so it is offset by total size minus
|
||||
// the behavior size.
|
||||
final expectedBehaviorOffset = const Offset(150.0, 0.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('Position start - start justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.start;
|
||||
final outsideJustification = common.OutsideJustification.start;
|
||||
final drawAreaBounds = const Rectangle<int>(75, 25, 150, 50);
|
||||
|
||||
// Behavior takes up 50 width, so 150 width remains for the chart.
|
||||
final expectedChartSize = const Size(150.0, 100.0);
|
||||
// Behavior is positioned at the start (left) since this is NOT a RTL
|
||||
// so the chart is offset to the right by the behavior width of 50.
|
||||
final expectedChartOffset = const Offset(50.0, 0.0);
|
||||
// No offset because it is start justified.
|
||||
final expectedBehaviorOffset = const Offset(0.0, 0.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('Position start - end justified', (WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.start;
|
||||
final outsideJustification = common.OutsideJustification.end;
|
||||
final drawAreaBounds = const Rectangle<int>(75, 25, 150, 50);
|
||||
|
||||
// Behavior takes up 50 width, so 150 width remains for the chart.
|
||||
final expectedChartSize = const Size(150.0, 100.0);
|
||||
// Behavior is positioned at the start (left) since this is NOT a RTL
|
||||
// so the chart is offset to the right by the behavior width of 50.
|
||||
final expectedChartOffset = const Offset(50.0, 0.0);
|
||||
// End justified, total height minus behavior height
|
||||
final expectedBehaviorOffset = const Offset(0.0, 50.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('Position inside - top start justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.inside;
|
||||
final insideJustification = common.InsideJustification.topStart;
|
||||
final drawAreaBounds = const Rectangle<int>(25, 25, 175, 75);
|
||||
|
||||
// Behavior is layered on top, chart uses the full size.
|
||||
final expectedChartSize = const Size(200.0, 100.0);
|
||||
// No offset since chart takes up full size.
|
||||
final expectedChartOffset = const Offset(0.0, 0.0);
|
||||
// Top start justified, no offset
|
||||
final expectedBehaviorOffset = const Offset(0.0, 0.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
insideJustification: insideJustification,
|
||||
drawAreaBounds: drawAreaBounds));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('Position inside - top end justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.inside;
|
||||
final insideJustification = common.InsideJustification.topEnd;
|
||||
final drawAreaBounds = const Rectangle<int>(25, 25, 175, 75);
|
||||
|
||||
// Behavior is layered on top, chart uses the full size.
|
||||
final expectedChartSize = const Size(200.0, 100.0);
|
||||
// No offset since chart takes up full size.
|
||||
final expectedChartOffset = const Offset(0.0, 0.0);
|
||||
// Offset to the top end
|
||||
final expectedBehaviorOffset = const Offset(150.0, 0.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
insideJustification: insideJustification,
|
||||
drawAreaBounds: drawAreaBounds));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('RTL - Position top - start draw area justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.top;
|
||||
final outsideJustification = common.OutsideJustification.startDrawArea;
|
||||
final drawAreaBounds = const Rectangle<int>(0, 50, 175, 50);
|
||||
|
||||
// Behavior takes up 50 height, so 50 height remains for the chart.
|
||||
final expectedChartSize = const Size(200.0, 50.0);
|
||||
// Behavior is positioned on the top, so the chart is offset by 50.
|
||||
final expectedChartOffset = const Offset(0.0, 50.0);
|
||||
// Behavior is aligned to start draw area, which is to the left in RTL
|
||||
final expectedBehaviorOffset = const Offset(125.0, 0.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds,
|
||||
isRTL: true));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('RTL - Position bottom - end draw area justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.bottom;
|
||||
final outsideJustification = common.OutsideJustification.endDrawArea;
|
||||
final drawAreaBounds = const Rectangle<int>(0, 0, 175, 50);
|
||||
|
||||
// Behavior takes up 50 height, so 50 height remains for the chart.
|
||||
final expectedChartSize = const Size(200.0, 50.0);
|
||||
// Behavior is positioned on the bottom, so the chart is offset by 0.
|
||||
final expectedChartOffset = const Offset(0.0, 0.0);
|
||||
// Behavior is aligned to end draw area (left) and offset to the bottom.
|
||||
final expectedBehaviorOffset = const Offset(0.0, 50.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds,
|
||||
isRTL: true));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('RTL - Position start - start draw area justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.start;
|
||||
final outsideJustification = common.OutsideJustification.startDrawArea;
|
||||
final drawAreaBounds = const Rectangle<int>(0, 25, 125, 75);
|
||||
|
||||
// Behavior takes up 50 width, so 150 width remains for the chart.
|
||||
final expectedChartSize = const Size(150.0, 100.0);
|
||||
// Chart is on the left, so no offset.
|
||||
final expectedChartOffset = const Offset(0.0, 0.0);
|
||||
// Behavior is positioned at the start (right) and start draw area.
|
||||
final expectedBehaviorOffset = const Offset(150.0, 25.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds,
|
||||
isRTL: true));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('RTL - Position end - end draw area justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.end;
|
||||
final outsideJustification = common.OutsideJustification.endDrawArea;
|
||||
final drawAreaBounds = const Rectangle<int>(75, 25, 125, 75);
|
||||
|
||||
// Behavior takes up 50 width, so 150 width remains for the chart.
|
||||
final expectedChartSize = const Size(150.0, 100.0);
|
||||
// Chart is to the left of the behavior because of RTL.
|
||||
final expectedChartOffset = const Offset(50.0, 0.0);
|
||||
// Behavior is aligned to end draw area.
|
||||
final expectedBehaviorOffset = const Offset(0.0, 50.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds,
|
||||
isRTL: true));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('RTL - Position top - start justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.top;
|
||||
final outsideJustification = common.OutsideJustification.start;
|
||||
final drawAreaBounds = const Rectangle<int>(25, 50, 150, 50);
|
||||
|
||||
// Behavior takes up 50 height, so 50 height remains for the chart.
|
||||
final expectedChartSize = const Size(200.0, 50.0);
|
||||
// Behavior is positioned on the top, so the chart is offset by 50.
|
||||
final expectedChartOffset = const Offset(0.0, 50.0);
|
||||
// Behavior is aligned to the end, offset by behavior size.
|
||||
final expectedBehaviorOffset = const Offset(150.0, 0.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds,
|
||||
isRTL: true));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('RTL - Position top - end justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.top;
|
||||
final outsideJustification = common.OutsideJustification.end;
|
||||
final drawAreaBounds = const Rectangle<int>(25, 50, 150, 50);
|
||||
|
||||
// Behavior takes up 50 height, so 50 height remains for the chart.
|
||||
final expectedChartSize = const Size(200.0, 50.0);
|
||||
// Behavior is positioned on the top, so the chart is offset by 50.
|
||||
final expectedChartOffset = const Offset(0.0, 50.0);
|
||||
// Behavior is aligned to the end, no offset.
|
||||
final expectedBehaviorOffset = const Offset(0.0, 0.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds,
|
||||
isRTL: true));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('RTL - Position start - start justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.start;
|
||||
final outsideJustification = common.OutsideJustification.start;
|
||||
final drawAreaBounds = const Rectangle<int>(75, 25, 150, 50);
|
||||
|
||||
// Behavior takes up 50 width, so 150 width remains for the chart.
|
||||
final expectedChartSize = const Size(150.0, 100.0);
|
||||
// Behavior is positioned at the right since this is RTL so the chart is
|
||||
// has no offset.
|
||||
final expectedChartOffset = const Offset(0.0, 0.0);
|
||||
// No offset because it is start justified.
|
||||
final expectedBehaviorOffset = const Offset(150.0, 0.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds,
|
||||
isRTL: true));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('RTL - Position start - end justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.start;
|
||||
final outsideJustification = common.OutsideJustification.end;
|
||||
final drawAreaBounds = const Rectangle<int>(75, 25, 150, 50);
|
||||
|
||||
// Behavior takes up 50 width, so 150 width remains for the chart.
|
||||
final expectedChartSize = const Size(150.0, 100.0);
|
||||
// Behavior is positioned at the right since this is RTL so the chart is
|
||||
// has no offset.
|
||||
final expectedChartOffset = const Offset(0.0, 0.0);
|
||||
// End justified, total height minus behavior height
|
||||
final expectedBehaviorOffset = const Offset(150.0, 50.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
outsideJustification: outsideJustification,
|
||||
drawAreaBounds: drawAreaBounds,
|
||||
isRTL: true));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('RTL - Position inside - top start justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.inside;
|
||||
final insideJustification = common.InsideJustification.topStart;
|
||||
final drawAreaBounds = const Rectangle<int>(25, 25, 175, 75);
|
||||
|
||||
// Behavior is layered on top, chart uses the full size.
|
||||
final expectedChartSize = const Size(200.0, 100.0);
|
||||
// No offset since chart takes up full size.
|
||||
final expectedChartOffset = const Offset(0.0, 0.0);
|
||||
// Offset to the right
|
||||
final expectedBehaviorOffset = const Offset(150.0, 0.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
insideJustification: insideJustification,
|
||||
drawAreaBounds: drawAreaBounds,
|
||||
isRTL: true));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
|
||||
testWidgets('RTL - Position inside - top end justified',
|
||||
(WidgetTester tester) async {
|
||||
final behaviorPosition = common.BehaviorPosition.inside;
|
||||
final insideJustification = common.InsideJustification.topEnd;
|
||||
final drawAreaBounds = const Rectangle<int>(25, 25, 175, 75);
|
||||
|
||||
// Behavior is layered on top, chart uses the full size.
|
||||
final expectedChartSize = const Size(200.0, 100.0);
|
||||
// No offset since chart takes up full size.
|
||||
final expectedChartOffset = const Offset(0.0, 0.0);
|
||||
// No offset, since end is to the left.
|
||||
final expectedBehaviorOffset = const Offset(0.0, 0.0);
|
||||
|
||||
await tester.pumpWidget(createWidget(
|
||||
totalSize, behaviorSize, behaviorPosition,
|
||||
insideJustification: insideJustification,
|
||||
drawAreaBounds: drawAreaBounds,
|
||||
isRTL: true));
|
||||
|
||||
verifyResults(tester, expectedChartSize, expectedChartOffset,
|
||||
expectedBehaviorOffset);
|
||||
});
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user