Skip to content

Commit

Permalink
fixed rename and delete test
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Oct 20, 2023
1 parent d5f9fc6 commit 24baad9
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 64 deletions.
2 changes: 1 addition & 1 deletion integration_test/copy_to_clipboard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void main() {
when(mockTokenFolderRepository.loadFolders()).thenAnswer((_) async => []);
when(mockTokenFolderRepository.saveOrReplaceFolders(any)).thenAnswer((_) async => []);
});
testWidgets('AppTest', (tester) async {
testWidgets('Copy to Clipboard Test', (tester) async {
await tester.pumpWidget(TestsAppWrapper(
overrides: [
settingsProvider.overrideWith((ref) => SettingsNotifier(repository: mockSettingsRepository)),
Expand Down
118 changes: 55 additions & 63 deletions integration_test/rename_and_delete_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void main() {
when(mockTokenFolderRepository.loadFolders()).thenAnswer((_) async => []);
when(mockTokenFolderRepository.saveOrReplaceFolders(any)).thenAnswer((_) async => []);
});
testWidgets('Rename Token', (tester) async {
testWidgets('Rename and Delete Token', (tester) async {
await tester.pumpWidget(TestsAppWrapper(
overrides: [
settingsProvider.overrideWith((ref) => SettingsNotifier(repository: mockSettingsRepository)),
Expand All @@ -46,67 +46,59 @@ void main() {
],
child: PrivacyIDEAAuthenticator(customization: ApplicationCustomization.defaultCustomization),
));
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(HOTPTokenWidget), 1, const Duration(seconds: 10));
expect(find.byType(HOTPTokenWidget), findsOneWidget);
await tester.drag(find.byType(HOTPTokenWidget), const Offset(-300, 0));
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(EditHOTPTokenAction), 1, const Duration(seconds: 2));
await tester.tap(find.byType(EditHOTPTokenAction));
await tester.pumpAndSettle();
expect(find.text('Edit Token'), findsOneWidget);
expect(find.byType(TextFormField), findsNWidgets(3));
await tester.enterText(find.byType(TextFormField).first, 'Renamed Token');
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(find.text('Renamed Token'), findsOneWidget);
});
testWidgets('Rename Token again', (tester) async {
await tester.pumpWidget(TestsAppWrapper(
overrides: [
settingsProvider.overrideWith((ref) => SettingsNotifier(repository: mockSettingsRepository)),
tokenProvider.overrideWith((ref) => TokenNotifier(repository: mockTokenRepository)),
tokenFolderProvider.overrideWith((ref) => TokenFolderNotifier(repository: mockTokenFolderRepository)),
],
child: PrivacyIDEAAuthenticator(customization: ApplicationCustomization.defaultCustomization),
));
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(HOTPTokenWidget), 1, const Duration(seconds: 10));
expect(find.byType(HOTPTokenWidget), findsOneWidget);
await tester.drag(find.byType(HOTPTokenWidget), const Offset(-300, 0));
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(EditHOTPTokenAction), 1, const Duration(seconds: 2));
await tester.tap(find.byType(EditHOTPTokenAction));
await tester.pumpAndSettle();
expect(find.text('Edit Token'), findsOneWidget);
expect(find.byType(TextFormField), findsNWidgets(3));
await tester.enterText(find.byType(TextFormField).first, 'Renamed Token again');
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(find.text('Renamed Token again'), findsOneWidget);
});
testWidgets('Delete Token', (tester) async {
await tester.pumpWidget(TestsAppWrapper(
overrides: [
settingsProvider.overrideWith((ref) => SettingsNotifier(repository: mockSettingsRepository)),
tokenProvider.overrideWith((ref) => TokenNotifier(repository: mockTokenRepository)),
tokenFolderProvider.overrideWith((ref) => TokenFolderNotifier(repository: mockTokenFolderRepository)),
],
child: PrivacyIDEAAuthenticator(customization: ApplicationCustomization.defaultCustomization),
));
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(HOTPTokenWidget), 1, const Duration(seconds: 10));
expect(find.byType(HOTPTokenWidget), findsOneWidget);
await tester.drag(find.byType(HOTPTokenWidget), const Offset(-300, 0));
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(EditHOTPTokenAction), 1, const Duration(seconds: 2));
await tester.tap(find.byType(DefaultDeleteAction));
await tester.pumpAndSettle();
expect(find.text('Edit Token'), findsOneWidget);
expect(find.byType(TextFormField), findsNWidgets(3));
await tester.enterText(find.byType(TextFormField).first, 'Renamed Token');
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(find.text('Renamed Token'), findsOneWidget);
await _renameToken(tester);
await _renameTokenAgain(tester);
await _deleteToken(tester);
});
}

Future<void> _renameToken(WidgetTester tester) async {
// Rename Token
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(HOTPTokenWidget), 1, const Duration(seconds: 10));
expect(find.byType(HOTPTokenWidget), findsOneWidget);
await tester.drag(find.byType(HOTPTokenWidget), const Offset(-300, 0));
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(EditHOTPTokenAction), 1, const Duration(seconds: 2));
await tester.tap(find.byType(EditHOTPTokenAction));
await tester.pumpAndSettle();
expect(find.text('Edit Token'), findsOneWidget);
expect(find.byType(TextFormField), findsNWidgets(3));
await tester.enterText(find.byType(TextFormField).first, 'Renamed Token');
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(find.text('Renamed Token'), findsOneWidget);
}

Future<void> _renameTokenAgain(WidgetTester tester) async {
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(HOTPTokenWidget), 1, const Duration(seconds: 10));
expect(find.byType(HOTPTokenWidget), findsOneWidget);
await tester.drag(find.byType(HOTPTokenWidget), const Offset(-300, 0));
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(EditHOTPTokenAction), 1, const Duration(seconds: 2));
await tester.tap(find.byType(EditHOTPTokenAction));
await tester.pumpAndSettle();
expect(find.text('Edit Token'), findsOneWidget);
expect(find.byType(TextFormField), findsNWidgets(3));
await tester.enterText(find.byType(TextFormField).first, 'Renamed Token');
await tester.tap(find.text('Save'));
await tester.pumpAndSettle();
expect(find.text('Renamed Token'), findsOneWidget);
}

Future<void> _deleteToken(WidgetTester tester) async {
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(HOTPTokenWidget), 1, const Duration(seconds: 10));
expect(find.byType(HOTPTokenWidget), findsOneWidget);
await tester.drag(find.byType(HOTPTokenWidget), const Offset(-300, 0));
await tester.pumpAndSettle();
await pumpUntilFindNWidgets(tester, find.byType(EditHOTPTokenAction), 1, const Duration(seconds: 2));
await tester.tap(find.byType(DefaultDeleteAction));
await tester.pumpAndSettle();
expect(find.text('Confirm deletion'), findsOneWidget);
expect(find.text('Delete'), findsOneWidget);
await tester.tap(find.text('Delete'));
await tester.pumpAndSettle();
expect(find.byType(HOTPTokenWidget), findsNothing);
}

0 comments on commit 24baad9

Please sign in to comment.