Skip to content

Commit

Permalink
refactor(flutter_complex_list): improve test descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
felangel committed Jul 28, 2024
1 parent cf42796 commit 4477f74
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 26 deletions.
6 changes: 3 additions & 3 deletions examples/flutter_complex_list/test/app_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ void main() {
repository = MockRepository();
});

group('App', () {
testWidgets('is a MaterialApp', (tester) async {
group(App, () {
testWidgets('is a $MaterialApp', (tester) async {
expect(App(repository: repository), isA<MaterialApp>());
});

testWidgets('renders ComplexListPage', (tester) async {
testWidgets('renders $ComplexListPage', (tester) async {
when(repository.fetchItems).thenAnswer((_) async => []);
await tester.pumpWidget(App(repository: repository));
expect(find.byType(ComplexListPage), findsOneWidget);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import 'package:flutter_complex_list/repository.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

class MockRepository extends Mock implements Repository {}
class _MockRepository extends Mock implements Repository {}

void main() {
const mockItems = [
Expand All @@ -13,14 +13,14 @@ void main() {
Item(id: '3', value: '3'),
];

group('ComplexListCubit', () {
group(ComplexListCubit, () {
late Repository repository;

setUp(() {
repository = MockRepository();
repository = _MockRepository();
});

test('initial state is ComplexListState.loading', () {
test('initial state is ${ComplexListState.loading}', () {
expect(
ComplexListCubit(repository: repository).state,
const ComplexListState.loading(),
Expand All @@ -29,7 +29,7 @@ void main() {

group('fetchList', () {
blocTest<ComplexListCubit, ComplexListState>(
'emits ComplexListState.success after fetching list',
'emits ${ComplexListState.success} after fetching list',
setUp: () {
when(repository.fetchItems).thenAnswer((_) async => mockItems);
},
Expand All @@ -42,7 +42,7 @@ void main() {
);

blocTest<ComplexListCubit, ComplexListState>(
'emits ComplexListState.failure after failing to fetch list',
'emits ${ComplexListState.failure} after failing to fetch list',
setUp: () {
when(repository.fetchItems).thenThrow(Exception('Error'));
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter_complex_list/complex_list/complex_list.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('ComplexListState', () {
group(ComplexListState, () {
const mockItems = [Item(id: '1', value: '1')];
test('support value comparisons', () {
expect(ComplexListState.loading(), ComplexListState.loading());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import 'package:flutter_complex_list/complex_list/complex_list.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('Item', () {
group(Item, () {
const mockItem = Item(id: '1', value: 'Item 1');
test('support value comparisons', () {
test('supports value comparisons', () {
expect(mockItem, mockItem);
});

test('copyWith comparisons', () {
test('supports copyWith comparisons', () {
expect(mockItem.copyWith(), mockItem);
expect(
mockItem.copyWith(id: '2', value: 'Item 2'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import 'package:flutter_complex_list/repository.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';

class MockRepository extends Mock implements Repository {}
class _MockRepository extends Mock implements Repository {}

class MockComplexListCubit extends MockCubit<ComplexListState>
class _MockComplexListCubit extends MockCubit<ComplexListState>
implements ComplexListCubit {}

extension on WidgetTester {
Expand Down Expand Up @@ -46,21 +46,21 @@ void main() {
late ComplexListCubit listCubit;

setUp(() {
repository = MockRepository();
listCubit = MockComplexListCubit();
repository = _MockRepository();
listCubit = _MockComplexListCubit();
});

group('ListPage', () {
testWidgets('renders ComplexListView', (tester) async {
group(ComplexListPage, () {
testWidgets('renders $ComplexListView', (tester) async {
when(() => repository.fetchItems()).thenAnswer((_) async => []);
await tester.pumpListPage(repository);
expect(find.byType(ComplexListView), findsOneWidget);
});
});

group('ComplexListView', () {
group(ComplexListView, () {
testWidgets(
'renders CircularProgressIndicator while '
'renders $CircularProgressIndicator while '
'waiting for items to load', (tester) async {
when(() => listCubit.state).thenReturn(const ComplexListState.loading());
await tester.pumpListView(listCubit);
Expand All @@ -76,7 +76,7 @@ void main() {
});

testWidgets(
'renders ComplexListView after items '
'renders $ComplexListView after items '
'are finished loading', (tester) async {
when(() => listCubit.state).thenReturn(
const ComplexListState.success(mockItems),
Expand All @@ -94,7 +94,7 @@ void main() {
expect(find.text('No Content'), findsOneWidget);
});

testWidgets('renders three ItemTiles', (tester) async {
testWidgets('renders three ${ItemTile}s', (tester) async {
when(() => listCubit.state).thenReturn(
const ComplexListState.success(mockItems),
);
Expand All @@ -113,7 +113,7 @@ void main() {
});
});

group('ItemTile', () {
group(ItemTile, () {
testWidgets('renders value text', (tester) async {
const mockItem = Item(id: '1', value: 'Item 1');
when(() => listCubit.state).thenReturn(
Expand All @@ -135,7 +135,7 @@ void main() {
});

testWidgets(
'renders CircularProgressIndicator '
'renders $CircularProgressIndicator '
'when item is being deleting', (tester) async {
const mockItem = Item(id: '1', value: 'Item 1', isDeleting: true);
when(() => listCubit.state).thenReturn(
Expand Down
2 changes: 1 addition & 1 deletion examples/flutter_complex_list/test/repository_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import 'package:flutter_complex_list/repository.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
group('Repository', () {
group(Repository, () {
late Repository repository;

setUp(() {
Expand Down

0 comments on commit 4477f74

Please sign in to comment.