This repository has been archived by the owner on Dec 12, 2024. It is now read-only.
generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add `NumberPad` widget tests * add `MockKeyManager` for `AccountDidPage` test * add `AccountDidPage` widget test
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'package:flutter_starter/features/account/account_did_page.dart'; | ||
import 'package:flutter_starter/features/account/account_providers.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
import 'package:web5_flutter/web5_flutter.dart'; | ||
|
||
import '../../helpers/mocks.dart'; | ||
import '../../helpers/widget_helpers.dart'; | ||
|
||
void main() { | ||
late MockKeyManager keyManager; | ||
|
||
setUp(() { | ||
keyManager = MockKeyManager(); | ||
}); | ||
|
||
group('AccountDidPage', () { | ||
testWidgets('should show the DID', (tester) async { | ||
const uri = 'did:example:123'; | ||
|
||
await tester.pumpWidget( | ||
WidgetHelpers.testableWidget(child: const AccountDidPage(), overrides: [ | ||
didProvider.overrideWithValue( | ||
DidJwk(uri: uri, keyManager: keyManager), | ||
), | ||
]), | ||
); | ||
|
||
expect(find.text(uri), findsOneWidget); | ||
}); | ||
}); | ||
} |
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,4 @@ | ||
import 'package:mocktail/mocktail.dart'; | ||
import 'package:web5_flutter/web5_flutter.dart'; | ||
|
||
class MockKeyManager extends Mock implements KeyManager {} |
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,77 @@ | ||
import 'package:flutter_starter/shared/number_pad.dart'; | ||
import 'package:flutter_test/flutter_test.dart'; | ||
|
||
import '../helpers/widget_helpers.dart'; | ||
|
||
void main() { | ||
List<String> numberKeys = [ | ||
'1', | ||
'2', | ||
'3', | ||
'4', | ||
'5', | ||
'6', | ||
'7', | ||
'8', | ||
'9', | ||
'0', | ||
'.', | ||
'<', | ||
]; | ||
|
||
group('NumberPad', () { | ||
testWidgets('should show all number keys', (tester) async { | ||
await tester.pumpWidget( | ||
WidgetHelpers.testableWidget( | ||
child: NumberPad( | ||
onKeyPressed: (key) {}, | ||
onDeletePressed: () {}, | ||
), | ||
), | ||
); | ||
|
||
for (String key in numberKeys) { | ||
expect(find.text(key), findsOneWidget); | ||
} | ||
}); | ||
|
||
testWidgets('should call onKeyPressed when a key is pressed', | ||
(tester) async { | ||
var pressedKey = ''; | ||
await tester.pumpWidget( | ||
WidgetHelpers.testableWidget( | ||
child: NumberPad( | ||
onKeyPressed: (key) { | ||
pressedKey = key; | ||
}, | ||
onDeletePressed: () {}, | ||
), | ||
), | ||
); | ||
|
||
// exclude the delete key '<' | ||
for (String key in numberKeys.sublist(0, numberKeys.length - 1)) { | ||
await tester.tap(find.text(key)); | ||
expect(pressedKey, key); | ||
} | ||
}); | ||
|
||
testWidgets('should call onDeletePressed when delete key is pressed', | ||
(tester) async { | ||
var deletePressed = false; | ||
await tester.pumpWidget( | ||
WidgetHelpers.testableWidget( | ||
child: NumberPad( | ||
onKeyPressed: (key) {}, | ||
onDeletePressed: () { | ||
deletePressed = true; | ||
}, | ||
), | ||
), | ||
); | ||
|
||
await tester.tap(find.text('<')); | ||
expect(deletePressed, true); | ||
}); | ||
}); | ||
} |