-
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.
- Loading branch information
Suraj Adhikari
committed
Nov 19, 2021
1 parent
483a529
commit 0f619f4
Showing
5 changed files
with
226 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,96 +1,145 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:mockito/annotations.dart'; | ||
import 'package:mockito/mockito.dart'; | ||
import 'package:yonomi_device_widgets/providers/thermostat_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'; | ||
|
||
class MockSetPointActionFunction extends Mock { | ||
Future<void> call(Request? request, String? id, double? temperature); | ||
import 'thermostat_provider_test.mocks.dart'; | ||
|
||
class SetPoint extends Mock { | ||
Future<void> call(Request request, String id, double temperature); | ||
} | ||
|
||
class MockSetModeFunction extends Mock { | ||
Future<void> call(Request? request, String? id, GThermostatMode? mode); | ||
class SetMode extends Mock { | ||
Future<void> call(Request request, String id, GThermostatMode mode); | ||
} | ||
|
||
class MockGetThermostatDetailsFunction extends Mock { | ||
Future<Device> call(Request? request, String? id); | ||
class GetThermostatDetails extends Mock { | ||
Future<Device> call(Request request, String id); | ||
} | ||
|
||
@GenerateMocks([ | ||
SetPoint, | ||
SetMode, | ||
GetThermostatDetails, | ||
]) | ||
void main() { | ||
test('Calling setPointAction calls repository method', () async { | ||
Request request = Request("", {}); | ||
MockGetThermostatDetailsFunction mockGetThermostatDetailsFunction = | ||
MockGetThermostatDetailsFunction(); | ||
MockSetPointActionFunction mockSetPointActionFunction = | ||
MockSetPointActionFunction(); | ||
Request request = Request('', {}); | ||
final mockGetThermostatDetailsFunction = MockGetThermostatDetails(); | ||
final mockSetPointActionFunction = MockSetPoint(); | ||
when(mockSetPointActionFunction.call(any, any, any)) | ||
.thenAnswer((_) async => null); | ||
when(mockGetThermostatDetailsFunction.call(any, any)) | ||
.thenAnswer((_) async => Future.value( | ||
Device( | ||
'someId', | ||
'someDisplayName', | ||
'someDescription', | ||
'someManufacturerName', | ||
'someModel', | ||
'someFirmwareV', | ||
GDateTime('value'), | ||
GDateTime('value'), | ||
[ThermostatTrait('', TargetTemperature(23.1))], | ||
), | ||
)); | ||
ThermostatProvider thermostatProvider = ThermostatProvider( | ||
request, "deviceId", | ||
injectGetThermostatDetailsMethod: mockGetThermostatDetailsFunction); | ||
request, 'deviceId', | ||
getThermostatDetails: mockGetThermostatDetailsFunction); | ||
|
||
await thermostatProvider.setPointAction("DeviceId", 22.0, | ||
await thermostatProvider.setPointAction('DeviceId', 22.0, | ||
setPoint: mockSetPointActionFunction); | ||
|
||
verify(mockSetPointActionFunction(request, "someDeviceId", 22.0)).called(1); | ||
verify(mockSetPointActionFunction.call(request, 'DeviceId', 22.0)) | ||
.called(1); | ||
}); | ||
|
||
// test('Calling setThermostatMode calls repository method', () async { | ||
// Request request = Request("", {}); | ||
// MockGetThermostatDetailsFunction mockGetThermostatDetailsFunction = | ||
// MockGetThermostatDetailsFunction(); | ||
// MockSetModeFunction mockSetModeFunction = MockSetModeFunction(); | ||
// ThermostatProvider thermostatProvider = ThermostatProvider( | ||
// request, "deviceId", | ||
// injectGetThermostatDetailsMethod: mockGetThermostatDetailsFunction | ||
// as Future<Device> Function(Request?, String)?); | ||
test('Calling setThermostatMode calls repository method', () async { | ||
Request request = Request('', {}); | ||
final mockGetThermostatDetailsFunction = MockGetThermostatDetails(); | ||
final mockSetModeFunction = MockSetMode(); | ||
when(mockGetThermostatDetailsFunction.call(any, any)) | ||
.thenAnswer((_) async => Future.value( | ||
Device( | ||
'someId', | ||
'someDisplayName', | ||
'someDescription', | ||
'someManufacturerName', | ||
'someModel', | ||
'someFirmwareV', | ||
GDateTime('value'), | ||
GDateTime('value'), | ||
[ThermostatTrait('', TargetTemperature(23.1))], | ||
), | ||
)); | ||
when(mockSetModeFunction.call(any, any, any)).thenAnswer((_) async => null); | ||
ThermostatProvider thermostatProvider = ThermostatProvider( | ||
request, 'deviceId', | ||
getThermostatDetails: mockGetThermostatDetailsFunction); | ||
|
||
// await thermostatProvider.setThermostatMode("DeviceId", GThermostatMode.AUTO, | ||
// injectSetModeMethod: mockSetModeFunction); | ||
await thermostatProvider.setThermostatMode('DeviceId', GThermostatMode.AUTO, | ||
setMode: mockSetModeFunction); | ||
|
||
// verify(mockSetModeFunction(request, "someDeviceId", GThermostatMode.AUTO)) | ||
// .called(1); | ||
// }); | ||
verify(mockSetModeFunction.call(request, 'DeviceId', GThermostatMode.AUTO)) | ||
.called(1); | ||
}); | ||
|
||
test('Calling getDeviceDetail calls repository method', () async { | ||
Request request = Request("", {}); | ||
MockGetThermostatDetailsFunction mockGetThermostatDetailsFunction = | ||
MockGetThermostatDetailsFunction(); | ||
ThermostatProvider thermostatProvider = ThermostatProvider( | ||
request, "deviceId", | ||
injectGetThermostatDetailsMethod: mockGetThermostatDetailsFunction); | ||
Request request = Request('', {}); | ||
final mockGetThermostatDetailsFunction = MockGetThermostatDetails(); | ||
|
||
await thermostatProvider.getDeviceDetail("DeviceId", | ||
when(mockGetThermostatDetailsFunction.call(any, any)) | ||
.thenAnswer((_) async => Future.value( | ||
Device( | ||
'deviceId', | ||
'someDisplayName', | ||
'someDescription', | ||
'someManufacturerName', | ||
'someModel', | ||
'someFirmwareV', | ||
GDateTime('value'), | ||
GDateTime('value'), | ||
[ThermostatTrait('', TargetTemperature(23.1))], | ||
), | ||
)); | ||
ThermostatProvider thermostatProvider = ThermostatProvider( | ||
request, 'deviceId', | ||
getThermostatDetails: mockGetThermostatDetailsFunction); | ||
await thermostatProvider.getDeviceDetail('deviceId', | ||
getThermostatDetails: mockGetThermostatDetailsFunction); | ||
|
||
verify(mockGetThermostatDetailsFunction(request, "someDeviceId")).called(2); | ||
verify(mockGetThermostatDetailsFunction.call(request, 'deviceId')) | ||
.called(2); | ||
}); | ||
|
||
test('Device data is set using DeviceRepository\'s return values', () async { | ||
Request request = Request("", {}); | ||
Request request = Request('', {}); | ||
|
||
MockGetThermostatDetailsFunction mockGetThermostatDetailsFunction = | ||
MockGetThermostatDetailsFunction(); | ||
when(mockGetThermostatDetailsFunction(request, "someDeviceId")) | ||
final mockGetThermostatDetailsFunction = MockGetThermostatDetails(); | ||
when(mockGetThermostatDetailsFunction.call(any, any)) | ||
.thenAnswer((_) async => Future.value( | ||
Device( | ||
"someId", | ||
"someDisplayName", | ||
"someDescription", | ||
"someManufacturerName", | ||
"someModel", | ||
"someFirmwareV", | ||
GDateTime(), | ||
GDateTime(), | ||
[ThermostatTrait("", TargetTemperature(23.1))], | ||
'someId', | ||
'someDisplayName', | ||
'someDescription', | ||
'someManufacturerName', | ||
'someModel', | ||
'someFirmwareV', | ||
GDateTime('value'), | ||
GDateTime('value'), | ||
[ThermostatTrait('', TargetTemperature(23.1))], | ||
), | ||
)); | ||
ThermostatProvider thermostatProvider = ThermostatProvider( | ||
request, "deviceId", | ||
injectGetThermostatDetailsMethod: mockGetThermostatDetailsFunction); | ||
request, 'deviceId', | ||
getThermostatDetails: mockGetThermostatDetailsFunction); | ||
|
||
await thermostatProvider.getDeviceDetail("DeviceId", | ||
await thermostatProvider.getDeviceDetail('deviceId', | ||
getThermostatDetails: mockGetThermostatDetailsFunction); | ||
|
||
expect(thermostatProvider.deviceDetail?.displayName, "someDisplayName"); | ||
expect(thermostatProvider.deviceDetail?.displayName, 'someDisplayName'); | ||
expect(thermostatProvider.thermostatTargetTemperature, 23.1); | ||
}); | ||
} |
Oops, something went wrong.