Ensure FileTreeProvider stubbed props don't change in Cypress tests (#16758)

GitOrigin-RevId: 01c7fefdef8b28af0b52007209785b478e5d8600
This commit is contained in:
Alf Eaton 2024-01-30 15:36:06 +00:00 committed by Copybot
parent 8136036c33
commit 7f9d105d8c

View file

@ -1,17 +1,23 @@
import { FC } from 'react'
import { ComponentProps, FC, useRef } from 'react'
import FileTreeContext from '@/features/file-tree/components/file-tree-context'
export const FileTreeProvider: FC<{
refProviders?: Record<string, boolean>
}> = ({ children, refProviders = {} }) => {
const propsRef =
useRef<Omit<ComponentProps<typeof FileTreeContext>, 'refProviders'>>()
if (propsRef.current === undefined) {
propsRef.current = {
reindexReferences: cy.stub().as('reindexReferences'),
setRefProviderEnabled: cy.stub().as('setRefProviderEnabled'),
setStartedFreeTrial: cy.stub().as('setStartedFreeTrial'),
onSelect: cy.stub(),
}
}
return (
<FileTreeContext
refProviders={refProviders}
reindexReferences={cy.stub().as('reindexReferences')}
setRefProviderEnabled={cy.stub().as('setRefProviderEnabled')}
setStartedFreeTrial={cy.stub().as('setStartedFreeTrial')}
onSelect={() => {}}
>
<FileTreeContext refProviders={refProviders} {...propsRef.current}>
<>{children}</>
</FileTreeContext>
)