Skip to content

Commit

Permalink
Merge branch 'main' into feat/leaderboard/streak-team
Browse files Browse the repository at this point in the history
  • Loading branch information
alestiago authored Apr 9, 2024
2 parents 9e1494f + dbad276 commit 3047dcd
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 67 deletions.
40 changes: 22 additions & 18 deletions lib/word_focused/view/word_clue_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -26,15 +27,16 @@ class WordClueDesktopView extends StatelessWidget {
),
const Spacer(),
const SizedBox(height: 8),
OutlinedButton.icon(
onPressed: () {
context
.read<WordFocusedBloc>()
.add(const WordFocusedSolveRequested());
},
icon: const Icon(Icons.edit),
label: Text(l10n.solveIt),
),
if (!solved)
OutlinedButton.icon(
onPressed: () {
context
.read<WordFocusedBloc>()
.add(const WordFocusedSolveRequested());
},
icon: const Icon(Icons.edit),
label: Text(l10n.solveIt),
),
],
);
}
Expand All @@ -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,
Expand All @@ -60,15 +63,16 @@ class WordClueMobileView extends StatelessWidget {
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
OutlinedButton.icon(
onPressed: () {
context
.read<WordFocusedBloc>()
.add(const WordFocusedSolveRequested());
},
icon: const Icon(Icons.edit),
label: Text(l10n.solveIt),
),
if (!solved)
OutlinedButton.icon(
onPressed: () {
context
.read<WordFocusedBloc>()
.add(const WordFocusedSolveRequested());
},
icon: const Icon(Icons.edit),
label: Text(l10n.solveIt),
),
const SizedBox(height: 16),
],
);
Expand Down
155 changes: 106 additions & 49 deletions test/word_focused/view/word_clue_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,72 +38,129 @@ 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', () {
late WordSelection selectedWord;
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);
},
);
});
});
}

0 comments on commit 3047dcd

Please sign in to comment.