-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix defects by state finding helpers and improve code coverage
- Loading branch information
Showing
9 changed files
with
214 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,70 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:yonomi_device_widgets/providers/color_provider.dart'; | ||
import 'package:yonomi_platform_sdk/third_party/yonomi_graphql_schema/schema.docs.schema.gql.dart'; | ||
import 'package:yonomi_platform_sdk/yonomi-sdk.dart'; | ||
|
||
import '../mixins/color_testing.dart'; | ||
import '../mixins/device_testing.dart'; | ||
import 'color_provider_test.mocks.dart'; | ||
|
||
class BatteryLevelProviderTest with DeviceTesting, ColorTesting {} | ||
class GetDeviceDetailsMethod extends Mock { | ||
Future<Device> call(Request request, String id); | ||
} | ||
|
||
class SendSetColorActionMethod extends Mock { | ||
Future<void> call(Request request, String id, HSBColor hsbColor); | ||
} | ||
|
||
@GenerateMocks([GetDeviceDetailsMethod, SendSetColorActionMethod]) | ||
void main() { | ||
final colorTest = ColorProviderTest(); | ||
final defaultColorDevice = TestColorDevice( | ||
colorTest | ||
.device(id: 'aDeviceId', traits: [ColorTrait(HSBColor(130, 50, 50))]), | ||
colorTrait: ColorTrait(HSBColor(130, 50, 50))); | ||
; | ||
|
||
group('For ColorProvider', () { | ||
test("""When loading device data, we are notified that it is loading | ||
through isLoading.""", () async {}); | ||
test("""After successfully loading device data, should be in idle state | ||
when done.""", () async {}); | ||
test("""When an error occurs loading device data, we are notified | ||
an error occurred using isInErrorState and get | ||
an error message with getErrorMessage.""", () async {}); | ||
when done.""", () async { | ||
Request request = Request("", {}); | ||
String deviceId = 'aDeviceId'; | ||
|
||
final GetDeviceDetailsMethod mockDeviceDetailsMethod = | ||
colorTest.getMockDeviceDetailsMethod(request, deviceId); | ||
|
||
final colorProvider = await ColorProvider(request, deviceId, | ||
getDetails: mockDeviceDetailsMethod); | ||
|
||
expect(colorProvider.isLoading, equals(false), | ||
reason: 'is in loading state'); | ||
expect(colorProvider.isBusy, equals(false), reason: 'is in busy state'); | ||
expect(colorProvider.isInErrorState, equals(false), | ||
reason: 'is in error state'); | ||
expect(colorProvider.displayName, defaultColorDevice.displayName); | ||
expect(colorProvider.deviceDetail?.id, equals(deviceId)); | ||
expect(colorProvider.getColorTrait, isA<ColorTrait>()); | ||
expect(colorProvider.getColorState, isA<GHSBColorValueInput>()); | ||
}); | ||
|
||
}); | ||
} | ||
|
||
class ColorProviderTest with DeviceTesting, ColorTesting { | ||
MockGetDeviceDetailsMethod getMockDeviceDetailsMethod( | ||
Request request, String deviceId) { | ||
MockGetDeviceDetailsMethod mockDeviceDetailsMethod = | ||
MockGetDeviceDetailsMethod(); | ||
|
||
final device = TestColorDevice( | ||
this.device(id: deviceId, traits: [ColorTrait(HSBColor(130, 50, 50))]), | ||
colorTrait: ColorTrait(HSBColor(130, 50, 50))); | ||
|
||
when(mockDeviceDetailsMethod.call(request, deviceId)) | ||
.thenAnswer((_) => Future.value(device)); | ||
|
||
return mockDeviceDetailsMethod; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Mocks generated by Mockito 5.0.15 from annotations | ||
// in yonomi_device_widgets/test/providers/color_provider_test.dart. | ||
// Do not manually edit this file. | ||
|
||
import 'dart:async' as _i4; | ||
|
||
import 'package:mockito/mockito.dart' as _i1; | ||
import 'package:yonomi_platform_sdk/yonomi-sdk.dart' as _i2; | ||
|
||
import 'color_provider_test.dart' as _i3; | ||
|
||
// ignore_for_file: avoid_redundant_argument_values | ||
// ignore_for_file: avoid_setters_without_getters | ||
// ignore_for_file: comment_references | ||
// ignore_for_file: implementation_imports | ||
// ignore_for_file: invalid_use_of_visible_for_testing_member | ||
// ignore_for_file: prefer_const_constructors | ||
// ignore_for_file: unnecessary_parenthesis | ||
|
||
class _FakeDevice_0 extends _i1.Fake implements _i2.Device {} | ||
|
||
/// A class which mocks [GetDeviceDetailsMethod]. | ||
/// | ||
/// See the documentation for Mockito's code generation for more information. | ||
class MockGetDeviceDetailsMethod extends _i1.Mock | ||
implements _i3.GetDeviceDetailsMethod { | ||
MockGetDeviceDetailsMethod() { | ||
_i1.throwOnMissingStub(this); | ||
} | ||
|
||
@override | ||
_i4.Future<_i2.Device> call(_i2.Request? request, String? id) => | ||
(super.noSuchMethod(Invocation.method(#call, [request, id]), | ||
returnValue: Future<_i2.Device>.value(_FakeDevice_0())) | ||
as _i4.Future<_i2.Device>); | ||
@override | ||
String toString() => super.toString(); | ||
} | ||
|
||
/// A class which mocks [SendSetColorActionMethod]. | ||
/// | ||
/// See the documentation for Mockito's code generation for more information. | ||
class MockSendSetColorActionMethod extends _i1.Mock | ||
implements _i3.SendSetColorActionMethod { | ||
MockSendSetColorActionMethod() { | ||
_i1.throwOnMissingStub(this); | ||
} | ||
|
||
@override | ||
_i4.Future<void> call( | ||
_i2.Request? request, String? id, _i2.HSBColor? hsbColor) => | ||
(super.noSuchMethod(Invocation.method(#call, [request, id, hsbColor]), | ||
returnValue: Future<void>.value(), | ||
returnValueForMissingStub: Future<void>.value()) as _i4.Future<void>); | ||
@override | ||
String toString() => super.toString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters