Skip to content

Commit

Permalink
fit tests and optimize code
Browse files Browse the repository at this point in the history
  • Loading branch information
cyclingbyte committed Sep 7, 2024
1 parent 0ac692b commit 3d7acd0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/leaflet-sidepanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,7 @@ class SidePanel extends L.Control {

if (!!this.options.pushControls) {
const map = this._map;
if (!!map) {
const mapContainer =
map instanceof HTMLElement ? map : map.getContainer();
const mapContainer = map instanceof L.Map ? map.getContainer() : map;
const controlsContainer = mapContainer.querySelector(
'.leaflet-control-container'
) as HTMLElement;
Expand All @@ -83,7 +81,6 @@ class SidePanel extends L.Control {
`--panel-width-${this.options.panelPosition}`,
this.options.size!
); // `!` 'cause we have a default value
}
}

if (this.options.hasTabs) {
Expand Down
15 changes: 8 additions & 7 deletions tests/leaflet.sidepanel.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,9 @@ describe('SidePanel', () => {
) as HTMLElement;
expect(
controlsContainer.classList.contains('leaflet-animate-control-container')
).toBe(false);
).toBe(true);

sidePanel.toggle();
expect(
controlsContainer.classList.contains('leaflet-animate-control-container')
).toBe(true);
expect(
controlsContainer.classList.contains(options.panelPosition + '-opened')
).toBe(true);
Expand Down Expand Up @@ -204,10 +201,16 @@ describe('SidePanel', () => {
const controlsContainer = document.querySelector(
'.leaflet-control-container'
) as HTMLElement;
sidePanel.toggle();
expect(
controlsContainer.classList.contains('leaflet-animate-control-container')
).toBe(false);
expect(
controlsContainer.classList.toString().match(/-opened|-closed/g)
).toBeNull();
sidePanel.toggle();
expect(
controlsContainer.classList.toString().match(/-opened|-closed/g)
).toBeNull();
});

it('should warn if position option is set', () => {
Expand Down Expand Up @@ -604,8 +607,6 @@ describe('SidePanel with HTMLElement', () => {
// leaflet expects a map instance but also accepts HTMLElement
.addTo(map);

sidePanel.toggle(); // This will trigger the `pushControls` logic

const controlsContainer = (map as unknown as HTMLElement).querySelector(
'.leaflet-control-container'
) as HTMLElement;
Expand Down

0 comments on commit 3d7acd0

Please sign in to comment.