Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add act.enterTtext() #51

Merged
merged 35 commits into from
Mar 21, 2024
Merged

Add act.enterTtext() #51

merged 35 commits into from
Mar 21, 2024

Conversation

rehlma
Copy link
Collaborator

@rehlma rehlma commented Mar 19, 2024

Add the tester.enterText() functionality to Spot

testWidgets('enter text in text form field', (tester) async {
    await tester.pumpWidget(
      MaterialApp(home: Material(child: Form(child: TextFormField()))),
    );
    await act.enterText(spot<TextFormField>(), 'hello');
    spotText('hello').existsOnce();
});

Base automatically changed from add-onstage-offstage-support to main March 20, 2024 00:30
@passsy
Copy link
Owner

passsy commented Mar 21, 2024

I tried it, here's an example test for a login form.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:f93_forming_forms/main.dart';
import 'package:spot/spot.dart';

final textFieldLabelText = widgetProp<TextField, String?>(
  'labelText',
  (textField) => textField.decoration?.labelText,
);

void main() {
  group('Part 1', () {
    testWidgets('enter username password', (tester) async {
      await tester.pumpWidget(FormingFormsKata());

      final email = spot<TextField>()
          .whereWidgetProp(textFieldLabelText, (label) => label == 'Email')
        ..existsOnce();
      await act.enterText(email, 'pascal@phntm.xyz');

      final password = spot<TextField>()
          .whereWidgetProp(textFieldLabelText, (label) => label == 'Password')
        ..existsOnce();
      await act.enterText(password, 'asdfasdf');

      await act.tap(spotText('Accept AGBs'));
      await tester.pump();

      // wait for async matchers and debounce
      await tester.pump(Duration(milliseconds: 250));
      await tester.pump(Duration(seconds: 2));

      await act.tap(spotText('Sign in'));
      await tester.pump();
      await tester.pump(Duration(seconds: 1));

      spotText('Success').existsOnce();
    });
  });
}

@passsy passsy merged commit 4e88ca1 into main Mar 21, 2024
4 checks passed
@passsy passsy deleted the add-enter-text branch March 21, 2024 16:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants