forked from premieroctet/openchakra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix warnings * Improve stability * WIP tests
- Loading branch information
Showing
25 changed files
with
371 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React from 'react' | ||
import { render } from '@testing-library/react' | ||
import { init } from '@rematch/core' | ||
import { Provider } from 'react-redux' | ||
import { DndProvider } from 'react-dnd' | ||
import Backend from 'react-dnd-html5-backend' | ||
import { ThemeProvider, theme } from '@chakra-ui/core' | ||
|
||
import ComponentPreview from './ComponentPreview' | ||
import { storeConfig } from '../../core/store' | ||
|
||
function renderWithRedux( | ||
components: React.ReactNode, | ||
{ | ||
// @ts-ignore | ||
initialState, | ||
// @ts-ignore | ||
store = init(storeConfig), | ||
} = {}, | ||
) { | ||
return { | ||
...render( | ||
<ThemeProvider theme={theme}> | ||
<DndProvider backend={Backend}> | ||
<Provider store={store}>{components}</Provider> | ||
</DndProvider> | ||
</ThemeProvider>, | ||
), | ||
// adding `store` to the returned utilities to allow us | ||
// to reference it in our tests (just try to avoid using | ||
// this to test implementation details). | ||
store, | ||
} | ||
} | ||
|
||
const componentsToTest = [ | ||
'Badge', | ||
'Button', | ||
'Icon', | ||
'IconButton', | ||
'Image', | ||
'Text', | ||
'Progress', | ||
'Link', | ||
'Spinner', | ||
'CloseButton', | ||
'Checkbox', | ||
'Divider', | ||
'Code', | ||
'Textarea', | ||
'CircularProgress', | ||
'Heading', | ||
'Tag', | ||
'Switch', | ||
'FormLabel', | ||
'FormHelperText', | ||
'FormErrorMessage', | ||
'TabPanel', | ||
// 'Tab', | ||
'Input', | ||
'Radio', | ||
'ListItem', | ||
'ListIcon', | ||
// 'AlertIcon', | ||
// 'AccordionIcon', | ||
'Box', | ||
'SimpleGrid', | ||
'Flex', | ||
// 'AccordionPanel', | ||
// 'AccordionItem', | ||
'FormControl', | ||
// 'Tabs', | ||
// 'TabList', | ||
// 'TabPanels', | ||
'InputLeftElement', | ||
'InputRightElement', | ||
'List', | ||
'Avatar', | ||
'AvatarBadge', | ||
'AvatarGroup', | ||
'Alert', | ||
'AlertTitle', | ||
'AlertDescription', | ||
'Stack', | ||
'Accordion', | ||
// 'AccordionHeader', | ||
'RadioGroup', | ||
'Select', | ||
'InputGroup', | ||
'InputLeftAddon', | ||
'InputRightAddon', | ||
] | ||
|
||
test.each(componentsToTest)('Component Preview for %s', componentName => { | ||
// const spy = jest.spyOn(global.console, 'error') | ||
// @ts-ignore | ||
const store = init(storeConfig) | ||
store.dispatch.components.addComponent({ | ||
parentName: 'root', | ||
type: componentName, | ||
rootParentType: componentName, | ||
testId: 'test', | ||
}) | ||
|
||
// console.log(componentName, store.getState().components.present.components); | ||
// @ts-ignore | ||
renderWithRedux(<ComponentPreview componentName="test" />, { store }) | ||
// expect(spy).not.toHaveBeenCalled(); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React, { FunctionComponent, ComponentClass } from 'react' | ||
import { useInteractive } from '../../hooks/useInteractive' | ||
import { Box } from '@chakra-ui/core' | ||
|
||
const WithRefSimplePreviewContainer: React.FC<{ | ||
component: IComponent | ||
type: string | FunctionComponent<any> | ComponentClass<any, any> | ||
}> = ({ component, type }) => { | ||
const { props, ref } = useInteractive(component) | ||
let boxProps: any = {} | ||
|
||
return ( | ||
<Box {...boxProps} ref={ref}> | ||
{React.createElement(type, { ...props })} | ||
</Box> | ||
) | ||
} | ||
|
||
export default WithRefSimplePreviewContainer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,24 @@ | ||
import React from "react"; | ||
import { Box } from "@chakra-ui/core"; | ||
import ComponentPreview from "../ComponentPreview"; | ||
import { useDropComponent } from "../../../hooks/useDropComponent"; | ||
import { useInteractive } from "../../../hooks/useInteractive"; | ||
import React from 'react' | ||
import { Box } from '@chakra-ui/core' | ||
import ComponentPreview from '../ComponentPreview' | ||
import { useDropComponent } from '../../../hooks/useDropComponent' | ||
import { useInteractive } from '../../../hooks/useInteractive' | ||
|
||
const BoxPreview: React.FC<{ component: IComponent }> = ({ component }) => { | ||
const { drop, isOver } = useDropComponent(component.id); | ||
const { props, ref } = useInteractive(component, true); | ||
const { drop, isOver } = useDropComponent(component.id) | ||
const { props, ref } = useInteractive(component, true) | ||
|
||
if (isOver) { | ||
props.bg = "teal.50"; | ||
props.bg = 'teal.50' | ||
} | ||
|
||
return ( | ||
<Box pos="relative" ref={drop(ref)} {...props}> | ||
{component.children.map((key: string) => ( | ||
<ComponentPreview componentName={key} /> | ||
<ComponentPreview key={key} componentName={key} /> | ||
))} | ||
</Box> | ||
); | ||
}; | ||
) | ||
} | ||
|
||
export default BoxPreview; | ||
export default BoxPreview |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import React from "react"; | ||
import { RadioGroup, Box } from "@chakra-ui/core"; | ||
import { useInteractive } from "../../../hooks/useInteractive"; | ||
import { useDropComponent } from "../../../hooks/useDropComponent"; | ||
import ComponentPreview from "../ComponentPreview"; | ||
import React from 'react' | ||
import { RadioGroup, Box } from '@chakra-ui/core' | ||
import { useInteractive } from '../../../hooks/useInteractive' | ||
import { useDropComponent } from '../../../hooks/useDropComponent' | ||
import ComponentPreview from '../ComponentPreview' | ||
|
||
export const RadioGroupPreview: React.FC<{ component: IComponent }> = ({ | ||
component | ||
component, | ||
}) => { | ||
const { drop, isOver } = useDropComponent(component.id); | ||
const { props, ref } = useInteractive(component, true); | ||
const { drop, isOver } = useDropComponent(component.id) | ||
const { props, ref } = useInteractive(component, true) | ||
|
||
const propsBox: any = {}; | ||
const propsBox: any = {} | ||
|
||
if (isOver) { | ||
props.bg = "teal.50"; | ||
props.bg = 'teal.50' | ||
} | ||
|
||
return ( | ||
<Box {...propsBox} ref={drop(ref)}> | ||
<RadioGroup {...props}> | ||
{component.children.map((key: string) => ( | ||
<ComponentPreview componentName={key} /> | ||
<ComponentPreview key={key} componentName={key} /> | ||
))} | ||
</RadioGroup> | ||
</Box> | ||
); | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.