mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-28 02:02:08 +00:00
Address PR review comments
- Flatten directory structure: remove barrel file, move files up to /jobs - Remove .passthrough() from zPreviewOutput, zPaginationInfo, zJobsListResponse - Align nullable/optional with OpenAPI spec (outputs_count now nullable) - Remove big comment block sections - Change extractWorkflow return type to unknown - Move zWorkflowContainer schema to jobTypes.ts - Add interface types to test helper functions - Add fetchHistory offset test for priority calculation 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,18 +1,24 @@
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import type { z } from 'zod'
|
||||
|
||||
import {
|
||||
extractWorkflow,
|
||||
fetchHistory,
|
||||
fetchJobDetail,
|
||||
fetchQueue
|
||||
} from '@/platform/remote/comfyui/jobs'
|
||||
} from '@/platform/remote/comfyui/jobs/fetchJobs'
|
||||
import type {
|
||||
RawJobListItem,
|
||||
zJobsListResponse
|
||||
} from '@/platform/remote/comfyui/jobs/jobTypes'
|
||||
|
||||
type JobsListResponse = z.infer<typeof zJobsListResponse>
|
||||
|
||||
// Helper to create a mock job
|
||||
function createMockJob(
|
||||
id: string,
|
||||
status: 'pending' | 'in_progress' | 'completed' = 'completed',
|
||||
overrides: Record<string, unknown> = {}
|
||||
) {
|
||||
overrides: Partial<RawJobListItem> = {}
|
||||
): RawJobListItem {
|
||||
return {
|
||||
id,
|
||||
status,
|
||||
@@ -25,11 +31,10 @@ function createMockJob(
|
||||
}
|
||||
}
|
||||
|
||||
// Helper to create mock API response
|
||||
function createMockResponse(
|
||||
jobs: ReturnType<typeof createMockJob>[],
|
||||
jobs: RawJobListItem[],
|
||||
total: number = jobs.length
|
||||
) {
|
||||
): JobsListResponse {
|
||||
return {
|
||||
jobs,
|
||||
pagination: {
|
||||
@@ -89,6 +94,32 @@ describe('fetchJobs', () => {
|
||||
expect(result[2].priority).toBe(1) // total - 0 - 2
|
||||
})
|
||||
|
||||
it('calculates priority correctly with non-zero offset', async () => {
|
||||
const mockFetch = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
json: () =>
|
||||
Promise.resolve(
|
||||
createMockResponse(
|
||||
[
|
||||
createMockJob('job4', 'completed'),
|
||||
createMockJob('job5', 'completed')
|
||||
],
|
||||
10 // total of 10 jobs
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
// Fetch page 2 (offset=5)
|
||||
const result = await fetchHistory(mockFetch, 200, 5)
|
||||
|
||||
expect(mockFetch).toHaveBeenCalledWith(
|
||||
'/jobs?status=completed&limit=200&offset=5'
|
||||
)
|
||||
// Priority base is total - offset = 10 - 5 = 5
|
||||
expect(result[0].priority).toBe(5) // (total - offset) - 0
|
||||
expect(result[1].priority).toBe(4) // (total - offset) - 1
|
||||
})
|
||||
|
||||
it('preserves server-provided priority', async () => {
|
||||
const mockFetch = vi.fn().mockResolvedValue({
|
||||
ok: true,
|
||||
Reference in New Issue
Block a user