|
| 1 | +import Foundation |
| 2 | +import SharingGRDB |
| 3 | +import SwiftUI |
| 4 | +import Testing |
| 5 | + |
| 6 | +@testable import Reminders |
| 7 | + |
| 8 | +@Suite( |
| 9 | + .dependencies { |
| 10 | + $0.date.now = Date(timeIntervalSince1970: 1234567890) |
| 11 | + $0.defaultDatabase = try Reminders.appDatabase() |
| 12 | + try $0.defaultDatabase.write { try $0.seedTestData() } |
| 13 | + }, |
| 14 | + .snapshots(record: .failed) |
| 15 | +) |
| 16 | +struct BaseTestSuite {} |
| 17 | + |
| 18 | +extension Database { |
| 19 | + func seedTestData() throws { |
| 20 | + let baseDate = Date(timeIntervalSince1970: 1234567890) |
| 21 | + try seed { |
| 22 | + RemindersList( |
| 23 | + id: UUID(0), |
| 24 | + color: Color(red: 0x4a / 255, green: 0x99 / 255, blue: 0xef / 255), |
| 25 | + position: 0, |
| 26 | + title: "Personal" |
| 27 | + ) |
| 28 | + RemindersList( |
| 29 | + id: UUID(1), |
| 30 | + color: Color(red: 0xed / 255, green: 0x89 / 255, blue: 0x35 / 255), |
| 31 | + position: 1, |
| 32 | + title: "Family" |
| 33 | + ) |
| 34 | + RemindersList( |
| 35 | + id: UUID(2), |
| 36 | + color: Color(red: 0xb2 / 255, green: 0x5d / 255, blue: 0xd3 / 255), |
| 37 | + position: 2, |
| 38 | + title: "Business" |
| 39 | + ) |
| 40 | + Reminder( |
| 41 | + id: UUID(0), |
| 42 | + notes: "Milk\nEggs\nApples\nOatmeal\nSpinach", |
| 43 | + position: 0, |
| 44 | + remindersListID: UUID(0), |
| 45 | + title: "Groceries" |
| 46 | + ) |
| 47 | + Reminder( |
| 48 | + id: UUID(1), |
| 49 | + dueDate: baseDate.addingTimeInterval(-60 * 60 * 24 * 2), |
| 50 | + isFlagged: true, |
| 51 | + position: 1, |
| 52 | + remindersListID: UUID(0), |
| 53 | + title: "Haircut" |
| 54 | + ) |
| 55 | + Reminder( |
| 56 | + id: UUID(2), |
| 57 | + dueDate: baseDate, |
| 58 | + notes: "Ask about diet", |
| 59 | + position: 2, |
| 60 | + priority: .high, |
| 61 | + remindersListID: UUID(0), |
| 62 | + title: "Doctor appointment" |
| 63 | + ) |
| 64 | + Reminder( |
| 65 | + id: UUID(3), |
| 66 | + dueDate: baseDate.addingTimeInterval(-60 * 60 * 24 * 190), |
| 67 | + isCompleted: true, |
| 68 | + position: 3, |
| 69 | + remindersListID: UUID(0), |
| 70 | + title: "Take a walk" |
| 71 | + ) |
| 72 | + Reminder( |
| 73 | + id: UUID(4), |
| 74 | + dueDate: baseDate, |
| 75 | + position: 4, |
| 76 | + remindersListID: UUID(0), |
| 77 | + title: "Buy concert tickets" |
| 78 | + ) |
| 79 | + Reminder( |
| 80 | + id: UUID(5), |
| 81 | + dueDate: baseDate.addingTimeInterval(60 * 60 * 24 * 2), |
| 82 | + isFlagged: true, |
| 83 | + position: 5, |
| 84 | + priority: .high, |
| 85 | + remindersListID: UUID(1), |
| 86 | + title: "Pick up kids from school" |
| 87 | + ) |
| 88 | + Reminder( |
| 89 | + id: UUID(6), |
| 90 | + dueDate: baseDate.addingTimeInterval(-60 * 60 * 24 * 2), |
| 91 | + isCompleted: true, |
| 92 | + position: 6, |
| 93 | + priority: .low, |
| 94 | + remindersListID: UUID(1), |
| 95 | + title: "Get laundry" |
| 96 | + ) |
| 97 | + Reminder( |
| 98 | + id: UUID(7), |
| 99 | + dueDate: baseDate.addingTimeInterval(60 * 60 * 24 * 4), |
| 100 | + isCompleted: false, |
| 101 | + position: 7, |
| 102 | + priority: .high, |
| 103 | + remindersListID: UUID(1), |
| 104 | + title: "Take out trash" |
| 105 | + ) |
| 106 | + Reminder( |
| 107 | + id: UUID(8), |
| 108 | + dueDate: baseDate.addingTimeInterval(60 * 60 * 24 * 2), |
| 109 | + notes: """ |
| 110 | + Status of tax return |
| 111 | + Expenses for next year |
| 112 | + Changing payroll company |
| 113 | + """, |
| 114 | + position: 8, |
| 115 | + remindersListID: UUID(2), |
| 116 | + title: "Call accountant" |
| 117 | + ) |
| 118 | + Reminder( |
| 119 | + id: UUID(9), |
| 120 | + dueDate: baseDate.addingTimeInterval(-60 * 60 * 24 * 2), |
| 121 | + isCompleted: true, |
| 122 | + position: 9, |
| 123 | + priority: .medium, |
| 124 | + remindersListID: UUID(2), |
| 125 | + title: "Send weekly emails" |
| 126 | + ) |
| 127 | + Reminder( |
| 128 | + id: UUID(10), |
| 129 | + dueDate: baseDate.addingTimeInterval(60 * 60 * 24 * 2), |
| 130 | + isCompleted: false, |
| 131 | + position: 10, |
| 132 | + remindersListID: UUID(2), |
| 133 | + title: "Prepare for WWDC" |
| 134 | + ) |
| 135 | + Tag(id: UUID(0), title: "car") |
| 136 | + Tag(id: UUID(1), title: "kids") |
| 137 | + Tag(id: UUID(2), title: "someday") |
| 138 | + Tag(id: UUID(3), title: "optional") |
| 139 | + Tag(id: UUID(4), title: "social") |
| 140 | + Tag(id: UUID(5), title: "night") |
| 141 | + Tag(id: UUID(6), title: "adulting") |
| 142 | + ReminderTag(reminderID: UUID(0), tagID: UUID(2)) |
| 143 | + ReminderTag(reminderID: UUID(0), tagID: UUID(3)) |
| 144 | + ReminderTag(reminderID: UUID(0), tagID: UUID(6)) |
| 145 | + ReminderTag(reminderID: UUID(1), tagID: UUID(2)) |
| 146 | + ReminderTag(reminderID: UUID(1), tagID: UUID(3)) |
| 147 | + ReminderTag(reminderID: UUID(2), tagID: UUID(6)) |
| 148 | + ReminderTag(reminderID: UUID(3), tagID: UUID(0)) |
| 149 | + ReminderTag(reminderID: UUID(3), tagID: UUID(1)) |
| 150 | + ReminderTag(reminderID: UUID(4), tagID: UUID(4)) |
| 151 | + ReminderTag(reminderID: UUID(3), tagID: UUID(4)) |
| 152 | + ReminderTag(reminderID: UUID(10), tagID: UUID(4)) |
| 153 | + ReminderTag(reminderID: UUID(4), tagID: UUID(5)) |
| 154 | + } |
| 155 | + } |
| 156 | +} |
0 commit comments