Skip to content

Commit

Permalink
test: Add tests for brand Theme switching.
Browse files Browse the repository at this point in the history
  • Loading branch information
coire1 committed Apr 16, 2024
1 parent e0b7c40 commit 5438983
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 0 deletions.
@@ -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,
);
});

});

}
@@ -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),
),
),
};

0 comments on commit 5438983

Please sign in to comment.