fix: partner stack not recorded when not login (#34062)

This commit is contained in:
Joel
2026-03-25 16:16:52 +08:00
committed by GitHub
parent a8e1ff85db
commit f87dafa229
5 changed files with 69 additions and 10 deletions

View File

@ -0,0 +1,45 @@
import { render } from '@testing-library/react'
import PartnerStackCookieRecorder from '../cookie-recorder'
let isCloudEdition = true
const saveOrUpdate = vi.fn()
vi.mock('@/config', () => ({
get IS_CLOUD_EDITION() {
return isCloudEdition
},
}))
vi.mock('../use-ps-info', () => ({
default: () => ({
saveOrUpdate,
}),
}))
describe('PartnerStackCookieRecorder', () => {
beforeEach(() => {
vi.clearAllMocks()
isCloudEdition = true
})
it('should call saveOrUpdate once on mount when running in cloud edition', () => {
render(<PartnerStackCookieRecorder />)
expect(saveOrUpdate).toHaveBeenCalledTimes(1)
})
it('should not call saveOrUpdate when not running in cloud edition', () => {
isCloudEdition = false
render(<PartnerStackCookieRecorder />)
expect(saveOrUpdate).not.toHaveBeenCalled()
})
it('should render null', () => {
const { container } = render(<PartnerStackCookieRecorder />)
expect(container.innerHTML).toBe('')
})
})