Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion src/stores/imagePreviewStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@

vi.mock('@/scripts/app', () => ({
app: {
getPreviewFormatParam: vi.fn(() => '&format=test_webp')
getPreviewFormatParam: vi.fn(() => '&format=test_webp'),
nodeOutputs: {} as Record<string, unknown>,
nodePreviewImages: {} as Record<string, string[]>
}
}))

Expand All @@ -28,6 +30,62 @@
images?: ExecutedWsMessage['output']['images']
): ExecutedWsMessage['output'] => ({ images })

vi.mock('@/stores/executionStore', () => ({
useExecutionStore: vi.fn(() => ({
executionIdToNodeLocatorId: vi.fn((id: string) => id)
}))
}))

vi.mock('@/platform/workflow/management/stores/workflowStore', () => ({
useWorkflowStore: vi.fn(() => ({
nodeIdToNodeLocatorId: vi.fn((id: string | number) => String(id)),
nodeToNodeLocatorId: vi.fn((node: { id: number }) => String(node.id))
}))
}))

describe('imagePreviewStore setNodeOutputsByExecutionId with merge', () => {
beforeEach(() => {
setActivePinia(createTestingPinia({ stubActions: false }))

Check failure on line 48 in src/stores/imagePreviewStore.test.ts

View workflow job for this annotation

GitHub Actions / test

src/stores/imagePreviewStore.test.ts > imagePreviewStore setNodeOutputsByExecutionId with merge > should assign to reactive ref after merge for Vue reactivity

ReferenceError: createTestingPinia is not defined ❯ src/stores/imagePreviewStore.test.ts:48:5

Check failure on line 48 in src/stores/imagePreviewStore.test.ts

View workflow job for this annotation

GitHub Actions / test

src/stores/imagePreviewStore.test.ts > imagePreviewStore setNodeOutputsByExecutionId with merge > should assign to reactive ref after merge for Vue reactivity

ReferenceError: createTestingPinia is not defined ❯ src/stores/imagePreviewStore.test.ts:48:5

Check failure on line 48 in src/stores/imagePreviewStore.test.ts

View workflow job for this annotation

GitHub Actions / test

src/stores/imagePreviewStore.test.ts > imagePreviewStore setNodeOutputsByExecutionId with merge > should assign to reactive ref after merge for Vue reactivity

ReferenceError: createTestingPinia is not defined ❯ src/stores/imagePreviewStore.test.ts:48:5

Check failure on line 48 in src/stores/imagePreviewStore.test.ts

View workflow job for this annotation

GitHub Actions / test

src/stores/imagePreviewStore.test.ts > imagePreviewStore setNodeOutputsByExecutionId with merge > should update reactive nodeOutputs.value when merging outputs

ReferenceError: createTestingPinia is not defined ❯ src/stores/imagePreviewStore.test.ts:48:5

Check failure on line 48 in src/stores/imagePreviewStore.test.ts

View workflow job for this annotation

GitHub Actions / test

src/stores/imagePreviewStore.test.ts > imagePreviewStore setNodeOutputsByExecutionId with merge > should update reactive nodeOutputs.value when merging outputs

ReferenceError: createTestingPinia is not defined ❯ src/stores/imagePreviewStore.test.ts:48:5

Check failure on line 48 in src/stores/imagePreviewStore.test.ts

View workflow job for this annotation

GitHub Actions / test

src/stores/imagePreviewStore.test.ts > imagePreviewStore setNodeOutputsByExecutionId with merge > should update reactive nodeOutputs.value when merging outputs

ReferenceError: createTestingPinia is not defined ❯ src/stores/imagePreviewStore.test.ts:48:5

Check failure on line 48 in src/stores/imagePreviewStore.test.ts

View workflow job for this annotation

GitHub Actions / setup

Cannot find name 'createTestingPinia'.
vi.clearAllMocks()
app.nodeOutputs = {}
app.nodePreviewImages = {}
})

it('should update reactive nodeOutputs.value when merging outputs', () => {
const store = useNodeOutputStore()
const executionId = '1'

const initialOutput = createMockOutputs([{ filename: 'a.png' }])
store.setNodeOutputsByExecutionId(executionId, initialOutput)

expect(app.nodeOutputs[executionId]?.images).toHaveLength(1)
expect(store.nodeOutputs[executionId]?.images).toHaveLength(1)

const newOutput = createMockOutputs([{ filename: 'b.png' }])
store.setNodeOutputsByExecutionId(executionId, newOutput, { merge: true })

expect(app.nodeOutputs[executionId]?.images).toHaveLength(2)
expect(store.nodeOutputs[executionId]?.images).toHaveLength(2)
})

it('should assign to reactive ref after merge for Vue reactivity', () => {
const store = useNodeOutputStore()
const executionId = '1'

const initialOutput = createMockOutputs([{ filename: 'a.png' }])
store.setNodeOutputsByExecutionId(executionId, initialOutput)

const newOutput = createMockOutputs([{ filename: 'b.png' }])

store.setNodeOutputsByExecutionId(executionId, newOutput, { merge: true })

expect(store.nodeOutputs[executionId]).toStrictEqual(
app.nodeOutputs[executionId]
)
expect(store.nodeOutputs[executionId]?.images).toHaveLength(2)
})
})

describe('imagePreviewStore getPreviewParam', () => {
beforeEach(() => {
setActivePinia(createPinia())
Expand Down
1 change: 1 addition & 0 deletions src/stores/imagePreviewStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ export const useNodeOutputStore = defineStore('nodeOutput', () => {
existingOutput[k] = newValue
}
}
nodeOutputs.value[nodeLocatorId] = existingOutput
return
}
}
Expand Down
Loading