Skip to content

Commit

Permalink
feat: data-testids
Browse files Browse the repository at this point in the history
  • Loading branch information
atanasster committed Jul 10, 2020
1 parent f903953 commit 07b9f64
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const ComponentsBlockContainer: FC<ComponentsBlockContainerProps> = ({
of,
children,
visibility,
'data-testid': dataTestid,
...rest
}) => {
const [title, setTitle] = React.useState<string | undefined>();
Expand Down Expand Up @@ -79,7 +80,12 @@ export const ComponentsBlockContainer: FC<ComponentsBlockContainerProps> = ({
);
// console.log(child);
return (
<BlockContainer title={title} collapsible={collapsible} id={id}>
<BlockContainer
data-testid={dataTestid}
title={title}
collapsible={collapsible}
id={id}
>
{block}
</BlockContainer>
);
Expand Down
2 changes: 2 additions & 0 deletions ui/blocks/src/BlockContainer/story/StoryBlockContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export const StoryBlockContainer: FC<StoryBlockContainerAllProps> = ({
children,
useStoryDescription,
description: userDescription,
'data-testid': dataTestid,
...rest
}) => {
const context = useStoryContext({
Expand All @@ -46,6 +47,7 @@ export const StoryBlockContainer: FC<StoryBlockContainerAllProps> = ({
userDescription || (useStoryDescription ? story?.description : undefined);
return block ? (
<BlockContainer
data-testid={dataTestid}
title={title}
collapsible={collapsible}
id={userTitle === CURRENT_STORY && story ? story.id : undefined}
Expand Down
4 changes: 3 additions & 1 deletion ui/blocks/src/ComponentDeps/Dependencies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,5 +117,7 @@ export const Dependencies: FC<DependenciesProps> = ({ dependencies }) => {
return null;
}

return <Table data={dependencies} columns={columns} />;
return (
<Table data-testid="dependencies" data={dependencies} columns={columns} />
);
};
11 changes: 6 additions & 5 deletions ui/blocks/src/ComponentSource/ComponentSource.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
ComponentsBlockContainer,
ComponentsBlockContainerProps,
} from '../BlockContainer/components/ComponentsBlockContainer';
import { useCustomProps } from '../context';
import { repositoryActions } from '../utils/repositoryActions';

export type ComponentSourceProps = Omit<
Expand All @@ -13,16 +14,16 @@ export type ComponentSourceProps = Omit<
> &
Omit<SourceProps, 'children'>;

const NAME = 'componentsource';
/**
* Displays import statement for a component as well as the component file source code
* Optionally also displays some repository information from the component's package.json
*/

export const ComponentSource: FC<ComponentSourceProps> = ({
actions,
...rest
}) => {
export const ComponentSource: FC<ComponentSourceProps> = props => {
const [showFileSource, setShowFileSource] = React.useState<boolean>(false);
const custom = useCustomProps<ComponentSourceProps>(NAME, props);
const { actions, ...rest } = custom;
return (
<ComponentsBlockContainer visibility="info" {...rest}>
{(component, props, sourceProps) => {
Expand Down Expand Up @@ -61,7 +62,7 @@ export const ComponentSource: FC<ComponentSourceProps> = ({
allActions.push.apply(allActions, actions);
}
return (
<Source {...sourceProps} actions={allActions}>
<Source data-testid={NAME} {...sourceProps} actions={allActions}>
{showFileSource ? component?.source ?? '' : source}
</Source>
);
Expand Down
32 changes: 18 additions & 14 deletions ui/blocks/src/Playground/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
useTheme,
ActionItems,
} from '@component-controls/components';
import { BlockDataContext } from '../context';
import { BlockDataContext, useCustomProps } from '../context';

import {
StoryBlockContainer,
Expand All @@ -34,23 +34,26 @@ export type PlaygroundProps = PlaygroundOwnProps &
StoryBlockContainerProps &
PanelContainerProps;

const NAME = 'playground';

/**
* Component to display a live playground of component examples. Has custom actions for zooming, switch direction, review story source and configuration.
*/
export const Playground: FC<PlaygroundProps> = ({
title,
id,
name,
collapsible,
dark,
actions: userActions = [],
children,
openTab,
visibleTabs = false,
description,
scale: userScale = 1,
}) => {
export const Playground: FC<PlaygroundProps> = ({ children, ...props }) => {
const theme = useTheme();
const custom = useCustomProps<PlaygroundProps>(NAME, props);
const {
title,
id,
name,
collapsible,
dark,
actions: userActions = [],
openTab,
visibleTabs = false,
description,
scale: userScale = 1,
} = custom;

const [scale, setScale] = React.useState(userScale);
const [background, setBackground] = React.useState<BackgroundType>('light');
Expand Down Expand Up @@ -150,6 +153,7 @@ export const Playground: FC<PlaygroundProps> = ({
: [...storyActions, ...userActions];
return (
<StoryBlockContainer
data-testid={NAME}
description={description}
useStoryDescription={true}
name={name}
Expand Down
19 changes: 12 additions & 7 deletions ui/blocks/src/PropsTable/PropsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ComponentsBlockContainer,
ComponentsBlockContainerProps,
} from '../BlockContainer/components/ComponentsBlockContainer';

import { useCustomProps } from '../context';
import { BasePropsTable } from './BasePropsTable';

export interface PropsTableOwnProps {
Expand All @@ -22,16 +22,21 @@ export type PropsTableProps = PropsTableOwnProps &
Omit<ComponentsBlockContainerProps, 'children'> &
Omit<TableProps, 'columns' | 'data'>;

const NAME = 'propstable';

/**
* Displays the component's properties as well as configurable controls to interact with the component.
*/
export const PropsTable: FC<PropsTableProps> = ({
extraColumns = [],
visibility = 'all',
...props
}) => {
export const PropsTable: FC<PropsTableProps> = props => {
const custom = useCustomProps<PropsTableProps>(NAME, props);
const { extraColumns = [], visibility = 'all', ...rest } = custom;

return (
<ComponentsBlockContainer visibility={visibility} {...props}>
<ComponentsBlockContainer
data-testid={NAME}
visibility={visibility}
{...rest}
>
{(component, { story }, tableProps) => (
<BasePropsTable
component={component}
Expand Down
8 changes: 7 additions & 1 deletion ui/components/src/BlockContainer/BlockContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ export interface BlockContainerProps {
* theme-ui styling object for Block Box
*/
sxStyle?: SxStyleProp;

/**
* testing id
*/
'data-testid'?: string;
}

/**
Expand All @@ -46,12 +51,13 @@ export const BlockContainer: FC<BlockContainerProps> = ({
description,
collapsible = true,
sxStyle,
...rest
}) => {
const [isOpen, setIsOpen] = React.useState(true);
const blockId = id !== '.' ? id : undefined || title;

return (
<Box variant="blockcontainer.container" sx={sxStyle}>
<Box variant="blockcontainer.container" sx={sxStyle} {...rest}>
{(blockId || title || collapsible) && (
<LinkHeading
as={collapsible ? 'h3' : 'h4'}
Expand Down
1 change: 0 additions & 1 deletion ui/components/src/ThemeContext/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export type ControlsTheme = {
pagecontainer: ThemeUIStyleObject;
propstable: Record<string, ThemeUIStyleObject>;
story: Record<string, ThemeUIStyleObject>;
renderer: Record<string, ThemeUIStyleObject>;
colormode: Record<string, ThemeUIStyleObject>;
header: ThemeUIStyleObject;
navmenu: Record<string, ThemeUIStyleObject>;
Expand Down

0 comments on commit 07b9f64

Please sign in to comment.