Skip to content

Commit

Permalink
feat: include empty WordSelection status (#292)
Browse files Browse the repository at this point in the history
  • Loading branch information
alestiago authored Apr 16, 2024
1 parent 90b7ae2 commit e48cbf4
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 6 deletions.
10 changes: 10 additions & 0 deletions lib/word_selection/bloc/word_selection_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ part 'word_selection_state.dart';
class WordSelectionBloc extends Bloc<WordSelectionEvent, WordSelectionState> {
WordSelectionBloc() : super(const WordSelectionState.initial()) {
on<WordSelected>(_onWordSelected);
on<WordUnselected>(_onWordUnselected);
on<WordSolveRequested>(_onWordSolveRequested);
on<WordFocusedSuccessRequested>(_onWordFocusedSuccessRequested);
on<WordSolveAttempted>(_onWordAttemptRequested);
Expand All @@ -24,6 +25,15 @@ class WordSelectionBloc extends Bloc<WordSelectionEvent, WordSelectionState> {
);
}

void _onWordUnselected(
WordUnselected event,
Emitter<WordSelectionState> emit,
) {
emit(
const WordSelectionState.initial(),
);
}

void _onWordSolveRequested(
WordSolveRequested event,
Emitter<WordSelectionState> emit,
Expand Down
14 changes: 13 additions & 1 deletion lib/word_selection/bloc/word_selection_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sealed class WordSelectionEvent extends Equatable {
const WordSelectionEvent();
}

/// {@template word_selected_event}
/// {@template word_selected}
/// The user has selected a word.
///
/// The user is yet to decide if they want to solve the word or not.
Expand All @@ -21,6 +21,18 @@ class WordSelected extends WordSelectionEvent {
List<Object> get props => [wordIdentifier];
}

/// {@template word_unselected}
/// The user has unselected a word.
///
/// This means that the user is no longer interested in solving the word.
/// {@endtemplate}
class WordUnselected extends WordSelectionEvent {
const WordUnselected();

@override
List<Object> get props => [];
}

/// {@template word_solve_requested}
/// The user has requested to solve a word.
/// {@endtemplate}
Expand Down
5 changes: 4 additions & 1 deletion lib/word_selection/bloc/word_selection_state.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
part of 'word_selection_bloc.dart';

enum WordSelectionStatus {
/// No word has been selected by the user.
empty,

/// The word has not yet been solved, but it is being considered
/// by the user.
preSolving,
Expand Down Expand Up @@ -34,7 +37,7 @@ class WordSelectionState extends Equatable {
});

const WordSelectionState.initial()
: status = WordSelectionStatus.preSolving,
: status = WordSelectionStatus.empty,
wordIdentifier = null,
wordPoints = null;

Expand Down
1 change: 1 addition & 0 deletions lib/word_selection/view/word_selection_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class _WordSelectionBody extends StatelessWidget {
WordSolvingView(selectedWord: selectedWord),
WordSelectionStatus.solved =>
WordSuccessView(selectedWord: selectedWord),
WordSelectionStatus.empty => const SizedBox.shrink(),
};
// coverage:ignore-end
return view;
Expand Down
3 changes: 2 additions & 1 deletion lib/word_selection/view/word_success_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import 'package:io_crossword/crossword/crossword.dart';
import 'package:io_crossword/extensions/extensions.dart';
import 'package:io_crossword/l10n/l10n.dart';
import 'package:io_crossword/welcome/welcome.dart';
import 'package:io_crossword/word_selection/word_selection.dart';
import 'package:io_crossword/word_selection/word_selection.dart'
hide WordUnselected;
import 'package:io_crossword_ui/io_crossword_ui.dart';

/// {@template word_success_view}
Expand Down
13 changes: 13 additions & 0 deletions test/word_focused/bloc/word_selection_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,19 @@ void main() {
);
});

group('$WordUnselected', () {
blocTest<WordSelectionBloc, WordSelectionState>(
'emits initial state',
build: WordSelectionBloc.new,
seed: () => WordSelectionState(
status: WordSelectionStatus.preSolving,
wordIdentifier: '1',
),
act: (bloc) => bloc.add(WordUnselected()),
expect: () => <WordSelectionState>[WordSelectionState.initial()],
);
});

group('$WordSolveRequested', () {
blocTest<WordSelectionBloc, WordSelectionState>(
'does nothing if there is no word identifier',
Expand Down
9 changes: 9 additions & 0 deletions test/word_focused/bloc/word_selection_event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ void main() {
});
});

group('$WordUnselected', () {
test('supports equality', () {
expect(
WordUnselected(),
equals(WordUnselected()),
);
});
});

group('$WordSolveRequested', () {
test('supports equality', () {
expect(
Expand Down
2 changes: 1 addition & 1 deletion test/word_focused/bloc/word_selection_state_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void main() {
test('.initial initializes correctly', () {
final state = WordSelectionState.initial();

expect(state.status, WordSelectionStatus.preSolving);
expect(state.status, WordSelectionStatus.empty);
expect(state.wordIdentifier, isNull);
expect(state.wordPoints, isNull);
});
Expand Down
3 changes: 2 additions & 1 deletion test/word_focused/view/word_success_view_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import 'package:flutter_test/flutter_test.dart';
import 'package:game_domain/game_domain.dart';
import 'package:io_crossword/crossword/crossword.dart';
import 'package:io_crossword/l10n/l10n.dart';
import 'package:io_crossword/word_selection/word_selection.dart';
import 'package:io_crossword/word_selection/word_selection.dart'
hide WordUnselected;
import 'package:io_crossword_ui/io_crossword_ui.dart';
import 'package:mocktail/mocktail.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:io_crossword/crossword/crossword.dart';
import 'package:io_crossword/word_selection/word_selection.dart';
import 'package:io_crossword/word_selection/word_selection.dart'
hide WordUnselected;
import 'package:mocktail/mocktail.dart';

import '../../helpers/helpers.dart';
Expand Down

0 comments on commit e48cbf4

Please sign in to comment.