@@ -125,5 +125,72 @@ let remoteData =
125125 | RemoteDataCase.Loaded -> Loading ( Some true ))
126126 ]
127127
128+ let optimistic =
129+ testList " Optimistic" [
130+ testList " create" [
131+ testCase " creates new value with no history" <| fun _ ->
132+ let opt = Optimistic.create 42
133+ Expect.equal opt.Value ( Some 42 ) " Current value should be set"
134+ Expect.equal opt.Prev None " Previous value should be None"
135+ ]
136+
137+ testList " empty" [
138+ testCase " creates empty optimistic value" <| fun _ ->
139+ let opt = Optimistic.empty
140+ Expect.equal opt.Value None " Current value should be None"
141+ Expect.equal opt.Prev None " Previous value should be None"
142+ ]
143+
144+ testList " update" [
145+ testCase " updates value and shifts previous" <| fun _ ->
146+ let opt = Optimistic.create 42
147+ let updated = opt.Update 84
148+ Expect.equal updated.Value ( Some 84 ) " Current value should be updated"
149+ Expect.equal updated.Prev ( Some 42 ) " Previous value should be old current"
150+ ]
151+
152+ testList " rollback" [
153+ testCase " rolls back to previous value" <| fun _ ->
154+ let opt = Optimistic.create 42 |> Optimistic.update 84
155+ let rolled = opt.Rollback()
156+ Expect.equal rolled.Value ( Some 42 ) " Current value should be previous"
157+ Expect.equal rolled.Prev None " Previous value should be cleared"
158+ ]
159+
160+ testList " map" [
161+ testCase " maps both values" <| fun _ ->
162+ let opt = { Value = Some 42 ; Prev = Some 21 }
163+ let mapped = opt.Map string
164+ Expect.equal mapped.Value ( Some " 42" ) " Current value should be mapped"
165+ Expect.equal mapped.Prev ( Some " 21" ) " Previous value should be mapped"
166+ ]
167+
168+ testList " bind" [
169+ testCase " binds value with history" <| fun _ ->
170+ let opt = { Value = Some 42 ; Prev = Some 21 }
171+ let bound = opt.Bind ( fun x -> { Value = Some ( string x); Prev = None})
172+ Expect.equal bound.Value ( Some " 42" ) " Current value should be bound"
173+ Expect.equal bound.Prev ( None) " Previous value should be bound"
174+ ]
175+
176+ testList " asOption" [
177+ testCase " returns current value as option" <| fun _ ->
178+ let opt = Optimistic.create 42
179+ Expect.equal ( Optimistic.asOption opt) ( Some 42 ) " Should return current value"
180+ ]
181+
182+ testList " asPrevOption" [
183+ testCase " returns previous value as option" <| fun _ ->
184+ let opt = Optimistic.create 42 |> Optimistic.update 84
185+ Expect.equal ( Optimistic.asPrevOption opt) ( Some 42 ) " Should return previous value"
186+ ]
187+ ]
188+
189+ let allTests =
190+ testList " All Tests" [
191+ remoteData
192+ optimistic
193+ ]
194+
128195[<EntryPoint>]
129- let main _ = Mocha.runTests remoteData
196+ let main _ = Mocha.runTests allTests
0 commit comments