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
23 changes: 23 additions & 0 deletions src/app-layout/__tests__/skeleton.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import React from 'react';
import { render } from '@testing-library/react';

import { isThemeActive } from '@cloudscape-design/component-toolkit/internal';

import AppLayout from '../../../lib/components/app-layout';
import { BeforeMainSlotSkeleton } from '../../../lib/components/app-layout/visual-refresh-toolbar/skeleton/skeleton-parts';
import AppLayoutToolbar from '../../../lib/components/app-layout-toolbar';
import BreadcrumbGroup from '../../../lib/components/breadcrumb-group';
import { getFunnelKeySelector } from '../../../lib/components/internal/analytics/selectors';
import { getIconHTML } from '../../icon/__tests__/utils';
import { describeEachAppLayout, renderComponent } from './utils';

import testutilStyles from '../../../lib/components/app-layout/test-classes/styles.selectors.js';
Expand All @@ -34,6 +37,15 @@ jest.mock('../../../lib/components/internal/widgets', () => ({
createWidgetizedComponent: createWidgetizedComponentMock,
}));

jest.mock('@cloudscape-design/component-toolkit/internal', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit/internal'),
isThemeActive: jest.fn().mockReturnValue(false),
}));

afterEach(() => {
(isThemeActive as jest.Mock).mockReturnValue(false);
});

describeEachAppLayout({ themes: ['refresh-toolbar'] }, () => {
it('renders complete component by default', () => {
const { wrapper } = renderComponent(
Expand Down Expand Up @@ -61,6 +73,17 @@ describeEachAppLayout({ themes: ['refresh-toolbar'] }, () => {
widgetMockEnabled = false;
});

it('renders the menu icon on the navigation toggle', () => {
const { wrapper } = renderComponent(<AppLayout navigation="test nav" />);
expect(wrapper.findNavigationToggle()!.findIcon()!.getElement()).toContainHTML(getIconHTML('menu'));
});

it('renders the side-bar icon on the navigation toggle in One Theme', () => {
(isThemeActive as jest.Mock).mockReturnValue(true);
const { wrapper } = renderComponent(<AppLayout navigation="test nav" />);
expect(wrapper.findNavigationToggle()!.findIcon()!.getElement()).toContainHTML(getIconHTML('side-bar'));
});

it('renders skeleton parts only', () => {
const { wrapper } = renderComponent(
<AppLayout
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import React from 'react';
import clsx from 'clsx';

import { isThemeActive, Theme } from '@cloudscape-design/component-toolkit/internal';

import { AppLayoutProps } from '../../../app-layout/interfaces';
import { BreadcrumbGroupProps } from '../../../breadcrumb-group/interfaces';
import { BreadcrumbsSlotContextType } from '../contexts';
Expand Down Expand Up @@ -70,6 +72,7 @@ interface ToolbarSkeletonStructureProps {
export const ToolbarSkeletonStructure = React.forwardRef<HTMLElement, ToolbarSkeletonStructureProps>(
({ ariaLabels, expandedDrawerId, hasNavigation, navigationOpen, ownBreadcrumbs, discoveredBreadcrumbs }, ref) => {
const drawerExpandedMode = !!expandedDrawerId;
const isOneTheme = isThemeActive(Theme.OneTheme);
// istanbul ignore next: not interactive during SSR
const noop = () => {};
return (
Expand All @@ -80,7 +83,7 @@ export const ToolbarSkeletonStructure = React.forwardRef<HTMLElement, ToolbarSke
<TriggerButton
ariaLabel={ariaLabels?.navigationToggle ?? undefined}
ariaExpanded={!drawerExpandedMode && navigationOpen}
iconName="menu"
iconName={isOneTheme ? 'side-bar' : 'menu'}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggestion: can we make this Trigger a shared component in skeleton and toolbar, so we can avoid this discrepancy.

className={testutilStyles['navigation-toggle']}
onClick={noop}
selected={!drawerExpandedMode && navigationOpen}
Expand Down
Loading