-
Notifications
You must be signed in to change notification settings - Fork 320
Description
We'll want to write tests for many of our widgets. A number of our widgets refer to PerAccountStoreWidget.of(context)
to get their data, and we'll want to test many of those. So to do this, we'll need something a test can do to provide a PerAccountStoreWidget based on self-contained data chosen by the test.
I think the core of this will be what I mentioned in 882c8ae :
Widgets still hardcode the "live" GlobalStore, so we'll need
to make some further changes when we go to write tests for those
widgets.
That refers mainly to this line in the implementation of GlobalStoreWidget:
final store = await LiveGlobalStore.load();
I think the solution here will probably be to take inspiration from the "binding" concept in Flutter itself, as in WidgetsFlutterBinding vs. TestWidgetsFlutterBinding, and explained more at BindingBase. I wouldn't try to integrate directly into that system, I think, but build something small and analogous to it.
This would look something like:
abstract class DataBinding {
static DataBinding get instance => // …
Future<GlobalStore> loadGlobalStore();
}
class LiveDataBinding extends DataBinding {
static DataBinding ensureInitialized() {
// …
}
// …
}
and then
- the
main
function inlib/main.dart
callsLiveDataBinding.ensureInitialized()
before it callsrunApp
; - GlobalStoreWidget's implementation would say
final store = await DataBinding.instance.loadGlobalStore();
.
Meanwhile, in the test code, there'd be:
class TestDataBinding extends DataBinding // …
and our widget tests would call a TestDataBinding.ensureInitialized()
instead.
Or something like that. Will have to start writing the code and see where it takes us.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status