-
-
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.
computePanelFlexBoxStyle uses toPrecision for default sizes as well (…
…to avoid floating point precision errors)
- Loading branch information
Showing
2 changed files
with
125 additions
and
1 deletion.
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
packages/react-resizable-panels/src/utils/computePanelFlexBoxStyle.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,123 @@ | ||
import { PanelConstraints, PanelData } from "../Panel"; | ||
import { computePanelFlexBoxStyle } from "./computePanelFlexBoxStyle"; | ||
|
||
describe("computePanelFlexBoxStyle", () => { | ||
function createPanelData(constraints: PanelConstraints = {}): PanelData { | ||
return { | ||
callbacks: {}, | ||
constraints, | ||
id: "fake", | ||
idIsFromProps: false, | ||
order: undefined, | ||
}; | ||
} | ||
|
||
it("should observe a panel's default size if group layout has not yet been computed", () => { | ||
expect( | ||
computePanelFlexBoxStyle({ | ||
defaultSize: 0.1233456789, | ||
dragState: null, | ||
layout: [], | ||
panelData: [ | ||
createPanelData({ | ||
defaultSize: 0.1233456789, | ||
}), | ||
createPanelData(), | ||
], | ||
panelIndex: 0, | ||
precision: 2, | ||
}) | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"flexBasis": 0, | ||
"flexGrow": "0.12", | ||
"flexShrink": 1, | ||
"overflow": "hidden", | ||
"pointerEvents": undefined, | ||
} | ||
`); | ||
}); | ||
|
||
it("should always fill the full width for single-panel groups", () => { | ||
expect( | ||
computePanelFlexBoxStyle({ | ||
defaultSize: undefined, | ||
dragState: null, | ||
layout: [], | ||
panelData: [createPanelData()], | ||
panelIndex: 0, | ||
precision: 2, | ||
}) | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"flexBasis": 0, | ||
"flexGrow": "1", | ||
"flexShrink": 1, | ||
"overflow": "hidden", | ||
"pointerEvents": undefined, | ||
} | ||
`); | ||
}); | ||
|
||
it("should round sizes to avoid floating point precision errors", () => { | ||
const layout = [0.25435, 0.5758, 0.1698]; | ||
const panelData = [createPanelData(), createPanelData(), createPanelData()]; | ||
|
||
expect( | ||
computePanelFlexBoxStyle({ | ||
defaultSize: undefined, | ||
dragState: null, | ||
layout, | ||
panelData, | ||
panelIndex: 0, | ||
precision: 2, | ||
}) | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"flexBasis": 0, | ||
"flexGrow": "0.25", | ||
"flexShrink": 1, | ||
"overflow": "hidden", | ||
"pointerEvents": undefined, | ||
} | ||
`); | ||
|
||
expect( | ||
computePanelFlexBoxStyle({ | ||
defaultSize: undefined, | ||
dragState: null, | ||
layout, | ||
panelData, | ||
panelIndex: 1, | ||
precision: 2, | ||
}) | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"flexBasis": 0, | ||
"flexGrow": "0.58", | ||
"flexShrink": 1, | ||
"overflow": "hidden", | ||
"pointerEvents": undefined, | ||
} | ||
`); | ||
|
||
expect( | ||
computePanelFlexBoxStyle({ | ||
defaultSize: undefined, | ||
dragState: null, | ||
layout, | ||
panelData, | ||
panelIndex: 2, | ||
precision: 2, | ||
}) | ||
).toMatchInlineSnapshot(` | ||
{ | ||
"flexBasis": 0, | ||
"flexGrow": "0.17", | ||
"flexShrink": 1, | ||
"overflow": "hidden", | ||
"pointerEvents": undefined, | ||
} | ||
`); | ||
}); | ||
}); |
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