Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
flutter_screenutil
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
Mounir Bouaiche
2023-06-17 02:19:03 +0100
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
e618385371e07738647b49a549ab2e70459e9174
e6183853
1 parent
e96ac610
Adding tests
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
160 additions
and
0 deletions
test/flutter_screenutil_test.dart
test/home.test.dart
test/flutter_screenutil_test.dart
0 → 100644
View file @
e618385
import
'package:flutter/material.dart'
;
import
'package:flutter_screenutil/flutter_screenutil.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
import
'home.test.dart'
;
void
main
(
)
{
const
smallerDeviceSize
=
Size
(
300
,
600
);
const
smallerDeviceData
=
MediaQueryData
(
size:
smallerDeviceSize
);
const
biggerDeviceSize
=
Size
(
500
,
900
);
const
biggerDeviceData
=
MediaQueryData
(
size:
biggerDeviceSize
);
const
uiSize
=
Size
(
470
,
740
);
group
(
'[Test calculations]'
,
()
{
test
(
'Test smaller size'
,
()
{
ScreenUtil
.
configure
(
data:
smallerDeviceData
,
designSize:
uiSize
,
minTextAdapt:
true
,
splitScreenMode:
false
,
);
expect
(
1
.
w
,
smallerDeviceSize
.
width
/
uiSize
.
width
);
expect
(
1
.
w
<
1
,
true
);
expect
(
1
.
h
,
smallerDeviceSize
.
height
/
uiSize
.
height
);
expect
(
1
.
h
<
1
,
true
);
});
test
(
'Test bigger size'
,
()
{
ScreenUtil
.
configure
(
data:
biggerDeviceData
,
designSize:
uiSize
,
minTextAdapt:
true
,
splitScreenMode:
false
,
);
expect
(
1
.
w
,
biggerDeviceSize
.
width
/
uiSize
.
width
);
expect
(
1
.
w
>
1
,
true
);
expect
(
1
.
h
,
biggerDeviceSize
.
height
/
uiSize
.
height
);
expect
(
1
.
h
>
1
,
true
);
});
});
group
(
'[Test overflow]'
,
()
{
testWidgets
(
'Test overflow width'
,
(
tester
)
async
{
await
tester
.
pumpWidget
(
ScreenUtilInit
(
designSize:
uiSize
,
child:
MaterialApp
(
home:
WidgetTest
(
width:
()
=>
uiSize
.
width
.
w
)),
));
// Wait until all widget rendered
await
tester
.
pumpAndSettle
();
// a Text widget must be present
expect
(
find
.
text
(
'Test'
),
findsOneWidget
);
});
testWidgets
(
'Test overflow height'
,
(
tester
)
async
{
await
tester
.
pumpWidget
(
ScreenUtilInit
(
designSize:
uiSize
,
child:
MaterialApp
(
home:
WidgetTest
(
height:
()
=>
uiSize
.
height
.
h
)),
));
// Wait until all widget rendered
await
tester
.
pumpAndSettle
();
// a Text widget must be present
expect
(
find
.
text
(
'Test'
),
findsOneWidget
);
});
});
testWidgets
(
'[Rebuilding]'
,
(
tester
)
async
{
final
textFieldKey
=
UniqueKey
();
final
buildCountNotifier
=
ValueNotifier
(
0
);
final
focusNode
=
FocusNode
();
Finder
textField
()
=>
find
.
byKey
(
textFieldKey
);
await
tester
.
pumpWidget
(
ScreenUtilInit
(
designSize:
uiSize
,
rebuildFactor:
RebuildFactors
.
always
,
child:
MaterialApp
(
home:
Scaffold
(
body:
Builder
(
builder:
(
context
)
{
buildCountNotifier
.
value
+=
1
;
assert
(
uiSize
.
width
.
w
==
MediaQuery
.
of
(
context
).
size
.
width
);
return
SizedBox
(
width:
1
.
sw
,
child:
Column
(
children:
[
ValueListenableBuilder
<
int
>(
valueListenable:
buildCountNotifier
,
builder:
(
_
,
count
,
__
)
=>
Text
(
'Built count:
$count
'
),
),
TextField
(
key:
textFieldKey
,
focusNode:
focusNode
,
),
],
),
);
},
),
),
),
));
await
tester
.
pumpAndSettle
();
expect
(
buildCountNotifier
.
value
,
1
);
expect
(
textField
(),
findsOneWidget
);
expect
(
focusNode
.
hasFocus
,
false
);
await
tester
.
tap
(
textField
()).
then
((
_
)
=>
tester
.
pumpAndSettle
());
expect
(
textField
(),
findsOneWidget
);
expect
(
focusNode
.
hasFocus
,
true
);
expect
(
buildCountNotifier
.
value
,
1
);
// Simulate keyboard
tester
.
view
.
viewInsets
=
FakeViewPadding
(
bottom:
20
);
await
tester
.
pumpAndSettle
();
expect
(
focusNode
.
hasFocus
,
true
);
expect
(
buildCountNotifier
.
value
,
1
);
});
}
...
...
test/home.test.dart
0 → 100644
View file @
e618385
import
'package:flutter/widgets.dart'
;
class
WidgetTest
extends
StatelessWidget
{
const
WidgetTest
({
super
.
key
,
this
.
width
=
_zero
,
this
.
height
=
_zero
,
});
final
double
Function
()
width
;
final
double
Function
()
height
;
@override
Widget
build
(
BuildContext
context
)
{
return
LayoutBuilder
(
builder:
(
_
,
c
)
{
final
w
=
width
(),
h
=
height
();
if
(
c
.
biggest
>=
Size
(
w
,
h
))
{
return
const
Text
(
'Test'
);
}
throw
Error
();
},
);
}
static
double
_zero
()
=>
0
;
}
...
...
Please
register
or
login
to post a comment