diff --git a/lib/word_focused/view/word_clue_view.dart b/lib/word_focused/view/word_clue_view.dart index 037402475..c2cc8cb23 100644 --- a/lib/word_focused/view/word_clue_view.dart +++ b/lib/word_focused/view/word_clue_view.dart @@ -13,6 +13,7 @@ class WordClueDesktopView extends StatelessWidget { @override Widget build(BuildContext context) { final l10n = context.l10n; + final solved = selectedWord.solvedStatus == SolvedStatus.solved; return Column( children: [ @@ -26,15 +27,16 @@ class WordClueDesktopView extends StatelessWidget { ), const Spacer(), const SizedBox(height: 8), - OutlinedButton.icon( - onPressed: () { - context - .read() - .add(const WordFocusedSolveRequested()); - }, - icon: const Icon(Icons.edit), - label: Text(l10n.solveIt), - ), + if (!solved) + OutlinedButton.icon( + onPressed: () { + context + .read() + .add(const WordFocusedSolveRequested()); + }, + icon: const Icon(Icons.edit), + label: Text(l10n.solveIt), + ), ], ); } @@ -48,6 +50,7 @@ class WordClueMobileView extends StatelessWidget { @override Widget build(BuildContext context) { final l10n = context.l10n; + final solved = selectedWord.solvedStatus == SolvedStatus.solved; return Column( mainAxisSize: MainAxisSize.min, @@ -60,15 +63,16 @@ class WordClueMobileView extends StatelessWidget { textAlign: TextAlign.center, ), const SizedBox(height: 24), - OutlinedButton.icon( - onPressed: () { - context - .read() - .add(const WordFocusedSolveRequested()); - }, - icon: const Icon(Icons.edit), - label: Text(l10n.solveIt), - ), + if (!solved) + OutlinedButton.icon( + onPressed: () { + context + .read() + .add(const WordFocusedSolveRequested()); + }, + icon: const Icon(Icons.edit), + label: Text(l10n.solveIt), + ), const SizedBox(height: 16), ], ); diff --git a/test/word_focused/view/word_clue_view_test.dart b/test/word_focused/view/word_clue_view_test.dart index 42d44ca8b..6a81670e7 100644 --- a/test/word_focused/view/word_clue_view_test.dart +++ b/test/word_focused/view/word_clue_view_test.dart @@ -38,36 +38,65 @@ void main() { late Widget widget; late WordFocusedBloc wordFocusedBloc; - setUp(() { - selectedWord = WordSelection(section: (0, 0), word: _FakeWord()); - wordFocusedBloc = _MockWordFocusedBloc(); - - widget = BlocProvider( - create: (context) => wordFocusedBloc, - child: WordClueDesktopView(selectedWord), + group('with unsolved word', () { + setUp(() { + selectedWord = WordSelection(section: (0, 0), word: _FakeWord()); + wordFocusedBloc = _MockWordFocusedBloc(); + + widget = BlocProvider( + create: (context) => wordFocusedBloc, + child: WordClueDesktopView(selectedWord), + ); + }); + + testWidgets( + 'renders the selected word clue with solved button', + (tester) async { + await tester.pumpApp(widget); + + expect(find.text(selectedWord.word.clue), findsOneWidget); + expect(find.text(l10n.solveIt), findsOneWidget); + }, ); - }); - testWidgets( - 'renders the selected word clue', - (tester) async { - await tester.pumpApp(widget); + testWidgets( + 'tapping the solve button dispatches a WordFocusedSolveRequested event', + (tester) async { + await tester.pumpApp(widget); - expect(find.text(selectedWord.word.clue), findsOneWidget); - }, - ); + await tester.tap(find.text(l10n.solveIt)); - testWidgets( - 'tapping the solve button dispatches a WordFocusedSolveRequested event', - (tester) async { - await tester.pumpApp(widget); - - await tester.tap(find.text(l10n.solveIt)); + verify(() => wordFocusedBloc.add(const WordFocusedSolveRequested())) + .called(1); + }, + ); + }); - verify(() => wordFocusedBloc.add(const WordFocusedSolveRequested())) - .called(1); - }, - ); + group('with solved word', () { + setUp(() { + selectedWord = WordSelection( + section: (0, 0), + word: _FakeWord(), + solvedStatus: SolvedStatus.solved, + ); + wordFocusedBloc = _MockWordFocusedBloc(); + + widget = BlocProvider( + create: (context) => wordFocusedBloc, + child: WordClueDesktopView(selectedWord), + ); + }); + + testWidgets( + 'renders the selected word clue with solved button', + (tester) async { + await tester.pumpApp(widget); + + expect(find.text(selectedWord.word.clue), findsOneWidget); + expect(find.text(l10n.solveIt), findsNothing); + }, + ); + }); }); group('WordClueMobileView', () { @@ -75,35 +104,63 @@ void main() { late Widget widget; late WordFocusedBloc wordFocusedBloc; - setUp(() { - selectedWord = WordSelection(section: (0, 0), word: _FakeWord()); - wordFocusedBloc = _MockWordFocusedBloc(); + group('with unsolved word', () { + setUp(() { + selectedWord = WordSelection(section: (0, 0), word: _FakeWord()); + wordFocusedBloc = _MockWordFocusedBloc(); - widget = BlocProvider( - create: (context) => wordFocusedBloc, - child: WordClueMobileView(selectedWord), - ); - }); + widget = BlocProvider( + create: (context) => wordFocusedBloc, + child: WordClueMobileView(selectedWord), + ); + }); - testWidgets( - 'renders the selected word clue', - (tester) async { - await tester.pumpApp(widget); + testWidgets( + 'renders the selected word clue', + (tester) async { + await tester.pumpApp(widget); - expect(find.text(selectedWord.word.clue), findsOneWidget); - }, - ); + expect(find.text(selectedWord.word.clue), findsOneWidget); + }, + ); - testWidgets( - 'tapping the solve button dispatches a WordFocusedSolveRequested event', - (tester) async { - await tester.pumpApp(widget); + testWidgets( + 'tapping the solve button dispatches a WordFocusedSolveRequested event', + (tester) async { + await tester.pumpApp(widget); - await tester.tap(find.text(l10n.solveIt)); + await tester.tap(find.text(l10n.solveIt)); - verify(() => wordFocusedBloc.add(const WordFocusedSolveRequested())) - .called(1); - }, - ); + verify(() => wordFocusedBloc.add(const WordFocusedSolveRequested())) + .called(1); + }, + ); + }); + + group('with solved word', () { + setUp(() { + selectedWord = WordSelection( + section: (0, 0), + word: _FakeWord(), + solvedStatus: SolvedStatus.solved, + ); + wordFocusedBloc = _MockWordFocusedBloc(); + + widget = BlocProvider( + create: (context) => wordFocusedBloc, + child: WordClueMobileView(selectedWord), + ); + }); + + testWidgets( + 'renders the selected word clue with solved button', + (tester) async { + await tester.pumpApp(widget); + + expect(find.text(selectedWord.word.clue), findsOneWidget); + expect(find.text(l10n.solveIt), findsNothing); + }, + ); + }); }); }