0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-30 19:41:46 +01:00
posthog/cypress/support/helpers.js
Eric Duong 66641546d7
Trend component test (#3278)
* temp changes

* more tests

* initial trend tests

* merge master

* remove creepover

* remove stubs

* remove unnecessary check

* remove flaky test

* change fixture

* remove console

* focus tests

* update names

* make test more specific

* remove unecessary check

* fix insights file

* checkout insight file
2021-02-17 13:50:41 +02:00

52 lines
1.3 KiB
JavaScript

import React from 'react'
import { mount } from '@cypress/react'
import { Provider } from 'react-redux'
import { getContext, useValues } from 'kea'
import { initKea } from '~/initKea'
import { GlobalStyles } from '~/GlobalStyles'
import { userLogic } from 'scenes/userLogic'
import posthog from 'posthog-js'
import { toParams } from '~/lib/utils'
export const mountPage = (component) => {
initKea()
return mount(
<Provider store={getContext().store}>
<GlobalStyles />
<WaitUntilUserMounted>{component}</WaitUntilUserMounted>
</Provider>
)
}
function WaitUntilUserMounted({ children }) {
const { user } = useValues(userLogic)
return user ? children : null
}
export const setLocation = (path, params = null) => {
let qs = ''
if (params) {
qs = '?' + toParams(params)
}
window.history.replaceState(null, '', path + qs)
}
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 || [])
}
}