Merge pull request #655 from mathuo/654-resize

bug: fix layout force flag
This commit is contained in:
mathuo 2024-07-17 22:33:50 +01:00 committed by GitHub
commit 0211148b66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 1 deletions

View File

@ -66,6 +66,8 @@ class TestPanel implements IGridPanelView {
} }
class ClassUnderTest extends BaseGrid<TestPanel> { class ClassUnderTest extends BaseGrid<TestPanel> {
readonly gridview = this.gridview;
constructor(options: BaseGridOptions) { constructor(options: BaseGridOptions) {
super(options); super(options);
} }
@ -103,6 +105,31 @@ class ClassUnderTest extends BaseGrid<TestPanel> {
} }
describe('baseComponentGridview', () => { describe('baseComponentGridview', () => {
test('that .layout(...) force flag works', () => {
const cut = new ClassUnderTest({
parentElement: document.createElement('div'),
orientation: Orientation.HORIZONTAL,
proportionalLayout: true,
});
const spy = jest.spyOn(cut.gridview, 'layout');
cut.layout(100, 100);
expect(spy).toHaveBeenCalledTimes(1);
cut.layout(100, 100, false);
expect(spy).toHaveBeenCalledTimes(1);
cut.layout(100, 100, true);
expect(spy).toHaveBeenCalledTimes(2);
cut.layout(150, 150, false);
expect(spy).toHaveBeenCalledTimes(3);
cut.layout(150, 150, true);
expect(spy).toHaveBeenCalledTimes(4);
});
test('can add group', () => { test('can add group', () => {
const cut = new ClassUnderTest({ const cut = new ClassUnderTest({
parentElement: document.createElement('div'), parentElement: document.createElement('div'),

View File

@ -323,7 +323,7 @@ export abstract class BaseGrid<T extends IGridPanelView>
public layout(width: number, height: number, forceResize?: boolean): void { public layout(width: number, height: number, forceResize?: boolean): void {
const different = const different =
forceResize ?? (width !== this.width || height !== this.height); forceResize || width !== this.width || height !== this.height;
if (!different) { if (!different) {
return; return;