返回 oh-my-ppt
page-edit-generation-event.test.ts
根目录 / tests / unit / session / page-edit-generation-event.test.ts
1 import { describe, expect, it } from 'vitest'
2 import {
3 isDeckEditGenerationEvent,
4 isPageEditGenerationEvent,
5 isStyleSwitchGenerationEvent
6 } from '../../../src/renderer/src/components/session-detail/shared/pageEditGenerationEvent'
7
8 describe('isPageEditGenerationEvent', () => {
9 it('does not claim an untagged event before the backend attaches an activity marker', () => {
10 expect(
11 isPageEditGenerationEvent(
12 { runId: 'page-edit-run', activityKind: undefined },
13 { runId: undefined }
14 )
15 ).toBe(false)
16 })
17
18 it('does not take over chunks for a different run after the page job is identified', () => {
19 expect(
20 isPageEditGenerationEvent(
21 { runId: 'other-run', activityKind: undefined },
22 { runId: 'page-edit-run' }
23 )
24 ).toBe(false)
25 })
26
27 it('does not claim a tagged event without the active job run', () => {
28 expect(
29 isPageEditGenerationEvent({ runId: 'page-edit-run', activityKind: 'page-edit' }, null)
30 ).toBe(false)
31 })
32
33 it('matches only the active run for each dedicated job type', () => {
34 expect(
35 isDeckEditGenerationEvent(
36 { runId: 'deck-edit-run', activityKind: 'deck-edit' },
37 { runId: 'deck-edit-run' }
38 )
39 ).toBe(true)
40 })
41
42 it('claims the first tagged event while an optimistic job is still waiting for its run id', () => {
43 expect(
44 isDeckEditGenerationEvent(
45 { runId: 'deck-edit-run', activityKind: 'deck-edit' },
46 { runId: undefined }
47 )
48 ).toBe(true)
49 expect(
50 isDeckEditGenerationEvent(
51 { runId: 'page-edit-run', activityKind: 'page-edit' },
52 { runId: undefined }
53 )
54 ).toBe(false)
55 })
56
57 it('does not let an activity marker override an already-bound foreign run', () => {
58 expect(
59 isDeckEditGenerationEvent(
60 { runId: 'stale-run', activityKind: 'deck-edit' },
61 { runId: 'active-run' }
62 )
63 ).toBe(false)
64 expect(
65 isStyleSwitchGenerationEvent(
66 { runId: 'stale-style-run', activityKind: 'style-switch' },
67 { runId: 'active-style-run' }
68 )
69 ).toBe(false)
70 })
71 })
72
72 lines TYPESCRIPT