-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* test: add goldens * fix: add storageAdapter to fix golden tests --------- Co-authored-by: Joshua Wellbrock <[email protected]>
- Loading branch information
1 parent
219530d
commit aa19b69
Showing
45 changed files
with
437 additions
and
15 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_localizations/flutter_localizations.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:golden_toolkit/golden_toolkit.dart'; | ||
import 'package:liquid_flutter/liquid_flutter.dart'; | ||
import 'package:mtrust_imp_kit/mtrust_imp_kit.dart'; | ||
|
||
typedef WidgetBuilder = Future<Future<void> Function()?> Function( | ||
WidgetTester tester, | ||
Future<void> Function(Widget widget) placeWidget, | ||
); | ||
Widget liquidFrame({ | ||
required Key key, | ||
required Widget child, | ||
required bool isDark, | ||
required LdThemeSize size, | ||
}) { | ||
final theme = LdTheme()..setThemeSize(size); | ||
return Localizations( | ||
delegates: const [ | ||
GlobalWidgetsLocalizations.delegate, | ||
LiquidLocalizations.delegate, | ||
UrpUiLocalizations.delegate, | ||
ImpLocalizations.delegate, | ||
], | ||
locale: const Locale('en'), | ||
child: Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: LdThemeProvider( | ||
theme: theme, | ||
autoSize: false, | ||
brightnessMode: | ||
isDark ? LdThemeBrightnessMode.dark : LdThemeBrightnessMode.light, | ||
child: Builder( | ||
builder: (context) { | ||
return Container( | ||
padding: const EdgeInsets.all(16), | ||
margin: const EdgeInsets.all(16), | ||
decoration: BoxDecoration( | ||
color: theme.background, | ||
borderRadius: ldRadiusM, | ||
), | ||
child: Directionality( | ||
textDirection: TextDirection.ltr, | ||
child: Builder( | ||
builder: (context) { | ||
return SingleChildScrollView( | ||
child: Center(key: key, child: child), | ||
); | ||
}, | ||
), | ||
), | ||
); | ||
}, | ||
), | ||
), | ||
), | ||
); | ||
} | ||
|
||
Future<void> multiGolden( | ||
WidgetTester tester, | ||
String name, | ||
Map<String, WidgetBuilder> widgets, { | ||
int width = 900, | ||
}) async { | ||
ldDisableAnimations = true; | ||
urpUiDisableAnimations = true; | ||
await loadAppFonts(); | ||
for (final entry in widgets.entries) { | ||
for (final themeSize in LdThemeSize.values) { | ||
for (final brightness in Brightness.values) { | ||
final slug = '${entry.key}/' | ||
"${themeSize.toString().split(".").last}" | ||
"-${brightness.toString().split(".").last}"; | ||
await tester.binding.setSurfaceSize( | ||
Size(width.toDouble(), 1000), | ||
); | ||
final cleanup = await entry.value(tester, (widget) async { | ||
await tester.pumpWidget( | ||
liquidFrame( | ||
key: ValueKey(slug), | ||
child: widget, | ||
isDark: brightness == Brightness.dark, | ||
size: themeSize, | ||
), | ||
); | ||
}); | ||
final size = | ||
find.byKey(ValueKey(slug)).evaluate().single.size ?? Size.zero; | ||
await tester.binding.setSurfaceSize( | ||
Size(width.toDouble(), size.height + 64), | ||
); | ||
await tester.pump(); | ||
await screenMatchesGolden( | ||
tester, | ||
'$name/$slug', | ||
customPump: (tester) async { | ||
await tester.pumpAndSettle(); | ||
}, | ||
); | ||
if (cleanup != null) { | ||
await cleanup(); | ||
} | ||
await tester.pumpAndSettle(); | ||
} | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
...fault_identification_ui_builder_test.dart → test/imp_kit_test.dart
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,9 +1,9 @@ | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
void main() { | ||
group('pChipKit', () { | ||
group('ImpKit', () { | ||
test(' test suite example', () { | ||
expect(1, 1); | ||
}); | ||
}); | ||
} | ||
} |
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,210 @@ | ||
|
||
import 'package:flutter/material.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:golden_toolkit/golden_toolkit.dart'; | ||
import 'package:mtrust_imp_kit/mtrust_imp_kit.dart'; | ||
import 'package:mtrust_imp_kit/src/format_utils.dart'; | ||
|
||
import 'golden_utils.dart'; | ||
import 'test_utils.dart'; | ||
|
||
void main() { | ||
testGoldens('ImpWidget', (WidgetTester test) async { | ||
urpUiDisableAnimations = true; | ||
|
||
await multiGolden( | ||
test, | ||
'ImpWidget', | ||
{ | ||
'Idle': (tester, place) async { | ||
final strategy = CompleterStrategy(withReaders: true); | ||
|
||
final storageAdapter = MockStorageAdapter(); | ||
|
||
await place( | ||
AspectRatio( | ||
aspectRatio: 1, | ||
child: ImpWidget( | ||
connectionStrategy: strategy.strategy, | ||
storageAdapter: storageAdapter, | ||
chipIdFormat: ChipIdFormat.hex, | ||
onIdentificationDone: (_) async {}, | ||
onIdentificationFailed: () async {}, | ||
), | ||
), | ||
); | ||
|
||
await tester.pumpAndSettle(); | ||
return null; | ||
}, | ||
'Priming': (tester, place) async { | ||
final strategy = CompleterStrategy(withReaders: true); | ||
|
||
final storageAdapter = MockStorageAdapter(); | ||
|
||
await place( | ||
AspectRatio( | ||
aspectRatio: 1, | ||
child: ImpWidget( | ||
connectionStrategy: strategy.strategy, | ||
storageAdapter: storageAdapter, | ||
chipIdFormat: ChipIdFormat.hex, | ||
onIdentificationDone: (_) async {}, | ||
onIdentificationFailed: () async {}, | ||
), | ||
), | ||
); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
await tester.tap(find.byKey(const Key('connect_button'))); | ||
|
||
return () async { | ||
strategy.primeCompleter.complete(); | ||
}; | ||
}, | ||
'Waiting for measurement': (tester, place) async { | ||
final strategy = CompleterStrategy(withReaders: true); | ||
|
||
final storageAdapter = MockStorageAdapter(); | ||
|
||
await place( | ||
AspectRatio( | ||
aspectRatio: 1, | ||
child: ImpWidget( | ||
connectionStrategy: strategy.strategy, | ||
storageAdapter: storageAdapter, | ||
chipIdFormat: ChipIdFormat.hex, | ||
onIdentificationDone: (_) async {}, | ||
onIdentificationFailed: () async {}, | ||
), | ||
), | ||
); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
await tester.tap(find.byKey(const Key('connect_button'))); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
strategy.primeCompleter.complete(); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
return () async { | ||
strategy.startMeasurementCompleter.complete(); | ||
}; | ||
}, | ||
'Measuring': (tester, place) async { | ||
final strategy = CompleterStrategy(withReaders: true); | ||
|
||
final storageAdapter = MockStorageAdapter(); | ||
|
||
await place( | ||
AspectRatio( | ||
aspectRatio: 1, | ||
child: ImpWidget( | ||
connectionStrategy: strategy.strategy, | ||
storageAdapter: storageAdapter, | ||
chipIdFormat: ChipIdFormat.hex, | ||
onIdentificationDone: (_) async {}, | ||
onIdentificationFailed: () async {}, | ||
), | ||
), | ||
); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
await tester.tap(find.byKey(const Key('connect_button'))); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
strategy.primeCompleter.complete(); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
await tester.tap(find.text('Start reading')); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
return () async { | ||
strategy.startMeasurementCompleter.complete(); | ||
}; | ||
}, | ||
'Measure Fail': (tester, place) async { | ||
final strategy = CompleterStrategy(withReaders: true); | ||
|
||
final storageAdapter = MockStorageAdapter(); | ||
|
||
await place( | ||
AspectRatio( | ||
aspectRatio: 1, | ||
child: ImpWidget( | ||
connectionStrategy: strategy.strategy, | ||
storageAdapter: storageAdapter, | ||
chipIdFormat: ChipIdFormat.hex, | ||
onIdentificationDone: (_) async {}, | ||
onIdentificationFailed: () async {}, | ||
), | ||
), | ||
); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
await tester.tap(find.byKey(const Key('connect_button'))); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
strategy.primeCompleter.complete(); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
await tester.tap(find.text('Start reading')); | ||
|
||
strategy.startMeasurementCompleter.completeError(''); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
return () async {}; | ||
}, | ||
'Measure Complete': (tester, place) async { | ||
final strategy = CompleterStrategy(withReaders: true); | ||
|
||
final storageAdapter = MockStorageAdapter(); | ||
|
||
await place( | ||
AspectRatio( | ||
aspectRatio: 1, | ||
child: ImpWidget( | ||
connectionStrategy: strategy.strategy, | ||
storageAdapter: storageAdapter, | ||
chipIdFormat: ChipIdFormat.hex, | ||
onIdentificationDone: (_) async {}, | ||
onIdentificationFailed: () async {}, | ||
), | ||
), | ||
); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
await tester.tap(find.byKey(const Key('connect_button'))); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
strategy.primeCompleter.complete(); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
await tester.tap(find.text('Start reading')); | ||
|
||
strategy.startMeasurementCompleter.complete(); | ||
|
||
await tester.pumpAndSettle(); | ||
|
||
return () async {}; | ||
}, | ||
}, | ||
width: 500, | ||
); | ||
}); | ||
} |
Oops, something went wrong.