refactor(QueryBowl): query bowl logic as a separate class instead of a stateful widget

feat: add QueryCache class for storing, updating, removing all the query/mutation/infiniteQueries
refactor(test): update tests according to new query bowl refactor
refactor(fl_query_hooks): update the hooks according to new query bowl refactor
This commit is contained in:
Kingkor Roy Tirtho
2022-09-22 22:03:28 +06:00
parent f435f101c4
commit 2b835505a3
22 changed files with 804 additions and 733 deletions
+193 -170
View File
@@ -1,18 +1,14 @@
// Mocks generated by Mockito 5.2.0 from annotations
// Mocks generated by Mockito 5.3.0 from annotations
// in fl_query/test/query_test.dart.
// Do not manually edit this file.
import 'dart:async' as _i7;
// ignore_for_file: no_leading_underscores_for_library_prefixes
import 'dart:async' as _i4;
import 'package:connectivity_plus/connectivity_plus.dart' as _i11;
import 'package:fl_query/src/models/mutation_job.dart' as _i9;
import 'package:fl_query/src/models/query_job.dart' as _i8;
import 'package:fl_query/src/mutation.dart' as _i4;
import 'package:fl_query/src/query.dart' as _i3;
import 'package:fl_query/src/query_bowl.dart' as _i6;
import 'package:flutter/foundation.dart' as _i5;
import 'package:flutter/rendering.dart' as _i10;
import 'package:flutter/widgets.dart' as _i2;
import 'package:connectivity_plus/connectivity_plus.dart' as _i6;
import 'package:fl_query/fl_query.dart' as _i3;
import 'package:fl_query/src/query_cache.dart' as _i2;
import 'package:flutter/cupertino.dart' as _i5;
import 'package:mockito/mockito.dart' as _i1;
// ignore_for_file: type=lint
@@ -24,71 +20,92 @@ import 'package:mockito/mockito.dart' as _i1;
// ignore_for_file: prefer_const_constructors
// ignore_for_file: unnecessary_parenthesis
// ignore_for_file: camel_case_types
// ignore_for_file: subtype_of_sealed_class
class _FakeDuration_0 extends _i1.Fake implements Duration {}
class _FakeWidget_1 extends _i1.Fake implements _i2.Widget {
@override
String toString({_i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.info}) =>
super.toString();
class _FakeDuration_0 extends _i1.SmartFake implements Duration {
_FakeDuration_0(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeQuery_2<T extends Object, Outside> extends _i1.Fake
implements _i3.Query<T, Outside> {}
class _FakeMutation_3<T extends Object, V> extends _i1.Fake
implements _i4.Mutation<T, V> {}
class _FakeInheritedElement_4 extends _i1.Fake implements _i2.InheritedElement {
@override
String toString({_i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.info}) =>
super.toString();
class _FakeQueryCache_1 extends _i1.SmartFake implements _i2.QueryCache {
_FakeQueryCache_1(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeDiagnosticsNode_5 extends _i1.Fake implements _i2.DiagnosticsNode {
@override
String toString(
{_i5.TextTreeConfiguration? parentConfiguration,
_i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.info}) =>
super.toString();
class _FakeQuery_2<T extends Object, Outside> extends _i1.SmartFake
implements _i3.Query<T, Outside> {
_FakeQuery_2(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeObject_6 extends _i1.Fake implements Object {}
class _FakeInfiniteQuery_3<T extends Object, Outside, PageParam extends Object>
extends _i1.SmartFake implements _i3.InfiniteQuery<T, Outside, PageParam> {
_FakeInfiniteQuery_3(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeMutation_4<T extends Object, V> extends _i1.SmartFake
implements _i3.Mutation<T, V> {
_FakeMutation_4(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
class _FakeObject_5 extends _i1.SmartFake implements Object {
_FakeObject_5(Object parent, Invocation parentInvocation)
: super(parent, parentInvocation);
}
/// A class which mocks [QueryBowl].
///
/// See the documentation for Mockito's code generation for more information.
class MockQueryBowl extends _i1.Mock implements _i6.QueryBowl {
class MockQueryBowl extends _i1.Mock implements _i3.QueryBowl {
MockQueryBowl() {
_i1.throwOnMissingStub(this);
}
@override
Duration get staleTime => (super.noSuchMethod(Invocation.getter(#staleTime),
returnValue: _FakeDuration_0()) as Duration);
@override
Duration get cacheTime => (super.noSuchMethod(Invocation.getter(#cacheTime),
returnValue: _FakeDuration_0()) as Duration);
returnValue: _FakeDuration_0(this, Invocation.getter(#staleTime)))
as Duration);
@override
bool get refetchOnMount => (super
.noSuchMethod(Invocation.getter(#refetchOnMount), returnValue: false)
as bool);
@override
bool get refetchOnWindowFocus =>
(super.noSuchMethod(Invocation.getter(#refetchOnWindowFocus),
returnValue: false) as bool);
@override
bool get refetchOnApplicationResume =>
(super.noSuchMethod(Invocation.getter(#refetchOnApplicationResume),
returnValue: false) as bool);
@override
bool get refetchOnReconnect =>
(super.noSuchMethod(Invocation.getter(#refetchOnReconnect),
returnValue: false) as bool);
@override
Duration get refetchOnReconnectDelay =>
(super.noSuchMethod(Invocation.getter(#refetchOnReconnectDelay),
returnValue: _FakeDuration_0(
this, Invocation.getter(#refetchOnReconnectDelay))) as Duration);
@override
bool get refetchOnExternalDataChange =>
(super.noSuchMethod(Invocation.getter(#refetchOnExternalDataChange),
returnValue: false) as bool);
@override
int Function(List<String>) get removeQueries =>
(super.noSuchMethod(Invocation.getter(#removeQueries),
returnValue: (List<String> __p0) => 0) as int Function(List<String>));
Duration get refetchInterval =>
(super.noSuchMethod(Invocation.getter(#refetchInterval),
returnValue:
_FakeDuration_0(this, Invocation.getter(#refetchInterval)))
as Duration);
@override
void Function() get clear =>
(super.noSuchMethod(Invocation.getter(#clear), returnValue: () {}) as void
Function());
_i2.QueryCache get cache => (super.noSuchMethod(Invocation.getter(#cache),
returnValue: _FakeQueryCache_1(this, Invocation.getter(#cache)))
as _i2.QueryCache);
@override
set cache(_i2.QueryCache? _cache) =>
super.noSuchMethod(Invocation.setter(#cache, _cache),
returnValueForMissingStub: null);
@override
int get isFetching =>
(super.noSuchMethod(Invocation.getter(#isFetching), returnValue: 0)
@@ -98,38 +115,73 @@ class MockQueryBowl extends _i1.Mock implements _i6.QueryBowl {
(super.noSuchMethod(Invocation.getter(#isMutating), returnValue: 0)
as int);
@override
_i2.Widget get child => (super.noSuchMethod(Invocation.getter(#child),
returnValue: _FakeWidget_1()) as _i2.Widget);
void onQueriesUpdate<T extends Object, Outside>(
void Function(_i3.Query<T, Outside>)? listener) =>
super.noSuchMethod(Invocation.method(#onQueriesUpdate, [listener]),
returnValueForMissingStub: null);
@override
_i7.Future<T?> prefetchQuery<T extends Object, Outside>(
_i8.QueryJob<T, Outside>? options,
{Outside? externalData}) =>
(super.noSuchMethod(
Invocation.method(
#prefetchQuery, [options], {#externalData: externalData}),
returnValue: Future<T?>.value()) as _i7.Future<T?>);
void onMutationsUpdate<T extends Object, Outside>(
void Function(_i3.Mutation<T, Outside>)? listener) =>
super.noSuchMethod(Invocation.method(#onMutationsUpdate, [listener]),
returnValueForMissingStub: null);
@override
_i7.Future<T?> fetchQuery<T extends Object, Outside>(
_i8.QueryJob<T, Outside>? options,
{Outside? externalData,
_i3.QueryListener<T>? onData,
_i3.QueryListener<dynamic>? onError,
_i2.ValueKey<String>? key}) =>
(super.noSuchMethod(
Invocation.method(#fetchQuery, [
options
], {
#externalData: externalData,
#onData: onData,
#onError: onError,
#key: key
}),
returnValue: Future<T?>.value()) as _i7.Future<T?>);
void onInfiniteQueriesUpdate<T extends Object, Outside,
PageParam extends Object>(
void Function(_i3.InfiniteQuery<T, Outside, PageParam>)? listener) =>
super.noSuchMethod(
Invocation.method(#onInfiniteQueriesUpdate, [listener]),
returnValueForMissingStub: null);
@override
_i3.InfiniteQuery<T, Outside, PageParam>?
getInfiniteQuery<T extends Object, Outside, PageParam extends Object>(
String? queryKey) =>
(super.noSuchMethod(Invocation.method(#getInfiniteQuery, [queryKey]))
as _i3.InfiniteQuery<T, Outside, PageParam>?);
@override
_i3.Query<T, Outside>? getQuery<T extends Object, Outside>(
String? queryKey) =>
(super.noSuchMethod(Invocation.method(#getQuery, [queryKey]))
as _i3.Query<T, Outside>?);
@override
_i3.Mutation<T, V>? getMutation<T extends Object, V>(String? mutationKey) =>
(super.noSuchMethod(Invocation.method(#getMutation, [mutationKey]))
as _i3.Mutation<T, V>?);
@override
void setQueryData<T extends Object, Outside>(
String? queryKey, _i3.QueryUpdateFunction<T>? updateCb) =>
super.noSuchMethod(Invocation.method(#setQueryData, [queryKey, updateCb]),
returnValueForMissingStub: null);
@override
void
setInfiniteQueryData<T extends Object, Outside, PageParam extends Object>(
String? queryKey,
_i3.QueryUpdateFunction<Map<PageParam, T?>>? updateCb) =>
super.noSuchMethod(
Invocation.method(#setInfiniteQueryData, [queryKey, updateCb]),
returnValueForMissingStub: null);
@override
void resetQueries(List<String>? queryKeys) =>
super.noSuchMethod(Invocation.method(#resetQueries, [queryKeys]),
returnValueForMissingStub: null);
@override
void invalidateQueries(List<String>? queryKeys) =>
super.noSuchMethod(Invocation.method(#invalidateQueries, [queryKeys]),
returnValueForMissingStub: null);
@override
_i4.Future<void> refetchQueries(List<String>? queryKeys) =>
(super.noSuchMethod(Invocation.method(#refetchQueries, [queryKeys]),
returnValue: _i4.Future<void>.value(),
returnValueForMissingStub: _i4.Future<void>.value())
as _i4.Future<void>);
@override
int removeQueries(List<String>? queryKeys) =>
(super.noSuchMethod(Invocation.method(#removeQueries, [queryKeys]),
returnValue: 0) as int);
@override
_i3.Query<T, Outside> addQuery<T extends Object, Outside>(
_i8.QueryJob<T, Outside>? queryJob,
_i3.QueryJob<T, Outside>? queryJob,
{Outside? externalData,
_i2.ValueKey<String>? key,
_i5.ValueKey<String>? key,
_i3.QueryListener<T>? onData,
_i3.QueryListener<dynamic>? onError,
T? previousData}) =>
@@ -143,134 +195,105 @@ class MockQueryBowl extends _i1.Mock implements _i6.QueryBowl {
#onError: onError,
#previousData: previousData
}),
returnValue: _FakeQuery_2<T, Outside>()) as _i3.Query<T, Outside>);
returnValue: _FakeQuery_2<T, Outside>(
this,
Invocation.method(#addQuery, [
queryJob
], {
#externalData: externalData,
#key: key,
#onData: onData,
#onError: onError,
#previousData: previousData
}))) as _i3.Query<T, Outside>);
@override
_i4.Mutation<T, V> addMutation<T extends Object, V>(
_i9.MutationJob<T, V>? mutationJob,
{_i4.MutationListener<T, V>? onData,
_i4.MutationListener<dynamic, V>? onError,
_i4.MutationListenerReturnable<V, dynamic>? onMutate,
_i2.ValueKey<String>? key}) =>
_i3.InfiniteQuery<T, Outside, PageParam> addInfiniteQuery<T extends Object, Outside, PageParam extends Object>(
_i3.InfiniteQueryJob<T, Outside, PageParam>? infiniteQueryJob,
{Outside? externalData,
_i5.ValueKey<String>? key,
_i3.InfiniteQueryListeners<T, PageParam>? onData,
_i3.InfiniteQueryListeners<dynamic, PageParam>? onError}) =>
(super.noSuchMethod(Invocation.method(#addInfiniteQuery, [infiniteQueryJob], {#externalData: externalData, #key: key, #onData: onData, #onError: onError}),
returnValue: _FakeInfiniteQuery_3<T, Outside, PageParam>(
this,
Invocation.method(#addInfiniteQuery, [
infiniteQueryJob
], {
#externalData: externalData,
#key: key,
#onData: onData,
#onError: onError
}))) as _i3.InfiniteQuery<T, Outside, PageParam>);
@override
_i3.Mutation<T, V> addMutation<T extends Object, V>(
_i3.MutationJob<T, V>? mutationJob,
{_i3.MutationListener<T, V>? onData,
_i3.MutationListener<dynamic, V>? onError,
_i3.MutationListenerReturnable<V, dynamic>? onMutate,
_i5.ValueKey<String>? key}) =>
(super
.noSuchMethod(Invocation.method(#addMutation, [mutationJob], {#onData: onData, #onError: onError, #onMutate: onMutate, #key: key}),
returnValue: _FakeMutation_4<T, V>(
this,
Invocation.method(#addMutation, [
mutationJob
], {
#onData: onData,
#onError: onError,
#onMutate: onMutate,
#key: key
}))) as _i3.Mutation<T, V>);
@override
_i4.Future<T?> fetchQuery<T extends Object, Outside>(
_i3.QueryJob<T, Outside>? options,
{Outside? externalData,
_i3.QueryListener<T>? onData,
_i3.QueryListener<dynamic>? onError,
_i5.ValueKey<String>? key}) =>
(super.noSuchMethod(
Invocation.method(#addMutation, [
mutationJob
Invocation.method(#fetchQuery, [
options
], {
#externalData: externalData,
#onData: onData,
#onError: onError,
#onMutate: onMutate,
#key: key
}),
returnValue: _FakeMutation_3<T, V>()) as _i4.Mutation<T, V>);
@override
_i3.Query<T, Outside>? getQuery<T extends Object, Outside>(
String? queryKey) =>
(super.noSuchMethod(Invocation.method(#getQuery, [queryKey]))
as _i3.Query<T, Outside>?);
@override
_i4.Mutation<T, V>? getMutation<T extends Object, V>(String? mutationKey) =>
(super.noSuchMethod(Invocation.method(#getMutation, [mutationKey]))
as _i4.Mutation<T, V>?);
@override
void setQueryData<T extends Object, Outside>(
String? queryKey, _i3.QueryUpdateFunction<T>? updateCb) =>
super.noSuchMethod(Invocation.method(#setQueryData, [queryKey, updateCb]),
returnValueForMissingStub: null);
@override
void resetQueries(List<String>? queryKeys) =>
super.noSuchMethod(Invocation.method(#resetQueries, [queryKeys]),
returnValueForMissingStub: null);
@override
void invalidateQueries(List<String>? queryKeys) =>
super.noSuchMethod(Invocation.method(#invalidateQueries, [queryKeys]),
returnValueForMissingStub: null);
@override
_i7.Future<void> refetchQueries(List<String>? queryKeys) =>
(super.noSuchMethod(Invocation.method(#refetchQueries, [queryKeys]),
returnValue: Future<void>.value(),
returnValueForMissingStub: Future<void>.value()) as _i7.Future<void>);
@override
bool updateShouldNotify(_i2.InheritedWidget? oldWidget) =>
(super.noSuchMethod(Invocation.method(#updateShouldNotify, [oldWidget]),
returnValue: false) as bool);
@override
_i2.InheritedElement createElement() =>
(super.noSuchMethod(Invocation.method(#createElement, []),
returnValue: _FakeInheritedElement_4()) as _i2.InheritedElement);
@override
String toStringShort() => (super
.noSuchMethod(Invocation.method(#toStringShort, []), returnValue: '')
as String);
@override
void debugFillProperties(_i10.DiagnosticPropertiesBuilder? properties) =>
super.noSuchMethod(Invocation.method(#debugFillProperties, [properties]),
returnValueForMissingStub: null);
@override
String toStringShallow(
{String? joiner = r', ',
_i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.debug}) =>
(super.noSuchMethod(
Invocation.method(
#toStringShallow, [], {#joiner: joiner, #minLevel: minLevel}),
returnValue: '') as String);
@override
String toStringDeep(
{String? prefixLineOne = r'',
String? prefixOtherLines,
_i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.debug}) =>
(super.noSuchMethod(
Invocation.method(#toStringDeep, [], {
#prefixLineOne: prefixLineOne,
#prefixOtherLines: prefixOtherLines,
#minLevel: minLevel
}),
returnValue: '') as String);
@override
_i2.DiagnosticsNode toDiagnosticsNode(
{String? name, _i5.DiagnosticsTreeStyle? style}) =>
(super.noSuchMethod(
Invocation.method(
#toDiagnosticsNode, [], {#name: name, #style: style}),
returnValue: _FakeDiagnosticsNode_5()) as _i2.DiagnosticsNode);
@override
List<_i2.DiagnosticsNode> debugDescribeChildren() =>
(super.noSuchMethod(Invocation.method(#debugDescribeChildren, []),
returnValue: <_i2.DiagnosticsNode>[]) as List<_i2.DiagnosticsNode>);
@override
String toString({_i2.DiagnosticLevel? minLevel = _i2.DiagnosticLevel.info}) =>
super.toString();
returnValue: _i4.Future<T?>.value()) as _i4.Future<T?>);
}
/// A class which mocks [Connectivity].
///
/// See the documentation for Mockito's code generation for more information.
class MockConnectivity extends _i1.Mock implements _i11.Connectivity {
class MockConnectivity extends _i1.Mock implements _i6.Connectivity {
MockConnectivity() {
_i1.throwOnMissingStub(this);
}
@override
_i7.Stream<_i11.ConnectivityResult> get onConnectivityChanged =>
_i4.Stream<_i6.ConnectivityResult> get onConnectivityChanged =>
(super.noSuchMethod(Invocation.getter(#onConnectivityChanged),
returnValue: Stream<_i11.ConnectivityResult>.empty())
as _i7.Stream<_i11.ConnectivityResult>);
returnValue: _i4.Stream<_i6.ConnectivityResult>.empty())
as _i4.Stream<_i6.ConnectivityResult>);
@override
_i7.Future<_i11.ConnectivityResult> checkConnectivity() =>
_i4.Future<_i6.ConnectivityResult> checkConnectivity() =>
(super.noSuchMethod(Invocation.method(#checkConnectivity, []),
returnValue: Future<_i11.ConnectivityResult>.value(
_i11.ConnectivityResult.bluetooth))
as _i7.Future<_i11.ConnectivityResult>);
returnValue: _i4.Future<_i6.ConnectivityResult>.value(
_i6.ConnectivityResult.bluetooth))
as _i4.Future<_i6.ConnectivityResult>);
}
/// A class which mocks [QueryJob].
///
/// See the documentation for Mockito's code generation for more information.
class MockQueryJobVoidObject extends _i1.Mock
implements _i8.QueryJob<Object, void> {
implements _i3.QueryJob<Object, void> {
@override
_i3.QueryTaskFunction<Object, void> get task =>
(super.noSuchMethod(Invocation.getter(#task),
returnValue: (String queryKey, void externalData) =>
Future<Object>.value(_FakeObject_6()))
_i4.Future<Object>.value(
_FakeObject_5(this, Invocation.getter(#task))))
as _i3.QueryTaskFunction<Object, void>);
@override
set task(_i3.QueryTaskFunction<Object, void>? _task) =>