From 5ab34687a031fd951fd77a971e50c248f0c29f25 Mon Sep 17 00:00:00 2001 From: Alejandro Santiago Date: Mon, 28 Feb 2022 09:30:15 +0000 Subject: [PATCH] chore: remove generated counter example (#1) --- lib/app/view/app.dart | 3 +- lib/counter/counter.dart | 9 --- lib/counter/cubit/counter_cubit.dart | 15 ----- lib/counter/view/counter_page.dart | 62 ------------------ test/app/view/app_test.dart | 4 +- test/counter/cubit/counter_cubit_test.dart | 33 ---------- test/counter/view/counter_page_test.dart | 75 ---------------------- 7 files changed, 3 insertions(+), 198 deletions(-) delete mode 100644 lib/counter/counter.dart delete mode 100644 lib/counter/cubit/counter_cubit.dart delete mode 100644 lib/counter/view/counter_page.dart delete mode 100644 test/counter/cubit/counter_cubit_test.dart delete mode 100644 test/counter/view/counter_page_test.dart diff --git a/lib/app/view/app.dart b/lib/app/view/app.dart index 9ee67f74..164daf90 100644 --- a/lib/app/view/app.dart +++ b/lib/app/view/app.dart @@ -7,7 +7,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_localizations/flutter_localizations.dart'; -import 'package:pinball/counter/counter.dart'; import 'package:pinball/l10n/l10n.dart'; class App extends StatelessWidget { @@ -27,7 +26,7 @@ class App extends StatelessWidget { GlobalMaterialLocalizations.delegate, ], supportedLocales: AppLocalizations.supportedLocales, - home: const CounterPage(), + home: Container(), ); } } diff --git a/lib/counter/counter.dart b/lib/counter/counter.dart deleted file mode 100644 index c994a3d1..00000000 --- a/lib/counter/counter.dart +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright (c) 2021, Very Good Ventures -// https://verygood.ventures -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT. - -export 'cubit/counter_cubit.dart'; -export 'view/counter_page.dart'; diff --git a/lib/counter/cubit/counter_cubit.dart b/lib/counter/cubit/counter_cubit.dart deleted file mode 100644 index 74af7342..00000000 --- a/lib/counter/cubit/counter_cubit.dart +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2021, Very Good Ventures -// https://verygood.ventures -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT. - -import 'package:bloc/bloc.dart'; - -class CounterCubit extends Cubit { - CounterCubit() : super(0); - - void increment() => emit(state + 1); - void decrement() => emit(state - 1); -} diff --git a/lib/counter/view/counter_page.dart b/lib/counter/view/counter_page.dart deleted file mode 100644 index 4b87dfbb..00000000 --- a/lib/counter/view/counter_page.dart +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2021, Very Good Ventures -// https://verygood.ventures -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT. - -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:pinball/counter/counter.dart'; -import 'package:pinball/l10n/l10n.dart'; - -class CounterPage extends StatelessWidget { - const CounterPage({Key? key}) : super(key: key); - - @override - Widget build(BuildContext context) { - return BlocProvider( - create: (_) => CounterCubit(), - child: const CounterView(), - ); - } -} - -class CounterView extends StatelessWidget { - const CounterView({Key? key}) : super(key: key); - - @override - Widget build(BuildContext context) { - final l10n = context.l10n; - return Scaffold( - appBar: AppBar(title: Text(l10n.counterAppBarTitle)), - body: const Center(child: CounterText()), - floatingActionButton: Column( - mainAxisAlignment: MainAxisAlignment.end, - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - FloatingActionButton( - onPressed: () => context.read().increment(), - child: const Icon(Icons.add), - ), - const SizedBox(height: 8), - FloatingActionButton( - onPressed: () => context.read().decrement(), - child: const Icon(Icons.remove), - ), - ], - ), - ); - } -} - -class CounterText extends StatelessWidget { - const CounterText({Key? key}) : super(key: key); - - @override - Widget build(BuildContext context) { - final theme = Theme.of(context); - final count = context.select((CounterCubit cubit) => cubit.state); - return Text('$count', style: theme.textTheme.headline1); - } -} diff --git a/test/app/view/app_test.dart b/test/app/view/app_test.dart index 0809bf97..ab4cb16c 100644 --- a/test/app/view/app_test.dart +++ b/test/app/view/app_test.dart @@ -5,15 +5,15 @@ // license that can be found in the LICENSE file or at // https://opensource.org/licenses/MIT. +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pinball/app/app.dart'; -import 'package:pinball/counter/counter.dart'; void main() { group('App', () { testWidgets('renders CounterPage', (tester) async { await tester.pumpWidget(const App()); - expect(find.byType(CounterPage), findsOneWidget); + expect(find.byType(Container), findsOneWidget); }); }); } diff --git a/test/counter/cubit/counter_cubit_test.dart b/test/counter/cubit/counter_cubit_test.dart deleted file mode 100644 index 8d590266..00000000 --- a/test/counter/cubit/counter_cubit_test.dart +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (c) 2021, Very Good Ventures -// https://verygood.ventures -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT. - -import 'package:bloc_test/bloc_test.dart'; -import 'package:flutter_test/flutter_test.dart'; - -import 'package:pinball/counter/counter.dart'; - -void main() { - group('CounterCubit', () { - test('initial state is 0', () { - expect(CounterCubit().state, equals(0)); - }); - - blocTest( - 'emits [1] when increment is called', - build: CounterCubit.new, - act: (cubit) => cubit.increment(), - expect: () => [equals(1)], - ); - - blocTest( - 'emits [-1] when decrement is called', - build: CounterCubit.new, - act: (cubit) => cubit.decrement(), - expect: () => [equals(-1)], - ); - }); -} diff --git a/test/counter/view/counter_page_test.dart b/test/counter/view/counter_page_test.dart deleted file mode 100644 index 55fee5b7..00000000 --- a/test/counter/view/counter_page_test.dart +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) 2021, Very Good Ventures -// https://verygood.ventures -// -// Use of this source code is governed by an MIT-style -// license that can be found in the LICENSE file or at -// https://opensource.org/licenses/MIT. - -import 'package:bloc_test/bloc_test.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:flutter_test/flutter_test.dart'; -import 'package:mocktail/mocktail.dart'; - -import 'package:pinball/counter/counter.dart'; - -import '../../helpers/helpers.dart'; - -class MockCounterCubit extends MockCubit implements CounterCubit {} - -void main() { - group('CounterPage', () { - testWidgets('renders CounterView', (tester) async { - await tester.pumpApp(const CounterPage()); - expect(find.byType(CounterView), findsOneWidget); - }); - }); - - group('CounterView', () { - late CounterCubit counterCubit; - - setUp(() { - counterCubit = MockCounterCubit(); - }); - - testWidgets('renders current count', (tester) async { - const state = 42; - when(() => counterCubit.state).thenReturn(state); - await tester.pumpApp( - BlocProvider.value( - value: counterCubit, - child: const CounterView(), - ), - ); - expect(find.text('$state'), findsOneWidget); - }); - - testWidgets('calls increment when increment button is tapped', - (tester) async { - when(() => counterCubit.state).thenReturn(0); - when(() => counterCubit.increment()).thenReturn(null); - await tester.pumpApp( - BlocProvider.value( - value: counterCubit, - child: const CounterView(), - ), - ); - await tester.tap(find.byIcon(Icons.add)); - verify(() => counterCubit.increment()).called(1); - }); - - testWidgets('calls decrement when decrement button is tapped', - (tester) async { - when(() => counterCubit.state).thenReturn(0); - when(() => counterCubit.decrement()).thenReturn(null); - await tester.pumpApp( - BlocProvider.value( - value: counterCubit, - child: const CounterView(), - ), - ); - await tester.tap(find.byIcon(Icons.remove)); - verify(() => counterCubit.decrement()).called(1); - }); - }); -}