Skip to content

feat: Widgetise app layout skeleton #3396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 38 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1c5d6a2
feat: Widgetise app layout skeleton
georgylobko Apr 1, 2025
61aef35
Merge branch 'main' into feat/widgetize-app-layout-skeleton
georgylobko Apr 14, 2025
12dfb0a
chore: Move skeleton elements attributes to a widgetized hook
georgylobko Apr 15, 2025
1b33698
chore: Move skeleton slots to widgets
georgylobko Apr 15, 2025
75cb09e
Merge branch 'main' into feat/widgetize-app-layout-skeleton
georgylobko Apr 15, 2025
282a413
chore: Widgetize all remaining components
georgylobko Apr 15, 2025
e38730e
Merge branch 'main' into feat/widgetize-app-layout-skeleton
georgylobko Apr 16, 2025
a64c3a1
feat: AppLayout state as widget
georgylobko Apr 22, 2025
13f60f0
chore: small fix
georgylobko Apr 22, 2025
c3c8b63
Merge branch 'main' into feat/widgetize-app-layout-skeleton
georgylobko Apr 22, 2025
b0203ed
chore: small fix
georgylobko Apr 22, 2025
d8447e9
Merge remote-tracking branch 'origin/main' into feat/widgetize-app-la…
georgylobko Apr 22, 2025
90d178e
Merge branch 'main' into feat/widgetize-app-layout-skeleton
georgylobko Apr 22, 2025
d1f41c0
chore: Increase package limit size
georgylobko Apr 22, 2025
94ddfd0
Merge remote-tracking branch 'origin/main' into feat/widgetize-app-la…
georgylobko Apr 23, 2025
33e717f
chore: Small refactoring
georgylobko Apr 23, 2025
3beaa8f
chore: Pull react-reverse-portal as src util
georgylobko Apr 23, 2025
262ab1d
Merge branch 'main' into feat/widgetize-app-layout-skeleton
georgylobko Apr 23, 2025
2a4865b
chore: Revert unrelated changes in runtime-drawers.page.tsx
georgylobko Apr 23, 2025
467c88d
fix: SSR tests
georgylobko Apr 23, 2025
a00ad7b
fix: Skeleton part tests
georgylobko Apr 23, 2025
90873fe
feat: Deliver skeleton slots attributes as a widget part
georgylobko Apr 24, 2025
b1b525e
fix: Unit tests
georgylobko Apr 24, 2025
3088384
Merge remote-tracking branch 'origin/main' into feat/widgetize-app-la…
georgylobko Apr 24, 2025
8ef5d18
chore: Update snapshots
georgylobko Apr 24, 2025
cf8254e
chore: Tests for reverse portal
georgylobko Apr 24, 2025
c321d92
chore: Additional tests for reverse portal
georgylobko Apr 25, 2025
5b4e5a4
fix: Integ tests
georgylobko Apr 25, 2025
9431d21
Merge remote-tracking branch 'origin/main' into feat/widgetize-app-la…
georgylobko Apr 25, 2025
c92ba3c
chore: Skip hash for class names in widget contract tests
georgylobko Apr 25, 2025
887e74f
fix: Tests
georgylobko Apr 25, 2025
592817e
chore: Wrap up
georgylobko Apr 25, 2025
2a114b0
Merge branch 'main' into feat/widgetize-app-layout-skeleton
georgylobko Apr 25, 2025
1627182
Merge branch 'main' into feat/widgetize-app-layout-skeleton
georgylobko Apr 28, 2025
2ccd6ed
Merge branch 'main' into feat/widgetize-app-layout-skeleton
georgylobko Apr 29, 2025
89cd1d5
chore: Fallbacks for app layout component when is in loading state (a…
georgylobko Apr 29, 2025
393d2d9
Merge branch 'main' into feat/widgetize-app-layout-skeleton
georgylobko May 2, 2025
19ddb8b
chore: Delay breadcrumbs rendering until app layout state is loaded
georgylobko May 2, 2025
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
3,150 changes: 2,103 additions & 1,047 deletions src/app-layout/__tests__/__snapshots__/widget-contract-split-panel.test.tsx.snap

Large diffs are not rendered by default.

2,371 changes: 60 additions & 2,311 deletions src/app-layout/__tests__/__snapshots__/widget-contract.test.tsx.snap

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions src/app-layout/__tests__/app-layout.ssr.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import AppLayout from '../../../lib/components/app-layout';

import classicStyles from '../../../lib/components/app-layout/styles.selectors.js';
import refreshStyles from '../../../lib/components/app-layout/visual-refresh/styles.selectors.js';
import refreshToolbarStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/skeleton/styles.selectors.js';

const globalWithFlags = globalThis as any;

Expand All @@ -36,11 +35,11 @@ test('should render refresh-toolbar app layout with the widget flag', () => {
globalWithFlags[Symbol.for('awsui-visual-refresh-flag')] = () => true;
globalWithFlags[Symbol.for('awsui-global-flags')] = { appLayoutWidget: true };
const content = renderToStaticMarkup(<AppLayout />);
expect(content).toContain(refreshToolbarStyles.root);
expect(content).toBe('<div></div>');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition has changed because the styles now come from widget API, so they don't work with SSR

});
test('should render refresh-toolbar app layout with the toolbar flag', () => {
globalWithFlags[Symbol.for('awsui-visual-refresh-flag')] = () => true;
globalWithFlags[Symbol.for('awsui-global-flags')] = { appLayoutToolbar: true };
const content = renderToStaticMarkup(<AppLayout />);
expect(content).toContain(refreshToolbarStyles.root);
expect(content).toBe('<div></div>');
});
332 changes: 332 additions & 0 deletions src/app-layout/__tests__/reverse-portal.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,332 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import React, { useState } from 'react';
import { act, fireEvent, render, screen } from '@testing-library/react';

import { createHtmlPortalNode, InPortal, OutPortal } from '../visual-refresh-toolbar/reverse-portal';

describe('Reverse portal', () => {
const TestContent = ({ onClick = () => {} }) => (
<div data-testid="test-content" onClick={onClick}>
Test Content
</div>
);

it('should render content in InPortal and display it in OutPortal', () => {
const portalNode = createHtmlPortalNode({ containerElement: 'section' });

render(
<>
<InPortal node={portalNode}>
<TestContent />
</InPortal>
<OutPortal node={portalNode} />
</>
);

expect(screen.getByTestId('test-content')).toBeInTheDocument();
});

it('should not have multiple OutPortal instances with same node', () => {
const portalNode = createHtmlPortalNode();

render(
<>
<InPortal node={portalNode}>
<TestContent />
</InPortal>
<div data-testid="first-portal">
<OutPortal node={portalNode} />
</div>
<div data-testid="second-portal">
<OutPortal node={portalNode} />
</div>
</>
);

const instances = screen.getAllByText('Test Content');
expect(instances).toHaveLength(1);
});

it('should work with useMemo hook', () => {
const PortalComponent = () => {
const portalNode = React.useMemo(() => createHtmlPortalNode(), []);

return (
<>
<InPortal node={portalNode}>
<TestContent />
</InPortal>
<OutPortal node={portalNode} />
</>
);
};

render(<PortalComponent />);
expect(screen.getByTestId('test-content')).toBeInTheDocument();
});

it('should handle conditional rendering of OutPortal', () => {
const portalNode = createHtmlPortalNode();

const PortalWrapper = ({ showFirst = true }) => (
<>
<InPortal node={portalNode}>
<TestContent />
</InPortal>
{showFirst ? (
<div data-testid="first-container">
<OutPortal node={portalNode} />
</div>
) : (
<div data-testid="second-container">
<OutPortal node={portalNode} />
</div>
)}
</>
);

const { rerender } = render(<PortalWrapper showFirst={true} />);
expect(screen.getByTestId('first-container')).toBeInTheDocument();

rerender(<PortalWrapper showFirst={false} />);
expect(screen.getByTestId('second-container')).toBeInTheDocument();
});

it('should handle click events correctly', () => {
const handleClick = jest.fn();
const portalNode = createHtmlPortalNode();

render(
<div onClick={handleClick}>
<InPortal node={portalNode}>
<TestContent />
</InPortal>
<OutPortal node={portalNode} />
</div>
);

const element = screen.getByTestId('test-content');
fireEvent.click(element);
expect(handleClick).toHaveBeenCalled();
});

it('should handle keyboard events', () => {
const handleKeyDown = jest.fn();
const portalNode = createHtmlPortalNode();

render(
<div onKeyDown={handleKeyDown}>
<InPortal node={portalNode}>
<input data-testid="test-input" />
</InPortal>
<OutPortal node={portalNode} />
</div>
);

const input = screen.getByTestId('test-input');
fireEvent.keyDown(input, { key: 'Enter', code: 'Enter' });
expect(handleKeyDown).toHaveBeenCalled();
});

it('should update portal content when props change', () => {
const portalNode = createHtmlPortalNode();

const PortalContent = ({ text }: { text: string }) => <div data-testid="dynamic-content">{text}</div>;

const { rerender } = render(
<>
<InPortal node={portalNode}>
<PortalContent text="Initial" />
</InPortal>
<OutPortal node={portalNode} />
</>
);

expect(screen.getByText('Initial')).toBeInTheDocument();

rerender(
<>
<InPortal node={portalNode}>
<PortalContent text="Updated" />
</InPortal>
<OutPortal node={portalNode} />
</>
);

expect(screen.getByText('Updated')).toBeInTheDocument();
});

it('should handle missing portal node gracefully', () => {
const consoleError = jest.spyOn(console, 'error').mockImplementation(() => {});

expect(() => {
render(<OutPortal node={undefined as any} />);
}).not.toThrow();

consoleError.mockRestore();
});

it('should handle rapid state updates', () => {
const portalNode = createHtmlPortalNode();

const RapidUpdateComponent = () => {
const [count, setCount] = React.useState(0);

const handleClick = () => {
setCount(c => c + 1);
setCount(c => c + 1);
setCount(c => c + 1);
};

return (
<>
<InPortal node={portalNode}>
<button onClick={handleClick} data-testid="update-button">
Count: {count}
</button>
</InPortal>
<OutPortal node={portalNode} />
</>
);
};

render(<RapidUpdateComponent />);
const button = screen.getByTestId('update-button');

act(() => {
fireEvent.click(button);
});

expect(button.textContent).toBe('Count: 3');
});

it('should clean up properly on unmount', () => {
const portalNode = createHtmlPortalNode();
const { unmount } = render(
<>
<InPortal node={portalNode}>
<TestContent />
</InPortal>
<OutPortal node={portalNode} />
</>
);

unmount();
expect(document.body.innerHTML).not.toContain('test-content');
});

it('should handle unmounting and remounting without errors', () => {
const portalNode = createHtmlPortalNode();

const { unmount, rerender } = render(
<>
<InPortal node={portalNode}>
<TestContent />
</InPortal>
<OutPortal node={portalNode} />
</>
);

unmount();

expect(() => {
rerender(
<>
<InPortal node={portalNode}>
<TestContent />
</InPortal>
<OutPortal node={portalNode} />
</>
);
}).not.toThrow();
});

it('should set multiple attributes on element creation', () => {
const attributes = {
'data-testid': 'test-portal',
'aria-label': 'Test Portal',
class: 'portal-class',
role: 'dialog',
};

const portalNode = createHtmlPortalNode({
attributes,
});

for (const [key, value] of Object.entries(attributes)) {
expect(portalNode.element.getAttribute(key)).toBe(value);
}
});

it('should handle same placeholder mount attempts', () => {
const portalNode = createHtmlPortalNode();
const parent = document.createElement('div');
const placeholder = document.createElement('div');

parent.appendChild(placeholder);
document.body.appendChild(parent);

portalNode.mount(parent, placeholder);
const firstMountParent = portalNode.element.parentNode;

portalNode.mount(parent, placeholder);
const secondMountParent = portalNode.element.parentNode;

expect(firstMountParent).toBe(secondMountParent);

document.body.removeChild(parent);
});

it('should handle undefined node', () => {
expect(() => {
render(
<InPortal node={undefined as any}>
<div>Content</div>
</InPortal>
);
}).not.toThrow();
});

it('should handle non-React children correctly', () => {
const portalNode = createHtmlPortalNode();

const { container } = render(
<>
<InPortal node={portalNode}>123</InPortal>
<OutPortal node={portalNode} />
</>
);

expect(container.textContent).toContain('123');
});

it('should maintain props when switching portal nodes', () => {
const TestComponent = ({ count }: { count: number }) => <div>Count: {count}</div>;

const WrapperComponent = () => {
const [isNodesSwapped, setIsNodesSwapped] = useState(false);
const firstNode = createHtmlPortalNode();
const secondNode = createHtmlPortalNode();
return (
<>
<button data-testid="button" onClick={() => setIsNodesSwapped(true)}>
swap
</button>
<InPortal node={isNodesSwapped ? secondNode : firstNode}>
<TestComponent count={1} />
</InPortal>
<div id="portal-target">
<OutPortal node={isNodesSwapped ? secondNode : firstNode} />
</div>
</>
);
};

const { container } = render(<WrapperComponent />);

expect(container.textContent).toContain('Count: 1');
screen.getByTestId('button').click();
expect(container.textContent).toContain('Count: 1');
});
});
5 changes: 1 addition & 4 deletions src/app-layout/__tests__/skeleton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React from 'react';

import AppLayout from '../../../lib/components/app-layout';
import BreadcrumbGroup from '../../../lib/components/breadcrumb-group';
import { getFunnelKeySelector } from '../../internal/analytics/selectors';
import { describeEachAppLayout, renderComponent } from './utils';

let widgetMockEnabled = false;
Expand All @@ -26,7 +25,7 @@ jest.mock('../../../lib/components/internal/widgets', () => ({
createWidgetizedComponent: createWidgetizedComponentMock,
}));

describeEachAppLayout({ themes: ['refresh-toolbar'] }, () => {
describeEachAppLayout({ themes: ['refresh-toolbar'], skipInitialTest: true }, () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to skip the mocks applied correctly test in this case because we set widgetMockEnabled = false to test the behavior of skeleton widgets. Since styles now come from widgets and the test relies on those classes, the test will always fail. That’s why we need this extra condition.

it('renders complete component by default', () => {
const { wrapper } = renderComponent(
<AppLayout
Expand All @@ -39,7 +38,6 @@ describeEachAppLayout({ themes: ['refresh-toolbar'] }, () => {
expect(wrapper.findToolbar()).toBeTruthy();
expect(wrapper.findNavigation()).toBeTruthy();
expect(wrapper.findBreadcrumbs()).toBeTruthy();
expect(wrapper.find(getFunnelKeySelector('funnel-name'))).toBeTruthy();
expect(wrapper.findNotifications()).toBeTruthy();
expect(wrapper.findTools()).toBeTruthy();
expect(wrapper.findContentRegion()).toBeTruthy();
Expand All @@ -65,7 +63,6 @@ describeEachAppLayout({ themes: ['refresh-toolbar'] }, () => {
expect(wrapper.findToolbar()).toBeFalsy();
expect(wrapper.findNavigation()).toBeFalsy();
expect(wrapper.findBreadcrumbs()).toBeFalsy();
expect(wrapper.find(getFunnelKeySelector('funnel-name'))).toBeTruthy();
expect(wrapper.findNotifications()).toBeFalsy();
expect(wrapper.findTools()).toBeFalsy();
expect(wrapper.findContentRegion()).toBeTruthy();
Expand Down
Loading
Loading