Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
test: add pausePreview and resumePreview tests
  • Loading branch information
bselwe committed Aug 13, 2021
commit a470ff89d06eb14048779cbc7c05674da730b5f0
Original file line number Diff line number Diff line change
Expand Up @@ -1459,6 +1459,135 @@ void main() {
});
});

group('pausePreview', () {
testWidgets('calls pause on the camera', (tester) async {
final camera = MockCamera();

// Save the camera in the camera plugin.
(CameraPlatform.instance as CameraPlugin).cameras[cameraId] = camera;

await CameraPlatform.instance.pausePreview(cameraId);

verify(camera.pause).called(1);
});

group('throws PlatformException', () {
testWidgets(
'with notFound error '
'if the camera does not exist', (tester) async {
expect(
() async => await CameraPlatform.instance.pausePreview(cameraId),
throwsA(
isA<PlatformException>().having(
(e) => e.code,
'code',
CameraErrorCode.notFound.toString(),
),
),
);
});

testWidgets('when pause throws DomException', (tester) async {
final camera = MockCamera();
final exception = FakeDomException(DomException.NOT_SUPPORTED);

when(camera.pause).thenThrow(exception);

// Save the camera in the camera plugin.
(CameraPlatform.instance as CameraPlugin).cameras[cameraId] = camera;

expect(
() async => await CameraPlatform.instance.pausePreview(cameraId),
throwsA(
isA<PlatformException>().having(
(e) => e.code,
'code',
exception.name,
),
),
);
});
});
});

group('resumePreview', () {
testWidgets('calls play on the camera', (tester) async {
final camera = MockCamera();

when(camera.play).thenAnswer((_) async => {});

// Save the camera in the camera plugin.
(CameraPlatform.instance as CameraPlugin).cameras[cameraId] = camera;

await CameraPlatform.instance.resumePreview(cameraId);

verify(camera.play).called(1);
});

group('throws PlatformException', () {
testWidgets(
'with notFound error '
'if the camera does not exist', (tester) async {
expect(
() async => await CameraPlatform.instance.resumePreview(cameraId),
throwsA(
isA<PlatformException>().having(
(e) => e.code,
'code',
CameraErrorCode.notFound.toString(),
),
),
);
});

testWidgets('when play throws DomException', (tester) async {
final camera = MockCamera();
final exception = FakeDomException(DomException.NOT_SUPPORTED);

when(camera.play).thenThrow(exception);

// Save the camera in the camera plugin.
(CameraPlatform.instance as CameraPlugin).cameras[cameraId] = camera;

expect(
() async => await CameraPlatform.instance.resumePreview(cameraId),
throwsA(
isA<PlatformException>().having(
(e) => e.code,
'code',
exception.name,
),
),
);
});

testWidgets('when play throws CameraWebException', (tester) async {
final camera = MockCamera();
final exception = CameraWebException(
cameraId,
CameraErrorCode.unknown,
'description',
);

when(camera.play).thenThrow(exception);

// Save the camera in the camera plugin.
(CameraPlatform.instance as CameraPlugin).cameras[cameraId] = camera;

expect(
() async => await CameraPlatform.instance.resumePreview(cameraId),
throwsA(
isA<PlatformException>().having(
(e) => e.code,
'code',
exception.code.toString(),
),
),
);
});
});
});

testWidgets(
'buildPreview returns an HtmlElementView '
'with an appropriate view type', (tester) async {
Expand Down Expand Up @@ -1993,6 +2122,42 @@ void main() {

await streamQueue.cancel();
});

testWidgets(
'emits a CameraErrorEvent '
'on resumePreview error', (tester) async {
final exception = CameraWebException(
cameraId,
CameraErrorCode.unknown,
'description',
);

when(camera.play).thenThrow(exception);

final Stream<CameraErrorEvent> eventStream =
CameraPlatform.instance.onCameraError(cameraId);

final streamQueue = StreamQueue(eventStream);

expect(
() async => await CameraPlatform.instance.resumePreview(cameraId),
throwsA(
isA<PlatformException>(),
),
);

expect(
await streamQueue.next,
equals(
CameraErrorEvent(
cameraId,
'Error code: ${exception.code}, error message: ${exception.description}',
),
),
);

await streamQueue.cancel();
});
});

testWidgets('onVideoRecordedEvent throws UnimplementedError',
Expand Down