mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-28 01:45:55 +08:00
TestDriver: Take some more screenshots
* Add some existing notes * Screenshot the checklist edit * Screenshot the folders view
This commit is contained in:
67
test_driver/isolates_workaround.dart
Normal file
67
test_driver/isolates_workaround.dart
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flutter_driver/flutter_driver.dart';
|
||||||
|
|
||||||
|
/// Workaround for bug: https://github.com/flutter/flutter/issues/24703
|
||||||
|
///
|
||||||
|
/// USAGE
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// FlutterDriver driver;
|
||||||
|
/// IsolatesWorkaround workaround;
|
||||||
|
///
|
||||||
|
/// setUpAll(() async {
|
||||||
|
/// driver = await FlutterDriver.connect();
|
||||||
|
/// workaround = IsolatesWorkaround(driver);
|
||||||
|
/// await workaround.resumeIsolates();
|
||||||
|
/// });
|
||||||
|
///
|
||||||
|
/// tearDownAll(() async {
|
||||||
|
/// if (driver != null) {
|
||||||
|
/// await driver.close();
|
||||||
|
/// await workaround.tearDown();
|
||||||
|
/// }
|
||||||
|
/// });
|
||||||
|
/// ```
|
||||||
|
class IsolatesWorkaround {
|
||||||
|
IsolatesWorkaround(this._driver, {this.log = false});
|
||||||
|
final FlutterDriver _driver;
|
||||||
|
final bool log;
|
||||||
|
StreamSubscription _streamSubscription;
|
||||||
|
|
||||||
|
/// workaround for isolates
|
||||||
|
/// https://github.com/flutter/flutter/issues/24703
|
||||||
|
Future<void> resumeIsolates() async {
|
||||||
|
final vm = await _driver.serviceClient.getVM();
|
||||||
|
// // unpause any paused isolated
|
||||||
|
for (final isolateRef in vm.isolates) {
|
||||||
|
final isolate = await isolateRef.load();
|
||||||
|
if (isolate.isPaused) {
|
||||||
|
isolate.resume();
|
||||||
|
if (log) {
|
||||||
|
print("Resuming isolate: ${isolate.numberAsString}:${isolate.name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (_streamSubscription != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_streamSubscription = _driver.serviceClient.onIsolateRunnable
|
||||||
|
.asBroadcastStream()
|
||||||
|
.listen((isolateRef) async {
|
||||||
|
final isolate = await isolateRef.load();
|
||||||
|
if (isolate.isPaused) {
|
||||||
|
isolate.resume();
|
||||||
|
if (log) {
|
||||||
|
print("Resuming isolate: ${isolate.numberAsString}:${isolate.name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> tearDown() async {
|
||||||
|
if (_streamSubscription != null) {
|
||||||
|
await _streamSubscription.cancel();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,7 +1,16 @@
|
|||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter_driver/driver_extension.dart';
|
import 'package:flutter_driver/driver_extension.dart';
|
||||||
|
import 'package:gitjournal/apis/git.dart';
|
||||||
|
|
||||||
import 'package:gitjournal/app.dart';
|
import 'package:gitjournal/app.dart';
|
||||||
|
import 'package:gitjournal/appstate.dart';
|
||||||
import 'package:gitjournal/settings.dart';
|
import 'package:gitjournal/settings.dart';
|
||||||
|
import 'package:gitjournal/utils/datetime.dart';
|
||||||
|
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
import 'package:path/path.dart' as p;
|
||||||
|
import 'package:dart_git/git.dart';
|
||||||
|
|
||||||
void main() async {
|
void main() async {
|
||||||
enableFlutterDriverExtension();
|
enableFlutterDriverExtension();
|
||||||
@ -9,5 +18,95 @@ void main() async {
|
|||||||
var pref = await SharedPreferences.getInstance();
|
var pref = await SharedPreferences.getInstance();
|
||||||
Settings.instance.load(pref);
|
Settings.instance.load(pref);
|
||||||
|
|
||||||
|
await populateWithData(pref);
|
||||||
await JournalApp.main(pref);
|
await JournalApp.main(pref);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate lots of notes and folders better screenshots
|
||||||
|
Future<void> populateWithData(SharedPreferences pref) async {
|
||||||
|
var dir = await getGitBaseDirectory();
|
||||||
|
|
||||||
|
var appState = AppState(pref);
|
||||||
|
appState.gitBaseDirectory = dir.path;
|
||||||
|
appState.localGitRepoConfigured = true;
|
||||||
|
appState.localGitRepoFolderName = "journal_local";
|
||||||
|
appState.save(pref);
|
||||||
|
|
||||||
|
var repoPath = p.join(dir.path, appState.localGitRepoFolderName);
|
||||||
|
await GitRepository.init(repoPath);
|
||||||
|
|
||||||
|
print("Filling fake data in $repoPath");
|
||||||
|
|
||||||
|
// Write Folders
|
||||||
|
Directory(p.join(repoPath, "GitJournal")).createSync();
|
||||||
|
Directory(p.join(repoPath, "Journal/Work")).createSync(recursive: true);
|
||||||
|
Directory(p.join(repoPath, "Journal/Personal")).createSync(recursive: true);
|
||||||
|
Directory(p.join(repoPath, "Food")).createSync();
|
||||||
|
|
||||||
|
// Write notes
|
||||||
|
createChecklist(p.join(repoPath, "checklist.md"), DateTime.now());
|
||||||
|
createNoteWithTitle(
|
||||||
|
p.join(repoPath, "note1.md"),
|
||||||
|
DateTime.now(),
|
||||||
|
"Desire",
|
||||||
|
"Haven't you always wanted such an app?",
|
||||||
|
);
|
||||||
|
createNote(
|
||||||
|
p.join(repoPath, "note2.md"),
|
||||||
|
DateTime.now(),
|
||||||
|
"There is not a pipe",
|
||||||
|
);
|
||||||
|
|
||||||
|
createNote(
|
||||||
|
p.join(repoPath, "note2.md"),
|
||||||
|
DateTime.now(),
|
||||||
|
"There is not a pipe",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void createNote(String filePath, DateTime dt, String body) {
|
||||||
|
var content = """---
|
||||||
|
modified: ${toIso8601WithTimezone(dt)}
|
||||||
|
created: ${toIso8601WithTimezone(dt)}
|
||||||
|
---
|
||||||
|
|
||||||
|
$body
|
||||||
|
""";
|
||||||
|
|
||||||
|
File(filePath).writeAsStringSync(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
void createNoteWithTitle(
|
||||||
|
String filePath,
|
||||||
|
DateTime dt,
|
||||||
|
String title,
|
||||||
|
String body,
|
||||||
|
) {
|
||||||
|
var content = """---
|
||||||
|
modified: ${toIso8601WithTimezone(dt)}
|
||||||
|
created: ${toIso8601WithTimezone(dt)}
|
||||||
|
title: $title
|
||||||
|
---
|
||||||
|
|
||||||
|
$body
|
||||||
|
""";
|
||||||
|
|
||||||
|
File(filePath).writeAsStringSync(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
void createChecklist(String filePath, DateTime dt) {
|
||||||
|
var content = """---
|
||||||
|
modified: ${toIso8601WithTimezone(dt)}
|
||||||
|
created: ${toIso8601WithTimezone(dt)}
|
||||||
|
title: Shopping List
|
||||||
|
type: Checklist
|
||||||
|
---
|
||||||
|
|
||||||
|
[ ] Bananas
|
||||||
|
[ ] Rice
|
||||||
|
[ ] Cat Food
|
||||||
|
[x] Tomatoes
|
||||||
|
""";
|
||||||
|
|
||||||
|
File(filePath).writeAsStringSync(content);
|
||||||
|
}
|
||||||
|
@ -2,22 +2,30 @@ import 'package:flutter_driver/flutter_driver.dart';
|
|||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:screenshots/screenshots.dart';
|
import 'package:screenshots/screenshots.dart';
|
||||||
|
|
||||||
|
import 'isolates_workaround.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('Test', () {
|
group('Test', () {
|
||||||
FlutterDriver driver;
|
FlutterDriver driver;
|
||||||
|
IsolatesWorkaround workaround;
|
||||||
|
|
||||||
int screenshotNum = 0;
|
int screenshotNum = 0;
|
||||||
final config = Config();
|
final config = Config();
|
||||||
|
|
||||||
// Connect to the Flutter driver before running any tests
|
// Connect to the Flutter driver before running any tests
|
||||||
setUpAll(() async {
|
setUpAll(() async {
|
||||||
driver = await FlutterDriver.connect();
|
driver = await FlutterDriver.connect();
|
||||||
|
workaround = IsolatesWorkaround(driver);
|
||||||
|
await workaround.resumeIsolates();
|
||||||
|
|
||||||
await Future.delayed(const Duration(seconds: 5));
|
await Future.delayed(const Duration(seconds: 5));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Close the connection to the driver after the tests have completed
|
// Close the connection to the driver after the tests have completed
|
||||||
tearDownAll(() async {
|
tearDownAll(() async {
|
||||||
if (driver != null) {
|
if (driver != null) {
|
||||||
driver.close();
|
await driver.close();
|
||||||
|
await workaround.tearDown();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -52,13 +60,13 @@ void main() {
|
|||||||
await driver.tap(find.byValueKey("GetStarted"));
|
await driver.tap(find.byValueKey("GetStarted"));
|
||||||
|
|
||||||
// Main Screen
|
// Main Screen
|
||||||
final loadedFinder = find.text("Let's add some notes?");
|
//final loadedFinder = find.text("Let's add some notes?");
|
||||||
await driver.waitFor(loadedFinder, timeout: const Duration(seconds: 5));
|
// await driver.waitFor(loadedFinder, timeout: const Duration(seconds: 5));
|
||||||
// await _takeScreenshot();
|
// await _takeScreenshot();
|
||||||
|
|
||||||
// Create a new note
|
// Create a new note
|
||||||
var fab = find.byValueKey("FAB");
|
var fab = find.byValueKey("FAB");
|
||||||
await driver.waitFor(fab, timeout: const Duration(seconds: 2));
|
await driver.waitFor(fab, timeout: const Duration(seconds: 5));
|
||||||
await driver.tap(fab);
|
await driver.tap(fab);
|
||||||
await driver.waitFor(find.text('Write here'),
|
await driver.waitFor(find.text('Write here'),
|
||||||
timeout: const Duration(seconds: 5));
|
timeout: const Duration(seconds: 5));
|
||||||
@ -149,12 +157,34 @@ void main() {
|
|||||||
await Future.delayed(const Duration(milliseconds: 100));
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
await _takeScreenshot();
|
await _takeScreenshot();
|
||||||
|
|
||||||
|
// Select the Checklist
|
||||||
|
var checklist = find.text("Shopping List");
|
||||||
|
await driver.waitFor(checklist, timeout: const Duration(seconds: 2));
|
||||||
|
await driver.tap(checklist);
|
||||||
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
await _takeScreenshot();
|
||||||
|
await driver.tap(find.byValueKey("NewEntry"));
|
||||||
|
|
||||||
// Open the Drawer
|
// Open the Drawer
|
||||||
final drawerButtonFinder = find.byValueKey("DrawerButton");
|
final drawerButtonFinder = find.byValueKey("DrawerButton");
|
||||||
await driver.tap(drawerButtonFinder);
|
await driver.tap(drawerButtonFinder);
|
||||||
await Future.delayed(const Duration(milliseconds: 100));
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
await _takeScreenshot();
|
await _takeScreenshot();
|
||||||
|
|
||||||
|
// Folders View
|
||||||
|
var foldersButon = find.text("Folders");
|
||||||
|
await driver.waitFor(foldersButon, timeout: const Duration(seconds: 2));
|
||||||
|
await driver.tap(foldersButon);
|
||||||
|
|
||||||
|
var rootFolder = find.text("Root Folder");
|
||||||
|
await driver.waitFor(rootFolder, timeout: const Duration(seconds: 2));
|
||||||
|
await _takeScreenshot();
|
||||||
|
|
||||||
|
// Open the Drawer
|
||||||
|
await driver.tap(drawerButtonFinder);
|
||||||
|
await Future.delayed(const Duration(milliseconds: 100));
|
||||||
|
await _takeScreenshot();
|
||||||
|
|
||||||
// The Git Host setup screen
|
// The Git Host setup screen
|
||||||
await driver.tap(find.text("Setup Git Host"));
|
await driver.tap(find.text("Setup Git Host"));
|
||||||
await driver.waitFor(find.text("GitHub"),
|
await driver.waitFor(find.text("GitHub"),
|
||||||
|
Reference in New Issue
Block a user