2021-02-09 16:28:01 +01:00
|
|
|
import React from 'react'
|
|
|
|
|
|
|
|
import { mount } from '@cypress/react'
|
|
|
|
import { Provider } from 'react-redux'
|
2021-02-11 20:14:28 +01:00
|
|
|
import { getContext, useValues } from 'kea'
|
2021-02-09 16:28:01 +01:00
|
|
|
import { initKea } from '~/initKea'
|
|
|
|
import { GlobalStyles } from '~/GlobalStyles'
|
2021-02-11 20:14:28 +01:00
|
|
|
import { userLogic } from 'scenes/userLogic'
|
2021-02-09 16:28:01 +01:00
|
|
|
import posthog from 'posthog-js'
|
2021-02-17 12:50:41 +01:00
|
|
|
import { toParams } from '~/lib/utils'
|
2021-02-09 16:28:01 +01:00
|
|
|
|
|
|
|
export const mountPage = (component) => {
|
|
|
|
initKea()
|
|
|
|
return mount(
|
|
|
|
<Provider store={getContext().store}>
|
|
|
|
<GlobalStyles />
|
2021-02-11 20:14:28 +01:00
|
|
|
<WaitUntilUserMounted>{component}</WaitUntilUserMounted>
|
2021-02-09 16:28:01 +01:00
|
|
|
</Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-02-11 20:14:28 +01:00
|
|
|
function WaitUntilUserMounted({ children }) {
|
|
|
|
const { user } = useValues(userLogic)
|
|
|
|
|
|
|
|
return user ? children : null
|
|
|
|
}
|
|
|
|
|
2021-02-17 12:50:41 +01:00
|
|
|
export const setLocation = (path, params = null) => {
|
|
|
|
let qs = ''
|
|
|
|
if (params) {
|
|
|
|
qs = '?' + toParams(params)
|
|
|
|
}
|
|
|
|
window.history.replaceState(null, '', path + qs)
|
2021-02-09 16:28:01 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export const getSearchParameters = ({ request }) => {
|
|
|
|
const searchParams = new URL(request.url).searchParams
|
|
|
|
const result = {}
|
|
|
|
for (const [key, value] of searchParams.entries()) {
|
|
|
|
result[key] = value
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
export const mockPosthog = () => {
|
|
|
|
cy.stub(posthog)
|
|
|
|
posthog.people = { set: () => {} }
|
|
|
|
posthog.onFeatureFlags = (callback) => {
|
|
|
|
callback(given.featureFlags || [])
|
|
|
|
}
|
|
|
|
}
|