Skip to content

Commit 3936454

Browse files
[feat] Add logout button to user popover (#4022)
1 parent 30ee669 commit 3936454

File tree

2 files changed

+53
-5
lines changed

2 files changed

+53
-5
lines changed

src/components/topbar/CurrentUserPopover.spec.ts

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,11 @@ vi.mock('@/composables/auth/useCurrentUser', () => ({
5050
}))
5151

5252
// Mock the useFirebaseAuthActions composable
53+
const mockLogout = vi.fn()
5354
vi.mock('@/composables/auth/useFirebaseAuthActions', () => ({
5455
useFirebaseAuthActions: vi.fn(() => ({
55-
fetchBalance: vi.fn().mockResolvedValue(undefined)
56+
fetchBalance: vi.fn().mockResolvedValue(undefined),
57+
logout: mockLogout
5658
}))
5759
}))
5860

@@ -100,8 +102,7 @@ describe('CurrentUserPopover', () => {
100102
global: {
101103
plugins: [i18n],
102104
stubs: {
103-
Divider: true,
104-
Button: true
105+
Divider: true
105106
}
106107
}
107108
})
@@ -114,6 +115,18 @@ describe('CurrentUserPopover', () => {
114115
expect(wrapper.text()).toContain('[email protected]')
115116
})
116117

118+
it('renders logout button with correct props', () => {
119+
const wrapper = mountComponent()
120+
121+
// Find all buttons and get the logout button (second one)
122+
const buttons = wrapper.findAllComponents(Button)
123+
const logoutButton = buttons[1]
124+
125+
// Check that logout button has correct props
126+
expect(logoutButton.props('label')).toBe('Log Out')
127+
expect(logoutButton.props('icon')).toBe('pi pi-sign-out')
128+
})
129+
117130
it('opens user settings and emits close event when settings button is clicked', async () => {
118131
const wrapper = mountComponent()
119132

@@ -132,12 +145,30 @@ describe('CurrentUserPopover', () => {
132145
expect(wrapper.emitted('close')!.length).toBe(1)
133146
})
134147

148+
it('calls logout function and emits close event when logout button is clicked', async () => {
149+
const wrapper = mountComponent()
150+
151+
// Find all buttons and get the logout button (second one)
152+
const buttons = wrapper.findAllComponents(Button)
153+
const logoutButton = buttons[1]
154+
155+
// Click the logout button
156+
await logoutButton.trigger('click')
157+
158+
// Verify logout was called
159+
expect(mockLogout).toHaveBeenCalled()
160+
161+
// Verify close event was emitted
162+
expect(wrapper.emitted('close')).toBeTruthy()
163+
expect(wrapper.emitted('close')!.length).toBe(1)
164+
})
165+
135166
it('opens API pricing docs and emits close event when API pricing button is clicked', async () => {
136167
const wrapper = mountComponent()
137168

138-
// Find all buttons and get the API pricing button (second one)
169+
// Find all buttons and get the API pricing button (third one now)
139170
const buttons = wrapper.findAllComponents(Button)
140-
const apiPricingButton = buttons[1]
171+
const apiPricingButton = buttons[2]
141172

142173
// Click the API pricing button
143174
await apiPricingButton.trigger('click')

src/components/topbar/CurrentUserPopover.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@
3737

3838
<Divider class="my-2" />
3939

40+
<Button
41+
class="justify-start"
42+
:label="$t('auth.signOut.signOut')"
43+
icon="pi pi-sign-out"
44+
text
45+
fluid
46+
severity="secondary"
47+
@click="handleLogout"
48+
/>
49+
50+
<Divider class="my-2" />
51+
4052
<Button
4153
class="justify-start"
4254
:label="$t('credits.apiPricing')"
@@ -90,6 +102,11 @@ const handleTopUp = () => {
90102
emit('close')
91103
}
92104
105+
const handleLogout = async () => {
106+
await authActions.logout()
107+
emit('close')
108+
}
109+
93110
const handleOpenApiPricing = () => {
94111
window.open('https://docs.comfy.org/tutorials/api-nodes/pricing', '_blank')
95112
emit('close')

0 commit comments

Comments
 (0)