-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Adds tests and storybook to PopoverSection component (#13438)
* test: Adds storybook to PopoverSection component * test: Adds tests and storybook to PopoverSection component
- Loading branch information
1 parent
f0a9dcc
commit fc36de2
Showing
7 changed files
with
207 additions
and
118 deletions.
There are no files selected for viewing
52 changes: 0 additions & 52 deletions
52
superset-frontend/spec/javascripts/components/PopoverSection_spec.jsx
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
superset-frontend/src/components/PopoverSection/PopoverSection.stories.tsx
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,55 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import PopoverSection from '.'; | ||
|
||
export default { | ||
title: 'PopoverSection', | ||
}; | ||
|
||
export const InteractivePopoverSection = (args: any) => ( | ||
<PopoverSection {...args}> | ||
<div | ||
css={{ | ||
display: 'flex', | ||
justifyContent: 'center', | ||
border: '1px solid', | ||
alignItems: 'center', | ||
width: 100, | ||
height: 100, | ||
}} | ||
> | ||
Content | ||
</div> | ||
</PopoverSection> | ||
); | ||
|
||
InteractivePopoverSection.args = { | ||
title: 'Title', | ||
isSelected: true, | ||
info: 'Some description about the content', | ||
}; | ||
|
||
InteractivePopoverSection.story = { | ||
parameters: { | ||
knobs: { | ||
disable: true, | ||
}, | ||
}, | ||
}; |
62 changes: 62 additions & 0 deletions
62
superset-frontend/src/components/PopoverSection/PopoverSection.test.tsx
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,62 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React from 'react'; | ||
import { render, screen } from 'spec/helpers/testing-library'; | ||
import userEvent from '@testing-library/user-event'; | ||
import PopoverSection from 'src/components/PopoverSection'; | ||
|
||
test('renders with default props', () => { | ||
render( | ||
<PopoverSection title="Title"> | ||
<div role="form" /> | ||
</PopoverSection>, | ||
); | ||
expect(screen.getByRole('form')).toBeInTheDocument(); | ||
expect(screen.getAllByRole('img').length).toBe(1); | ||
}); | ||
|
||
test('renders tooltip icon', () => { | ||
render( | ||
<PopoverSection title="Title" info="Tooltip"> | ||
<div role="form" /> | ||
</PopoverSection>, | ||
); | ||
expect(screen.getAllByRole('img').length).toBe(2); | ||
}); | ||
|
||
test('renders a tooltip when hovered', async () => { | ||
render( | ||
<PopoverSection title="Title" info="Tooltip"> | ||
<div role="form" /> | ||
</PopoverSection>, | ||
); | ||
userEvent.hover(screen.getAllByRole('img')[0]); | ||
expect(await screen.findByRole('tooltip')).toBeInTheDocument(); | ||
}); | ||
|
||
test('calls onSelect when clicked', () => { | ||
const onSelect = jest.fn(); | ||
render( | ||
<PopoverSection title="Title" onSelect={onSelect}> | ||
<div role="form" /> | ||
</PopoverSection>, | ||
); | ||
userEvent.click(screen.getByRole('img')); | ||
expect(onSelect).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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
import React, { MouseEventHandler, ReactNode } from 'react'; | ||
import { useTheme } from '@superset-ui/core'; | ||
import { Tooltip } from 'src/common/components/Tooltip'; | ||
import Icon from 'src/components/Icon'; | ||
|
||
export interface PopoverSectionProps { | ||
title: string; | ||
isSelected?: boolean; | ||
onSelect?: MouseEventHandler<HTMLDivElement>; | ||
info?: string; | ||
children?: ReactNode; | ||
} | ||
|
||
export default function PopoverSection({ | ||
title, | ||
isSelected, | ||
children, | ||
onSelect, | ||
info, | ||
}: PopoverSectionProps) { | ||
const theme = useTheme(); | ||
return ( | ||
<div | ||
css={{ | ||
paddingBottom: theme.gridUnit * 2, | ||
opacity: isSelected ? 1 : theme.opacity.mediumHeavy, | ||
}} | ||
> | ||
<div | ||
role="button" | ||
tabIndex={0} | ||
onClick={onSelect} | ||
css={{ | ||
display: 'flex', | ||
alignItems: 'center', | ||
cursor: onSelect ? 'pointer' : 'default', | ||
}} | ||
> | ||
<strong data-test="popover-title">{title}</strong> | ||
{info && ( | ||
<Tooltip title={info} css={{ marginLeft: theme.gridUnit }}> | ||
<Icon | ||
role="img" | ||
name="info-solid" | ||
width={14} | ||
height={14} | ||
color={theme.colors.grayscale.light1} | ||
/> | ||
</Tooltip> | ||
)} | ||
<Icon | ||
role="img" | ||
name="check" | ||
color={ | ||
isSelected ? theme.colors.primary.base : theme.colors.grayscale.base | ||
} | ||
/> | ||
</div> | ||
<div | ||
css={{ | ||
marginLeft: theme.gridUnit, | ||
marginTop: theme.gridUnit, | ||
}} | ||
> | ||
{children} | ||
</div> | ||
</div> | ||
); | ||
} |
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