Update Chips examples and rename files (#108538)

This commit is contained in:
Taha Tesser
2022-07-29 10:17:06 +03:00
committed by GitHub
parent 8da73f7229
commit 76df7368b5
14 changed files with 422 additions and 128 deletions

View File

@@ -0,0 +1,22 @@
// 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 'package:flutter_api_samples/material/action_chip/action_chip.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('ActionChip updates avatar when tapped', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ChipApp(),
);
expect(find.byIcon(Icons.favorite_border), findsOneWidget);
await tester.tap(find.byType(ActionChip));
await tester.pumpAndSettle();
expect(find.byIcon(Icons.favorite), findsOneWidget);
});
}

View File

@@ -0,0 +1,24 @@
// 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 'package:flutter_api_samples/material/choice_chip/choice_chip.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Can choose an item using ChoiceChip', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ChipApp(),
);
ChoiceChip choosenChip = tester.widget(find.byType(ChoiceChip).at(1));
expect(choosenChip.selected, true);
await tester.tap(find.byType(ChoiceChip).at(0));
await tester.pumpAndSettle();
choosenChip = tester.widget(find.byType(ChoiceChip).at(0));
expect(choosenChip.selected, true);
});
}

View File

@@ -0,0 +1,36 @@
// 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 'package:flutter_api_samples/material/filter_chip/filter_chip.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('Filter exercises using FilterChip', (WidgetTester tester) async {
const String baseText = 'Looking for: ';
await tester.pumpWidget(
const example.ChipApp(),
);
expect(find.text(baseText), findsOneWidget);
FilterChip filterChip = tester.widget(find.byType(FilterChip).at(2));
expect(filterChip.selected, false);
await tester.tap(find.byType(FilterChip).at(2));
await tester.pumpAndSettle();
filterChip = tester.widget(find.byType(FilterChip).at(2));
expect(filterChip.selected, true);
expect(find.text('${baseText}cycling'), findsOneWidget);
await tester.tap(find.byType(FilterChip).at(3));
await tester.pumpAndSettle();
filterChip = tester.widget(find.byType(FilterChip).at(3));
expect(filterChip.selected, true);
expect(find.text('${baseText}cycling, hiking'), findsOneWidget);
});
}

View File

@@ -0,0 +1,33 @@
// 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 'package:flutter_api_samples/material/input_chip/input_chip.0.dart' as example;
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('', (WidgetTester tester) async {
await tester.pumpWidget(
const example.ChipApp(),
);
expect(find.byType(InputChip), findsNWidgets(3));
await tester.tap(find.byIcon(Icons.clear).at(0));
await tester.pumpAndSettle();
expect(find.byType(InputChip), findsNWidgets(2));
await tester.tap(find.byIcon(Icons.clear).at(0));
await tester.pumpAndSettle();
expect(find.byType(InputChip), findsNWidgets(1));
await tester.tap(find.byIcon(Icons.clear).at(0));
await tester.pumpAndSettle();
expect(find.byType(InputChip), findsNWidgets(0));
await tester.tap(find.text('Reset'));
await tester.pumpAndSettle();
expect(find.byType(InputChip), findsNWidgets(3));
});
}