Skip to content

Commit

Permalink
Pump smart, not hard (#334)
Browse files Browse the repository at this point in the history
  • Loading branch information
passsy authored Mar 4, 2024
1 parent 92cf4b8 commit 8ba83b8
Show file tree
Hide file tree
Showing 7 changed files with 176 additions and 91 deletions.
12 changes: 6 additions & 6 deletions test/feedback_flow_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void main() {
final confirmDiscardButton =
_larryPageView.spotSingleText('l10n.feedbackDiscardConfirmButton');
confirmDiscardButton.existsOnce();
await tester.pumpAndSettle(const Duration(seconds: 3));
await tester.pumpSmart(const Duration(seconds: 3));
confirmDiscardButton.doesNotExist();
});

Expand Down Expand Up @@ -179,7 +179,7 @@ void main() {
await robot.enterFeedbackMessage('test message');
await robot.goToNextStep();
await robot.skipScreenshot();
await tester.pumpAndSettle(const Duration(seconds: 1));
await tester.pumpSmart(const Duration(seconds: 1));
await robot.goToNextStep();
await robot.submitFeedback();
await robot.waitUntilWiredashIsClosed();
Expand Down Expand Up @@ -209,7 +209,7 @@ void main() {
await robot.enterFeedbackMessage('test message');
await robot.goToNextStep();
await robot.skipScreenshot();
await tester.pumpAndSettle(const Duration(seconds: 1));
await tester.pumpSmart(const Duration(seconds: 1));
await robot.enterEmail(adjustedEmail);
// Go back to Screenshot Overview
await robot.goToPrevStep();
Expand Down Expand Up @@ -249,7 +249,7 @@ void main() {
await robot.enterScreenshotMode();
await robot.goToPrevStep();
await robot.skipScreenshot();
await tester.pumpAndSettle(const Duration(seconds: 1));
await tester.pumpSmart(const Duration(seconds: 1));
await robot.goToNextStep();
await robot.submitFeedback();
await robot.waitUntilWiredashIsClosed();
Expand Down Expand Up @@ -596,7 +596,7 @@ void main() {
// Then tap to close while backdrop is still moving
await robot.closeWiredashWithButton(); // caused crash

await tester.pumpAndSettle();
await tester.pumpSmart();
spot<FeedbackBackdrop>().doesNotExist();
});

Expand Down Expand Up @@ -637,7 +637,7 @@ void main() {
spotSingle<Step1FeedbackMessage>().doesNotExist();

// wait for wiredash hide() after 1s delay
await tester.pumpAndSettle(const Duration(seconds: 1));
await tester.pumpSmart(const Duration(seconds: 1));

// back on first step, the form got reset
spotSingle<Step1FeedbackMessage>().existsOnce();
Expand Down
6 changes: 2 additions & 4 deletions test/metadata_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ void main() {
);
});
// send ping
await tester.pump(const Duration(seconds: 5));
await tester.pumpHardAndSettle();
await tester.pumpSmart(const Duration(seconds: 5));
final latestPing = robot.mockServices.mockApi.pingInvocations.latest;
final ping = latestPing[0] as PingRequestBody?;
expect(ping!.buildVersion, '1.2.3');
Expand All @@ -81,8 +80,7 @@ void main() {
);
});
// send ping
await tester.pump(const Duration(seconds: 5));
await tester.pumpHardAndSettle();
await tester.pumpSmart(const Duration(seconds: 5));
final latestPing = robot.mockServices.mockApi.pingInvocations.latest;
final ping = latestPing[0] as PingRequestBody?;
expect(ping!.buildVersion, '0.1.0'); // from appInfo
Expand Down
14 changes: 4 additions & 10 deletions test/offline_feedback_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,13 @@ void main() {
};

// wait for the UploadPendingFeedbackJob to start
await tester.pumpAndSettle(const Duration(seconds: 5));
await tester.pumpSmart(const Duration(seconds: 5));

final future = ResultFuture(
robot.mockServices.services.syncEngine
.onEvent(SdkEvent.appStartDelayed),
);
while (!future.isComplete) {
// every disk io call needs to be pumped
await tester.pumpHardAndSettle();
}
await tester.waitUntil(() => future.isComplete, isTrue);

final latestFeedbackCall =
robot.mockServices.mockApi.sendFeedbackInvocations.latest;
Expand Down Expand Up @@ -111,16 +108,13 @@ void main() {
};

// wait for the UploadPendingFeedbackJob to start
await tester.pumpAndSettle(const Duration(seconds: 5));
await tester.pumpSmart(const Duration(seconds: 5));

final future = ResultFuture(
robot.mockServices.services.syncEngine
.onEvent(SdkEvent.appStartDelayed),
);
while (!future.isComplete) {
// every disk io call needs to be pumped
await tester.pumpHardAndSettle();
}
await tester.waitUntil(() => future.isComplete, isTrue);

final latestFeedbackCall =
robot.mockServices.mockApi.sendFeedbackInvocations.latest;
Expand Down
3 changes: 2 additions & 1 deletion test/promoterscore_flow_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:wiredash/src/_wiredash_internal.dart';

import 'util/flutter_error.dart';
import 'util/robot.dart';
import 'util/wiredash_tester.dart';

void main() {
group('promoter score', () {
Expand Down Expand Up @@ -192,7 +193,7 @@ void main() {
spotSingle<PsStep1Rating>().doesNotExist();

// wait for wiredash hide() after 2s delay
await tester.pumpAndSettle(const Duration(seconds: 3));
await tester.pumpSmart(const Duration(seconds: 3));

// back on first step, the form got reset
spotSingle<PsStep1Rating>().existsOnce();
Expand Down
86 changes: 32 additions & 54 deletions test/util/robot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,7 @@ class WiredashTestRobot {
final feedbackText = spotSingle<MaterialApp>().spotSingleText('Feedback')
..existsOnce();
await _tap(feedbackText);

// process the event, wait for backdrop to appear in the widget tree
await tester.pumpN(4);
// wait for animation finish
await tester.pump(const Duration(milliseconds: 500));
// When the pump pattern on top fails, use this instead
// await tester.pumpAndSettle();
await tester.pumpSmart();

_spotBackdrop.spotSingle<WiredashFeedbackFlow>().existsOnce();
print('opened Wiredash');
Expand All @@ -253,13 +247,7 @@ class WiredashTestRobot {
.spotSingleText('Promoter Score')
..existsOnce();
await _tap(promoterScoreText);

// process the event, wait for backdrop to appear in the widget tree
await tester.pumpN(4);
// wait for animation finish
await tester.pump(const Duration(milliseconds: 500));
// When the pump pattern on top fails, use this instead
// await tester.pumpAndSettle();
await tester.pumpSmart();

_spotBackdrop.spotSingle<PromoterScoreFlow>().existsOnce();
print('opened promoter score');
Expand All @@ -273,14 +261,15 @@ class WiredashTestRobot {
],
)..existsOnce();
await _tap(spotCloseButton);
await tester.pumpSmart();
print('closed Wiredash');
}

Future<void> closeWiredash() async {
// tap app which is located at the bottom of the screen
final bottomRight = tester.getBottomRight(find.byType(Wiredash));
await tester.tapAt(Offset(bottomRight.dx / 2, bottomRight.dy - 20));
await tester.pumpAndSettle();
await tester.pumpSmart();
_spotBackdrop.spotSingle<WiredashFeedbackFlow>().doesNotExist();
_spotBackdrop.spotSingle<PromoterScoreFlow>().doesNotExist();
print('closed Wiredash');
Expand All @@ -289,7 +278,7 @@ class WiredashTestRobot {
Future<void> enterFeedbackMessage(String message) async {
_spotPageView.spotSingle<Step1FeedbackMessage>().existsOnce();
await tester.enterText(find.byType(TextField), message);
await tester.pumpAndSettle();
await tester.pumpSmart();
final button = spotSingle<TronButton>(
children: [spotSingleText('l10n.feedbackNextButton')],
);
Expand All @@ -309,7 +298,7 @@ class WiredashTestRobot {
)..existsOnce();
step.spotSingleText('l10n.promoterScoreBackButton').existsOnce();
await tester.enterText(find.byType(TextField), message);
await tester.pumpAndSettle();
await tester.pumpSmart();

// TODO find easier way to check if the button is clickable. Hit Testing?
await done.waitUntil(tester, (it) => it.isTappable(true));
Expand All @@ -320,7 +309,7 @@ class WiredashTestRobot {
Future<void> enterEmail(String emailAddress) async {
final step = _spotPageView.spotSingle<Step5Email>()..existsOnce();
await tester.enterText(step.spotSingle<TextField>().finder, emailAddress);
await tester.pumpAndSettle();
await tester.pumpSmart();
print('entered email: $emailAddress');
}

Expand All @@ -330,8 +319,7 @@ class WiredashTestRobot {
await _tap(
step.spotSingleText('l10n.feedbackStep3ScreenshotOverviewSkipButton'),
);
await tester.pumpAndSettle();
await tester.pumpAndSettle();
await tester.pumpSmart();
final newStatus = services.feedbackModel.feedbackFlowStatus;
print('Skipped taking screenshot, next $newStatus');
}
Expand All @@ -352,13 +340,13 @@ class WiredashTestRobot {
);
print('submit feedback');
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
}

Future<void> skipEmail({bool catchError = true}) async {
final step = _spotPageView.spotSingle<Step5Email>()..existsOnce();
await _tap(step.spotSingleText('l10n.feedbackNextButton'));
await tester.pumpAndSettle();
await tester.pumpAndSettle();
await tester.pumpSmart();

final newStatus = services.feedbackModel.feedbackFlowStatus;
if (catchError) {
Expand All @@ -372,15 +360,15 @@ class WiredashTestRobot {
Future<void> submitEmailViaButton() async {
final step = _spotPageView.spotSingle<Step5Email>()..existsOnce();
await _tap(step.spotSingleText('l10n.feedbackNextButton'));
await tester.pumpAndSettle();
await tester.pumpSmart();

final newStatus = services.feedbackModel.feedbackFlowStatus;
print('Submitted email, next $newStatus');
}

Future<void> submitEmailViaKeyboard() async {
await tester.testTextInput.receiveAction(TextInputAction.send);
await tester.pumpAndSettle();
await tester.pumpSmart();

final newStatus = services.feedbackModel.feedbackFlowStatus;
print('Submitted email, next $newStatus');
Expand All @@ -389,8 +377,7 @@ class WiredashTestRobot {
Future<void> goToNextStep() async {
final oldStatus = services.feedbackModel.feedbackFlowStatus;
await _tap(spotSingleText('l10n.feedbackNextButton'));
await tester.pumpAndSettle();
await tester.pumpAndSettle();
await tester.pumpSmart();
final newStatus = services.feedbackModel.feedbackFlowStatus;
print('Jumped from $oldStatus to next $newStatus');
}
Expand All @@ -406,7 +393,7 @@ class WiredashTestRobot {
await _tap(texts.first());
}

await tester.pumpAndSettle();
await tester.pumpSmart();
final newStatus = services.feedbackModel.feedbackFlowStatus;
print('Jumped back from $oldStatus to prev $newStatus');
}
Expand All @@ -421,8 +408,7 @@ class WiredashTestRobot {
const Offset(0, -5000),
5000,
);
await tester.pump(const Duration(milliseconds: 100));
await tester.pumpAndSettle();
await tester.pumpSmart();
}

Future<void> enterScreenshotMode() async {
Expand All @@ -442,7 +428,7 @@ class WiredashTestRobot {
..existsOnce();
await _tap(addAttachmentItem);
}

await tester.pumpSmart();
await tester.waitUntil(find.byType(ScreenshotBar), findsOneWidget);
await tester.waitUntil(find.byIcon(Wirecons.camera), findsOneWidget);
expect(
Expand All @@ -466,10 +452,10 @@ class WiredashTestRobot {
screenshotBar
.spotSingleText('l10n.feedbackStep3ScreenshotBarCaptureButton'),
);
while (services.feedbackModel.feedbackFlowStatus !=
FeedbackFlowStatus.screenshotDrawing) {
await tester.pumpHardAndSettle();
}
await tester.waitUntil(
() => services.feedbackModel.feedbackFlowStatus,
isNot(FeedbackFlowStatus.screenshotDrawing),
);

// Wait for active "Save" button
final nextButton = screenshotBar.spotSingle<TronButton>(
Expand All @@ -496,7 +482,7 @@ class WiredashTestRobot {
await _tap(
screenshotBar.spotSingleText('l10n.feedbackStep3ScreenshotBarSaveButton'),
);
await tester.pumpHardAndSettle(const Duration(milliseconds: 100));
await tester.pumpSmart(const Duration(milliseconds: 100));

// wait until the animation is closed
await tester.waitUntil(
Expand All @@ -507,7 +493,7 @@ class WiredashTestRobot {
);

await tester.waitUntil(
services.feedbackModel.feedbackFlowStatus,
() => services.feedbackModel.feedbackFlowStatus,
isNot(
anyOf(
FeedbackFlowStatus.screenshotDrawing,
Expand All @@ -524,17 +510,17 @@ class WiredashTestRobot {

Future<void> selectLabel(String labelText) async {
await _tap(spotSingleText(labelText));
await tester.pumpAndSettle();
await tester.pumpSmart();
}

Future<void> pressAndroidBackButton() async {
// ignore: invalid_use_of_protected_member
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
await tester.pumpSmart();
}

Future<void> waitUntilWiredashIsClosed() async {
await tester.pump(const Duration(seconds: 1));
await tester.pumpSmart();
await tester.waitUntil(
() => services.wiredashModel.isWiredashActive,
isFalse,
Expand All @@ -554,12 +540,8 @@ class WiredashTestRobot {
.first();

await _tap(spotRatingCard(rating));
await tester.pumpAndSettle();

/// automatically goes to next step
await tester.pumpAndSettle();
await tester.pumpAndSettle();
await tester.pumpAndSettle(const Duration(milliseconds: 600));
await tester.pumpSmart();
await tester.pumpSmart(const Duration(milliseconds: 600));
}

Future<void> submitPromoterScore() async {
Expand All @@ -580,7 +562,7 @@ class WiredashTestRobot {
scrollable: scrollable.finder,
);
await _tap(submitButton);
await tester.pumpAndSettle();
await tester.pumpSmart();
print('submit Promoter Score');
}

Expand All @@ -605,7 +587,7 @@ class WiredashTestRobot {
Future<void> discardFeedback() async {
_discard.existsOnce();
await _tap(_discard);
await tester.pump();
await tester.pumpSmart();
_reallyDiscard.existsOnce();
}

Expand All @@ -614,7 +596,7 @@ class WiredashTestRobot {
_discard.doesNotExist();
_reallyDiscard.existsOnce();
await _tap(_reallyDiscard);
await tester.pump();
await tester.pumpSmart();
}
}

Expand Down Expand Up @@ -791,12 +773,8 @@ extension SpotWaitUntil<W extends Widget> on SingleWidgetSelector<W> {
'\tException: $error',
);
}
if (attempt < 10) {
await tester.pumpAndSettle(duration);
} else {
await tester.pumpHardAndSettle(duration);
await tester.pump();
}

await tester.pumpSmart();
}
}
}
Expand Down
Loading

0 comments on commit 8ba83b8

Please sign in to comment.