-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
EDSC-4346: Make the entire map to be visible when I select data #1855
base: main
Are you sure you want to change the base?
Changes from all commits
3c46798
0f02498
09ac0cd
faf53c8
639a3aa
753965a
50d94f5
99ade41
7f26e84
5e30282
b56d286
f53f052
8d7f9a7
c35051f
373e16c
43dec59
254c157
5e64604
eb891e2
61cd282
c79cccc
7f53722
28aa0a7
c9c77f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import React from 'react' | ||
import { render, screen } from '@testing-library/react' | ||
import { | ||
render, | ||
screen, | ||
fireEvent | ||
} from '@testing-library/react' | ||
|
||
import Panels from '../Panels' | ||
import { PanelSection } from '../PanelSection' | ||
|
@@ -468,4 +472,176 @@ describe('Panels component', () => { | |
expect(screen.getByTestId('panels-section')).not.toHaveClass('panels--is-open') | ||
}) | ||
}) | ||
|
||
describe('Panels handle click map offset update', () => { | ||
let mainPanelEl | ||
|
||
beforeEach(() => { | ||
mainPanelEl = document.createElement('div') | ||
mainPanelEl.className = 'project-collections' | ||
Object.defineProperty(mainPanelEl, 'clientWidth', { | ||
configurable: true, | ||
value: 500 | ||
}) | ||
|
||
document.body.appendChild(mainPanelEl) | ||
}) | ||
|
||
Comment on lines
+477
to
+489
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update this to test the way a user would test |
||
afterEach(() => { | ||
document.body.removeChild(mainPanelEl) | ||
}) | ||
|
||
test('clicking handle when panel is open sets map offset correctly (panel closes)', () => { | ||
setup(render, { show: true }) | ||
|
||
const dispatchSpy = jest.spyOn(window, 'dispatchEvent') | ||
|
||
const handle = screen.getByTestId('panels__handle') | ||
fireEvent.click(handle) | ||
|
||
expect(document.documentElement.style.getPropertyValue('--map-offset')).toBe('500px') | ||
expect(dispatchSpy).toHaveBeenCalledWith(expect.any(CustomEvent)) | ||
|
||
dispatchSpy.mockRestore() | ||
}) | ||
|
||
test('clicking handle when panel is closed sets map offset correctly (panel opens)', () => { | ||
setup(render, { show: false }) | ||
|
||
const dispatchSpy = jest.spyOn(window, 'dispatchEvent') | ||
const handle = screen.getByTestId('panels__handle') | ||
fireEvent.click(handle) | ||
|
||
expect(document.documentElement.style.getPropertyValue('--map-offset')).toBe('1100px') | ||
expect(dispatchSpy).toHaveBeenCalledWith(expect.any(CustomEvent)) | ||
|
||
dispatchSpy.mockRestore() | ||
}) | ||
}) | ||
|
||
describe('updatePanelWidth', () => { | ||
let mainPanelEl | ||
let panelsRef | ||
|
||
beforeEach(() => { | ||
// Create and setup the main panel element | ||
mainPanelEl = document.createElement('div') | ||
mainPanelEl.className = 'project-collections' | ||
Object.defineProperty(mainPanelEl, 'clientWidth', { | ||
configurable: true, | ||
value: 500 | ||
}) | ||
|
||
document.body.appendChild(mainPanelEl) | ||
}) | ||
|
||
afterEach(() => { | ||
mainPanelEl?.remove() | ||
}) | ||
|
||
test('correctly updates panel width and map offset', () => { | ||
// Create a ref to capture the Panels component instance | ||
let panelsInstance | ||
const TestWrapper = () => { | ||
panelsRef = (ref) => { | ||
panelsInstance = ref | ||
} | ||
|
||
return ( | ||
<Panels | ||
ref={panelsRef} | ||
show | ||
activePanel="0.0.0" | ||
draggable | ||
> | ||
<PanelSection> | ||
<PanelGroup> | ||
<PanelItem>Content</PanelItem> | ||
</PanelGroup> | ||
</PanelSection> | ||
</Panels> | ||
) | ||
} | ||
|
||
render(<TestWrapper />) | ||
|
||
// Spy on the updateMapOffset method | ||
const dispatchSpy = jest.spyOn(window, 'dispatchEvent') | ||
|
||
// Call updatePanelWidth with a new width | ||
const newWidth = 800 | ||
panelsInstance.updatePanelWidth(newWidth) | ||
|
||
// Check if the panel width was updated correctly | ||
expect(screen.getByTestId('panels-section')).toHaveStyle(`width: ${newWidth}px`) | ||
|
||
// Check if the map offset was calculated and set correctly | ||
const expectedOffset = 500 + newWidth // MainPanelWidth + newWidth | ||
expect(document.documentElement.style.getPropertyValue('--map-offset')) | ||
.toBe(`${expectedOffset}px`) | ||
|
||
// Verify that the custom event was dispatched | ||
expect(dispatchSpy).toHaveBeenCalledWith( | ||
expect.any(CustomEvent) | ||
) | ||
|
||
// Verify the event details | ||
const dispatchedEvent = dispatchSpy.mock.calls[0][0] | ||
expect(dispatchedEvent.type).toBe('mapOffsetChanged') | ||
|
||
dispatchSpy.mockRestore() | ||
}) | ||
|
||
test('handles missing main panel element', () => { | ||
// Create a ref to capture the Panels component instance | ||
let panelsInstance | ||
const TestWrapper = () => { | ||
panelsRef = (ref) => { | ||
panelsInstance = ref | ||
} | ||
|
||
return ( | ||
<Panels | ||
ref={panelsRef} | ||
show | ||
activePanel="0.0.0" | ||
draggable | ||
> | ||
<PanelSection> | ||
<PanelGroup> | ||
<PanelItem>Content</PanelItem> | ||
</PanelGroup> | ||
</PanelSection> | ||
</Panels> | ||
) | ||
} | ||
|
||
render(<TestWrapper />) | ||
|
||
// Remove the main panel element to test the fallback | ||
mainPanelEl?.remove() | ||
|
||
// Spy on the updateMapOffset method | ||
const dispatchSpy = jest.spyOn(window, 'dispatchEvent') | ||
|
||
// Call updatePanelWidth with a new width | ||
const newWidth = 800 | ||
panelsInstance.updatePanelWidth(newWidth) | ||
|
||
// Check if the panel width was updated correctly | ||
expect(screen.getByTestId('panels-section')).toHaveStyle(`width: ${newWidth}px`) | ||
|
||
// Check if the map offset was calculated correctly with 0 for mainPanelWidth | ||
const expectedOffset = newWidth // 0 + newWidth | ||
expect(document.documentElement.style.getPropertyValue('--map-offset')) | ||
.toBe(`${expectedOffset}px`) | ||
|
||
// Verify that the custom event was still dispatched | ||
expect(dispatchSpy).toHaveBeenCalledWith( | ||
expect.any(CustomEvent) | ||
) | ||
|
||
dispatchSpy.mockRestore() | ||
}) | ||
}) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
|
||
.map { | ||
position: absolute; | ||
left: 0; | ||
left: var(--map-offset, 0); | ||
bottom: 0; | ||
top: 0; | ||
right: 0; | ||
width: 100%; | ||
width: calc(100% - var(--map-offset, 0)); | ||
align-items: center; | ||
justify-content: center; | ||
flex-basis: auto; | ||
|
@@ -19,4 +19,4 @@ | |
.is-panels-dragging & { | ||
pointer-events: none; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. newline |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { useLayoutEffect } from 'react' | ||
import { useLayoutEffect, useEffect } from 'react' | ||
import PropTypes from 'prop-types' | ||
import { useMap, useMapEvents } from 'react-leaflet' | ||
|
||
|
@@ -25,6 +25,18 @@ const MapEvents = (props) => { | |
} | ||
}) | ||
|
||
useEffect(() => { | ||
const handleMapOffsetChange = () => { | ||
map.invalidateSize() | ||
} | ||
|
||
window.addEventListener('mapOffsetChanged', handleMapOffsetChange) | ||
|
||
return () => { | ||
window.removeEventListener('mapOffsetChanged', handleMapOffsetChange) | ||
} | ||
}, [map]) | ||
|
||
const handleOverlayChange = (event) => { | ||
Comment on lines
+28
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add comments for why this is needed |
||
const enabled = event.type === 'overlayadd' | ||
switch (event.name) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Try
user
interaction instead offireEvent