@@ -13,16 +13,16 @@ final class CalendarViewModelTests: XCTestCase {
13
13
var context : NSManagedObjectContext !
14
14
var viewModel : CalendarViewModel !
15
15
16
- override func setUp ( ) {
17
- super. setUp ( )
16
+ override func setUpWithError ( ) throws {
17
+ try super. setUpWithError ( )
18
18
19
- let date = Calendar . current. date ( from: DateComponents ( year: 2024 ,
20
- month: 1 ,
21
- day: 1 ) )
19
+ let date = try XCTUnwrap ( Calendar . current. date ( from: DateComponents ( year: 2024 ,
20
+ month: 1 ,
21
+ day: 1 ) ) )
22
22
23
23
context = CoreDataStack ( . inMemory) . persistentContainer. viewContext
24
- viewModel = CalendarViewModel ( today: date! , context: context)
25
- setupCoreData ( )
24
+ viewModel = CalendarViewModel ( today: date, context: context)
25
+ try setupCoreData ( )
26
26
}
27
27
28
28
override func tearDown( ) {
@@ -61,9 +61,9 @@ final class CalendarViewModelTests: XCTestCase {
61
61
day: 1 ) )
62
62
63
63
viewModel = CalendarViewModel ( today: date!, context: context)
64
- viewModel. selectedDate = Calendar . current. date ( from: DateComponents ( year: 2024 ,
65
- month: 1 ,
66
- day: 1 ) ) !
64
+ viewModel. selectedDate = try XCTUnwrap ( Calendar . current. date ( from: DateComponents ( year: 2024 ,
65
+ month: 1 ,
66
+ day: 1 ) ) )
67
67
viewModel. addingMonth ( value: 1 )
68
68
69
69
let nilCount = viewModel. days. filter { $0 == nil } . count
@@ -83,7 +83,7 @@ final class CalendarViewModelTests: XCTestCase {
83
83
viewModel. fetch ( )
84
84
85
85
let expectedRecordsCount = 3
86
- XCTAssertTrue ( viewModel. moods. count == expectedRecordsCount)
86
+ XCTAssertEqual ( viewModel. moods. count, expectedRecordsCount)
87
87
}
88
88
89
89
func test_원하는_날짜의_mood_받기( ) throws {
@@ -100,9 +100,9 @@ final class CalendarViewModelTests: XCTestCase {
100
100
101
101
// 저장된 정보 없을 경우 Nil
102
102
let result2 = viewModel. mood ( of: CalendarModel ( year: 2024 ,
103
- month: 1 ,
104
- day: 2 ,
105
- isToday: false ) )
103
+ month: 1 ,
104
+ day: 2 ,
105
+ isToday: false ) )
106
106
107
107
XCTAssertNil ( result2)
108
108
}
@@ -119,12 +119,28 @@ final class CalendarViewModelTests: XCTestCase {
119
119
XCTAssertEqual ( self . viewModel. moods. count, expectedDataCount)
120
120
notiExpectation. fulfill ( )
121
121
} )
122
-
122
+
123
123
wait ( for: [ notiExpectation] , timeout: 1.5 )
124
124
}
125
125
126
- private func setupCoreData( ) {
127
- let timestapms = [ " 2024-02-24 " , " 2024-01-01 " , " 2024-01-06 " , " 2024-01-24 " ]
126
+ private func setupCoreData( ) throws {
127
+ let date1 = try XCTUnwrap ( Calendar . current. date ( from: DateComponents ( year: 2024 ,
128
+ month: 2 ,
129
+ day: 24 ) ) )
130
+
131
+ let date2 = try XCTUnwrap ( Calendar . current. date ( from: DateComponents ( year: 2024 ,
132
+ month: 1 ,
133
+ day: 1 ) ) )
134
+
135
+ let date3 = try XCTUnwrap ( Calendar . current. date ( from: DateComponents ( year: 2024 ,
136
+ month: 1 ,
137
+ day: 6 ) ) )
138
+
139
+ let date4 = try XCTUnwrap ( Calendar . current. date ( from: DateComponents ( year: 2024 ,
140
+ month: 1 ,
141
+ day: 24 ) ) )
142
+
143
+ let timestapms = [ date1, date2, date3, date4]
128
144
let moods : [ Mood ] = [ . nice, . normal, . notBad, . bad]
129
145
let reasons : [ String ? ] = [ " happy birthday " , nil , " developing... " , " eww " ]
130
146
0 commit comments