Browse Source

fix history test.

null-safety
Herbert Poul 4 years ago
parent
commit
7b83648755
  1. 18
      test/kdbx_history_test.dart

18
test/kdbx_history_test.dart

@ -23,7 +23,7 @@ class StreamExpect<T> {
}); });
} }
Future<RET> expectNext<RET>(T value, FutureOr<RET>? Function() cb) async { Future<RET> expectNext<RET>(T value, FutureOr<RET> Function() cb) async {
if (_expectNext != null) { if (_expectNext != null) {
fail('The last event was never received. last: $_expectNext'); fail('The last event was never received. last: $_expectNext');
} }
@ -58,30 +58,30 @@ void main() {
final first = file.body.rootGroup.entries.first; final first = file.body.rootGroup.entries.first;
expect(file.header.version.major, 3); expect(file.header.version.major, 3);
expect(first.getString(TestUtil.keyTitle)!.getText(), valueOrig); expect(first.getString(TestUtil.keyTitle)!.getText(), valueOrig);
await dirtyExpect.expectNext({first}, () { await dirtyExpect.expectNext({first}, () async {
first.setString(TestUtil.keyTitle, PlainValue(value1)); first.setString(TestUtil.keyTitle, PlainValue(value1));
}); });
} }
expect(file.dirtyObjects, hasLength(1)); expect(file.dirtyObjects, hasLength(1));
final f2 = final f2 = await dirtyExpect
await dirtyExpect.expectNext({}, () => TestUtil.saveAndRead(file)); .expectNext({}, () async => TestUtil.saveAndRead(file));
expect(file.dirtyObjects, isEmpty); expect(file.dirtyObjects, isEmpty);
{ {
final first = f2.body.rootGroup.entries.first; final first = f2.body.rootGroup.entries.first;
expect(first.getString(TestUtil.keyTitle)!.getText(), value1); expect(first.getString(TestUtil.keyTitle)!.getText(), value1);
expect(first.history.last.getString(TestUtil.keyTitle)!.getText(), expect(first.history.last.getString(TestUtil.keyTitle)!.getText(),
valueOrig); valueOrig);
await dirtyExpect.expectNext({}, () => file.save()); await dirtyExpect.expectNext({}, () async => file.save());
} }
// edit the original file again, and there should be a second history // edit the original file again, and there should be a second history
{ {
final first = file.body.rootGroup.entries.first; final first = file.body.rootGroup.entries.first;
await dirtyExpect.expectNext({first}, await dirtyExpect.expectNext({first},
() => first.setString(TestUtil.keyTitle, PlainValue(value2))); () async => first.setString(TestUtil.keyTitle, PlainValue(value2)));
} }
final f3 = final f3 = await dirtyExpect
await dirtyExpect.expectNext({}, () => TestUtil.saveAndRead(file)); .expectNext({}, () async => TestUtil.saveAndRead(file));
expect(file.dirtyObjects, isEmpty); expect(file.dirtyObjects, isEmpty);
{ {
final first = f3.body.rootGroup.entries.first; final first = f3.body.rootGroup.entries.first;
@ -91,7 +91,7 @@ void main() {
first.history.last.getString(TestUtil.keyTitle)!.getText(), value1); first.history.last.getString(TestUtil.keyTitle)!.getText(), value1);
expect(first.history.first.getString(TestUtil.keyTitle)!.getText(), expect(first.history.first.getString(TestUtil.keyTitle)!.getText(),
valueOrig); valueOrig);
await dirtyExpect.expectNext({}, () => file.save()); await dirtyExpect.expectNext({}, () async => file.save());
} }
file.dispose(); file.dispose();
await pumpEventQueue(); await pumpEventQueue();

Loading…
Cancel
Save