Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/app-layout/__tests__/main.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import * as React from 'react';
import { useLayoutEffect } from 'react';
import { waitFor } from '@testing-library/react';

import '../../__a11y__/to-validate-a11y';
Expand All @@ -11,6 +12,22 @@ import { describeEachAppLayout, renderComponent, testDrawer } from './utils';
import mobileStyles from '../../../lib/components/app-layout/mobile-toolbar/styles.css.js';
import sharedStyles from '../../../lib/components/app-layout/styles.css.js';

jest.mock('@cloudscape-design/component-toolkit/internal', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit/internal'),
useResizeObserver: (getElement: any, onObserve: any) => {
useLayoutEffect(() => {
if (typeof getElement === 'function') {
const element = getElement();
if (element) {
// Extract height from inline styles for JSDOM compatibility
const height = parseInt(element.style.height) || 0;
onObserve({ borderBoxHeight: height });
}
}
}, [getElement, onObserve]);
},
}));

test('does not render mobile mode by default', () => {
const { wrapper } = renderComponent(<AppLayout />);
expect(wrapper.findByClassName(mobileStyles['mobile-bar'])).toBeFalsy();
Expand Down
8 changes: 4 additions & 4 deletions src/table/__integ__/resizable-columns-misc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ test(
await page.installObserver(wrapper.find('table').toSelector());
await page.click('#shrink-container');
await page.waitForJsTimers();
// expected 1 observation after creating observer and 1 caused by container shrink
await expect(page.getObservations()).resolves.toBe(2);
// check to ensure that we haven't triggered an infinite resize loop
await expect(page.getObservations()).resolves.toBeLessThanOrEqual(3);
await page.waitForJsTimers();
// ensure there are no more observations added after the expected 2
await expect(page.getObservations()).resolves.toBe(2);
// check again to ensure that we haven't triggered an infinite resize loop
await expect(page.getObservations()).resolves.toBeLessThanOrEqual(3);
})
);

Expand Down
Loading