Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add tests for brand Theme switching.
- Loading branch information
Showing
2 changed files
with
148 additions
and
0 deletions.
There are no files selected for viewing
124 changes: 124 additions & 0 deletions
124
catalyst_voices/packages/catalyst_voices_blocs/test/src/brand_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BrandBloc, BrandState>( | ||
builder: (context, state) { | ||
return MaterialApp( | ||
builder: (context, state) => Scaffold( | ||
body: Row( | ||
children: [ | ||
MaterialButton( | ||
key: catalystKey, | ||
color: Theme.of(context).primaryColor, | ||
onPressed: () { | ||
context.read<BrandBloc>().add( | ||
const BrandChanged(BrandKey.catalyst), | ||
); | ||
}, | ||
child: const Text('Catalyst'), | ||
), | ||
MaterialButton( | ||
key: dummyKey, | ||
color: Theme.of(context).primaryColor, | ||
child: const Text('Dummy'), | ||
onPressed: () { | ||
context.read<BrandBloc>().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<MaterialButton>(catalystButton).color, | ||
VoicesColors.blue, | ||
); | ||
expect( | ||
tester.widget<MaterialButton>(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<MaterialButton>(catalystButton).color, | ||
dummyColor, | ||
); | ||
expect( | ||
tester.widget<MaterialButton>(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<MaterialButton>(catalystButton).color, | ||
VoicesColors.blue, | ||
); | ||
expect( | ||
tester.widget<MaterialButton>(catalystButton).color, | ||
VoicesColors.blue, | ||
); | ||
}); | ||
|
||
}); | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
catalyst_voices/packages/catalyst_voices_models/lib/src/brands.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<BrandKey, ThemeData> 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), | ||
), | ||
), | ||
}; |