Skip to content

Commit

Permalink
fix: test suite (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
erickzanardo authored Mar 11, 2024
1 parent 8c30a87 commit 301acdc
Show file tree
Hide file tree
Showing 17 changed files with 301 additions and 238 deletions.
4 changes: 2 additions & 2 deletions lib/src/widgets/dashbook_icon.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class DashbookIcon extends StatelessWidget {
required this.icon,
required this.onClick,
required this.tooltip,
Key? key,
}) : super(key: key);
super.key,
});

@override
Widget build(BuildContext context) {
Expand Down
5 changes: 0 additions & 5 deletions lib/src/widgets/device_settings_container.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ class _DeviceSettingsContainerState extends State<DeviceSettingsContainer> {
final _formKey = GlobalKey<FormState>();
bool _isCustom = false;

@override
void initState() {
super.initState();
}

void _setIsCustom(bool isCustom) {
setState(() {
_isCustom = isCustom;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class DeviceDropdown extends StatelessWidget {
...Devices.android.all,
...Devices.ios.all,
].map((DeviceInfo device) {
return DropdownMenuItem(
return DropdownMenuItem<DeviceInfo>(
value: device,
child: Text(device.name),
);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/side_bar_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class SideBarPanel extends StatelessWidget {
if (titleIcon != null)
Padding(
padding: const EdgeInsets.only(
left: 8,
left: 16,
),
child: Opacity(
opacity: showTitleIcon ? 1 : 0,
Expand Down
1 change: 1 addition & 0 deletions test/helpers/helpers.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'set_screen_size.dart';
10 changes: 10 additions & 0 deletions test/helpers/set_screen_size.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import 'dart:ui';

import 'package:flutter_test/flutter_test.dart';

extension WidgetTesterSetScreenSize on WidgetTester {
void setScreenSize(Size size) {
view.physicalSize = size;
addTearDown(view.resetPhysicalSize);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../helpers.dart';
import '../../helpers/helpers.dart';

Dashbook _getDashbookTextPropertyAnonymousBuilder() {
final dashbook = Dashbook();
Expand Down Expand Up @@ -45,6 +46,7 @@ void main() {
});

testWidgets('can change the property', (tester) async {
tester.setScreenSize(const Size(2000, 1000));
await tester.pumpDashbook(_getDashbookTextPropertyAnonymousBuilder());

await tester.openPropertiesPanel();
Expand Down
2 changes: 2 additions & 0 deletions test/properties/custom_propertis/custom_property_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../../helpers.dart';
import '../../helpers/helpers.dart';

Dashbook _getDashbookTextPropertyAnonymousBuilder() {
final dashbook = Dashbook();
Expand Down Expand Up @@ -31,6 +32,7 @@ void main() {
});

testWidgets('can change the property', (tester) async {
tester.setScreenSize(const Size(2000, 1000));
await tester.pumpDashbook(_getDashbookTextPropertyAnonymousBuilder());

await tester.openPropertiesPanel();
Expand Down
2 changes: 2 additions & 0 deletions test/properties/list_property_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../helpers.dart';
import '../helpers/helpers.dart';

Dashbook _getDashbook() {
final dashbook = Dashbook();
Expand Down Expand Up @@ -35,6 +36,7 @@ void main() {
});

testWidgets('can change the property', (tester) async {
tester.setScreenSize(const Size(2000, 1000));
await tester.pumpDashbook(_getDashbook());

await tester.openPropertiesPanel();
Expand Down
2 changes: 2 additions & 0 deletions test/properties/options_property_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../helpers.dart';
import '../helpers/helpers.dart';

Dashbook _getDashbook() {
final dashbook = Dashbook();
Expand Down Expand Up @@ -35,6 +36,7 @@ void main() {
});

testWidgets('can change the property', (tester) async {
tester.setScreenSize(const Size(2000, 1000));
await tester.pumpDashbook(_getDashbook());

await tester.openPropertiesPanel();
Expand Down
2 changes: 2 additions & 0 deletions test/properties/text_property_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../helpers.dart';
import '../helpers/helpers.dart';

Dashbook _getDashbook() {
final dashbook = Dashbook();
Expand Down Expand Up @@ -32,6 +33,7 @@ void main() {
});

testWidgets('can change the property', (tester) async {
tester.setScreenSize(const Size(2000, 1000));
await tester.pumpDashbook(_getDashbook());

await tester.openPropertiesPanel();
Expand Down
4 changes: 4 additions & 0 deletions test/widget/actions_list_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../helpers.dart';
import '../helpers/helpers.dart';

Dashbook _getDashbook() {
final dashbook = Dashbook();
Expand All @@ -30,6 +31,7 @@ void main() {
});

testWidgets('can open the actions list', (tester) async {
tester.setScreenSize(const Size(2000, 1000));
await tester.pumpDashbook(_getDashbook());

await tester.tap(find.byKey(kActionsIcon));
Expand All @@ -38,6 +40,7 @@ void main() {
});

testWidgets('can close the actions list', (tester) async {
tester.setScreenSize(const Size(2000, 1000));
await tester.pumpDashbook(_getDashbook());

await tester.tap(find.byKey(kActionsIcon));
Expand All @@ -50,6 +53,7 @@ void main() {
});

testWidgets('can tap an action', (tester) async {
tester.setScreenSize(const Size(2000, 1000));
await tester.pumpDashbook(_getDashbook());

await tester.tap(find.byKey(kActionsIcon));
Expand Down
2 changes: 2 additions & 0 deletions test/widget/chapter_info_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../helpers.dart';
import '../helpers/helpers.dart';

Dashbook _getDashbookWithIconInfo() {
final dashbook = Dashbook();
Expand Down Expand Up @@ -42,6 +43,7 @@ void main() {
testWidgets(
'show the info dialog when the icon is clicked',
(tester) async {
tester.setScreenSize(const Size(2000, 1000));
await tester.pumpDashbook(_getDashbookWithIconInfo());

await tester.tap(
Expand Down
7 changes: 7 additions & 0 deletions test/widget/device_dialog_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

import '../helpers.dart';
import '../helpers/helpers.dart';

void main() {
Dashbook _getDashbook({
Expand Down Expand Up @@ -36,6 +37,7 @@ void main() {

group('Device settings', () {
testWidgets('show select device settings', (tester) async {
tester.setScreenSize(const Size(2000, 1000));
await tester.pumpDashbook(_getDashbook());
await tester.tap(find.byKey(kDevicePreviewIcon));
await tester.pumpAndSettle();
Expand Down Expand Up @@ -77,6 +79,7 @@ void main() {
testWidgets(
'When click in Custom Device button, '
'should toggle to form to customize device info', (tester) async {
tester.setScreenSize(const Size(2000, 1000));
await tester.pumpDashbook(_getDashbook());
await tester.tap(find.byKey(kDevicePreviewIcon));
await tester.pumpAndSettle();
Expand Down Expand Up @@ -112,13 +115,16 @@ void main() {

testWidgets('Should customize a device info and return it', (tester) async {
DeviceSettingsData? settings;
tester.setScreenSize(const Size(2000, 1000));
await tester.pumpDashbook(
_getDashbook(
onDeviceSettingsChanged: (selected) async {
settings = selected;
},
),
);
await tester.pump();
await tester.pumpAndSettle();
await tester.tap(find.byKey(kDevicePreviewIcon));
await tester.pumpAndSettle();

Expand All @@ -135,6 +141,7 @@ void main() {
'1000',
);
}
await tester.ensureVisible(find.text('iOS'));
await tester.tap(find.text('iOS'));

await tester.drag(find.byType(Slider), const Offset(20, 0));
Expand Down
Loading

0 comments on commit 301acdc

Please sign in to comment.