-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pixel to percentage conversion methods better handle negative group s…
…izes
- Loading branch information
Showing
5 changed files
with
170 additions
and
9 deletions.
There are no files selected for viewing
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
47 changes: 47 additions & 0 deletions
47
packages/react-resizable-panels/src/utils/convertPixelConstraintsToPercentages.test.ts
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,47 @@ | ||
import { convertPixelConstraintsToPercentages } from "./convertPixelConstraintsToPercentages"; | ||
|
||
describe("convertPixelConstraintsToPercentages", () => { | ||
it("should respect percentage panel constraints if group size is negative", () => { | ||
jest.spyOn(console, "warn").mockImplementation(() => {}); | ||
|
||
expect( | ||
convertPixelConstraintsToPercentages( | ||
{ | ||
minSizePercentage: 25, | ||
defaultSizePercentage: 50, | ||
maxSizePercentage: 75, | ||
}, | ||
-100 | ||
) | ||
).toEqual({ | ||
collapsedSizePercentage: 0, | ||
defaultSizePercentage: 50, | ||
maxSizePercentage: 75, | ||
minSizePercentage: 25, | ||
}); | ||
|
||
expect(console.warn).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
// Edge case test (issues/206) | ||
it("should ignore pixel panel constraints if group size is negative", () => { | ||
jest.spyOn(console, "warn").mockImplementation(() => {}); | ||
|
||
expect( | ||
convertPixelConstraintsToPercentages( | ||
{ | ||
minSizePixels: 25, | ||
maxSizePixels: 75, | ||
}, | ||
-100 | ||
) | ||
).toEqual({ | ||
collapsedSizePercentage: 0, | ||
defaultSizePercentage: undefined, | ||
maxSizePercentage: 0, | ||
minSizePercentage: 0, | ||
}); | ||
|
||
expect(console.warn).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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
45 changes: 45 additions & 0 deletions
45
packages/react-resizable-panels/src/utils/resizePanel.test.ts
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,45 @@ | ||
import { resizePanel } from "./resizePanel"; | ||
|
||
describe("resizePanel", () => { | ||
// Edge case test (issues/206) | ||
fit("should respect percentage panel constraints if group size is negative", () => { | ||
jest.spyOn(console, "warn").mockImplementation(() => {}); | ||
|
||
expect( | ||
resizePanel({ | ||
groupSizePixels: -100, | ||
panelConstraints: [ | ||
{ | ||
minSizePercentage: 25, | ||
maxSizePercentage: 75, | ||
}, | ||
], | ||
panelIndex: 0, | ||
size: 50, | ||
}) | ||
).toBe(50); | ||
|
||
expect(console.warn).toHaveBeenCalledTimes(0); | ||
}); | ||
|
||
// Edge case test (issues/206) | ||
it("should handle pixel panel constraints if group size is negative", () => { | ||
jest.spyOn(console, "warn").mockImplementation(() => {}); | ||
|
||
expect( | ||
resizePanel({ | ||
groupSizePixels: -100, | ||
panelConstraints: [ | ||
{ | ||
minSizePixels: 25, | ||
maxSizePixels: 75, | ||
}, | ||
], | ||
panelIndex: 0, | ||
size: 50, | ||
}) | ||
).toBe(0); | ||
|
||
expect(console.warn).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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