Skip to content

Commit

Permalink
feat: creates how_made.dart (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
AyadLaouissi authored Apr 23, 2024
1 parent 9788e68 commit 438b5ff
Show file tree
Hide file tree
Showing 11 changed files with 146 additions and 246 deletions.
31 changes: 1 addition & 30 deletions lib/about/view/about_project_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,36 +24,7 @@ class AboutProjectDetails extends StatelessWidget {
child: const Icon(Icons.image, size: 50),
),
const SizedBox(height: 24),
RichText(
text: TextSpan(
text: '${l10n.learn} ',
style: textTheme.titleMedium,
children: [
TextSpan(
text: l10n.howMade,
style: textTheme.titleMedium?.copyWith(
color: linkColor,
),
// TODO(Ayad): add link
// recognizer: TapGestureRecognizer()..onTap = () {},
),
TextSpan(text: ' ${l10n.and} '),
TextSpan(
text: l10n.openSourceCode,
style: textTheme.titleMedium?.copyWith(
color: linkColor,
),
recognizer: TapGestureRecognizer()
..onTap = () {
context.launchUrl(ProjectDetailsLinks.github);
},
),
const TextSpan(
text: '.',
),
],
),
),
const HowMade(),
const SizedBox(height: 24),
Text(
'${l10n.otherLinks}:',
Expand Down
1 change: 1 addition & 0 deletions lib/about/view/about_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:io_crossword/extensions/extensions.dart';
import 'package:io_crossword/l10n/l10n.dart';
import 'package:io_crossword/project_details/link/project_details_links.dart';
import 'package:io_crossword/widget/widget.dart';
import 'package:io_crossword_ui/io_crossword_ui.dart';

part 'about_how_to_play.dart';
Expand Down
4 changes: 1 addition & 3 deletions lib/end_game/view/end_game_page.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:game_domain/game_domain.dart';
import 'package:io_crossword/assets/assets.dart';
import 'package:io_crossword/extensions/context_ext.dart';
import 'package:io_crossword/game_intro/game_intro.dart';
import 'package:io_crossword/l10n/l10n.dart';
import 'package:io_crossword/leaderboard/view/leaderboard_page.dart';
import 'package:io_crossword/player/player.dart';
import 'package:io_crossword/project_details/link/project_details_links.dart';
import 'package:io_crossword/share/share.dart';
import 'package:io_crossword/widget/widget.dart';
import 'package:io_crossword_ui/io_crossword_ui.dart';

part '../widgets/leaderboard_button.dart';
Expand Down
48 changes: 1 addition & 47 deletions lib/end_game/view/end_game_view_content.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EndGameContent extends StatelessWidget {
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
const EndGameHowMade(),
const HowMade(),
const SizedBox(height: 24),
const Center(
child: PlayerInitials(),
Expand Down Expand Up @@ -105,52 +105,6 @@ class ActionButtonsEndGame extends StatelessWidget {
}
}

@visibleForTesting
class EndGameHowMade extends StatelessWidget {
@visibleForTesting
const EndGameHowMade({super.key});

@override
Widget build(BuildContext context) {
final l10n = context.l10n;

final textTheme = Theme.of(context).textTheme;
const linkColor = IoCrosswordColors.linkBlue;

return RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: '${l10n.learn} ',
style: textTheme.titleMedium,
children: [
TextSpan(
text: l10n.howMade,
style: textTheme.titleMedium?.copyWith(
color: linkColor,
),
// TODO(Ayad): add link
// recognizer: TapGestureRecognizer()..onTap = () {},
),
TextSpan(text: ' ${l10n.and} '),
TextSpan(
text: l10n.openSourceCode,
style: textTheme.titleMedium?.copyWith(
color: linkColor,
),
recognizer: TapGestureRecognizer()
..onTap = () {
context.launchUrl(ProjectDetailsLinks.github);
},
),
const TextSpan(
text: '.',
),
],
),
);
}
}

@visibleForTesting
class EndGameImage extends StatelessWidget {
@visibleForTesting
Expand Down
37 changes: 2 additions & 35 deletions lib/project_details/view/project_details_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:flutter/material.dart';
import 'package:io_crossword/extensions/extensions.dart';
import 'package:io_crossword/l10n/l10n.dart';
import 'package:io_crossword/project_details/link/project_details_links.dart';
import 'package:io_crossword/widget/widget.dart';
import 'package:io_crossword_ui/io_crossword_ui.dart';

class ProjectDetailsView extends StatelessWidget {
Expand Down Expand Up @@ -105,41 +106,7 @@ class ProjectDetailsContent extends StatelessWidget {
child: const Icon(Icons.image, size: 50),
),
SizedBox(height: verticalSpacing),
RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: '${l10n.learn} ',
style: textTheme.titleMedium,
children: [
TextSpan(
text: l10n.howMade,
style: textTheme.titleMedium?.copyWith(
color: linkColor,
decoration: TextDecoration.underline,
decorationColor: linkColor,
),
// TODO(Ayad): add link
// recognizer: TapGestureRecognizer()..onTap = () {},
),
TextSpan(text: ' ${l10n.and} '),
TextSpan(
text: l10n.openSourceCode,
style: textTheme.titleMedium?.copyWith(
color: linkColor,
decoration: TextDecoration.underline,
decorationColor: linkColor,
),
recognizer: TapGestureRecognizer()
..onTap = () {
context.launchUrl(ProjectDetailsLinks.github);
},
),
const TextSpan(
text: '.',
),
],
),
),
const HowMade(),
SizedBox(height: verticalSpacing),
Text(
'${l10n.otherLinks}:',
Expand Down
50 changes: 50 additions & 0 deletions lib/widget/how_made.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:io_crossword/extensions/context_ext.dart';
import 'package:io_crossword/l10n/l10n.dart';
import 'package:io_crossword/project_details/link/project_details_links.dart';
import 'package:io_crossword_ui/io_crossword_ui.dart';

class HowMade extends StatelessWidget {
const HowMade({super.key});

@override
Widget build(BuildContext context) {
final l10n = context.l10n;

final textTheme = Theme.of(context).textTheme;
const linkColor = IoCrosswordColors.linkBlue;

return RichText(
textAlign: TextAlign.center,
text: TextSpan(
text: '${l10n.learn} ',
style: textTheme.titleMedium,
children: [
TextSpan(
text: l10n.howMade,
style: textTheme.titleMedium?.copyWith(
color: linkColor,
),
// TODO(Ayad): add link
// recognizer: TapGestureRecognizer()..onTap = () {},
),
TextSpan(text: ' ${l10n.and} '),
TextSpan(
text: l10n.openSourceCode,
style: textTheme.titleMedium?.copyWith(
color: linkColor,
),
recognizer: TapGestureRecognizer()
..onTap = () {
context.launchUrl(ProjectDetailsLinks.github);
},
),
const TextSpan(
text: '.',
),
],
),
);
}
}
1 change: 1 addition & 0 deletions lib/widget/widget.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'how_made.dart';
35 changes: 3 additions & 32 deletions test/about/view/about_project_details_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:io_crossword/about/view/about_view.dart';
import 'package:io_crossword/l10n/l10n.dart';
import 'package:io_crossword/widget/widget.dart';
import 'package:mocktail/mocktail.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';
Expand Down Expand Up @@ -37,41 +38,11 @@ void main() {
});

testWidgets(
'displays initial information how made and open source',
'renders HowMade',
(tester) async {
await tester.pumpApp(AboutProjectDetails());

final text =
'${l10n.learn} ${l10n.howMade} ${l10n.and} ${l10n.openSourceCode}.';

expect(find.text(text, findRichText: true), findsOneWidget);
},
);

testWidgets(
'calls launchUrl when tapped on open source code',
(tester) async {
await tester.pumpApp(AboutProjectDetails());

final finder = find.byWidgetPredicate(
(widget) =>
widget is RichText &&
find.tapTextSpan(
widget,
l10n.openSourceCode,
),
);

await tester.tap(finder);

await tester.pumpAndSettle();

verify(
() => urlLauncher.launchUrl(
'https://github.com/VGVentures/io_crossword',
any(),
),
);
expect(find.byType(HowMade), findsOneWidget);
},
);

Expand Down
70 changes: 3 additions & 67 deletions test/end_game/view/end_game_view_content_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,11 @@ import 'package:io_crossword/game_intro/game_intro.dart';
import 'package:io_crossword/l10n/l10n.dart';
import 'package:io_crossword/player/player.dart';
import 'package:io_crossword/share/share.dart';
import 'package:io_crossword/widget/widget.dart';
import 'package:mocktail/mocktail.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:url_launcher_platform_interface/url_launcher_platform_interface.dart';

import '../../helpers/helpers.dart';

class _MockUrlLauncherPlatform extends Mock
with MockPlatformInterfaceMixin
implements UrlLauncherPlatform {}

class _FakeLaunchOptions extends Fake implements LaunchOptions {}

class _MockPlayerBloc extends MockBloc<PlayerEvent, PlayerState>
implements PlayerBloc {}

Expand All @@ -39,10 +32,10 @@ void main() {
expect(find.text(l10n.thanksForContributing), findsOneWidget);
});

testWidgets('displays EndGameHowMade', (tester) async {
testWidgets('displays HowMade', (tester) async {
await tester.pumpApp(SingleChildScrollView(child: EndGameContent()));

expect(find.byType(EndGameHowMade), findsOneWidget);
expect(find.byType(HowMade), findsOneWidget);
});

testWidgets('displays EndGameImage', (tester) async {
Expand Down Expand Up @@ -110,63 +103,6 @@ void main() {
});
});

group('$EndGameHowMade', () {
late UrlLauncherPlatform urlLauncher;

setUpAll(() {
registerFallbackValue(_FakeLaunchOptions());
});

setUp(() {
urlLauncher = _MockUrlLauncherPlatform();

UrlLauncherPlatform.instance = urlLauncher;

when(() => urlLauncher.canLaunch(any())).thenAnswer((_) async => true);
when(() => urlLauncher.launchUrl(any(), any()))
.thenAnswer((_) async => true);
});

testWidgets(
'displays information how made and open source',
(tester) async {
await tester.pumpApp(EndGameHowMade());

final text =
'${l10n.learn} ${l10n.howMade} ${l10n.and} ${l10n.openSourceCode}.';

expect(find.text(text, findRichText: true), findsOneWidget);
},
);

testWidgets(
'calls launchUrl when tapped on open source code',
(tester) async {
await tester.pumpApp(EndGameHowMade());

final finder = find.byWidgetPredicate(
(widget) =>
widget is RichText &&
find.tapTextSpan(
widget,
l10n.openSourceCode,
),
);

await tester.tap(finder);

await tester.pumpAndSettle();

verify(
() => urlLauncher.launchUrl(
'https://github.com/VGVentures/io_crossword',
any(),
),
);
},
);
});

group('$EndGameImage', () {
late PlayerBloc playerBloc;

Expand Down
Loading

0 comments on commit 438b5ff

Please sign in to comment.