-
Notifications
You must be signed in to change notification settings - Fork 650
Road to No Explicit Any Part 6: Composables and Extensions #8083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 10 commits
9ce1a60
d332695
ac6e51f
752d33a
a30d809
a71fda2
b7db9da
9f7da8d
f58d9c5
8c3e80c
217b679
a11e026
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -4,6 +4,11 @@ import { defineComponent, nextTick } from 'vue' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import JobGroupsList from '@/components/queue/job/JobGroupsList.vue' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { JobGroup, JobListItem } from '@/composables/queue/useJobList' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import type { TaskItemImpl } from '@/stores/queueStore' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Test helper type that allows mock taskRef objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type MockTaskRef = Record<string, unknown> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type TestJobListItem = Omit<JobListItem, 'taskRef'> & { taskRef?: MockTaskRef } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const QueueJobItemStub = defineComponent({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| name: 'QueueJobItemStub', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -25,20 +30,27 @@ const QueueJobItemStub = defineComponent({ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| template: '<div class="queue-job-item-stub"></div>' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const createJobItem = (overrides: Partial<JobListItem> = {}): JobListItem => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: 'job-id', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: 'Example job', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| meta: 'Meta text', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state: 'running', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iconName: 'icon', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iconImageUrl: 'https://example.com/icon.png', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showClear: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| taskRef: { workflow: { id: 'workflow-id' } }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| progressTotalPercent: 60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| progressCurrentPercent: 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runningNodeName: 'Node A', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...overrides | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const createJobItem = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| overrides: Partial<TestJobListItem> = {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ): JobListItem => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { taskRef, ...rest } = overrides | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| id: 'job-id', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| title: 'Example job', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| meta: 'Meta text', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| state: 'running', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iconName: 'icon', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iconImageUrl: 'https://example.com/icon.png', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| showClear: true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| taskRef: (taskRef ?? { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| workflow: { id: 'workflow-id' } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }) as unknown as TaskItemImpl | undefined, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| progressTotalPercent: 60, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| progressCurrentPercent: 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| runningNodeName: 'Node A', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...rest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+29
to
+47
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider explicit partial type acknowledgment for the mock. The minimal mock object 🔧 Suggested improvement- taskRef: (taskRef ?? {
- workflow: { id: 'workflow-id' }
- }) as TaskItemImpl,
+ taskRef: (taskRef ?? {
+ workflow: { id: 'workflow-id' }
+ }) as Partial<TaskItemImpl> as TaskItemImpl,Based on learnings, this pattern explicitly acknowledges that the mock doesn't fully implement the interface. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mountComponent = (groups: JobGroup[]) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mount(JobGroupsList, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -117,13 +117,22 @@ vi.mock('@/utils/formatUtil', () => ({ | |||||||||||||||||||||||
| })) | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| import { useJobMenu } from '@/composables/queue/useJobMenu' | ||||||||||||||||||||||||
| import type { TaskItemImpl } from '@/stores/queueStore' | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const createJobItem = (overrides: Partial<JobListItem> = {}): JobListItem => ({ | ||||||||||||||||||||||||
| type MockTaskRef = Record<string, unknown> | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| type TestJobListItem = Omit<JobListItem, 'taskRef'> & { | ||||||||||||||||||||||||
| taskRef?: MockTaskRef | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const createJobItem = ( | ||||||||||||||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This one is a good big gnarlier and potentially out of scope for |
||||||||||||||||||||||||
| overrides: Partial<TestJobListItem> = {} | ||||||||||||||||||||||||
| ): JobListItem => ({ | ||||||||||||||||||||||||
| id: overrides.id ?? 'job-1', | ||||||||||||||||||||||||
| title: overrides.title ?? 'Test job', | ||||||||||||||||||||||||
| meta: overrides.meta ?? 'meta', | ||||||||||||||||||||||||
| state: overrides.state ?? 'completed', | ||||||||||||||||||||||||
| taskRef: overrides.taskRef, | ||||||||||||||||||||||||
| taskRef: overrides.taskRef as unknown as TaskItemImpl | undefined, | ||||||||||||||||||||||||
| iconName: overrides.iconName, | ||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||
| iconImageUrl: overrides.iconImageUrl, | ||||||||||||||||||||||||
| showClear: overrides.showClear, | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The null coalesce guarantees that taskRef is non-null., which is great since we can remove the mock types entirely