Skip to content

Commit

Permalink
Merge branch 'feature/test-implement' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tokku5552 committed Dec 14, 2020
2 parents 28e3ae4 + e586ecf commit 6e5034e
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# TODOAppSample-Flutter

A sample Todo App with Provider
A sample Todo App with Provider
This project uses Git-Flow

## DEMO
![Screenshot showing TODOAppSample-Flutter for TodoList](docs/images/demo_todo_list.png "Demo Todo List")
Expand Down
125 changes: 125 additions & 0 deletions test/todo_item_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
/*
* Copyright (c) 2020 tokku5552
*
* This software is released under the MIT License.
* https://opensource.org/licenses/mit-license.php
*
*/
import 'package:flutter_test/flutter_test.dart';
import 'package:todo_app_sample_flutter/data/todo_item.dart';

void main() {
group("TodoItemのゲッターのテスト", () {
final TodoItem todoItem = TodoItem(
id: 0,
title: 'title',
body: 'body',
createdAt: DateTime(2020, 1, 1),
updatedAt: DateTime(2020, 1, 1),
isDone: true,
);

test('idのテスト', () async {
expect(todoItem.getId, 0);
});

test('titleのテスト', () async {
expect(todoItem.getTitle, "title");
});

test('bodyのテスト', () async {
expect(todoItem.getBody, "body");
});

test('createdAtのテスト', () async {
expect(todoItem.createdAt, DateTime(2020, 1, 1));
});

test('updatedAtのテスト', () async {
expect(todoItem.getUpdatedAt, DateTime(2020, 1, 1));
});

test('isDoneのテスト', () async {
expect(todoItem.getIsDone, true);
});
});

group("toMapのテスト", () {
final TodoItem todoItem = TodoItem(
id: 0,
title: 'title',
body: 'body',
createdAt: DateTime(2020, 1, 1),
updatedAt: DateTime(2020, 1, 1),
isDone: true,
);

final todoItemMap = todoItem.toMap();
final keyList = todoItemMap.keys.toList();
final valueList = todoItemMap.values.toList();

test('keyが一致しているか', () async {
expect(keyList[0], 'id');
expect(keyList[1], 'title');
expect(keyList[2], 'body');
expect(keyList[3], 'createdAt');
expect(keyList[4], 'updatedAt');
expect(keyList[5], 'isDone');
});

test('valueが一致しているか', () async {
expect(valueList[0], 0);
expect(valueList[1], 'title');
expect(valueList[2], 'body');
expect(valueList[3], DateTime(2020, 1, 1).toUtc().toIso8601String());
expect(valueList[4], DateTime(2020, 1, 1).toUtc().toIso8601String());
expect(valueList[5], 1);
});
});

group("fromMapのテスト", () {
final Map<String, dynamic> json = {
'id': 0,
'title': 'title',
'body': 'body',
'createdAt': DateTime(2020, 1, 1).toString(),
'updatedAt': DateTime(2020, 1, 1).toString(),
'isDone': '1', // SQLiteの仕様上真偽値はtrue=1,false=0のString
};

test('idが一致しているか', () {
expect(TodoItem.fromMap(json).getId, 0);
});
test('titleが一致しているか', () {
expect(TodoItem.fromMap(json).getTitle, 'title');
});
test('bodyが一致しているか', () {
expect(TodoItem.fromMap(json).getBody, 'body');
});
test('createdAtが一致しているか', () {
expect(TodoItem.fromMap(json).createdAt, DateTime(2020, 1, 1));
});
test('updatedAtが一致しているか', () {
expect(TodoItem.fromMap(json).getUpdatedAt, DateTime(2020, 1, 1));
});
test('isDoneが一致しているか', () {
expect(TodoItem.fromMap(json).isDone, true);
});
});

group("toStringのテスト", () {
final TodoItem todoItem = TodoItem(
id: 0,
title: 'title',
body: 'body',
createdAt: DateTime(2020, 1, 1),
updatedAt: DateTime(2020, 1, 1),
isDone: true,
);

test('toStringで取得した結果が一致しているか', () async {
expect(todoItem.toString(),
'Todo{id: 0, title: title, createdAt: 2020-01-01 00:00:00.000}');
});
});
}

0 comments on commit 6e5034e

Please sign in to comment.