Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
fluttertpc_get
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
Jonny Borges
2022-01-03 11:39:07 -0300
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
0963bae13de6f8d03c8cdbf10371c4b0d4a28e7c
0963bae1
1 parent
74a5433b
Get.replace on tests
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
34 additions
and
76 deletions
example/test/main_test.dart
example/test/widget_test.dart
example/test/main_test.dart
View file @
0963bae
import
'dart:io'
;
import
'dart:math'
;
import
'package:flutter/material.dart'
;
import
'package:flutter_test/flutter_test.dart'
;
...
...
@@ -11,28 +10,29 @@ import 'package:get_demo/pages/home/presentation/controllers/home_controller.dar
// import 'package:get_test/get_test.dart';
import
'package:matcher/matcher.dart'
as
m
;
class
MockRepository
implements
IHomeRepository
{
class
MockRepository
Success
implements
IHomeRepository
{
@override
Future
<
CasesModel
>
getCases
()
async
{
await
Future
.
delayed
(
Duration
(
milliseconds:
100
));
if
(
Random
().
nextBool
())
{
return
CasesModel
(
global:
Global
(
totalDeaths:
100
,
totalConfirmed:
200
,
date:
DateTime
.
now
(),
newConfirmed:
0
,
newDeaths:
0
,
newRecovered:
0
,
totalRecovered:
0
),
countries:
[],
date:
DateTime
.
now
(),
id:
''
,
message:
''
,
);
}
return
CasesModel
(
global:
Global
(
totalDeaths:
100
,
totalConfirmed:
200
,
date:
DateTime
.
now
(),
newConfirmed:
0
,
newDeaths:
0
,
newRecovered:
0
,
totalRecovered:
0
),
countries:
[],
date:
DateTime
.
now
(),
id:
''
,
message:
''
,
);
}
}
class
MockRepositoryFailure
implements
IHomeRepository
{
@override
Future
<
CasesModel
>
getCases
()
async
{
return
Future
<
CasesModel
>.
error
(
'error'
);
}
}
...
...
@@ -41,28 +41,18 @@ void main() {
WidgetsFlutterBinding
.
ensureInitialized
();
setUpAll
(()
=>
HttpOverrides
.
global
=
null
);
final
binding
=
BindingsBuilder
(()
{
Get
.
lazyPut
<
IHomeRepository
>(()
=>
MockRepository
());
Get
.
lazyPut
<
IHomeRepository
>(()
=>
MockRepository
Success
());
Get
.
lazyPut
<
HomeController
>(
()
=>
HomeController
(
homeRepository:
Get
.
find
()));
()
=>
HomeController
(
homeRepository:
Get
.
find
()),
);
});
test
(
'Test Binding'
,
()
{
expect
(
Get
.
isPrepared
<
HomeController
>(),
false
);
expect
(
Get
.
isPrepared
<
IHomeRepository
>(),
false
);
/// test you Binding class with BindingsBuilder
binding
.
builder
();
expect
(
Get
.
isPrepared
<
HomeController
>(),
true
);
expect
(
Get
.
isPrepared
<
IHomeRepository
>(),
true
);
Get
.
reset
();
});
test
(
'Test Controller'
,
()
async
{
/// Controller can't be on memory
expect
(()
=>
Get
.
find
<
HomeController
>(),
throwsA
(
m
.
TypeMatcher
<
String
>()));
expect
(()
=>
Get
.
find
<
HomeController
>(
tag:
'success'
),
throwsA
(
m
.
TypeMatcher
<
String
>()));
/// b
uild Binding
/// b
inding will put the controller on memory
binding
.
builder
();
/// recover your controller
...
...
@@ -77,24 +67,15 @@ void main() {
/// await time request
await
Future
.
delayed
(
Duration
(
milliseconds:
100
));
if
(
controller
.
status
.
isError
)
{
expect
(
controller
.
state
,
null
);
}
if
(
controller
.
status
.
isSuccess
)
{
expect
(
controller
.
state
.
global
.
totalDeaths
,
100
);
expect
(
controller
.
state
.
global
.
totalConfirmed
,
200
);
}
});
/// test if status is success
expect
(
controller
.
status
.
isSuccess
,
true
);
expect
(
controller
.
state
.
global
.
totalDeaths
,
100
);
expect
(
controller
.
state
.
global
.
totalConfirmed
,
200
);
test
(
'ever'
,
()
async
{
final
count
=
''
.
obs
;
var
result
=
''
;
ever
<
String
>(
count
,
(
value
)
{
result
=
value
;
});
count
.
value
=
'1'
;
expect
(
'1'
,
result
);
/// test if status is error
Get
.
lazyReplace
<
IHomeRepository
>(()
=>
MockRepositoryFailure
());
expect
(
controller
.
status
.
isError
,
true
);
expect
(
controller
.
state
,
null
);
});
/// Tests with GetTests
...
...
@@ -151,26 +132,3 @@ void main() {
},
);*/
}
class
Controller
extends
GetxController
{
final
count
=
0
.
obs
;
void
increment
()
=>
count
.
value
++;
@override
void
onInit
()
{
print
(
'inittt'
);
super
.
onInit
();
}
@override
void
onReady
()
{
print
(
'onReady'
);
super
.
onReady
();
}
@override
void
onClose
()
{
super
.
onClose
();
print
(
'onClose'
);
}
}
...
...
example/test/widget_test.dart
0 → 100644
View file @
0963bae
Please
register
or
login
to post a comment