From e7d70288d9222a6953307d1306a386b307693549 Mon Sep 17 00:00:00 2001 From: Arteev Raina Date: Wed, 27 Jan 2021 12:09:05 +0530 Subject: [PATCH] [animations]: added test for AnimatedList (#637) --- animations/test/misc/animated_list_test.dart | 138 +++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 animations/test/misc/animated_list_test.dart diff --git a/animations/test/misc/animated_list_test.dart b/animations/test/misc/animated_list_test.dart new file mode 100644 index 000000000..e810ddab4 --- /dev/null +++ b/animations/test/misc/animated_list_test.dart @@ -0,0 +1,138 @@ +// Copyright 2020 The Flutter team. 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:animations/src/misc/animated_list.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_test/flutter_test.dart'; + +Widget createAnimatedListDemoScreen() => MaterialApp( + home: AnimatedListDemo(), + ); + +void main() { + group('Animated List Tests', () { + testWidgets('Initial length of list', (tester) async { + await tester.pumpWidget(createAnimatedListDemoScreen()); + + // Get the initial length of list. + var initialLength = tester.widgetList(find.byType(ListTile)).length; + + // Initial length of list should be equal to 5. + expect( + initialLength, + equals(5), + ); + }); + + testWidgets('Length of list increases on Add Icon Button tap', + (tester) async { + await tester.pumpWidget(createAnimatedListDemoScreen()); + + // Get the initial length of list. + var initialLength = tester.widgetList(find.byType(ListTile)).length; + + // Tap on the Add Icon Button. + await tester.tap(find.byIcon(Icons.add)); + await tester.pumpAndSettle(); + + // Get the new length of list. + var newLength = tester.widgetList(find.byType(ListTile)).length; + + // New length should be greater than initial length by one. + expect( + newLength, + equals(initialLength + 1), + ); + }); + + testWidgets( + 'Length of list decreases on Delete Icon Button tap at middle index', + (tester) async { + await tester.pumpWidget(createAnimatedListDemoScreen()); + + // Get the initial length of list. + var initialLength = tester.widgetList(find.byType(ListTile)).length; + + // Tap on the Delete Icon Button at middle index. + await tester.tap(find.byIcon(Icons.delete).at(initialLength ~/ 2)); + await tester.pumpAndSettle(); + + // Get the new length of list. + var newLength = tester.widgetList(find.byType(ListTile)).length; + + // New length should be less than initial length by one. + expect( + newLength, + equals(initialLength - 1), + ); + }); + + testWidgets( + 'Length of list decreases on Delete Icon Button tap at start index', + (tester) async { + await tester.pumpWidget(createAnimatedListDemoScreen()); + + // Get the initial length of list. + var initialLength = tester.widgetList(find.byType(ListTile)).length; + + // Tap on the Delete Icon Button at start index. + await tester.tap(find.byIcon(Icons.delete).at(0)); + await tester.pumpAndSettle(); + + // Get the new length of list. + var newLength = tester.widgetList(find.byType(ListTile)).length; + + // New length should be less than initial length by one. + expect( + newLength, + equals(initialLength - 1), + ); + }); + + testWidgets( + 'Length of list decreases on Delete Icon Button tap at end index', + (tester) async { + await tester.pumpWidget(createAnimatedListDemoScreen()); + + // Get the initial length of list. + var initialLength = tester.widgetList(find.byType(ListTile)).length; + + // Tap on the Delete Icon Button at end index. + await tester.tap(find.byIcon(Icons.delete).at(initialLength - 1)); + await tester.pumpAndSettle(); + + // Get the new length of list. + var newLength = tester.widgetList(find.byType(ListTile)).length; + + // New Length should be less than initial length by one. + expect( + newLength, + equals(initialLength - 1), + ); + }); + + testWidgets('All ListTiles deleted', (tester) async { + await tester.pumpWidget(createAnimatedListDemoScreen()); + + // Get the initial length of list. + var initialLength = tester.widgetList(find.byType(ListTile)).length; + + // Iterating over all the Delete Icon Buttons. + for (var i = 0; i < initialLength; i++) { + // Tap on the Delete Icon + await tester.tap(find.byIcon(Icons.delete).first); + await tester.pumpAndSettle(); + } + + // Get the final length of list. + var finalLength = tester.widgetList(find.byType(ListTile)).length; + + // New length should be zero. + expect( + finalLength, + equals(0), + ); + }); + }); +}