@quenty/scoredactionservice 16.52.0 → 16.53.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/deploy.nevermore.json +10 -0
- package/package.json +11 -8
- package/src/Client/InputList/InputListScoreHelper.spec.lua +306 -0
- package/src/Client/Picker/ScoredActionPicker.lua +5 -8
- package/src/Client/Picker/ScoredActionPicker.spec.lua +348 -0
- package/src/Client/Picker/ScoredActionPickerProvider.spec.lua +271 -0
- package/src/Client/Picker/TouchButtonScoredActionPicker.lua +22 -8
- package/src/Client/Picker/TouchButtonScoredActionPicker.spec.lua +278 -0
- package/src/Client/ScoredAction.spec.lua +262 -0
- package/src/Client/ScoredActionServiceClient.lua +9 -3
- package/src/Client/ScoredActionServiceClient.spec.lua +343 -0
- package/src/Client/ScoredActionUtils.spec.lua +187 -0
- package/src/Server/ScoredActionService.spec.lua +81 -0
- package/src/jest.config.lua +3 -0
- package/test/default.project.json +17 -0
- package/test/scripts/Server/ServerMain.server.lua +25 -0
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
@class ScoredActionServiceClient.spec.lua
|
|
4
|
+
]]
|
|
5
|
+
|
|
6
|
+
local require = require(script.Parent.loader).load(script)
|
|
7
|
+
|
|
8
|
+
local InputKeyMap = require("InputKeyMap")
|
|
9
|
+
local InputKeyMapList = require("InputKeyMapList")
|
|
10
|
+
local InputModeServiceClient = require("InputModeServiceClient")
|
|
11
|
+
local InputModeTypes = require("InputModeTypes")
|
|
12
|
+
local Jest = require("Jest")
|
|
13
|
+
local Maid = require("Maid")
|
|
14
|
+
local Observable = require("Observable")
|
|
15
|
+
local ScoredActionServiceClient = require("ScoredActionServiceClient")
|
|
16
|
+
local ServiceBag = require("ServiceBag")
|
|
17
|
+
local StepUtils = require("StepUtils")
|
|
18
|
+
local ValueObject = require("ValueObject")
|
|
19
|
+
|
|
20
|
+
local describe = Jest.Globals.describe
|
|
21
|
+
local expect = Jest.Globals.expect
|
|
22
|
+
local it = Jest.Globals.it
|
|
23
|
+
|
|
24
|
+
local function setup(): any
|
|
25
|
+
local maid = Maid.new()
|
|
26
|
+
|
|
27
|
+
local serviceBag: any = maid:Add(ServiceBag.new())
|
|
28
|
+
local service = serviceBag:GetService(ScoredActionServiceClient)
|
|
29
|
+
serviceBag:Init()
|
|
30
|
+
serviceBag:Start()
|
|
31
|
+
|
|
32
|
+
serviceBag:GetService(InputModeServiceClient):GetInputMode(InputModeTypes.Keyboard):Enable()
|
|
33
|
+
|
|
34
|
+
-- ObserveNewFromInputKeyMapList scopes each emitted action to the subscription, so a source
|
|
35
|
+
-- that completes on emission hands back an already-destroyed action.
|
|
36
|
+
local function observeLists(lists: { InputKeyMapList.InputKeyMapList })
|
|
37
|
+
return Observable.new(function(sub)
|
|
38
|
+
for _, list in lists do
|
|
39
|
+
sub:Fire(list)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
return nil
|
|
43
|
+
end)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
local controller = {
|
|
47
|
+
service = service,
|
|
48
|
+
|
|
49
|
+
newList = function(inputTypes: { any })
|
|
50
|
+
return maid:Add(InputKeyMapList.new("SPEC_SERVICE_ACTION", {
|
|
51
|
+
InputKeyMap.new(InputModeTypes.Keyboard, inputTypes),
|
|
52
|
+
}, {
|
|
53
|
+
bindingName = "Spec Service Action",
|
|
54
|
+
rebindable = false,
|
|
55
|
+
})) :: any
|
|
56
|
+
end,
|
|
57
|
+
|
|
58
|
+
newAction = function(list)
|
|
59
|
+
return maid:Add(service:GetScoredAction(list)) :: any
|
|
60
|
+
end,
|
|
61
|
+
|
|
62
|
+
newLooseAction = function(list)
|
|
63
|
+
return service:GetScoredAction(list)
|
|
64
|
+
end,
|
|
65
|
+
|
|
66
|
+
newValue = function(score: number)
|
|
67
|
+
return maid:Add(ValueObject.new(score, "number")) :: any
|
|
68
|
+
end,
|
|
69
|
+
|
|
70
|
+
-- Scores are only ranked by the service's own step connection, so they land a frame later.
|
|
71
|
+
-- Two waits, because the first may be the same fire our own handler is already resuming from.
|
|
72
|
+
scoreAndStep = function(action, score: number)
|
|
73
|
+
action:SetScore(score)
|
|
74
|
+
|
|
75
|
+
local signal = StepUtils.getSteppedSignal()
|
|
76
|
+
signal:Wait()
|
|
77
|
+
signal:Wait()
|
|
78
|
+
end,
|
|
79
|
+
|
|
80
|
+
collect = function(lists, scoreValue)
|
|
81
|
+
local actions = {}
|
|
82
|
+
local sub = (observeLists(lists) :: any)
|
|
83
|
+
:Pipe({
|
|
84
|
+
service:ObserveNewFromInputKeyMapList(scoreValue) :: any,
|
|
85
|
+
})
|
|
86
|
+
:Subscribe(function(action)
|
|
87
|
+
table.insert(actions, action)
|
|
88
|
+
end)
|
|
89
|
+
maid:GiveTask(sub)
|
|
90
|
+
|
|
91
|
+
return actions, function()
|
|
92
|
+
sub:Destroy()
|
|
93
|
+
end
|
|
94
|
+
end,
|
|
95
|
+
|
|
96
|
+
destroyService = function()
|
|
97
|
+
service:Destroy()
|
|
98
|
+
end,
|
|
99
|
+
|
|
100
|
+
destroy = function()
|
|
101
|
+
maid:DoCleaning()
|
|
102
|
+
end,
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return controller
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
describe("ScoredActionServiceClient.GetScoredAction", function()
|
|
109
|
+
it("returns a fresh unscored action", function()
|
|
110
|
+
local controller = setup()
|
|
111
|
+
local action = controller.newAction(controller.newList({ Enum.KeyCode.E }))
|
|
112
|
+
|
|
113
|
+
expect(action.ClassName).toBe("ScoredAction")
|
|
114
|
+
expect(action:GetScore()).toBe(-math.huge)
|
|
115
|
+
expect(action:IsEnabled()).toBe(true)
|
|
116
|
+
expect(action:IsPreferred()).toBe(false)
|
|
117
|
+
|
|
118
|
+
controller.destroy()
|
|
119
|
+
end)
|
|
120
|
+
|
|
121
|
+
it("throws on something that is not an inputKeyMapList", function()
|
|
122
|
+
local controller = setup()
|
|
123
|
+
|
|
124
|
+
expect(function()
|
|
125
|
+
(controller.service :: any):GetScoredAction({})
|
|
126
|
+
end).toThrow()
|
|
127
|
+
|
|
128
|
+
controller.destroy()
|
|
129
|
+
end)
|
|
130
|
+
|
|
131
|
+
it("prefers the highest scoring action bound to the same key", function()
|
|
132
|
+
local controller = setup()
|
|
133
|
+
local list = controller.newList({ Enum.KeyCode.E })
|
|
134
|
+
|
|
135
|
+
local low = controller.newAction(list)
|
|
136
|
+
local high = controller.newAction(list)
|
|
137
|
+
|
|
138
|
+
controller.scoreAndStep(low, 1)
|
|
139
|
+
controller.scoreAndStep(high, 2)
|
|
140
|
+
|
|
141
|
+
expect(high:IsPreferred()).toBe(true)
|
|
142
|
+
expect(low:IsPreferred()).toBe(false)
|
|
143
|
+
|
|
144
|
+
controller.destroy()
|
|
145
|
+
end)
|
|
146
|
+
|
|
147
|
+
it("hands the preference over when the winner is disabled", function()
|
|
148
|
+
local controller = setup()
|
|
149
|
+
local list = controller.newList({ Enum.KeyCode.E })
|
|
150
|
+
|
|
151
|
+
local low = controller.newAction(list)
|
|
152
|
+
local high = controller.newAction(list)
|
|
153
|
+
|
|
154
|
+
controller.scoreAndStep(low, 1)
|
|
155
|
+
controller.scoreAndStep(high, 2)
|
|
156
|
+
|
|
157
|
+
high:SetIsEnabled(false)
|
|
158
|
+
|
|
159
|
+
expect(high:IsPreferred()).toBe(false)
|
|
160
|
+
expect(low:IsPreferred()).toBe(true)
|
|
161
|
+
|
|
162
|
+
controller.destroy()
|
|
163
|
+
end)
|
|
164
|
+
|
|
165
|
+
it("does not make actions on different keys compete", function()
|
|
166
|
+
local controller = setup()
|
|
167
|
+
|
|
168
|
+
local first = controller.newAction(controller.newList({ Enum.KeyCode.E }))
|
|
169
|
+
local second = controller.newAction(controller.newList({ Enum.KeyCode.Q }))
|
|
170
|
+
|
|
171
|
+
controller.scoreAndStep(first, 1)
|
|
172
|
+
controller.scoreAndStep(second, 2)
|
|
173
|
+
|
|
174
|
+
expect(first:IsPreferred()).toBe(true)
|
|
175
|
+
expect(second:IsPreferred()).toBe(true)
|
|
176
|
+
|
|
177
|
+
controller.destroy()
|
|
178
|
+
end)
|
|
179
|
+
|
|
180
|
+
it("releases the preference when the action is destroyed", function()
|
|
181
|
+
local controller = setup()
|
|
182
|
+
local list = controller.newList({ Enum.KeyCode.E })
|
|
183
|
+
|
|
184
|
+
local action = controller.newLooseAction(list)
|
|
185
|
+
controller.scoreAndStep(action, 1)
|
|
186
|
+
expect(action:IsPreferred()).toBe(true)
|
|
187
|
+
|
|
188
|
+
action:Destroy()
|
|
189
|
+
|
|
190
|
+
expect((action :: any).Destroy).toBeNil()
|
|
191
|
+
|
|
192
|
+
controller.destroy()
|
|
193
|
+
end)
|
|
194
|
+
|
|
195
|
+
it("lets a later action win the key a destroyed action held", function()
|
|
196
|
+
local controller = setup()
|
|
197
|
+
local list = controller.newList({ Enum.KeyCode.E })
|
|
198
|
+
|
|
199
|
+
local first = controller.newLooseAction(list)
|
|
200
|
+
controller.scoreAndStep(first, 5)
|
|
201
|
+
first:Destroy()
|
|
202
|
+
|
|
203
|
+
local second = controller.newAction(list)
|
|
204
|
+
controller.scoreAndStep(second, 1)
|
|
205
|
+
|
|
206
|
+
expect(second:IsPreferred()).toBe(true)
|
|
207
|
+
|
|
208
|
+
controller.destroy()
|
|
209
|
+
end)
|
|
210
|
+
end)
|
|
211
|
+
|
|
212
|
+
describe("ScoredActionServiceClient.ObserveNewFromInputKeyMapList", function()
|
|
213
|
+
it("throws on something that is not a valueObject", function()
|
|
214
|
+
local controller = setup()
|
|
215
|
+
|
|
216
|
+
expect(function()
|
|
217
|
+
(controller.service :: any):ObserveNewFromInputKeyMapList({})
|
|
218
|
+
end).toThrow()
|
|
219
|
+
|
|
220
|
+
controller.destroy()
|
|
221
|
+
end)
|
|
222
|
+
|
|
223
|
+
it("emits an action carrying the current score", function()
|
|
224
|
+
local controller = setup()
|
|
225
|
+
local list = controller.newList({ Enum.KeyCode.E })
|
|
226
|
+
|
|
227
|
+
local actions = controller.collect({ list }, controller.newValue(5))
|
|
228
|
+
|
|
229
|
+
expect(#actions).toBe(1)
|
|
230
|
+
expect(actions[1]:GetScore()).toBe(5)
|
|
231
|
+
|
|
232
|
+
controller.destroy()
|
|
233
|
+
end)
|
|
234
|
+
|
|
235
|
+
it("follows later changes to the score value", function()
|
|
236
|
+
local controller = setup()
|
|
237
|
+
local list = controller.newList({ Enum.KeyCode.E })
|
|
238
|
+
local scoreValue = controller.newValue(5)
|
|
239
|
+
|
|
240
|
+
local actions = controller.collect({ list }, scoreValue)
|
|
241
|
+
scoreValue.Value = 9
|
|
242
|
+
|
|
243
|
+
expect(actions[1]:GetScore()).toBe(9)
|
|
244
|
+
|
|
245
|
+
controller.destroy()
|
|
246
|
+
end)
|
|
247
|
+
|
|
248
|
+
it("emits once for a repeated inputKeyMapList", function()
|
|
249
|
+
local controller = setup()
|
|
250
|
+
local list = controller.newList({ Enum.KeyCode.E })
|
|
251
|
+
|
|
252
|
+
local actions = controller.collect({ list, list }, controller.newValue(1))
|
|
253
|
+
|
|
254
|
+
expect(#actions).toBe(1)
|
|
255
|
+
|
|
256
|
+
controller.destroy()
|
|
257
|
+
end)
|
|
258
|
+
|
|
259
|
+
it("emits again for a different inputKeyMapList", function()
|
|
260
|
+
local controller = setup()
|
|
261
|
+
local first = controller.newList({ Enum.KeyCode.E })
|
|
262
|
+
local second = controller.newList({ Enum.KeyCode.Q })
|
|
263
|
+
|
|
264
|
+
local actions = controller.collect({ first, second }, controller.newValue(1))
|
|
265
|
+
|
|
266
|
+
expect(#actions).toBe(2)
|
|
267
|
+
expect(actions[2]).never.toBe(actions[1])
|
|
268
|
+
|
|
269
|
+
controller.destroy()
|
|
270
|
+
end)
|
|
271
|
+
|
|
272
|
+
it("destroys the previous action when a new one is emitted", function()
|
|
273
|
+
local controller = setup()
|
|
274
|
+
local first = controller.newList({ Enum.KeyCode.E })
|
|
275
|
+
local second = controller.newList({ Enum.KeyCode.Q })
|
|
276
|
+
|
|
277
|
+
local actions = controller.collect({ first, second }, controller.newValue(1))
|
|
278
|
+
|
|
279
|
+
expect(actions[1].Destroy).toBeNil()
|
|
280
|
+
expect(actions[2].Destroy).never.toBeNil()
|
|
281
|
+
|
|
282
|
+
controller.destroy()
|
|
283
|
+
end)
|
|
284
|
+
|
|
285
|
+
it("destroys the emitted action when the subscription ends", function()
|
|
286
|
+
local controller = setup()
|
|
287
|
+
local list = controller.newList({ Enum.KeyCode.E })
|
|
288
|
+
|
|
289
|
+
local actions, unsubscribe = controller.collect({ list }, controller.newValue(1))
|
|
290
|
+
unsubscribe()
|
|
291
|
+
|
|
292
|
+
expect(actions[1].Destroy).toBeNil()
|
|
293
|
+
|
|
294
|
+
controller.destroy()
|
|
295
|
+
end)
|
|
296
|
+
end)
|
|
297
|
+
|
|
298
|
+
describe("ScoredActionServiceClient.Start", function()
|
|
299
|
+
it("re-ranks a rescored action on the step signal alone", function()
|
|
300
|
+
local controller = setup()
|
|
301
|
+
local list = controller.newList({ Enum.KeyCode.E })
|
|
302
|
+
|
|
303
|
+
local action = controller.newAction(list)
|
|
304
|
+
expect(action:IsPreferred()).toBe(false)
|
|
305
|
+
|
|
306
|
+
controller.scoreAndStep(action, 1)
|
|
307
|
+
|
|
308
|
+
expect(action:IsPreferred()).toBe(true)
|
|
309
|
+
|
|
310
|
+
controller.destroy()
|
|
311
|
+
end)
|
|
312
|
+
|
|
313
|
+
it("stops re-ranking once the service is destroyed", function()
|
|
314
|
+
local controller = setup()
|
|
315
|
+
local list = controller.newList({ Enum.KeyCode.E })
|
|
316
|
+
|
|
317
|
+
local action = controller.newAction(list)
|
|
318
|
+
controller.destroyService()
|
|
319
|
+
|
|
320
|
+
controller.scoreAndStep(action, 1)
|
|
321
|
+
|
|
322
|
+
expect(action:IsPreferred()).toBe(false)
|
|
323
|
+
|
|
324
|
+
controller.destroy()
|
|
325
|
+
end)
|
|
326
|
+
end)
|
|
327
|
+
|
|
328
|
+
describe("ScoredActionServiceClient.Destroy", function()
|
|
329
|
+
it("releases the preferences its actions were holding", function()
|
|
330
|
+
local controller = setup()
|
|
331
|
+
local list = controller.newList({ Enum.KeyCode.E })
|
|
332
|
+
|
|
333
|
+
local action = controller.newAction(list)
|
|
334
|
+
controller.scoreAndStep(action, 1)
|
|
335
|
+
expect(action:IsPreferred()).toBe(true)
|
|
336
|
+
|
|
337
|
+
controller.destroyService()
|
|
338
|
+
|
|
339
|
+
expect(action:IsPreferred()).toBe(false)
|
|
340
|
+
|
|
341
|
+
controller.destroy()
|
|
342
|
+
end)
|
|
343
|
+
end)
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
@class ScoredActionUtils.spec.lua
|
|
4
|
+
]]
|
|
5
|
+
|
|
6
|
+
local require = require(script.Parent.loader).load(script)
|
|
7
|
+
|
|
8
|
+
local Jest = require("Jest")
|
|
9
|
+
local Maid = require("Maid")
|
|
10
|
+
local ScoredAction = require("ScoredAction")
|
|
11
|
+
local ScoredActionUtils = require("ScoredActionUtils")
|
|
12
|
+
|
|
13
|
+
local describe = Jest.Globals.describe
|
|
14
|
+
local expect = Jest.Globals.expect
|
|
15
|
+
local it = Jest.Globals.it
|
|
16
|
+
|
|
17
|
+
type Controller = {
|
|
18
|
+
newAction: () -> ScoredAction.ScoredAction,
|
|
19
|
+
connect: (ScoredAction.ScoredAction, (Maid.Maid) -> ()) -> Maid.Maid,
|
|
20
|
+
connectLoose: (ScoredAction.ScoredAction, (Maid.Maid) -> ()) -> Maid.Maid,
|
|
21
|
+
destroy: () -> (),
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
local function setup(): Controller
|
|
25
|
+
local maid = Maid.new()
|
|
26
|
+
|
|
27
|
+
local controller: Controller = {
|
|
28
|
+
newAction = function()
|
|
29
|
+
return maid:Add(ScoredAction.new()) :: any
|
|
30
|
+
end,
|
|
31
|
+
|
|
32
|
+
connect = function(action, callback)
|
|
33
|
+
return maid:Add(ScoredActionUtils.connectToPreferred(action, callback)) :: any
|
|
34
|
+
end,
|
|
35
|
+
|
|
36
|
+
connectLoose = function(action, callback)
|
|
37
|
+
return ScoredActionUtils.connectToPreferred(action, callback)
|
|
38
|
+
end,
|
|
39
|
+
|
|
40
|
+
destroy = function()
|
|
41
|
+
maid:DoCleaning()
|
|
42
|
+
end,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return controller
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
describe("ScoredActionUtils.connectToPreferred", function()
|
|
49
|
+
it("does not invoke the callback for an unpreferred action", function()
|
|
50
|
+
local controller = setup()
|
|
51
|
+
local action = controller.newAction()
|
|
52
|
+
|
|
53
|
+
local calls = 0
|
|
54
|
+
controller.connect(action, function()
|
|
55
|
+
calls += 1
|
|
56
|
+
end)
|
|
57
|
+
|
|
58
|
+
expect(calls).toBe(0)
|
|
59
|
+
|
|
60
|
+
controller.destroy()
|
|
61
|
+
end)
|
|
62
|
+
|
|
63
|
+
it("invokes the callback immediately for an already preferred action", function()
|
|
64
|
+
local controller = setup()
|
|
65
|
+
local action = controller.newAction()
|
|
66
|
+
action:PushPreferred()
|
|
67
|
+
|
|
68
|
+
local calls = 0
|
|
69
|
+
controller.connect(action, function()
|
|
70
|
+
calls += 1
|
|
71
|
+
end)
|
|
72
|
+
|
|
73
|
+
expect(calls).toBe(1)
|
|
74
|
+
|
|
75
|
+
controller.destroy()
|
|
76
|
+
end)
|
|
77
|
+
|
|
78
|
+
it("invokes the callback when the action becomes preferred", function()
|
|
79
|
+
local controller = setup()
|
|
80
|
+
local action = controller.newAction()
|
|
81
|
+
|
|
82
|
+
local calls = 0
|
|
83
|
+
controller.connect(action, function()
|
|
84
|
+
calls += 1
|
|
85
|
+
end)
|
|
86
|
+
|
|
87
|
+
action:PushPreferred()
|
|
88
|
+
|
|
89
|
+
expect(calls).toBe(1)
|
|
90
|
+
|
|
91
|
+
controller.destroy()
|
|
92
|
+
end)
|
|
93
|
+
|
|
94
|
+
it("does not re-invoke the callback for a second push", function()
|
|
95
|
+
local controller = setup()
|
|
96
|
+
local action = controller.newAction()
|
|
97
|
+
|
|
98
|
+
local calls = 0
|
|
99
|
+
controller.connect(action, function()
|
|
100
|
+
calls += 1
|
|
101
|
+
end)
|
|
102
|
+
|
|
103
|
+
action:PushPreferred()
|
|
104
|
+
action:PushPreferred()
|
|
105
|
+
|
|
106
|
+
expect(calls).toBe(1)
|
|
107
|
+
|
|
108
|
+
controller.destroy()
|
|
109
|
+
end)
|
|
110
|
+
|
|
111
|
+
it("invokes the callback again on a later push", function()
|
|
112
|
+
local controller = setup()
|
|
113
|
+
local action = controller.newAction()
|
|
114
|
+
|
|
115
|
+
local calls = 0
|
|
116
|
+
controller.connect(action, function()
|
|
117
|
+
calls += 1
|
|
118
|
+
end)
|
|
119
|
+
|
|
120
|
+
action:PushPreferred()()
|
|
121
|
+
action:PushPreferred()
|
|
122
|
+
|
|
123
|
+
expect(calls).toBe(2)
|
|
124
|
+
|
|
125
|
+
controller.destroy()
|
|
126
|
+
end)
|
|
127
|
+
|
|
128
|
+
it("cleans up the callback maid when the action stops being preferred", function()
|
|
129
|
+
local controller = setup()
|
|
130
|
+
local action = controller.newAction()
|
|
131
|
+
|
|
132
|
+
local cleaned = false
|
|
133
|
+
controller.connect(action, function(preferredMaid)
|
|
134
|
+
preferredMaid:GiveTask(function()
|
|
135
|
+
cleaned = true
|
|
136
|
+
end)
|
|
137
|
+
end)
|
|
138
|
+
|
|
139
|
+
local pop = action:PushPreferred()
|
|
140
|
+
expect(cleaned).toBe(false)
|
|
141
|
+
|
|
142
|
+
pop()
|
|
143
|
+
|
|
144
|
+
expect(cleaned).toBe(true)
|
|
145
|
+
|
|
146
|
+
controller.destroy()
|
|
147
|
+
end)
|
|
148
|
+
|
|
149
|
+
it("cleans up the callback maid when the returned maid is destroyed", function()
|
|
150
|
+
local controller = setup()
|
|
151
|
+
local action = controller.newAction()
|
|
152
|
+
action:PushPreferred()
|
|
153
|
+
|
|
154
|
+
local cleaned = false
|
|
155
|
+
local topMaid = controller.connectLoose(action, function(preferredMaid)
|
|
156
|
+
preferredMaid:GiveTask(function()
|
|
157
|
+
cleaned = true
|
|
158
|
+
end)
|
|
159
|
+
end)
|
|
160
|
+
|
|
161
|
+
topMaid:DoCleaning()
|
|
162
|
+
|
|
163
|
+
expect(cleaned).toBe(true)
|
|
164
|
+
|
|
165
|
+
controller.destroy()
|
|
166
|
+
end)
|
|
167
|
+
|
|
168
|
+
it("cleans up a callback maid abandoned by a pop during the callback", function()
|
|
169
|
+
local controller = setup()
|
|
170
|
+
local action = controller.newAction()
|
|
171
|
+
local pop = action:PushPreferred()
|
|
172
|
+
|
|
173
|
+
local cleaned = false
|
|
174
|
+
controller.connect(action, function(preferredMaid)
|
|
175
|
+
preferredMaid:GiveTask(function()
|
|
176
|
+
cleaned = true
|
|
177
|
+
end)
|
|
178
|
+
|
|
179
|
+
pop()
|
|
180
|
+
end)
|
|
181
|
+
|
|
182
|
+
expect(action:IsPreferred()).toBe(false)
|
|
183
|
+
expect(cleaned).toBe(true)
|
|
184
|
+
|
|
185
|
+
controller.destroy()
|
|
186
|
+
end)
|
|
187
|
+
end)
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
@class ScoredActionService.spec.lua
|
|
4
|
+
]]
|
|
5
|
+
|
|
6
|
+
local require = require(script.Parent.loader).load(script)
|
|
7
|
+
|
|
8
|
+
local InputKeyMapService = require("InputKeyMapService")
|
|
9
|
+
local Jest = require("Jest")
|
|
10
|
+
local Maid = require("Maid")
|
|
11
|
+
local ScoredActionService = require("ScoredActionService")
|
|
12
|
+
local ServiceBag = require("ServiceBag")
|
|
13
|
+
|
|
14
|
+
local describe = Jest.Globals.describe
|
|
15
|
+
local expect = Jest.Globals.expect
|
|
16
|
+
local it = Jest.Globals.it
|
|
17
|
+
|
|
18
|
+
type Controller = {
|
|
19
|
+
serviceBag: ServiceBag.ServiceBag,
|
|
20
|
+
service: any,
|
|
21
|
+
destroy: () -> (),
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
local function setup(): Controller
|
|
25
|
+
local maid = Maid.new()
|
|
26
|
+
|
|
27
|
+
local serviceBag: ServiceBag.ServiceBag = maid:Add(ServiceBag.new()) :: any
|
|
28
|
+
local service = serviceBag:GetService(ScoredActionService)
|
|
29
|
+
serviceBag:Init()
|
|
30
|
+
serviceBag:Start()
|
|
31
|
+
|
|
32
|
+
local controller: Controller = {
|
|
33
|
+
serviceBag = serviceBag,
|
|
34
|
+
service = service,
|
|
35
|
+
|
|
36
|
+
destroy = function()
|
|
37
|
+
maid:DoCleaning()
|
|
38
|
+
end,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return controller
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe("ScoredActionService.Init", function()
|
|
45
|
+
it("initializes through the service bag", function()
|
|
46
|
+
local controller = setup()
|
|
47
|
+
|
|
48
|
+
expect(controller.service).never.toBeNil()
|
|
49
|
+
expect(ScoredActionService.ServiceName).toBe("ScoredActionService")
|
|
50
|
+
|
|
51
|
+
controller.destroy()
|
|
52
|
+
end)
|
|
53
|
+
|
|
54
|
+
it("registers the input key map service", function()
|
|
55
|
+
local controller = setup()
|
|
56
|
+
|
|
57
|
+
expect(controller.serviceBag:HasService(InputKeyMapService)).toBe(true)
|
|
58
|
+
|
|
59
|
+
controller.destroy()
|
|
60
|
+
end)
|
|
61
|
+
|
|
62
|
+
it("throws when initialized twice", function()
|
|
63
|
+
local controller = setup()
|
|
64
|
+
|
|
65
|
+
expect(function()
|
|
66
|
+
controller.service:Init(controller.serviceBag)
|
|
67
|
+
end).toThrow()
|
|
68
|
+
|
|
69
|
+
controller.destroy()
|
|
70
|
+
end)
|
|
71
|
+
|
|
72
|
+
it("throws without a serviceBag", function()
|
|
73
|
+
local controller = setup()
|
|
74
|
+
|
|
75
|
+
expect(function()
|
|
76
|
+
(ScoredActionService :: any):Init(nil)
|
|
77
|
+
end).toThrow()
|
|
78
|
+
|
|
79
|
+
controller.destroy()
|
|
80
|
+
end)
|
|
81
|
+
end)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ScoredActionServiceTest",
|
|
3
|
+
"tree": {
|
|
4
|
+
"$className": "DataModel",
|
|
5
|
+
"ServerScriptService": {
|
|
6
|
+
"$properties": {
|
|
7
|
+
"LoadStringEnabled": true
|
|
8
|
+
},
|
|
9
|
+
"scoredactionservice": {
|
|
10
|
+
"$path": ".."
|
|
11
|
+
},
|
|
12
|
+
"Script": {
|
|
13
|
+
"$path": "scripts/Server"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
--!nonstrict
|
|
2
|
+
local ServerScriptService = game:GetService("ServerScriptService")
|
|
3
|
+
|
|
4
|
+
local root = ServerScriptService.scoredactionservice
|
|
5
|
+
local loader = root:FindFirstChild("LoaderUtils", true).Parent
|
|
6
|
+
local require = require(loader).bootstrapGame(root)
|
|
7
|
+
|
|
8
|
+
local NevermoreTestRunnerUtils = require("NevermoreTestRunnerUtils")
|
|
9
|
+
|
|
10
|
+
if NevermoreTestRunnerUtils.runTestsIfNeededAsync(root) then
|
|
11
|
+
return
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
local Maid = require("Maid")
|
|
15
|
+
|
|
16
|
+
local maid = Maid.new()
|
|
17
|
+
|
|
18
|
+
maid:Add(task.defer(function()
|
|
19
|
+
maid:DoCleaning()
|
|
20
|
+
|
|
21
|
+
while true do
|
|
22
|
+
task.wait(0.1)
|
|
23
|
+
error("UPDATE (this should never print)")
|
|
24
|
+
end
|
|
25
|
+
end))
|