From 5438983775347c0d335d43b66d6ee302f1442d95 Mon Sep 17 00:00:00 2001 From: Lucio Baglione Date: Tue, 16 Apr 2024 17:52:59 +0200 Subject: [PATCH] test: Add tests for brand Theme switching. --- .../test/src/brand_test.dart | 124 ++++++++++++++++++ .../lib/src/brands.dart | 24 ++++ 2 files changed, 148 insertions(+) create mode 100644 catalyst_voices/packages/catalyst_voices_blocs/test/src/brand_test.dart create mode 100644 catalyst_voices/packages/catalyst_voices_models/lib/src/brands.dart diff --git a/catalyst_voices/packages/catalyst_voices_blocs/test/src/brand_test.dart b/catalyst_voices/packages/catalyst_voices_blocs/test/src/brand_test.dart new file mode 100644 index 000000000..154c5264a --- /dev/null +++ b/catalyst_voices/packages/catalyst_voices_blocs/test/src/brand_test.dart @@ -0,0 +1,124 @@ + +import 'package:catalyst_voices_assets/catalyst_voices_assets.dart'; +import 'package:catalyst_voices_blocs/src/brand/brand_bloc.dart'; +import 'package:catalyst_voices_models/catalyst_voices_models.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_bloc/flutter_bloc.dart'; +import 'package:flutter_test/flutter_test.dart'; + +void main() { + const catalystKey = Key('C'); + const dummyKey = Key('D'); + + Widget buildApp() => BlocProvider( + create: (context) => BrandBloc(), + child: BlocBuilder( + builder: (context, state) { + return MaterialApp( + builder: (context, state) => Scaffold( + body: Row( + children: [ + MaterialButton( + key: catalystKey, + color: Theme.of(context).primaryColor, + onPressed: () { + context.read().add( + const BrandChanged(BrandKey.catalyst), + ); + }, + child: const Text('Catalyst'), + ), + MaterialButton( + key: dummyKey, + color: Theme.of(context).primaryColor, + child: const Text('Dummy'), + onPressed: () { + context.read().add( + const BrandChanged(BrandKey.dummy), + ); + }, + ), + ], + ), + ), + theme: state.themeData, + ); + }, + ), + ); + + group('Test brands', () { + + const dummyColor = Color(0xFFFF5722); + + testWidgets('Default Catalyst theme is applied', (tester) async { + await tester.pumpWidget( + buildApp(), + ); + + final catalystButton = find.byKey(catalystKey); + final dummyButton = find.byKey(dummyKey); + + expect(catalystButton, findsOneWidget); + expect(dummyButton, findsOneWidget); + expect( + tester.widget(catalystButton).color, + VoicesColors.blue, + ); + expect( + tester.widget(dummyButton).color, + VoicesColors.blue, + ); + }); + testWidgets('Dummy Theme is applied after switch', (tester) async { + await tester.pumpWidget( + buildApp(), + ); + + final catalystButton = find.byKey(catalystKey); + final dummyButton = find.byKey(dummyKey); + + expect(catalystButton, findsOneWidget); + expect(dummyButton, findsOneWidget); + + await tester.tap(dummyButton); + // We need to wait for the animation to complete + await tester.pumpAndSettle(); + expect( + tester.widget(catalystButton).color, + dummyColor, + ); + expect( + tester.widget(catalystButton).color, + dummyColor, + ); + }); + + testWidgets('Catalyst Theme is applied after switch', (tester) async { + await tester.pumpWidget( + buildApp(), + ); + + final catalystButton = find.byKey(catalystKey); + final dummyButton = find.byKey(dummyKey); + + expect(catalystButton, findsOneWidget); + expect(dummyButton, findsOneWidget); + + await tester.tap(dummyButton); + await tester.pumpAndSettle(); + await tester.tap(catalystButton); + await tester.pumpAndSettle(); + expect( + tester.widget(catalystButton).color, + VoicesColors.blue, + ); + expect( + tester.widget(catalystButton).color, + VoicesColors.blue, + ); + }); + + }); + +} diff --git a/catalyst_voices/packages/catalyst_voices_models/lib/src/brands.dart b/catalyst_voices/packages/catalyst_voices_models/lib/src/brands.dart new file mode 100644 index 000000000..0a64fff9f --- /dev/null +++ b/catalyst_voices/packages/catalyst_voices_models/lib/src/brands.dart @@ -0,0 +1,24 @@ +import 'package:catalyst_voices_assets/catalyst_voices_assets.dart'; +import 'package:catalyst_voices_assets/generated/colors.gen.dart'; + +import 'package:flutter/material.dart'; + +enum BrandKey { + catalyst, + dummy, +} + +final Map brands = { + BrandKey.catalyst: ThemeData( + colorScheme: ColorScheme.fromSeed( + seedColor: VoicesColors.blue, + primary: VoicesColors.blue, + ), + ), + BrandKey.dummy: ThemeData.from( + colorScheme: ColorScheme.fromSeed( + seedColor: Color(0xFFFF5722), + primary: Color(0xFFFF5722), + ), + ), +};