Skip to content
This repository has been archived by the owner on Jul 31, 2021. It is now read-only.

Commit

Permalink
fix change wallpaper, fix registration & login tests, messagesender t…
Browse files Browse the repository at this point in the history
…emporary fix, chat move wasblocked, minor changes
  • Loading branch information
mkofdwu committed Feb 7, 2021
1 parent 8541286 commit da9f3b8
Show file tree
Hide file tree
Showing 20 changed files with 254 additions and 212 deletions.
24 changes: 14 additions & 10 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"name": "tundr integration tests: launch app",
"request": "launch",
"type": "dart",
"program": "test_driver/app.dart",
"program": "integration_test/app.dart",
"args": [
"--flavor",
"dev",
Expand All @@ -50,14 +50,18 @@
"--disable-service-auth-codes"
]
},
// {
// "name": "tundr integration tests: launch driver",
// "request": "launch",
// "env": {
// "VM_SERVICE_URL": "https://localhost:8888"
// },
// "type": "dart",
// "program": "${file}" // "test_driver/app_test.dart"
// }
{
"name": "tundr integration tests: launch driver",
"request": "launch",
// "env": {
// "VM_SERVICE_URL": "https://localhost:8888"
// },
"type": "dart",
"program": "integration_test/app_test.dart",
"args": [
"--flavor",
"dev"
]
},
]
}
4 changes: 2 additions & 2 deletions integration_test/accounts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class Account {

class Accounts {
// john will be created and then deleted after test is completed
static final john = Account('john', 'password2', exists: false);
static final mary = Account('mary', 'testee', exists: false);
static final john = Account('johncremley', 'password2', exists: false);
static final mary = Account('maryauter', 'testee', exists: false);
static final test = Account('test', '123456', exists: true);

static Account current;
Expand Down
42 changes: 0 additions & 42 deletions integration_test/app.dart

This file was deleted.

41 changes: 40 additions & 1 deletion integration_test/app_test.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
import 'dart:io';

import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:path_provider/path_provider.dart';

import 'groups/auth.dart' as auth;

Future<void> mockMethodChannels() async {
// load sample image for testing
final imageBytes = (await rootBundle.load('assets/test_images/Wall.jpg'))
.buffer
.asUint8List();
final videoBytes = (await rootBundle.load('assets/test_images/Vid.mp4'))
.buffer
.asUint8List();
final tempDir = await getTemporaryDirectory();
final imageFile =
await File('${tempDir.path}/wall.jpg').writeAsBytes(imageBytes);
final videoFile =
await File('${tempDir.path}/vid.mp4').writeAsBytes(videoBytes);

const imagePickerChannel = MethodChannel('plugins.flutter.io/image_picker');
imagePickerChannel.setMockMethodCallHandler((call) async {
if (call.method == 'pickImage') {
return imageFile.path;
}
if (call.method == 'pickVideo') {
return videoFile.path;
}
});

const imageCropperChannel = MethodChannel('plugins.hunghd.vn/image_cropper');
imageCropperChannel.setMockMethodCallHandler((call) async {
assert(
call.method == 'cropImage', 'unexpected call method: ' + call.method);
return imageFile.path;
});
}

void main() {
group('Registration', auth.main);
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
mockMethodChannels();
group('Authentication flows', auth.main);
// group('Login', login.main);
// group('Swiping page', swiping.main);
// group('Most popular page', most_popular.main);
Expand Down
3 changes: 3 additions & 0 deletions integration_test/flows/delete_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ import '../accounts.dart';
void deleteAccount(WidgetTester tester) async {
expect(find.byType(HomePage), findsOneWidget);
await tester.tap(find.byKey(ValueKey('meTab')));
await tester.pumpAndSettle();
await tester.tap(find.byKey(ValueKey('settingsBtn')));
await tester.pumpAndSettle();
await tester.scrollUntilVisible(
find.byKey(ValueKey('deleteAccountBtn')), 100);
await tester.tap(find.byKey(ValueKey('deleteAccountBtn')));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(ValueKey('confirmPasswordField')), Accounts.current.password);
await tester.tap(find.byKey(ValueKey('confirmDeleteAccountBtn')));
Expand Down
11 changes: 3 additions & 8 deletions integration_test/flows/login.dart
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tundr/pages/home.dart';
import 'package:tundr/pages/login.dart';
import 'package:tundr/pages/welcome.dart';

import '../accounts.dart';
import '../utils.dart';

Future<void> loginWith(
WidgetTester tester, {
@required Account account,
bool expectHome = true,
}) async {
assert(account.exists);

expect(find.byType(WelcomePage), findsOneWidget);
await tester.tap(find.byKey(ValueKey('loginBtn')));
await tester.pumpAndSettle();
expect(find.byType(LoginPage), findsOneWidget);
await tester.enterText(
find.byKey(ValueKey('usernameField')), account.username);
await tester.enterText(
find.byKey(ValueKey('passwordField')), account.password);
await tester.tap(find.byKey(ValueKey('loginSubmitBtn')));
// await tester.pump(Duration(seconds: 4));
await tester.pumpAndSettle();
await tester.pump(Duration(seconds: 4));
if (expectHome) expect(find.byType(HomePage), findsOneWidget);

Accounts.current = account;
Expand All @@ -37,7 +33,6 @@ Future<void> testInvalidLoginWith(
);
expect(find.byType(AlertDialog), findsOneWidget);
await tester.tap(find.text('CLOSE'));
await back();
await tester.pumpAndSettle();
}

Expand Down
3 changes: 2 additions & 1 deletion integration_test/flows/most_popular.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ import 'package:flutter/material.dart';
import 'package:integration_test/integration_test.dart';
import 'package:flutter_test/flutter_test.dart';

import '../accounts.dart';
import 'login.dart';

void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();

testWidgets('Loads pictures within 6 seconds', (tester) async {
await loginWith(tester);
await loginWith(tester, account: Accounts.john);
await tester.tap(find.byKey(ValueKey('mostPopularTab')));
await tester.pump(Duration(seconds: 6));
expect(find.byType(CachedNetworkImage), findsWidgets);
Expand Down
79 changes: 44 additions & 35 deletions integration_test/flows/registration.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:tundr/pages/home.dart';
import 'package:tundr/pages/register.dart';
import 'package:tundr/pages/setup/birthday.dart';
import 'package:tundr/pages/setup/gender.dart';
import 'package:tundr/pages/setup/interests.dart';
Expand All @@ -9,7 +10,6 @@ import 'package:tundr/pages/setup/phone_number.dart';
import 'package:tundr/pages/setup/phone_verification.dart';
import 'package:tundr/pages/setup/profile_pic.dart';
import 'package:tundr/pages/setup/theme.dart';
import 'package:tundr/pages/welcome.dart';
import 'package:tundr/widgets/scroll_down_arrow.dart';
import 'package:tundr/widgets/textfields/digit.dart';

Expand All @@ -20,54 +20,52 @@ Future<void> _registerWith(
WidgetTester tester,
String username,
String password,
String confirmPassword,
) async {
expect(find.byType(WelcomePage), findsOneWidget);
await tester.tap(find.byKey(ValueKey('registerBtn')));
String confirmPassword, {
bool waitForSettle = true,
}) async {
expect(find.byType(RegisterPage), findsOneWidget);
await tester.enterText(find.byKey(ValueKey('usernameField')), username);
await tester.enterText(find.byKey(ValueKey('passwordField')), password);
await tester.enterText(
find.byKey(ValueKey('confirmPasswordField')), confirmPassword);
await tester.tap(find.text('Setup'));
if (waitForSettle) await tester.pumpAndSettle();
}

Future<void> invalidRegistration(WidgetTester tester) async {
// existing username
await _registerWith(tester, 'test', 'password', 'password');
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsOneWidget);
await tester.tap(find.text('CLOSE'));
await back();
expect(find.text('This username is already taken'), findsOneWidget);
// not matching passwords
await _registerWith(tester, 'username9978', 'password', 'password1');
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsOneWidget);
await tester.tap(find.text('CLOSE'));
await back();
expect(find.text('The passwords do not match'), findsOneWidget);
// invalid username
await _registerWith(tester, ' usernam\ne9978\r \t', 'password', 'password');
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsOneWidget);
await tester.tap(find.text('CLOSE'));
await back();
expect(find.text('Your username cannot contain any spaces'), findsOneWidget);
// nothing
await _registerWith(tester, '', '', '');
await tester.pumpAndSettle();
expect(find.byType(AlertDialog), findsOneWidget);
await tester.tap(find.text('CLOSE'));
await back();
expect(find.text('Your username must be at least 4 characters long'),
findsOneWidget);
expect(find.text('Your password must be at least 6 characters long'),
findsOneWidget);
}

Future<void> registerWith(WidgetTester tester, Account account) async {
await _registerWith(
tester, account.username, account.password, account.password);
tester,
account.username,
account.password,
account.password,
waitForSettle: false,
);
// can't pumpAndSettle because the scrolldownarrow is still animating
await pump(tester, Duration(seconds: 1), 3);

await tester.pumpAndSettle();
expect(find.byType(SetupNamePage), findsOneWidget);
await tester.enterText(find.byKey(ValueKey('nameField')), account.username);
await tester.tap(find.byType(ScrollDownArrow));

await tester.pumpAndSettle();
await tester.pump(Duration(seconds: 1));
expect(find.byType(SetupBirthdayPage), findsOneWidget);
var index = 0;
for (final digitChar in '20102005'.split('')) {
Expand All @@ -76,49 +74,58 @@ Future<void> registerWith(WidgetTester tester, Account account) async {
}
await tester.tap(find.byType(ScrollDownArrow));

await tester.pumpAndSettle();
await tester.pump(Duration(seconds: 1));
expect(find.byType(SetupGenderPage), findsOneWidget);
await tester.tap(find.text('Male'));
await tester.tap(find.byType(ScrollDownArrow));

await tester.pumpAndSettle();
await tester.pump(Duration(seconds: 1));
expect(find.byType(SetupProfilePicPage), findsOneWidget);
await tester.tap(find.text('Camera'));
// image will be taken automatically
await tester.pump(Duration(seconds: 1));
await tester.tap(find.byType(ScrollDownArrow));

await tester.pumpAndSettle();
await tester.pump(Duration(seconds: 1));
expect(find.byType(SetupInterestsPage), findsOneWidget);
// await tester.tap(find.text('Custom'));
// await tester.tap(find.text('Add new'));
// await tester.enterText('my custom interest\n');
// await tester.tap(find.text('Animals'));
await tester.tap(find.text('Custom'));
await tester.pump(Duration(milliseconds: 100));
await tester.tap(find.text('Add new'));
await tester.pump();
await tester.enterText(
find.byKey(ValueKey('addCustomInterestField')), 'my custom interest');
await tester.testTextInput.receiveAction(TextInputAction.done);
await tester.tap(find.text('Animals'));
await tester.pump(Duration(milliseconds: 100));
await tester.tap(find.text('Animals').at(1));
await tester.tap(find.text('Birds'));
await tester.tap(find.text('Cats'));
await tester.tap(find.text('Dogs'));
await tester.tap(find.text('Outdoors'));
await tester.pump(Duration(milliseconds: 100));
await tester.tap(find.text('Hiking'));
await tester.tap(find.text('Camping'));
await tester.tap(find.text('Climbing'));
await tester.tap(find.text('Environment'));
await tester.tap(find.text('Nature'));
await tester.enterText(find.byType(TextField), 'comput'); // search field
await tester.pump(Duration(milliseconds: 100));
await tester.tap(find.text('Computers'));
await tester.tap(find.text('Computer Graphics'));
await tester.tap(find.text('Computer Science'));
await tester.tap(find.text('Computer Security'));
await tester.tap(find.text('Computer Hardware'));
await tester.tap(find.byType(ScrollDownArrow));

await tester.pumpAndSettle();
await tester.pump(Duration(seconds: 1));
expect(find.byType(SetupPhoneNumberPage), findsOneWidget);
await tester.enterText(
find.byType(TextField), // phone number field
'88888888', // this test phone number should always be free during testing
);
await tester.tap(find.byType(ScrollDownArrow));

await tester.pumpAndSettle();
await pump(tester, Duration(seconds: 1), 4);
expect(find.byType(PhoneVerificationPage), findsOneWidget);
await tester.tap(
find
Expand All @@ -136,10 +143,12 @@ Future<void> registerWith(WidgetTester tester, Account account) async {
}
await tester.tap(find.byType(ScrollDownArrow));

await tester.pumpAndSettle();
await pump(tester, Duration(seconds: 1), 20);
expect(find.byType(SetupThemePage), findsOneWidget);
await tester.tap(find.text('Light'));

await tester.pumpAndSettle();
await tester.pump(Duration(seconds: 2));
expect(find.byType(HomePage), findsOneWidget);

Accounts.current = account;
}
Loading

0 comments on commit da9f3b8

Please sign in to comment.