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