Skip to content

Commit

Permalink
[FIX] viewport: warning message on resized viewport size
Browse files Browse the repository at this point in the history
Fix warning not closing issue caused by changing the value of
DEFAULT_SHEETVIEW_SIZE to 0 from 1000 in a previous PR #2188. The problem
arose due to xRatio and yRatio becoming NaN and Infinity prior to mounting.

To resolve this issue, Added an if condition that returns the function if either
xRatio or yRatio is Infinity.

Task-3318806

closes #2504

X-original-commit: 254ac6c
Signed-off-by: Lucas Lefèvre (lul) <lul@odoo.com>
  • Loading branch information
dhrp-odoo authored and LucasLefevre committed May 23, 2023
1 parent 3169b5c commit 3632c62
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/components/spreadsheet/spreadsheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,12 @@ export class Spreadsheet extends Component<SpreadsheetProps, SpreadsheetChildEnv
const { xRatio, yRatio } = this.env.model.getters.getFrozenSheetViewRatio(
this.env.model.getters.getActiveSheetId()
);

if (!isFinite(xRatio) || !isFinite(yRatio)) {
// before mounting, the ratios can be NaN or Infinity if the viewport size is 0
return;
}

if (yRatio > MAXIMAL_FREEZABLE_RATIO || xRatio > MAXIMAL_FREEZABLE_RATIO) {
if (this.isViewportTooSmall) {
return;
Expand Down
16 changes: 15 additions & 1 deletion tests/components/spreadsheet.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Model } from "../../src";
import { Model, setDefaultSheetViewSize } from "../../src";
import { OPEN_CF_SIDEPANEL_ACTION } from "../../src/actions/menu_items_actions";
import { Spreadsheet } from "../../src/components";
import { getDefaultSheetViewSize } from "../../src/constants";
import { functionRegistry } from "../../src/functions";
import { toZone } from "../../src/helpers";
import { SpreadsheetChildEnv } from "../../src/types";
Expand Down Expand Up @@ -256,6 +257,19 @@ test("Spreadsheet detects frozen panes that exceed the limit size at start", asy
expect(notifyUser).toHaveBeenCalled();
});

test("Warns user when viewport is too small for frozen panes but stops warning after resizing/Unmounted", async () => {
const originalViewSize = getDefaultSheetViewSize();

// Setting the sheet viewport size to 0 to represent the "real life" scenario where the default size is 0
setDefaultSheetViewSize(0);
const notifyUser = jest.fn();
const model = new Model({ sheets: [{ panes: { xSplit: 0, ySplit: 20 } }] });
({ parent, fixture } = await mountSpreadsheet({ model }, { notifyUser }));
expect(notifyUser).toHaveBeenCalledTimes(0);

setDefaultSheetViewSize(originalViewSize);
});

test("Warn user only once when the viewport is too small for its frozen panes", async () => {
const notifyUser = jest.fn();
({ parent, model, fixture } = await mountSpreadsheet(undefined, { notifyUser }));
Expand Down
2 changes: 1 addition & 1 deletion tests/setup/resize_observer.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class MockResizeObserver {
observe() {
//@ts-ignore
global.resizers.add(this);
this.cb();
Promise.resolve().then(() => this.cb());
}

unobserve() {
Expand Down

0 comments on commit 3632c62

Please sign in to comment.