Skip to content

Commit 4e12800

Browse files
Expand component test coverage to BrowserTabTitle (#3623)
Co-authored-by: Benjamin Lu <[email protected]>
1 parent d883448 commit 4e12800

File tree

2 files changed

+117
-2
lines changed

2 files changed

+117
-2
lines changed

src/components/BrowserTabTitle.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const executionText = computed(() =>
2323
)
2424
2525
const settingStore = useSettingStore()
26-
const betaMenuEnabled = computed(
26+
const newMenuEnabled = computed(
2727
() => settingStore.get('Comfy.UseNewMenu') !== 'Disabled'
2828
)
2929
@@ -50,7 +50,7 @@ const nodeExecutionTitle = computed(() =>
5050
const workflowTitle = computed(
5151
() =>
5252
executionText.value +
53-
(betaMenuEnabled.value ? workflowNameText.value : DEFAULT_TITLE)
53+
(newMenuEnabled.value ? workflowNameText.value : DEFAULT_TITLE)
5454
)
5555
5656
const title = computed(() => nodeExecutionTitle.value || workflowTitle.value)
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import { mount } from '@vue/test-utils'
2+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
3+
import { nextTick, reactive } from 'vue'
4+
5+
import BrowserTabTitle from '@/components/BrowserTabTitle.vue'
6+
7+
// Mock the execution store
8+
const executionStore = reactive({
9+
isIdle: true,
10+
executionProgress: 0,
11+
executingNode: null as any,
12+
executingNodeProgress: 0
13+
})
14+
vi.mock('@/stores/executionStore', () => ({
15+
useExecutionStore: () => executionStore
16+
}))
17+
18+
// Mock the setting store
19+
const settingStore = reactive({
20+
get: vi.fn(() => 'Enabled')
21+
})
22+
vi.mock('@/stores/settingStore', () => ({
23+
useSettingStore: () => settingStore
24+
}))
25+
26+
// Mock the workflow store
27+
const workflowStore = reactive({
28+
activeWorkflow: null as any
29+
})
30+
vi.mock('@/stores/workflowStore', () => ({
31+
useWorkflowStore: () => workflowStore
32+
}))
33+
34+
describe('BrowserTabTitle.vue', () => {
35+
let wrapper: ReturnType<typeof mount> | null
36+
37+
beforeEach(() => {
38+
wrapper = null
39+
// reset execution store
40+
executionStore.isIdle = true
41+
executionStore.executionProgress = 0
42+
executionStore.executingNode = null as any
43+
executionStore.executingNodeProgress = 0
44+
45+
// reset setting and workflow stores
46+
;(settingStore.get as any).mockReturnValue('Enabled')
47+
workflowStore.activeWorkflow = null
48+
49+
// reset document title
50+
document.title = ''
51+
})
52+
53+
afterEach(() => {
54+
wrapper?.unmount()
55+
})
56+
57+
it('sets default title when idle and no workflow', () => {
58+
wrapper = mount(BrowserTabTitle)
59+
expect(document.title).toBe('ComfyUI')
60+
})
61+
62+
it('sets workflow name as title when workflow exists and menu enabled', async () => {
63+
;(settingStore.get as any).mockReturnValue('Enabled')
64+
workflowStore.activeWorkflow = {
65+
filename: 'myFlow',
66+
isModified: false,
67+
isPersisted: true
68+
}
69+
wrapper = mount(BrowserTabTitle)
70+
await nextTick()
71+
expect(document.title).toBe('myFlow - ComfyUI')
72+
})
73+
74+
it('adds asterisk for unsaved workflow', async () => {
75+
;(settingStore.get as any).mockReturnValue('Enabled')
76+
workflowStore.activeWorkflow = {
77+
filename: 'myFlow',
78+
isModified: true,
79+
isPersisted: true
80+
}
81+
wrapper = mount(BrowserTabTitle)
82+
await nextTick()
83+
expect(document.title).toBe('*myFlow - ComfyUI')
84+
})
85+
86+
it('disables workflow title when menu disabled', async () => {
87+
;(settingStore.get as any).mockReturnValue('Disabled')
88+
workflowStore.activeWorkflow = {
89+
filename: 'myFlow',
90+
isModified: false,
91+
isPersisted: true
92+
}
93+
wrapper = mount(BrowserTabTitle)
94+
await nextTick()
95+
expect(document.title).toBe('ComfyUI')
96+
})
97+
98+
it('shows execution progress when not idle without workflow', async () => {
99+
executionStore.isIdle = false
100+
executionStore.executionProgress = 0.3
101+
wrapper = mount(BrowserTabTitle)
102+
await nextTick()
103+
expect(document.title).toBe('[30%]ComfyUI')
104+
})
105+
106+
it('shows node execution title when executing a node', async () => {
107+
executionStore.isIdle = false
108+
executionStore.executionProgress = 0.4
109+
executionStore.executingNodeProgress = 0.5
110+
executionStore.executingNode = { type: 'Foo' }
111+
wrapper = mount(BrowserTabTitle)
112+
await nextTick()
113+
expect(document.title).toBe('[40%][50%] Foo')
114+
})
115+
})

0 commit comments

Comments
 (0)