Skip to content

Commit

Permalink
Merge branch 'main' into chapter5
Browse files Browse the repository at this point in the history
  • Loading branch information
jiyuujin committed Oct 13, 2023
2 parents a19d50d + b3da55c commit 69445f2
Show file tree
Hide file tree
Showing 5 changed files with 317 additions and 18 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/pr-review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: PR review/test

on:
pull_request:

jobs:
analyze:
runs-on: ubuntu-latest
timeout-minutes: 10

steps:
- uses: actions/checkout@v3
- name: Setup Flutter
uses: subosito/flutter-action@v2
- name: Install dependencies
run: |
flutter pub get
- uses: invertase/github-action-dart-analyzer@v1
- name: Run tests
run: |
flutter test
6 changes: 3 additions & 3 deletions lib/view/board.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Board extends ConsumerWidget {
data: (ticTacToe) {
return Padding(
padding: const EdgeInsets.all(16),
child: Column(
child: SingleChildScrollView(child: Column(
children: [
Padding(
padding: const EdgeInsets.all(16),
Expand Down Expand Up @@ -76,8 +76,8 @@ class Board extends ConsumerWidget {
),
],
),
);
},
));
}
);
}

Expand Down
139 changes: 139 additions & 0 deletions test/place_mark_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:tic_tac_toe_handson/provider/tic_tac_toe_provider.dart';

Check failure on line 4 in test/place_mark_test.dart

View workflow job for this annotation

GitHub Actions / analyze

Target of URI doesn't exist: 'package:tic_tac_toe_handson/provider/tic_tac_toe_provider.dart'.

Try creating the file referenced by the URI, or try using a URI for a file that does exist. See https://dart.dev/diagnostics/uri_does_not_exist to learn more about this problem.

void main() {
late TicTacToeProvider target;

Check failure on line 7 in test/place_mark_test.dart

View workflow job for this annotation

GitHub Actions / analyze

Undefined class 'TicTacToeProvider'.

Try changing the name to the name of an existing class, or creating a class with the name 'TicTacToeProvider'. See https://dart.dev/diagnostics/undefined_class to learn more about this problem.

setUp(() {
final container = ProviderContainer();
target = container.read(ticTacToeProvider.notifier);

Check failure on line 11 in test/place_mark_test.dart

View workflow job for this annotation

GitHub Actions / analyze

Undefined name 'ticTacToeProvider'.

Try correcting the name to one that is defined, or defining the name. See https://dart.dev/diagnostics/undefined_identifier to learn more about this problem.
});

test("placeMark test - row: 0, col: 0", () {
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
target.placeMark(0, 0);
expect(target.state.board, [
['X', '', ''],
['', '', ''],
['', '', ''],
]);
});

test("placeMark test - row: 0, col: 1", () {
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
target.placeMark(0, 1);
expect(target.state.board, [
['', 'X', ''],
['', '', ''],
['', '', ''],
]);
});

test("placeMark test - row: 0, col: 2", () {
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
target.placeMark(0, 2);
expect(target.state.board, [
['', '', 'X'],
['', '', ''],
['', '', ''],
]);
});

test("placeMark test - row: 1, col: 0", () {
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
target.placeMark(1, 0);
expect(target.state.board, [
['', '', ''],
['X', '', ''],
['', '', ''],
]);
});

test("placeMark test - row: 1, col: 1", () {
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
target.placeMark(1, 1);
expect(target.state.board, [
['', '', ''],
['', 'X', ''],
['', '', ''],
]);
});

test("placeMark test - row: 1, col: 2", () {
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
target.placeMark(1, 2);
expect(target.state.board, [
['', '', ''],
['', '', 'X'],
['', '', ''],
]);
});

test("placeMark test - row: 2, col: 0", () {
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
target.placeMark(2, 0);
expect(target.state.board, [
['', '', ''],
['', '', ''],
['X', '', ''],
]);
});

test("placeMark test - row: 2, col: 1", () {
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
target.placeMark(2, 1);
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', 'X', ''],
]);
});

test("placeMark test - row: 2, col: 2", () {
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
target.placeMark(2, 2);
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', 'X'],
]);
});
}
148 changes: 148 additions & 0 deletions test/reset_board_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:tic_tac_toe_handson/provider/tic_tac_toe_provider.dart';

Check failure on line 4 in test/reset_board_test.dart

View workflow job for this annotation

GitHub Actions / analyze

Target of URI doesn't exist: 'package:tic_tac_toe_handson/provider/tic_tac_toe_provider.dart'.

Try creating the file referenced by the URI, or try using a URI for a file that does exist. See https://dart.dev/diagnostics/uri_does_not_exist to learn more about this problem.

void main() {
late TicTacToeProvider target;

Check failure on line 7 in test/reset_board_test.dart

View workflow job for this annotation

GitHub Actions / analyze

Undefined class 'TicTacToeProvider'.

Try changing the name to the name of an existing class, or creating a class with the name 'TicTacToeProvider'. See https://dart.dev/diagnostics/undefined_class to learn more about this problem.

setUp(() {
final container = ProviderContainer();
target = container.read(ticTacToeProvider.notifier);

Check failure on line 11 in test/reset_board_test.dart

View workflow job for this annotation

GitHub Actions / analyze

Undefined name 'ticTacToeProvider'.

Try correcting the name to one that is defined, or defining the name. See https://dart.dev/diagnostics/undefined_identifier to learn more about this problem.
});

test("resetBoard test - row: 0, col: 0", () {
target.placeMark(0, 0);
expect(target.state.board, [
['X', '', ''],
['', '', ''],
['', '', ''],
]);
target.resetBoard();
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
});

test("resetBoard test - row: 0, col: 1", () {
target.placeMark(0, 1);
expect(target.state.board, [
['', 'X', ''],
['', '', ''],
['', '', ''],
]);
target.resetBoard();
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
});

test("resetBoard test - row: 0, col: 2", () {
target.placeMark(0, 2);
expect(target.state.board, [
['', '', 'X'],
['', '', ''],
['', '', ''],
]);
target.resetBoard();
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
});

test("resetBoard test - row: 1, col: 0", () {
target.placeMark(1, 0);
expect(target.state.board, [
['', '', ''],
['X', '', ''],
['', '', ''],
]);
target.resetBoard();
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
});

test("resetBoard test - row: 1, col: 1", () {
target.placeMark(1, 1);
expect(target.state.board, [
['', '', ''],
['', 'X', ''],
['', '', ''],
]);
target.resetBoard();
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
});

test("resetBoard test - row: 1, col: 2", () {
target.placeMark(1, 2);
expect(target.state.board, [
['', '', ''],
['', '', 'X'],
['', '', ''],
]);
target.resetBoard();
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
});

test("resetBoard test - row: 2, col: 0", () {
target.placeMark(2, 0);
expect(target.state.board, [
['', '', ''],
['', '', ''],
['X', '', ''],
]);
target.resetBoard();
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
});

test("resetBoard test - row: 2, col: 1", () {
target.placeMark(2, 1);
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', 'X', ''],
]);
target.resetBoard();
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
});

test("resetBoard test - row: 2, col: 2", () {
target.placeMark(2, 2);
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', 'X'],
]);
target.resetBoard();
expect(target.state.board, [
['', '', ''],
['', '', ''],
['', '', ''],
]);
});
}
21 changes: 6 additions & 15 deletions test/widget_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,17 @@
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';

import 'package:tic_tac_toe_handson/main.dart';

void main() {
testWidgets('Counter increments smoke test', (WidgetTester tester) async {
// Build our app and trigger a frame.
await tester.pumpWidget(const MyApp());
testWidgets('Title rendering test', (WidgetTester tester) async {
await tester.pumpWidget(const ProviderScope(
child: MyApp(),
));

// Verify that our counter starts at 0.
expect(find.text('0'), findsOneWidget);
expect(find.text('1'), findsNothing);

// Tap the '+' icon and trigger a frame.
await tester.tap(find.byIcon(Icons.add));
await tester.pump();

// Verify that our counter has incremented.
expect(find.text('0'), findsNothing);
expect(find.text('1'), findsOneWidget);
expect(find.text('FlutterKaigi 2023 - TicTacToe'), findsOneWidget);
});
}

0 comments on commit 69445f2

Please sign in to comment.