Skip to content

Commit 9301980

Browse files
test: add unit tests for map padding (#270)
1 parent 635a56c commit 9301980

File tree

2 files changed

+96
-4
lines changed

2 files changed

+96
-4
lines changed

test/google_navigation_flutter_test.dart

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,57 @@ void main() {
595595
verify(viewMockApi.setMapToolbarEnabled(captureAny, captureAny)),
596596
true);
597597
});
598+
599+
test('set padding for map', () async {
600+
// Create padding
601+
EdgeInsets insets =
602+
const EdgeInsets.only(left: 5, right: 10, top: 15, bottom: 20);
603+
604+
// Mock api response
605+
when(viewMockApi.setPadding(any, any))
606+
.thenAnswer((Invocation _) async => ());
607+
608+
// Set padding
609+
await GoogleMapsNavigationPlatform.instance
610+
.setPadding(viewId: 0, padding: insets);
611+
612+
// Verify correct message sent from view api
613+
final VerificationResult result =
614+
verify(viewMockApi.setPadding(captureAny, captureAny));
615+
final MapPaddingDto paddingMessage =
616+
result.captured[1] as MapPaddingDto;
617+
618+
// Verify message
619+
expect(insets.left, paddingMessage.left);
620+
expect(insets.right, paddingMessage.right);
621+
expect(insets.top, paddingMessage.top);
622+
expect(insets.bottom, paddingMessage.bottom);
623+
});
624+
625+
test('get padding from map', () async {
626+
// Create padding
627+
EdgeInsets insets =
628+
const EdgeInsets.only(top: 5, left: 10, bottom: 15, right: 20);
629+
630+
// Mock api response
631+
final MapPaddingDto messagePadding =
632+
MapPaddingDto(top: 5, left: 10, bottom: 15, right: 20);
633+
when(viewMockApi.getPadding(any))
634+
.thenAnswer((Invocation _) => messagePadding);
635+
636+
// Get padding
637+
final EdgeInsets paddingOut =
638+
await GoogleMapsNavigationPlatform.instance.getPadding(viewId: 0);
639+
640+
// Verify correct message sent from view api
641+
final VerificationResult result =
642+
verify(viewMockApi.getPadding(captureAny));
643+
final int viewId = result.captured[0] as int;
644+
645+
// Verify response padding
646+
expect(viewId, 0);
647+
expect(insets, paddingOut);
648+
});
598649
});
599650

600651
group('Navigation session API', () {

test/google_navigation_flutter_test.mocks.dart

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2024 Google LLC
1+
// Copyright 2025 Google LLC
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -73,9 +73,19 @@ class _FakeLatLngBoundsDto_2 extends _i1.SmartFake
7373
);
7474
}
7575

76-
class _FakeImageDescriptorDto_3 extends _i1.SmartFake
76+
class _FakeMapPaddingDto_3 extends _i1.SmartFake implements _i2.MapPaddingDto {
77+
_FakeMapPaddingDto_3(
78+
Object parent,
79+
Invocation parentInvocation,
80+
) : super(
81+
parent,
82+
parentInvocation,
83+
);
84+
}
85+
86+
class _FakeImageDescriptorDto_4 extends _i1.SmartFake
7787
implements _i2.ImageDescriptorDto {
78-
_FakeImageDescriptorDto_3(
88+
_FakeImageDescriptorDto_4(
7989
Object parent,
8090
Invocation parentInvocation,
8191
) : super(
@@ -1668,6 +1678,37 @@ class MockTestMapViewApi extends _i1.Mock implements _i3.TestMapViewApi {
16681678
),
16691679
returnValueForMissingStub: null,
16701680
);
1681+
1682+
@override
1683+
void setPadding(
1684+
int? viewId,
1685+
_i2.MapPaddingDto? padding,
1686+
) =>
1687+
super.noSuchMethod(
1688+
Invocation.method(
1689+
#setPadding,
1690+
[
1691+
viewId,
1692+
padding,
1693+
],
1694+
),
1695+
returnValueForMissingStub: null,
1696+
);
1697+
1698+
@override
1699+
_i2.MapPaddingDto getPadding(int? viewId) => (super.noSuchMethod(
1700+
Invocation.method(
1701+
#getPadding,
1702+
[viewId],
1703+
),
1704+
returnValue: _FakeMapPaddingDto_3(
1705+
this,
1706+
Invocation.method(
1707+
#getPadding,
1708+
[viewId],
1709+
),
1710+
),
1711+
) as _i2.MapPaddingDto);
16711712
}
16721713

16731714
/// A class which mocks [TestImageRegistryApi].
@@ -1698,7 +1739,7 @@ class MockTestImageRegistryApi extends _i1.Mock
16981739
height,
16991740
],
17001741
),
1701-
returnValue: _FakeImageDescriptorDto_3(
1742+
returnValue: _FakeImageDescriptorDto_4(
17021743
this,
17031744
Invocation.method(
17041745
#registerBitmapImage,

0 commit comments

Comments
 (0)