Skip to content

Commit 0ff49c1

Browse files
Merge pull request #1465 from navidR/dev/navidr/fix-proof-layout-tests
Make Spark proof layout tests platform-independent
2 parents a5411a5 + abc1053 commit 0ff49c1

5 files changed

Lines changed: 64 additions & 11 deletions

File tree

‎lib/utilities/util.dart‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import 'package:device_info_plus/device_info_plus.dart';
1616
import 'package:flutter/material.dart';
1717
import 'package:intl/number_symbols.dart';
1818
import 'package:intl/number_symbols_data.dart';
19+
import 'package:platform/platform.dart' as platform;
1920

2021
import '../app_config.dart';
2122
import '../wallets/wallet/impl/monero_wallet.dart';
@@ -30,6 +31,7 @@ abstract class Util {
3031

3132
static final Map<String, NumberSymbols?> _numberSymbolsCache = {};
3233

34+
static platform.Platform layoutPlatform = const platform.LocalPlatform();
3335
static double? screenWidth;
3436
static bool? isIpad;
3537

@@ -84,16 +86,17 @@ abstract class Util {
8486
}
8587

8688
static bool get isDesktop {
89+
final p = layoutPlatform;
8790
// special check for running on linux based phones
88-
if (Platform.isLinux && screenWidth != null && screenWidth! < 800) {
91+
if (p.isLinux && screenWidth != null && screenWidth! < 800) {
8992
return false;
9093
}
9194

9295
if (isIpad == true) {
9396
return true;
9497
}
9598

96-
return Platform.isLinux || Platform.isMacOS || Platform.isWindows;
99+
return p.isLinux || p.isMacOS || p.isWindows;
97100
}
98101

99102
static Future<bool> get getIsIPad async {

‎pubspec.lock‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1903,7 +1903,7 @@ packages:
19031903
source: hosted
19041904
version: "0.6.0"
19051905
platform:
1906-
dependency: transitive
1906+
dependency: "direct main"
19071907
description:
19081908
name: platform
19091909
sha256: "5d6b1b0036a5f331ebc77c850ebc8506cbc1e9416c27e59b439f917a902a4984"

‎scripts/app_config/templates/pubspec.template.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ dependencies:
2121
flutter:
2222
sdk: flutter
2323
ffi: ^2.0.1
24+
platform: ^3.1.6
2425
mutex: ^3.0.0
2526
web_socket_channel: ^2.4.0
2627

‎test/pages/spark_address_ownership_proof_test.dart‎

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
55
import 'package:flutter_riverpod/flutter_riverpod.dart';
66
import 'package:flutter_test/flutter_test.dart';
77
import 'package:mockito/mockito.dart';
8+
import 'package:platform/platform.dart' as platform;
89
import 'package:stackwallet/db/drift/database.dart';
910
import 'package:stackwallet/db/isar/main_db.dart';
1011
import 'package:stackwallet/models/isar/models/isar_models.dart';
@@ -63,6 +64,20 @@ class _LabelDB extends Mock implements MainDB {
6364
}
6465

6566
void main() {
67+
setUp(() {
68+
final previousPlatform = Util.layoutPlatform;
69+
final previousWidth = Util.screenWidth;
70+
final previousIsIpad = Util.isIpad;
71+
addTearDown(() {
72+
Util.layoutPlatform = previousPlatform;
73+
Util.screenWidth = previousWidth;
74+
Util.isIpad = previousIsIpad;
75+
});
76+
Util.layoutPlatform = platform.FakePlatform(operatingSystem: 'android');
77+
Util.screenWidth = null;
78+
Util.isIpad = false;
79+
});
80+
6681
setUpAll(() async {
6782
final directory = await Directory.systemTemp.createTemp('spark-proof-ui-');
6883
StackFileSystem.setDesktopOverrideDir(directory.path);
@@ -81,9 +96,10 @@ void main() {
8196
testWidgets(
8297
'${desktop ? "desktop" : "mobile"} proof layout and exact message',
8398
(tester) async {
84-
final oldWidth = Util.screenWidth;
99+
Util.layoutPlatform = platform.FakePlatform(
100+
operatingSystem: desktop ? 'macos' : 'android',
101+
);
85102
Util.screenWidth = desktop ? 1000 : 390;
86-
addTearDown(() => Util.screenWidth = oldWidth);
87103
await tester.binding.setSurfaceSize(
88104
Size(desktop ? 1000 : 390, desktop ? 600 : 844),
89105
);
@@ -186,14 +202,9 @@ void main() {
186202
testWidgets('ownership action layout on ${ipad ? "iPad" : "small phone"}', (
187203
tester,
188204
) async {
189-
final oldWidth = Util.screenWidth;
190-
final oldIpad = Util.isIpad;
205+
Util.layoutPlatform = platform.FakePlatform(operatingSystem: 'ios');
191206
Util.screenWidth = ipad ? 1024 : 320;
192207
Util.isIpad = ipad;
193-
addTearDown(() {
194-
Util.screenWidth = oldWidth;
195-
Util.isIpad = oldIpad;
196-
});
197208
final size = Size(ipad ? 1024 : 320, ipad ? 768 : 568);
198209
await tester.binding.setSurfaceSize(size);
199210
addTearDown(() => tester.binding.setSurfaceSize(null));
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import 'package:flutter_test/flutter_test.dart';
2+
import 'package:platform/platform.dart' as platform;
3+
import 'package:stackwallet/utilities/util.dart';
4+
5+
void main() {
6+
setUp(() {
7+
final previousPlatform = Util.layoutPlatform;
8+
final previousWidth = Util.screenWidth;
9+
final previousIsIpad = Util.isIpad;
10+
addTearDown(() {
11+
Util.layoutPlatform = previousPlatform;
12+
Util.screenWidth = previousWidth;
13+
Util.isIpad = previousIsIpad;
14+
});
15+
});
16+
17+
for (final (os, width, ipad, desktop) in <(String, double?, bool, bool)>[
18+
('android', 390, false, false),
19+
('android', 1000, false, false),
20+
('ios', 390, false, false),
21+
('ios', 1024, false, false),
22+
('ios', 390, true, true),
23+
('ios', 1024, true, true),
24+
('macos', 390, false, true),
25+
('windows', 390, false, true),
26+
('linux', 799, false, false),
27+
('linux', 800, false, true),
28+
('linux', null, false, true),
29+
]) {
30+
test('layout for $os at width $width with isIpad=$ipad', () {
31+
Util.layoutPlatform = platform.FakePlatform(operatingSystem: os);
32+
Util.screenWidth = width;
33+
Util.isIpad = ipad;
34+
35+
expect(Util.isDesktop, desktop);
36+
});
37+
}
38+
}

0 commit comments

Comments
 (0)