Unverified Commit 99790cc8 authored by chunhtai's avatar chunhtai Committed by GitHub

Add more use cases to a11y assessments (#132325)

see [go/flutter-gar-reporting-q3-2023](http://go/flutter-gar-reporting-q3-2023)
parent 33ef5e41
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'use_cases.dart';
class DatePickerUseCase extends UseCase {
@override
String get name => 'DatePicker';
@override
String get route => '/date-picker';
@override
Widget build(BuildContext context) => const _MainWidget();
}
class _MainWidget extends StatefulWidget {
const _MainWidget();
@override
State<_MainWidget> createState() => _MainWidgetState();
}
class _MainWidgetState extends State<_MainWidget> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('DatePicker'),
),
body: Center(
child: TextButton(
onPressed: () => showDatePicker(
context: context,
initialEntryMode: DatePickerEntryMode.calendarOnly,
initialDate: DateTime.now(),
firstDate: DateTime.now().subtract(const Duration(days: 365)),
lastDate: DateTime.now().add(const Duration(days: 365)),
),
child: const Text('Show Date Picker'),
),
),
);
}
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'use_cases.dart';
class DialogUseCase extends UseCase {
@override
String get name => 'Dialog';
@override
String get route => '/dialog';
@override
Widget build(BuildContext context) => const _MainWidget();
}
class _MainWidget extends StatelessWidget {
const _MainWidget();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('Dialog'),
),
body: Center(
child: TextButton(
onPressed: () => showDialog<String>(
context: context,
builder: (BuildContext context) => Dialog(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
const Text('This is a typical dialog.'),
const SizedBox(height: 15),
TextButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close'),
),
],
),
),
),
),
child: const Text('Show Dialog'),
),
),
);
}
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'use_cases.dart';
class SliderUseCase extends UseCase {
@override
String get name => 'Slider';
@override
String get route => '/slider';
@override
Widget build(BuildContext context) => const MainWidget();
}
class MainWidget extends StatefulWidget {
const MainWidget({super.key});
@override
State<MainWidget> createState() => MainWidgetState();
}
class MainWidgetState extends State<MainWidget> {
double currentSliderValue = 20;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('Slider'),
),
body: Center(
child: Slider(
value: currentSliderValue,
max: 100,
divisions: 5,
label: currentSliderValue.round().toString(),
onChanged: (double value) {
setState(() {
currentSliderValue = value;
});
},
),
),
);
}
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'use_cases.dart';
class TextFieldUseCase extends UseCase {
@override
String get name => 'TextField';
@override
String get route => '/text-field';
@override
Widget build(BuildContext context) => const _MainWidget();
}
class _MainWidget extends StatelessWidget {
const _MainWidget();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('TextField'),
),
body: const Center(
child: TextField(
decoration: InputDecoration(
labelText: 'Email',
suffixText: '@gmail.com',
hintText: 'Enter your email',
),
)
),
);
}
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'use_cases.dart';
class TextFieldDisabledUseCase extends UseCase {
@override
String get name => 'TextField disabled';
@override
String get route => '/text-field-disabled';
@override
Widget build(BuildContext context) => const _MainWidget();
}
class _MainWidget extends StatelessWidget {
const _MainWidget();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('TextField disabled'),
),
body: Center(
child: TextField(
decoration: const InputDecoration(
labelText: 'Email',
suffixText: '@gmail.com',
hintText: 'Enter your email',
enabled: false,
),
controller: TextEditingController(text: 'abc'),
)
),
);
}
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'use_cases.dart';
class TextFieldPasswordUseCase extends UseCase {
@override
String get name => 'TextField password';
@override
String get route => '/text-field-password';
@override
Widget build(BuildContext context) => const _MainWidget();
}
class _MainWidget extends StatelessWidget {
const _MainWidget();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: const Text('TextField password'),
),
body: const Center(
child: TextField(
decoration: InputDecoration(
labelText: 'Password',
hintText: 'Enter your password',
),
obscureText: true,
)
),
);
}
}
......@@ -6,6 +6,12 @@ import 'package:flutter/widgets.dart';
import 'check_box_list_tile.dart';
import 'check_box_list_tile_disabled.dart';
import 'date_picker.dart';
import 'dialog.dart';
import 'slider.dart';
import 'text_field.dart';
import 'text_field_disabled.dart';
import 'text_field_password.dart';
abstract class UseCase {
String get name;
......@@ -16,4 +22,10 @@ abstract class UseCase {
final List<UseCase> useCases = <UseCase>[
CheckBoxListTile(),
CheckBoxListTileDisabled(),
DialogUseCase(),
SliderUseCase(),
TextFieldUseCase(),
TextFieldDisabledUseCase(),
TextFieldPasswordUseCase(),
DatePickerUseCase(),
];
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:a11y_assessments/use_cases/date_picker.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'test_utils.dart';
void main() {
testWidgets('date picker can run', (WidgetTester tester) async {
await pumpsUseCase(tester, DatePickerUseCase());
expect(find.text('Show Date Picker'), findsOneWidget);
await tester.tap(find.text('Show Date Picker'));
await tester.pumpAndSettle();
expect(find.byType(DatePickerDialog), findsOneWidget);
});
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:a11y_assessments/use_cases/dialog.dart';
import 'package:flutter_test/flutter_test.dart';
import 'test_utils.dart';
void main() {
testWidgets('dialog can run', (WidgetTester tester) async {
await pumpsUseCase(tester, DialogUseCase());
expect(find.text('Show Dialog'), findsOneWidget);
await tester.tap(find.text('Show Dialog'));
await tester.pumpAndSettle();
expect(find.text('This is a typical dialog.'), findsOneWidget);
await tester.tap(find.text('Close'));
await tester.pumpAndSettle();
expect(find.text('Show Dialog'), findsOneWidget);
});
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:a11y_assessments/use_cases/slider.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'test_utils.dart';
void main() {
testWidgets('slider can run', (WidgetTester tester) async {
await pumpsUseCase(tester, SliderUseCase());
expect(find.byType(Slider), findsOneWidget);
await tester.tapAt(tester.getCenter(find.byType(Slider)));
await tester.pumpAndSettle();
final MainWidgetState state = tester.state<MainWidgetState>(find.byType(MainWidget));
expect(state.currentSliderValue, 60);
});
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:a11y_assessments/use_cases/use_cases.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
Future<void> pumpsUseCase(WidgetTester tester, UseCase useCase) async {
await tester.pumpWidget(MaterialApp(
home: Builder(
builder: (BuildContext context) {
return useCase.build(context);
},
),
));
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:a11y_assessments/use_cases/text_field_disabled.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'test_utils.dart';
void main() {
testWidgets('text field disabled can run', (WidgetTester tester) async {
await pumpsUseCase(tester, TextFieldDisabledUseCase());
expect(find.byType(TextField), findsOneWidget);
expect(find.text('abc'), findsOneWidget);
await tester.tap(find.byType(TextField));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextField), 'bde');
await tester.pumpAndSettle();
expect(find.text('abc'), findsOneWidget);
});
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:a11y_assessments/use_cases/text_field_password.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'test_utils.dart';
void main() {
testWidgets('text field password can run', (WidgetTester tester) async {
await pumpsUseCase(tester, TextFieldPasswordUseCase());
expect(find.byType(TextField), findsOneWidget);
await tester.tap(find.byType(TextField));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextField), 'abc');
await tester.pumpAndSettle();
expect(find.text('abc'), findsOneWidget);
});
}
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:a11y_assessments/use_cases/text_field.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'test_utils.dart';
void main() {
testWidgets('text field can run', (WidgetTester tester) async {
await pumpsUseCase(tester, TextFieldUseCase());
expect(find.byType(TextField), findsOneWidget);
await tester.tap(find.byType(TextField));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextField), 'abc');
await tester.pumpAndSettle();
expect(find.text('abc'), findsOneWidget);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment