|
1 | 1 | import { render, screen } from '@testing-library/vue' |
2 | 2 | import userEvent from '@testing-library/user-event' |
3 | | -import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' |
| 3 | +import { beforeEach, describe, expect, it, vi } from 'vitest' |
4 | 4 | import { defineComponent, h, reactive } from 'vue' |
5 | 5 | import { createI18n } from 'vue-i18n' |
6 | 6 |
|
@@ -36,7 +36,15 @@ vi.mock('@/platform/settings/settingStore', () => ({ |
36 | 36 | })) |
37 | 37 |
|
38 | 38 | vi.mock('@/composables/auth/useCurrentUser', () => ({ |
39 | | - useCurrentUser: () => ({ isLoggedIn: { value: false } }) |
| 39 | + useCurrentUser: () => ({ |
| 40 | + isLoggedIn: { value: false }, |
| 41 | + userEmail: { value: undefined } |
| 42 | + }) |
| 43 | +})) |
| 44 | + |
| 45 | +const openFeedbackDialog = vi.hoisted(() => vi.fn()) |
| 46 | +vi.mock('@/platform/support/feedbackDialog', () => ({ |
| 47 | + openFeedbackDialog |
40 | 48 | })) |
41 | 49 |
|
42 | 50 | vi.mock('@/composables/useFeatureFlags', () => ({ |
@@ -132,44 +140,28 @@ function renderComponent() { |
132 | 140 | } |
133 | 141 |
|
134 | 142 | describe('WorkflowTabs feedback button', () => { |
135 | | - let openSpy: ReturnType<typeof vi.spyOn> |
136 | | - |
137 | 143 | beforeEach(() => { |
138 | 144 | distribution.isCloud = false |
139 | 145 | distribution.isDesktop = false |
140 | 146 | distribution.isNightly = false |
141 | 147 | tabBarLayout.value = 'Default' |
142 | | - openSpy = vi.spyOn(window, 'open').mockReturnValue(null) |
143 | | - }) |
144 | | - |
145 | | - afterEach(() => { |
146 | | - openSpy.mockRestore() |
| 148 | + openFeedbackDialog.mockReset() |
147 | 149 | }) |
148 | 150 |
|
149 | | - it('opens the Typeform survey tagged with topbar source on Cloud', async () => { |
| 151 | + it('opens the feedback dialog tagged with topbar source when clicked', async () => { |
150 | 152 | distribution.isCloud = true |
151 | 153 | const { user } = renderComponent() |
152 | 154 |
|
153 | 155 | await user.click(screen.getByRole('button', { name: 'Feedback' })) |
154 | 156 |
|
155 | | - expect(openSpy).toHaveBeenCalledWith( |
156 | | - 'https://form.typeform.com/to/q7azbWPi#distribution=ccloud&source=topbar', |
157 | | - '_blank', |
158 | | - 'noopener,noreferrer' |
159 | | - ) |
| 157 | + expect(openFeedbackDialog).toHaveBeenCalledWith('topbar') |
160 | 158 | }) |
161 | 159 |
|
162 | | - it('opens the Typeform survey tagged with topbar source on Nightly', async () => { |
| 160 | + it('renders the feedback button on Nightly', () => { |
163 | 161 | distribution.isNightly = true |
164 | | - const { user } = renderComponent() |
165 | | - |
166 | | - await user.click(screen.getByRole('button', { name: 'Feedback' })) |
| 162 | + renderComponent() |
167 | 163 |
|
168 | | - expect(openSpy).toHaveBeenCalledWith( |
169 | | - 'https://form.typeform.com/to/q7azbWPi#distribution=oss-nightly&source=topbar', |
170 | | - '_blank', |
171 | | - 'noopener,noreferrer' |
172 | | - ) |
| 164 | + expect(screen.getByRole('button', { name: 'Feedback' })).toBeInTheDocument() |
173 | 165 | }) |
174 | 166 |
|
175 | 167 | it('does not render the feedback button on non-Cloud/non-Nightly builds', () => { |
|
0 commit comments