|
| 1 | +/* |
| 2 | + * Copyright (c) 2020 tokku5552 |
| 3 | + * |
| 4 | + * This software is released under the MIT License. |
| 5 | + * https://opensource.org/licenses/mit-license.php |
| 6 | + * |
| 7 | + */ |
| 8 | +import 'package:flutter_test/flutter_test.dart'; |
| 9 | +import 'package:todo_app_sample_flutter/data/todo_item.dart'; |
| 10 | + |
| 11 | +void main() { |
| 12 | + group("TodoItemのゲッターのテスト", () { |
| 13 | + final TodoItem todoItem = TodoItem( |
| 14 | + id: 0, |
| 15 | + title: 'title', |
| 16 | + body: 'body', |
| 17 | + createdAt: DateTime(2020, 1, 1), |
| 18 | + updatedAt: DateTime(2020, 1, 1), |
| 19 | + isDone: true, |
| 20 | + ); |
| 21 | + |
| 22 | + test('idのテスト', () async { |
| 23 | + expect(todoItem.getId, 0); |
| 24 | + }); |
| 25 | + |
| 26 | + test('titleのテスト', () async { |
| 27 | + expect(todoItem.getTitle, "title"); |
| 28 | + }); |
| 29 | + |
| 30 | + test('bodyのテスト', () async { |
| 31 | + expect(todoItem.getBody, "body"); |
| 32 | + }); |
| 33 | + |
| 34 | + test('createdAtのテスト', () async { |
| 35 | + expect(todoItem.createdAt, DateTime(2020, 1, 1)); |
| 36 | + }); |
| 37 | + |
| 38 | + test('updatedAtのテスト', () async { |
| 39 | + expect(todoItem.getUpdatedAt, DateTime(2020, 1, 1)); |
| 40 | + }); |
| 41 | + |
| 42 | + test('isDoneのテスト', () async { |
| 43 | + expect(todoItem.getIsDone, true); |
| 44 | + }); |
| 45 | + }); |
| 46 | + |
| 47 | + group("toMapのテスト", () { |
| 48 | + final TodoItem todoItem = TodoItem( |
| 49 | + id: 0, |
| 50 | + title: 'title', |
| 51 | + body: 'body', |
| 52 | + createdAt: DateTime(2020, 1, 1), |
| 53 | + updatedAt: DateTime(2020, 1, 1), |
| 54 | + isDone: true, |
| 55 | + ); |
| 56 | + |
| 57 | + final todoItemMap = todoItem.toMap(); |
| 58 | + final keyList = todoItemMap.keys.toList(); |
| 59 | + final valueList = todoItemMap.values.toList(); |
| 60 | + |
| 61 | + test('keyが一致しているか', () async { |
| 62 | + expect(keyList[0], 'id'); |
| 63 | + expect(keyList[1], 'title'); |
| 64 | + expect(keyList[2], 'body'); |
| 65 | + expect(keyList[3], 'createdAt'); |
| 66 | + expect(keyList[4], 'updatedAt'); |
| 67 | + expect(keyList[5], 'isDone'); |
| 68 | + }); |
| 69 | + |
| 70 | + test('valueが一致しているか', () async { |
| 71 | + expect(valueList[0], 0); |
| 72 | + expect(valueList[1], 'title'); |
| 73 | + expect(valueList[2], 'body'); |
| 74 | + expect(valueList[3], DateTime(2020, 1, 1).toUtc().toIso8601String()); |
| 75 | + expect(valueList[4], DateTime(2020, 1, 1).toUtc().toIso8601String()); |
| 76 | + expect(valueList[5], 1); |
| 77 | + }); |
| 78 | + }); |
| 79 | + |
| 80 | + group("fromMapのテスト", () { |
| 81 | + final Map<String, dynamic> json = { |
| 82 | + 'id': 0, |
| 83 | + 'title': 'title', |
| 84 | + 'body': 'body', |
| 85 | + 'createdAt': DateTime(2020, 1, 1).toString(), |
| 86 | + 'updatedAt': DateTime(2020, 1, 1).toString(), |
| 87 | + 'isDone': '1', // SQLiteの仕様上真偽値はtrue=1,false=0のString |
| 88 | + }; |
| 89 | + |
| 90 | + test('idが一致しているか', () { |
| 91 | + expect(TodoItem.fromMap(json).getId, 0); |
| 92 | + }); |
| 93 | + test('titleが一致しているか', () { |
| 94 | + expect(TodoItem.fromMap(json).getTitle, 'title'); |
| 95 | + }); |
| 96 | + test('bodyが一致しているか', () { |
| 97 | + expect(TodoItem.fromMap(json).getBody, 'body'); |
| 98 | + }); |
| 99 | + test('createdAtが一致しているか', () { |
| 100 | + expect(TodoItem.fromMap(json).createdAt, DateTime(2020, 1, 1)); |
| 101 | + }); |
| 102 | + test('updatedAtが一致しているか', () { |
| 103 | + expect(TodoItem.fromMap(json).getUpdatedAt, DateTime(2020, 1, 1)); |
| 104 | + }); |
| 105 | + test('isDoneが一致しているか', () { |
| 106 | + expect(TodoItem.fromMap(json).isDone, true); |
| 107 | + }); |
| 108 | + }); |
| 109 | + |
| 110 | + group("toStringのテスト", () { |
| 111 | + final TodoItem todoItem = TodoItem( |
| 112 | + id: 0, |
| 113 | + title: 'title', |
| 114 | + body: 'body', |
| 115 | + createdAt: DateTime(2020, 1, 1), |
| 116 | + updatedAt: DateTime(2020, 1, 1), |
| 117 | + isDone: true, |
| 118 | + ); |
| 119 | + |
| 120 | + test('toStringで取得した結果が一致しているか', () async { |
| 121 | + expect(todoItem.toString(), |
| 122 | + 'Todo{id: 0, title: title, createdAt: 2020-01-01 00:00:00.000}'); |
| 123 | + }); |
| 124 | + }); |
| 125 | +} |
0 commit comments