@sprucelabs/spruce-cli 24.1.2 → 24.1.4
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 +16 -0
- package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.d.ts +2 -0
- package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.js +16 -0
- package/build/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.js.map +1 -1
- package/build/__tests__/behavioral/tests/migrationToInstance/support/AbstractInstanceTest2.txt +24 -0
- package/build/__tests__/behavioral/tests/migrationToInstance/support/AbstractStaticTest2.txt +24 -0
- package/build/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest.txt +8 -0
- package/build/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest3.txt +1 -1
- package/build/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest4.txt +531 -0
- package/build/__tests__/behavioral/tests/migrationToInstance/support/StaticTest.txt +8 -0
- package/build/__tests__/behavioral/tests/migrationToInstance/support/StaticTest3.txt +1 -1
- package/build/__tests__/behavioral/tests/migrationToInstance/support/StaticTest4.txt +530 -0
- package/build/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.js +17 -13
- package/build/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.js.map +1 -1
- package/package.json +3 -3
- package/src/__tests__/behavioral/tests/migrationToInstance/StaticToInstanceTestFileMigrator.test.ts +16 -0
- package/src/__tests__/behavioral/tests/migrationToInstance/support/AbstractInstanceTest2.txt +24 -0
- package/src/__tests__/behavioral/tests/migrationToInstance/support/AbstractStaticTest2.txt +24 -0
- package/src/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest.txt +8 -0
- package/src/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest3.txt +1 -1
- package/src/__tests__/behavioral/tests/migrationToInstance/support/InstanceTest4.txt +531 -0
- package/src/__tests__/behavioral/tests/migrationToInstance/support/StaticTest.txt +8 -0
- package/src/__tests__/behavioral/tests/migrationToInstance/support/StaticTest3.txt +1 -1
- package/src/__tests__/behavioral/tests/migrationToInstance/support/StaticTest4.txt +530 -0
- package/src/tests/staticToInstanceMigration/StaticToInstanceTestFileMigrator.ts +23 -16
|
@@ -0,0 +1,530 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FormViewController,
|
|
3
|
+
SkillViewControllerId,
|
|
4
|
+
buttonAssert,
|
|
5
|
+
formAssert,
|
|
6
|
+
interactor,
|
|
7
|
+
navigationAssert,
|
|
8
|
+
vcAssert,
|
|
9
|
+
} from '@sprucelabs/heartwood-view-controllers'
|
|
10
|
+
import { selectAssert } from '@sprucelabs/schema'
|
|
11
|
+
import { SelectChoice } from '@sprucelabs/spruce-core-schemas'
|
|
12
|
+
import { FormCardViewController } from '@sprucelabs/spruce-form-utils'
|
|
13
|
+
import { eventFaker, fake, seed } from '@sprucelabs/spruce-test-fixtures'
|
|
14
|
+
import { assert, generateId, test } from '@sprucelabs/test-utils'
|
|
15
|
+
import GenerateSkillViewController, {
|
|
16
|
+
CurrentChallengeSchema,
|
|
17
|
+
GenerateStorySchema,
|
|
18
|
+
} from '../../../generation/Generate.svc'
|
|
19
|
+
import { storyElements } from '../../../generation/storyElements'
|
|
20
|
+
import AbstractEightBitTest from '../../support/AbstractEightBitTest'
|
|
21
|
+
import {
|
|
22
|
+
GenerateStoryTargetAndPayload,
|
|
23
|
+
GetStoryStatusTargetAndPayload,
|
|
24
|
+
} from '../../support/EventFaker'
|
|
25
|
+
|
|
26
|
+
@fake.login()
|
|
27
|
+
export default class GenerateSkillViewTest extends AbstractEightBitTest {
|
|
28
|
+
private static vc: SpyGenerateSkillView
|
|
29
|
+
private static checkStatusIntervalCb: undefined | (() => Promise<void>)
|
|
30
|
+
private static checkStatusIntervalMs: number | undefined
|
|
31
|
+
private static intervalId: string
|
|
32
|
+
private static passedIntervalIdToClear?: string
|
|
33
|
+
|
|
34
|
+
@seed('familyMembers', 3)
|
|
35
|
+
protected static async beforeEach(): Promise<void> {
|
|
36
|
+
await super.beforeEach()
|
|
37
|
+
|
|
38
|
+
this.views.setController(
|
|
39
|
+
'eightbitstories.generate',
|
|
40
|
+
SpyGenerateSkillView
|
|
41
|
+
)
|
|
42
|
+
this.views.setController('forms.card', SpyFormCard)
|
|
43
|
+
|
|
44
|
+
this.vc = this.Vc()
|
|
45
|
+
|
|
46
|
+
await this.eventFaker.fakeListFamilyMembers(() => this.members.find({}))
|
|
47
|
+
await this.loadVc()
|
|
48
|
+
|
|
49
|
+
delete this.checkStatusIntervalCb
|
|
50
|
+
delete this.checkStatusIntervalMs
|
|
51
|
+
delete this.passedIntervalIdToClear
|
|
52
|
+
|
|
53
|
+
this.intervalId = generateId()
|
|
54
|
+
|
|
55
|
+
//@ts-ignore
|
|
56
|
+
GenerateSkillViewController.setInterval = (
|
|
57
|
+
cb: () => Promise<void>,
|
|
58
|
+
intervalMs: number
|
|
59
|
+
) => {
|
|
60
|
+
this.checkStatusIntervalMs = intervalMs
|
|
61
|
+
this.checkStatusIntervalCb = cb
|
|
62
|
+
return this.intervalId
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//@ts-ignore
|
|
66
|
+
GenerateSkillViewController.clearInterval = (id: string) => {
|
|
67
|
+
this.passedIntervalIdToClear = id
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
console.log(this.locationIds)
|
|
71
|
+
console.log(this.organizationIds)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
private static get locationIds() {
|
|
75
|
+
console.log('here')
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private static set organizationIds() {
|
|
79
|
+
console.log('here')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@test()
|
|
83
|
+
protected static async requiresLogin() {
|
|
84
|
+
await vcAssert.assertLoginIsRequired(this.vc)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@test()
|
|
88
|
+
protected static async rendersExpectedCards() {
|
|
89
|
+
vcAssert.assertSkillViewRendersCards(this.vc, [
|
|
90
|
+
'elements',
|
|
91
|
+
'members',
|
|
92
|
+
'currentChallenge',
|
|
93
|
+
'controls',
|
|
94
|
+
])
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@test()
|
|
98
|
+
protected static async controlsCardRendersExpectedButtons() {
|
|
99
|
+
buttonAssert.cardRendersButtons(this.controlsVc, ['back', 'generate'])
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@test()
|
|
103
|
+
protected static async rendersAlertAndRedirectsIfNoMembers() {
|
|
104
|
+
await this.eventFaker.fakeListFamilyMembers(() => [])
|
|
105
|
+
this.vc = this.Vc()
|
|
106
|
+
await vcAssert.assertRendersAlertThenRedirects({
|
|
107
|
+
vc: this.vc,
|
|
108
|
+
router: this.views.getRouter(),
|
|
109
|
+
destination: {
|
|
110
|
+
id: 'eightbitstories.root',
|
|
111
|
+
},
|
|
112
|
+
action: () => this.loadVc(),
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
@test()
|
|
117
|
+
protected static async clickingBackGoesBackToRoot() {
|
|
118
|
+
await vcAssert.assertActionRedirects({
|
|
119
|
+
action: () => interactor.clickButton(this.controlsVc, 'back'),
|
|
120
|
+
destination: {
|
|
121
|
+
id: 'eightbitstories.root',
|
|
122
|
+
},
|
|
123
|
+
router: this.views.getRouter(),
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
@test()
|
|
128
|
+
protected static elementsAndMembersCardsRendersForms() {
|
|
129
|
+
formAssert.cardRendersForm(this.elementsVc)
|
|
130
|
+
formAssert.cardRendersForm(this.membersVc)
|
|
131
|
+
formAssert.cardRendersForm(this.currentChallengeVc)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
@test()
|
|
135
|
+
protected static async formCardsDoNotRenderButtons() {
|
|
136
|
+
assert.isFalse(this.elementsFormVc.getShouldRenderSubmitControls())
|
|
137
|
+
assert.isFalse(this.membersFormVc.getShouldRenderSubmitControls())
|
|
138
|
+
assert.isFalse(
|
|
139
|
+
this.currentChallengeFormVc.getShouldRenderSubmitControls()
|
|
140
|
+
)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
@test()
|
|
144
|
+
protected static async elementsFormRendersExpectedFields() {
|
|
145
|
+
formAssert.formRendersFields(this.elementsFormVc, ['elements'])
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
@test()
|
|
149
|
+
protected static async elementsFormRendersExpectedChoices() {
|
|
150
|
+
const schema = this.elementsFormVc.getSchema()
|
|
151
|
+
selectAssert.assertSelectChoicesMatch(
|
|
152
|
+
schema.fields.elements.options.choices,
|
|
153
|
+
storyElements.map((element) => element.id)
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
@test()
|
|
158
|
+
protected static async rendersElementsAsTags() {
|
|
159
|
+
formAssert.formFieldRendersAs(this.elementsFormVc, 'elements', 'tags')
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@test()
|
|
163
|
+
protected static async membersFormRendersExpectedFields() {
|
|
164
|
+
formAssert.formRendersFields(this.membersFormVc, ['members'])
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
@test()
|
|
168
|
+
protected static async membersFormRendersAsTags() {
|
|
169
|
+
formAssert.formFieldRendersAs(this.membersFormVc, 'members', 'tags')
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
@test()
|
|
173
|
+
protected static async membersRendersExpectedChoices() {
|
|
174
|
+
const members = await this.getAllMembers()
|
|
175
|
+
const expected = members.map((member) => member.id)
|
|
176
|
+
|
|
177
|
+
const schema = this.membersFormVc.getSchema()
|
|
178
|
+
selectAssert.assertSelectChoicesMatch(
|
|
179
|
+
schema.fields.members.options.choices as SelectChoice[],
|
|
180
|
+
expected
|
|
181
|
+
)
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
@test()
|
|
185
|
+
protected static async currentChallengeFormRendersAsExpected() {
|
|
186
|
+
formAssert.formRendersField(
|
|
187
|
+
this.currentChallengeFormVc,
|
|
188
|
+
'currentChallenge'
|
|
189
|
+
)
|
|
190
|
+
formAssert.formFieldRendersAs(
|
|
191
|
+
this.currentChallengeFormVc,
|
|
192
|
+
'currentChallenge',
|
|
193
|
+
'textarea'
|
|
194
|
+
)
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@test()
|
|
198
|
+
protected static async clickingGenerateSetsControlsToBusy() {
|
|
199
|
+
await this.eventFaker.fakeGenerateStory(() => {})
|
|
200
|
+
|
|
201
|
+
await this.selectFirstMember()
|
|
202
|
+
await this.selectFirstElement()
|
|
203
|
+
|
|
204
|
+
const promise = this.clickGenerateAndAssertRedirect()
|
|
205
|
+
this.assertFooterIsBusy()
|
|
206
|
+
|
|
207
|
+
await promise
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
@test()
|
|
211
|
+
protected static async rendersAlertIfFailsToGenerateStory() {
|
|
212
|
+
await eventFaker.makeEventThrow(
|
|
213
|
+
'eightbitstories.generate-story::v2023_09_05'
|
|
214
|
+
)
|
|
215
|
+
|
|
216
|
+
const alertVc = await vcAssert.assertRendersAlert(this.vc, () =>
|
|
217
|
+
this.clickGenerate()
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
this.assertFooterIsBusy()
|
|
221
|
+
|
|
222
|
+
await alertVc.hide()
|
|
223
|
+
|
|
224
|
+
this.assertFooterIsNotBusy()
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
@test('submits selected members and elements 1', [0], [0])
|
|
228
|
+
@test('submits selected members and elements 2', [1], [2])
|
|
229
|
+
@test('submits selected members and elements 3', [0, 1], [2, 3])
|
|
230
|
+
protected static async generatePassesSelectedMembersAndElements(
|
|
231
|
+
memberIdxs: number[],
|
|
232
|
+
elementIdxs: number[]
|
|
233
|
+
) {
|
|
234
|
+
let passedPayload: GenerateStoryTargetAndPayload['payload'] | undefined
|
|
235
|
+
|
|
236
|
+
await this.eventFaker.fakeGenerateStory(({ payload }) => {
|
|
237
|
+
passedPayload = payload
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
const selectedMembers = await this.selectMembers(memberIdxs)
|
|
241
|
+
const selectedElements = await this.selectElements(elementIdxs)
|
|
242
|
+
|
|
243
|
+
const currentChallenge = generateId()
|
|
244
|
+
await this.currentChallengeFormVc.setValue(
|
|
245
|
+
'currentChallenge',
|
|
246
|
+
currentChallenge
|
|
247
|
+
)
|
|
248
|
+
|
|
249
|
+
await this.clickGenerateAndAssertRedirect()
|
|
250
|
+
|
|
251
|
+
assert.isEqualDeep(passedPayload, {
|
|
252
|
+
familyMembers: selectedMembers,
|
|
253
|
+
storyElements: selectedElements,
|
|
254
|
+
currentChallenge,
|
|
255
|
+
storyHash: this.vc.getHash(),
|
|
256
|
+
})
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@test()
|
|
260
|
+
protected static async generatingStoryRedirectsToStoryWithArgs() {
|
|
261
|
+
await this.eventFaker.fakeGenerateStory()
|
|
262
|
+
|
|
263
|
+
await this.selectFirstElement()
|
|
264
|
+
await this.selectFirstMember()
|
|
265
|
+
|
|
266
|
+
const destination = {
|
|
267
|
+
id: 'eightbitstories.story' as SkillViewControllerId,
|
|
268
|
+
args: {
|
|
269
|
+
story: generateId(),
|
|
270
|
+
},
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
await this.clickGenerateAndAssertRedirect(destination)
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
@test()
|
|
277
|
+
protected static async callingDestroyRemovesDidGenerateListener() {
|
|
278
|
+
await this.vc.destroy()
|
|
279
|
+
|
|
280
|
+
await eventFaker.handleReactiveEvent(
|
|
281
|
+
'eightbitstories.did-generate-story::v2023_09_05'
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
await this.emitDidGenerate()
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
@test()
|
|
288
|
+
protected static async rendersNullNavigation() {
|
|
289
|
+
navigationAssert.skillViewDoesNotRenderNavigation(this.vc)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
@test()
|
|
293
|
+
protected static async checksForGeneratedStoryAfterSubmitting() {
|
|
294
|
+
let passedTarget: GetStoryStatusTargetAndPayload['target'] | undefined
|
|
295
|
+
await this.eventFaker.fakeGetStoryGenerationStatus(({ target }) => {
|
|
296
|
+
passedTarget = target
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
await this.fakeGenerateSelectEverythingClickGenerateAndInvokeIntervalCb()
|
|
300
|
+
|
|
301
|
+
assert.isEqualDeep(passedTarget, {
|
|
302
|
+
storyHash: this.vc.getHash(),
|
|
303
|
+
})
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
@test()
|
|
307
|
+
protected static async passesExpectedIntervalToChecksAfterSubmit() {
|
|
308
|
+
await this.eventFaker.fakeGenerateStory()
|
|
309
|
+
await this.selectElementFamilyMemberAndClickGenerate()
|
|
310
|
+
assert.isEqual(this.checkStatusIntervalMs, 1000 * 10)
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
@test()
|
|
314
|
+
protected static async doesNotSetIntervalIfGenerateThrows() {
|
|
315
|
+
await eventFaker.makeEventThrow(
|
|
316
|
+
'eightbitstories.generate-story::v2023_09_05'
|
|
317
|
+
)
|
|
318
|
+
|
|
319
|
+
await vcAssert.assertRendersAlert(this.vc, () =>
|
|
320
|
+
this.selectElementFamilyMemberAndClickGenerate()
|
|
321
|
+
)
|
|
322
|
+
assert.isUndefined(
|
|
323
|
+
this.checkStatusIntervalCb,
|
|
324
|
+
'should not have been set'
|
|
325
|
+
)
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
@test()
|
|
329
|
+
protected static async redirectsIfResponseIsStoryGenerated() {
|
|
330
|
+
const storyId = generateId()
|
|
331
|
+
await this.eventFaker.fakeGetStoryGenerationStatus(() => {
|
|
332
|
+
return {
|
|
333
|
+
status: 'ready',
|
|
334
|
+
storyId,
|
|
335
|
+
}
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
await this.fakeGenerateSelectEverythingAndClickGenerate()
|
|
339
|
+
await vcAssert.assertActionRedirects({
|
|
340
|
+
action: () => this.checkStatusIntervalCb?.(),
|
|
341
|
+
destination: {
|
|
342
|
+
id: 'eightbitstories.story',
|
|
343
|
+
args: {
|
|
344
|
+
story: storyId,
|
|
345
|
+
},
|
|
346
|
+
},
|
|
347
|
+
router: this.views.getRouter(),
|
|
348
|
+
})
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
@test()
|
|
352
|
+
protected static async clearsTimeoutOnBlur() {
|
|
353
|
+
await this.fakeGenerateSelectEverythingAndClickGenerate()
|
|
354
|
+
assert.isFalsy(this.passedIntervalIdToClear)
|
|
355
|
+
await interactor.blur(this.vc)
|
|
356
|
+
assert.isEqual(
|
|
357
|
+
this.passedIntervalIdToClear,
|
|
358
|
+
this.intervalId,
|
|
359
|
+
'did not pass response to setInterval to clearInterval'
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
private static async fakeGenerateSelectEverythingClickGenerateAndInvokeIntervalCb() {
|
|
364
|
+
await this.fakeGenerateSelectEverythingAndClickGenerate()
|
|
365
|
+
await this.checkStatusIntervalCb?.()
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
private static async fakeGenerateSelectEverythingAndClickGenerate() {
|
|
369
|
+
await this.eventFaker.fakeGenerateStory()
|
|
370
|
+
await this.selectElementFamilyMemberAndClickGenerate()
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
private static async selectElementFamilyMemberAndClickGenerate() {
|
|
374
|
+
await this.selectFirstElement()
|
|
375
|
+
await this.selectFirstMember()
|
|
376
|
+
await this.clickGenerate()
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
private static async clickGenerateAndAssertRedirect(destination?: {
|
|
380
|
+
id: SkillViewControllerId
|
|
381
|
+
args: { story: string }
|
|
382
|
+
}) {
|
|
383
|
+
await vcAssert.assertActionRedirects({
|
|
384
|
+
action: async () => {
|
|
385
|
+
await this.clickGenerate()
|
|
386
|
+
await this.emitDidGenerate(destination?.args?.story)
|
|
387
|
+
},
|
|
388
|
+
router: this.views.getRouter(),
|
|
389
|
+
destination,
|
|
390
|
+
})
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
private static async emitDidGenerate(storyId?: string) {
|
|
394
|
+
await this.fakedClient.emitAndFlattenResponses(
|
|
395
|
+
'eightbitstories.did-generate-story::v2023_09_05',
|
|
396
|
+
{
|
|
397
|
+
target: {
|
|
398
|
+
personId: generateId(),
|
|
399
|
+
},
|
|
400
|
+
payload: {
|
|
401
|
+
storyId: storyId ?? generateId(),
|
|
402
|
+
},
|
|
403
|
+
}
|
|
404
|
+
)
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
private static async selectFirstElement() {
|
|
408
|
+
const selectedElement = await this.selectElement(0)
|
|
409
|
+
return selectedElement
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
private static async selectElement(idx: number) {
|
|
413
|
+
const selectedElements = await this.selectElements([idx])
|
|
414
|
+
return selectedElements[0]
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
private static async selectElements(allIdxs: number[]) {
|
|
418
|
+
const selectedElements = allIdxs.map((idx) => storyElements[idx].id)
|
|
419
|
+
await this.elementsFormVc.setValue('elements', selectedElements)
|
|
420
|
+
return selectedElements
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
private static async selectFirstMember() {
|
|
424
|
+
const selectedMember = await this.selectMember(0)
|
|
425
|
+
return selectedMember
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
private static async selectMember(idx: number) {
|
|
429
|
+
const selectedMembers = await this.selectMembers([idx])
|
|
430
|
+
return selectedMembers[0]
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
private static async selectMembers(allIdxs: number[]) {
|
|
434
|
+
const members = await this.getAllMembers()
|
|
435
|
+
const selectedMembers = allIdxs.map((idx) => members[idx].id)
|
|
436
|
+
await this.membersFormVc.setValue('members', selectedMembers as any)
|
|
437
|
+
return selectedMembers
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
private static async getAllMembers() {
|
|
441
|
+
return await this.members.find({})
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private static assertFooterIsNotBusy() {
|
|
445
|
+
assert.isFalse(this.getIsFooterBusy())
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
private static assertFooterIsBusy() {
|
|
449
|
+
assert.isTrue(this.getIsFooterBusy())
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
private static getIsFooterBusy(): boolean | null | undefined {
|
|
453
|
+
return this.controlsVc.getFooter()?.isBusy
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
private static async clickGenerate() {
|
|
457
|
+
await interactor.clickButton(this.controlsVc, 'generate')
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
private static get membersFormVc() {
|
|
461
|
+
return this.vc.getMembersFormVc()
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
private static get elementsFormVc() {
|
|
465
|
+
return this.vc.getElementsFormVc()
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
private static async loadVc() {
|
|
469
|
+
await this.views.load(this.vc)
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
private static get membersVc() {
|
|
473
|
+
return this.vc.getMembersVc()
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
private static get currentChallengeVc() {
|
|
477
|
+
return this.vc.getCurrentChallengeVc()
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
private static get currentChallengeFormVc() {
|
|
481
|
+
return this.currentChallengeVc.getFormVc() as FormViewController<CurrentChallengeSchema>
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
private static get elementsVc() {
|
|
485
|
+
return this.vc.getElementsVc()
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
private static get controlsVc() {
|
|
489
|
+
return this.vc.getControlsCardVc()
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
private static Vc(): SpyGenerateSkillView {
|
|
493
|
+
return this.views.Controller(
|
|
494
|
+
'eightbitstories.generate',
|
|
495
|
+
{}
|
|
496
|
+
) as SpyGenerateSkillView
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
class SpyGenerateSkillView extends GenerateSkillViewController {
|
|
501
|
+
public getHash() {
|
|
502
|
+
return this.storyHash!
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
public getCurrentChallengeVc() {
|
|
506
|
+
return this.currentChallengeVc
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
public getMembersFormVc() {
|
|
510
|
+
return this.getMembersVc().getFormVc() as FormViewController<GenerateStorySchema>
|
|
511
|
+
}
|
|
512
|
+
public getElementsFormVc() {
|
|
513
|
+
return this.getElementsVc().getFormVc() as FormViewController<GenerateStorySchema>
|
|
514
|
+
}
|
|
515
|
+
public getElementsVc() {
|
|
516
|
+
return this.elementsVc as SpyFormCard
|
|
517
|
+
}
|
|
518
|
+
public getMembersVc() {
|
|
519
|
+
return this.membersVc as SpyFormCard
|
|
520
|
+
}
|
|
521
|
+
public getControlsCardVc() {
|
|
522
|
+
return this.controlsVc
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
class SpyFormCard extends FormCardViewController {
|
|
527
|
+
public getFormVc() {
|
|
528
|
+
return this.formVc
|
|
529
|
+
}
|
|
530
|
+
}
|
|
@@ -16,19 +16,21 @@ export default class StaticToInstanceTestFileMigratorImpl
|
|
|
16
16
|
// that has the `@test()` decorator
|
|
17
17
|
// 1b. If the contents include `export default abstract class`,
|
|
18
18
|
// remove `static` from all methods
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
const isAbstractTest =
|
|
20
|
+
/export\s+default\s+(?:abstract\s+class\b|class\s+(Abstract\w*))/m.test(
|
|
21
|
+
contents
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
let cleanedUp = isAbstractTest
|
|
23
25
|
? contents.replaceAll(' static ', ' ')
|
|
24
26
|
: contents.replace(
|
|
25
27
|
// Matches @test() or @seed(...) followed (on next line) by optional visibility and `static`.
|
|
26
|
-
/(@(?:test
|
|
28
|
+
/(@(?:(?:test|seed)\([\s\S]*?\))\s*\n\s*(?:public|protected)\s+)static\s+/g,
|
|
27
29
|
'$1'
|
|
28
30
|
)
|
|
29
31
|
|
|
30
32
|
// 2. Add `@suite()` above `export default class` if it's not already present
|
|
31
|
-
if (!cleanedUp.includes('@suite')) {
|
|
33
|
+
if (!isAbstractTest && !cleanedUp.includes('@suite')) {
|
|
32
34
|
cleanedUp = cleanedUp.replace(
|
|
33
35
|
/export default class/,
|
|
34
36
|
'@suite()\nexport default class'
|
|
@@ -55,13 +57,16 @@ export default class StaticToInstanceTestFileMigratorImpl
|
|
|
55
57
|
const methods = ['beforeEach', 'afterEach']
|
|
56
58
|
for (const method of methods) {
|
|
57
59
|
cleanedUp = cleanedUp.replace(
|
|
58
|
-
`
|
|
59
|
-
`
|
|
60
|
+
`static async ${method}()`,
|
|
61
|
+
`async ${method}()`
|
|
60
62
|
)
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
cleanedUp = this.fixNonNullAssertions(cleanedUp)
|
|
64
66
|
|
|
67
|
+
cleanedUp = cleanedUp.replaceAll('= >', '=>')
|
|
68
|
+
cleanedUp = cleanedUp.replaceAll('! =', ' =')
|
|
69
|
+
|
|
65
70
|
return cleanedUp
|
|
66
71
|
}
|
|
67
72
|
|
|
@@ -73,8 +78,9 @@ export default class StaticToInstanceTestFileMigratorImpl
|
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
private findThisCalls(contents: string): string[] {
|
|
76
|
-
// Matches `this.myProp`
|
|
77
|
-
|
|
81
|
+
// Matches either `this.myProp` or `delete this.myProp`
|
|
82
|
+
// if followed by space, punctuation, parentheses, or end of string
|
|
83
|
+
const thisPropertyRegex = /(?:delete\s+)?this\.(\w+)(?=[\s.(),;]|$)/g
|
|
78
84
|
const names: string[] = []
|
|
79
85
|
let match: RegExpExecArray | null
|
|
80
86
|
|
|
@@ -117,21 +123,22 @@ export default class StaticToInstanceTestFileMigratorImpl
|
|
|
117
123
|
)
|
|
118
124
|
|
|
119
125
|
/**
|
|
120
|
-
* 2) Remove `static` from property declarations and add a non-null assertion
|
|
126
|
+
* 2) Remove `static` from property declarations and add a non-null assertion
|
|
127
|
+
* if the property is not optional.
|
|
121
128
|
* e.g.
|
|
122
129
|
* private static myProp: Type => private myProp!: Type
|
|
130
|
+
* private static passedIntervalIdToClear?: string => private passedIntervalIdToClear?: string
|
|
123
131
|
*/
|
|
124
132
|
const propertyPattern = new RegExp(
|
|
125
133
|
`((?:public|protected|private)?\\s+)?` + // group 1: optional visibility
|
|
126
134
|
`static\\s+` + // literal "static "
|
|
127
|
-
`(${name})
|
|
135
|
+
`(${name})(\\?)?` + // group 2: property name, group 3: optional "?"
|
|
128
136
|
`(?=[\\s=:\\[;]|$)`, // lookahead: space, '=', ':', '[', ';', or end-of-string
|
|
129
137
|
'g'
|
|
130
138
|
)
|
|
131
|
-
updated = updated.replace(propertyPattern, (match, g1, g2) => {
|
|
132
|
-
//
|
|
133
|
-
|
|
134
|
-
return `${g1 ?? ''}${g2}!`
|
|
139
|
+
updated = updated.replace(propertyPattern, (match, g1, g2, g3) => {
|
|
140
|
+
// If the property is optional (g3 is "?"), leave it. Otherwise, add a non-null assertion.
|
|
141
|
+
return `${g1 ?? ''}${g2}${g3 !== undefined ? g3 : '!'}`
|
|
135
142
|
})
|
|
136
143
|
|
|
137
144
|
return updated
|