Skip to content

Commit

Permalink
test: update password
Browse files Browse the repository at this point in the history
  • Loading branch information
thelukewalton committed Jun 24, 2024
1 parent 3a6be95 commit a83e26c
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
8 changes: 1 addition & 7 deletions lib/src/components/password/password_input.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,8 @@ class ZetaPasswordInput extends ZetaFormField<String> {
..add(StringProperty('hintText', hintText))
..add(StringProperty('label', label))
..add(StringProperty('footerText', hintText))
..add(
ObjectFlagProperty<String? Function(String? p1)?>.has(
'validator',
validator,
),
)
..add(ObjectFlagProperty<String? Function(String? p1)?>.has('validator', validator))
..add(EnumProperty<ZetaWidgetSize>('size', size))
..add(DiagnosticsProperty<bool>('rounded', rounded))
..add(StringProperty('placeholder', placeholder))
..add(ObjectFlagProperty<void Function(String? val)?>.has('onSubmit', onSubmit))
..add(StringProperty('errorText', errorText));
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions test/src/components/password/password_input_test.dart
Original file line number Diff line number Diff line change
@@ -1,17 +1,31 @@
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:path/path.dart';
import 'package:zeta_flutter/zeta_flutter.dart';

import '../../../test_utils/test_app.dart';
import '../../../test_utils/tolerant_comparator.dart';
import '../../../test_utils/utils.dart';

void main() {
setUpAll(() {
final testUri = Uri.parse(getCurrentPath('password'));
goldenFileComparator = TolerantComparator(testUri, tolerance: 0.01);
});

testWidgets('ZetaPasswordInput initializes correctly', (WidgetTester tester) async {
await tester.pumpWidget(
const TestApp(
home: ZetaPasswordInput(),
),
);
expect(find.byType(ZetaPasswordInput), findsOneWidget);

await expectLater(
find.byType(ZetaPasswordInput),
matchesGoldenFile(join(getCurrentPath('password'), 'password_default.png')),
);
});

testWidgets('Test password visibility', (WidgetTester tester) async {
Expand Down Expand Up @@ -46,6 +60,7 @@ void main() {
child: ZetaPasswordInput(
controller: controller,
validator: testValidator,
rounded: false,
),
),
),
Expand All @@ -55,5 +70,28 @@ void main() {

// There will be two matches for the error text as the form field itself contains a hidden one.
expect(find.text('Error'), findsExactly(2));
final obscureIconOn = find.byIcon(ZetaIcons.visibility_off_sharp);
expect(obscureIconOn, findsOneWidget);

await expectLater(
find.byType(ZetaPasswordInput),
matchesGoldenFile(join(getCurrentPath('password'), 'password_error.png')),
);
});

testWidgets('debugFillProperties works correctly', (WidgetTester tester) async {
final diagnostics = DiagnosticPropertiesBuilder();
const ZetaPasswordInput().debugFillProperties(diagnostics);

expect(diagnostics.finder('controller'), 'null');
expect(diagnostics.finder('obscureText'), 'true');
expect(diagnostics.finder('hintText'), 'null');
expect(diagnostics.finder('label'), 'null');
expect(diagnostics.finder('footerText'), 'null');
expect(diagnostics.finder('validator'), 'null');
expect(diagnostics.finder('size'), 'large');
expect(diagnostics.finder('placeholder'), 'null');
expect(diagnostics.finder('onSubmit'), 'null');
expect(diagnostics.finder('errorText'), 'null');
});
}

0 comments on commit a83e26c

Please sign in to comment.