Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fetch crossword from firestore #32

Merged
merged 23 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
3e7bf3f
feat: use crossword repository in bloc
B0berman Mar 4, 2024
4d8169b
test: add app and bloc tests
B0berman Mar 5, 2024
c96a7dc
Merge branch 'main' of https://github.com/VGVentures/io_crossword int…
B0berman Mar 6, 2024
a2b669c
feat: remove initial section request
B0berman Mar 6, 2024
9787c51
feat: remove unused state and fix tests
B0berman Mar 6, 2024
23e7ddc
chore: merge main
B0berman Mar 6, 2024
b21bbf4
test: fix tests and fix section positioning
B0berman Mar 7, 2024
0cbf8e9
chore: remove unused code
B0berman Mar 7, 2024
c698d0c
Merge branch 'main' of https://github.com/VGVentures/io_crossword int…
B0berman Mar 7, 2024
94962bd
Merge branch 'main' of https://github.com/VGVentures/io_crossword int…
B0berman Mar 7, 2024
dd559ee
fix: fix words highlight
B0berman Mar 8, 2024
c3d305b
test: fix highlight test
B0berman Mar 8, 2024
a9e338b
test: fix crossword_game_tests
B0berman Mar 8, 2024
9a9dc05
test: fix bloc tests
B0berman Mar 8, 2024
480b9fb
test: update test board
B0berman Mar 8, 2024
d2c1aac
fix: fix crossword file for horizontal words
B0berman Mar 11, 2024
5795126
chore: left print
B0berman Mar 11, 2024
4e5dd6b
test: add hightlight word changes test
B0berman Mar 11, 2024
4f9f522
feat: pr suggestions
B0berman Mar 11, 2024
507ffa3
chore: analysis
B0berman Mar 11, 2024
6188658
feat: use Axis in board generator
B0berman Mar 11, 2024
1020c4f
feat: update in board generator instead of section creation
B0berman Mar 11, 2024
ee895de
chore: put back enum in create section
B0berman Mar 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/crossword/bloc/crossword_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class CrosswordBloc extends Bloc<CrosswordEvent, CrosswordState> {
) async {
return emit.forEach(
crosswordRepository.watchSectionFromPosition(
Point(event.position.$1, event.position.$2),
event.position.$1,
event.position.$2,
),
onData: (section) {
if (section == null) return state;
AyadLaouissi marked this conversation as resolved.
Show resolved Hide resolved
Expand Down
2 changes: 2 additions & 0 deletions lib/crossword/bloc/crossword_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ sealed class CrosswordState extends Equatable {

class CrosswordInitial extends CrosswordState {
const CrosswordInitial();

@override
List<Object> get props => [];
}
Expand All @@ -27,6 +28,7 @@ class CrosswordLoaded extends CrosswordState {
const CrosswordLoaded({
required this.sectionSize,
required this.sections,
// TODO(any): get configuration from db
this.width = 40,
this.height = 40,
this.selectedWord,
Expand Down
6 changes: 3 additions & 3 deletions lib/crossword/game/components/section_component.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class SectionTapController extends PositionComponent
final boardSection = parent._boardSection;

if (boardSection != null) {
final boardPosition =
final absolutePosition =
boardSection.position * CrosswordGame.cellSize * boardSection.size;
final localPosition = event.localPosition +
Vector2(
boardPosition.x.toDouble(),
boardPosition.y.toDouble(),
absolutePosition.x.toDouble(),
absolutePosition.y.toDouble(),
);
for (final word in boardSection.words) {
final wordLength =
Expand Down
2 changes: 1 addition & 1 deletion packages/board_generator/lib/create_sections.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void main(List<String> args) async {
clue: 'The answer is: ${row[2]}',
hints: const [],
visible: false,
axis: row[3] == 'horizontal' ? Axis.horizontal : Axis.vertical,
axis: row[3] == 'Axis.horizontal' ? Axis.horizontal : Axis.vertical,
B0berman marked this conversation as resolved.
Show resolved Hide resolved
solvedTimestamp: null,
);
}).toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ class CrosswordRepository {
});
}

/// Watches the section having the corresponding [position]
/// Watches the section having the corresponding position
Stream<BoardSection?> watchSectionFromPosition(
Point<int> position,
int x,
int y,
) {
final snapshot = sectionCollection
.where(
'position.x',
isEqualTo: position.x,
isEqualTo: x,
)
.where(
'position.y',
isEqualTo: position.y,
isEqualTo: y,
)
.snapshots();
return snapshot.map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ void main() {

test('returns the requested section depending on position', () {
expect(
crosswordRepository.watchSectionFromPosition(Point(0, 1)),
crosswordRepository.watchSectionFromPosition(0, 1),
emits(section),
);
});

test('returns null if there is no section with the position', () {
expect(
crosswordRepository.watchSectionFromPosition(Point(2, 2)),
crosswordRepository.watchSectionFromPosition(2, 2),
emits(null),
);
});
Expand Down
7 changes: 2 additions & 5 deletions test/app/view/app_test.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
// ignore_for_file: prefer_const_constructors

import 'dart:math';

// ignore_for_file: prefer_const_constructorsssword_repository/crossword_repository.dart';
import 'package:crossword_repository/crossword_repository.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:io_crossword/app/app.dart';
Expand All @@ -17,7 +14,7 @@ void main() {
crosswordRepository = _MockCrosswordRepository();

when(
() => crosswordRepository.watchSectionFromPosition(Point(0, 0)),
() => crosswordRepository.watchSectionFromPosition(0, 0),
).thenAnswer((_) => Stream.value(null));
});

Expand Down
4 changes: 2 additions & 2 deletions test/crossword/bloc/crossword_bloc_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void main() {
build: () => CrosswordBloc(crosswordRepository),
setUp: () {
when(
() => crosswordRepository.watchSectionFromPosition(Point(1, 1)),
() => crosswordRepository.watchSectionFromPosition(1, 1),
).thenAnswer((_) => Stream.value(section));
},
seed: () => const CrosswordInitial(),
Expand All @@ -94,7 +94,7 @@ void main() {
build: () => CrosswordBloc(crosswordRepository),
setUp: () {
when(
() => crosswordRepository.watchSectionFromPosition(Point(1, 1)),
() => crosswordRepository.watchSectionFromPosition(1, 1),
).thenAnswer((_) => Stream.value(section));
},
seed: () => const CrosswordLoaded(
Expand Down
12 changes: 9 additions & 3 deletions test/crossword/game/crossword_game_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,18 @@ void main() {
element.position.y == targetSection.index.$2,
);
final targetWord = targetBoardSection.words.first;
final targetPosition =
targetWord.position * 40 - (targetBoardSection.position * 40 * 20);
final targetAbsolutePosition =
targetWord.position * CrosswordGame.cellSize -
(targetBoardSection.position *
CrosswordGame.cellSize *
sectionSize);

final event = _MockTapUpEvent();
when(() => event.localPosition).thenReturn(
Vector2(targetPosition.x.toDouble(), targetPosition.y.toDouble()),
Vector2(
targetAbsolutePosition.x.toDouble(),
targetAbsolutePosition.y.toDouble(),
),
);

targetSection.children.whereType<SectionTapController>().first.onTapUp(
Expand Down
5 changes: 2 additions & 3 deletions test/helpers/pump_app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ extension PumpApp on WidgetTester {
final mockedCrosswordRepository = _MockCrosswordRepository();
registerFallbackValue(Point(0, 0));
when(
() => mockedCrosswordRepository.watchSectionFromPosition(any()),
() => mockedCrosswordRepository.watchSectionFromPosition(any(), any()),
).thenAnswer((_) => Stream.value(null));

return pumpWidget(
Expand Down Expand Up @@ -62,9 +62,8 @@ extension PumpRoute on WidgetTester {
),
);
final mockedCrosswordRepository = _MockCrosswordRepository();
registerFallbackValue(Point(0, 0));
when(
() => mockedCrosswordRepository.watchSectionFromPosition(any()),
() => mockedCrosswordRepository.watchSectionFromPosition(any(), any()),
).thenAnswer((_) => Stream.value(null));

await pumpWidget(
Expand Down
Loading