Skip to content

Commit

Permalink
Check if element clicked is link to skip the toggle of the section
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephanie Roy committed Oct 19, 2022
1 parent eaf22ce commit a981f3f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
26 changes: 26 additions & 0 deletions webview/src/plots/components/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,32 @@ describe('App', () => {
})
})

it('should not toggle the checkpoint plots section if a link is clicked', () => {
renderAppWithOptionalData({
checkpoint: checkpointPlotsFixture
})

const checkpointsTooltipToggle = screen.getAllByTestId(
'info-tooltip-toggle'
)[2]
fireEvent.mouseEnter(checkpointsTooltipToggle, {
bubbles: true,
cancelable: true
})

const tooltip = screen.getByTestId('tooltip-checkpoint-plots')
const tooltipLink = within(tooltip).getByRole('link')
fireEvent.click(tooltipLink, {
bubbles: true,
cancelable: true
})

expect(mockPostMessage).not.toHaveBeenCalledWith({
payload: { [Section.CHECKPOINT_PLOTS]: true },
type: MessageFromWebviewType.TOGGLE_PLOTS_SECTION
})
})

it('should not toggle the checkpoint plots section when its header is clicked and the content of its tooltip is selected', async () => {
renderAppWithOptionalData({
checkpoint: checkpointPlotsFixture
Expand Down
6 changes: 5 additions & 1 deletion webview/src/plots/components/PlotsContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
Lines
} from '../../shared/components/icons'
import { isSelecting } from '../../util/strings'
import { EventTargetWithNodeName } from '../../util/objects'

export interface CommonPlotsContainerProps {
onResize: (size: PlotSize) => void
Expand Down Expand Up @@ -139,7 +140,10 @@ export const PlotsContainer: React.FC<PlotsContainerProps> = ({

const toggleSection = (e: MouseEvent) => {
e.preventDefault()
if (!isSelecting([title, SectionDescription[sectionKey].props.children])) {
if (
!isSelecting([title, SectionDescription[sectionKey].props.children]) &&
!['A', 'BUTTON'].includes((e.target as EventTargetWithNodeName).nodeName)
) {
sendMessage({
payload: {
[sectionKey]: !sectionCollapsed
Expand Down
4 changes: 4 additions & 0 deletions webview/src/util/objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export type Obj = { [key: string]: Any }

export const keepReferenceIfEqual = (old: BaseType, recent: BaseType) =>
isEqual(old, recent) ? old : recent

export interface EventTargetWithNodeName extends EventTarget {
nodeName: string
}

0 comments on commit a981f3f

Please sign in to comment.