Skip to content
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

chore: Experiment: vr only #3272

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions build-tools/utils/themes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const themes = [
designTokensDir: 'design-tokens',
designTokensPackageJson: { name: '@cloudscape-design/design-tokens' },
outputPath: path.join(workspace.targetPath, 'components'),
primaryThemePath: './classic/index.js',
secondaryThemePaths: ['./visual-refresh-secondary/index.js'],
primaryThemePath: './visual-refresh/index.js',
secondaryThemePaths: [],
},
];

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"test:integ": "gulp test:integ",
"test:motion": "gulp test:motion",
"lint": "npm-run-all --parallel lint:*",
"lint:eslint": "eslint --ignore-path .gitignore --ext ts,tsx,js .",
"lint:eslint": "eslint --fix --ignore-path .gitignore --ext ts,tsx,js .",
"lint:stylelint": "stylelint --ignore-path .gitignore --fix '{src,pages}/**/*.{css,scss}'",
"start": "npm-run-all --parallel start:watch start:dev",
"start:watch": "gulp watch",
Expand Down
22 changes: 0 additions & 22 deletions src/alert/__tests__/alert.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ import Alert, { AlertProps } from '../../../lib/components/alert';
import Button from '../../../lib/components/button';
import TestI18nProvider from '../../../lib/components/i18n/testing';
import { DATA_ATTR_ANALYTICS_ALERT } from '../../../lib/components/internal/analytics/selectors';
import { useVisualRefresh } from '../../../lib/components/internal/hooks/use-visual-mode';
import createWrapper from '../../../lib/components/test-utils/dom';

import styles from '../../../lib/components/alert/styles.css.js';

jest.mock('../../../lib/components/internal/hooks/use-visual-mode', () => ({
...jest.requireActual('../../../lib/components/internal/hooks/use-visual-mode'),
useVisualRefresh: jest.fn().mockReturnValue(false),
}));

function renderAlert(props: AlertProps = {}) {
Expand All @@ -31,10 +29,6 @@ const i18nStrings: AlertProps.I18nStrings = {
dismissAriaLabel: 'dismiss',
};

beforeEach(() => {
jest.mocked(useVisualRefresh).mockReset();
});

describe('Alert Component', () => {
describe('structure', () => {
it('has no header container when no header is set', () => {
Expand Down Expand Up @@ -173,23 +167,7 @@ describe('Alert Component', () => {
});

describe('icon size', () => {
test('classic - big if has header and content', () => {
const { wrapper } = renderAlert({ header: 'Header', children: ['Content'] });
expect(wrapper.findByClassName(styles['icon-size-normal'])).toBeFalsy();
expect(wrapper.findByClassName(styles['icon-size-big'])).toBeTruthy();
});
test('classic - normal if only header', () => {
const { wrapper } = renderAlert({ header: 'Header' });
expect(wrapper.findByClassName(styles['icon-size-big'])).toBeFalsy();
expect(wrapper.findByClassName(styles['icon-size-normal'])).toBeTruthy();
});
test('classic - normal if only content', () => {
const { wrapper } = renderAlert({ children: ['Content'] });
expect(wrapper.findByClassName(styles['icon-size-big'])).toBeFalsy();
expect(wrapper.findByClassName(styles['icon-size-normal'])).toBeTruthy();
});
test('visual refresh - always normal', () => {
jest.mocked(useVisualRefresh).mockReturnValue(true);
const { wrapper } = renderAlert({ header: 'Header', children: ['Content'] });
expect(wrapper.findByClassName(styles['icon-size-big'])).toBeFalsy();
expect(wrapper.findByClassName(styles['icon-size-normal'])).toBeTruthy();
Expand Down
9 changes: 1 addition & 8 deletions src/alert/internal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import { useContainerBreakpoints } from '../internal/hooks/container-queries';
import useForwardFocus from '../internal/hooks/forward-focus';
import { InternalBaseComponentProps } from '../internal/hooks/use-base-component';
import { useMergeRefs } from '../internal/hooks/use-merge-refs';
import { useVisualRefresh } from '../internal/hooks/use-visual-mode';
import { awsuiPluginsInternal } from '../internal/plugins/api';
import { createUseDiscoveredAction, createUseDiscoveredContent } from '../internal/plugins/helpers';
import { SomeRequired } from '../internal/types';
Expand Down Expand Up @@ -84,13 +83,7 @@ const InternalAlert = React.forwardRef(
const headerRef = useMergeRefs(headerRefAction, headerRefContent);
const contentRef = useMergeRefs(contentRefAction, contentRefContent);

const isRefresh = useVisualRefresh();
const size = isRefresh
? 'normal'
: headerReplacementType !== 'remove' && header && contentReplacementType !== 'remove' && children
? 'big'
: 'normal';

const size = 'normal';
const hasAction = Boolean(action || buttonText || discoveredActions.length);

const analyticsAttributes = {
Expand Down
1 change: 0 additions & 1 deletion src/app-layout/__tests__/background-overlap.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { useDynamicOverlap } from '../../../lib/components/internal/hooks/use-dy

jest.mock('../../../lib/components/internal/hooks/use-visual-mode', () => ({
...jest.requireActual('../../../lib/components/internal/hooks/use-visual-mode'),
useVisualRefresh: jest.fn().mockReturnValue(true),
}));

let positiveHeight = true;
Expand Down
62 changes: 1 addition & 61 deletions src/app-layout/__tests__/desktop.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
/* eslint simple-import-sort/imports: 0 */
import React from 'react';
import { act, fireEvent, screen, within } from '@testing-library/react';
import { act } from '@testing-library/react';

import {
describeEachAppLayout,
Expand All @@ -18,10 +18,8 @@ import notificationStyles from '../../../lib/components/app-layout/notifications
import visualRefreshStyles from '../../../lib/components/app-layout/visual-refresh/styles.css.js';
import visualRefreshToolbarNotificationStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/notifications/styles.css.js';
import toolbarStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/toolbar/styles.css.js';
import drawerStyles from '../../../lib/components/app-layout/drawer/styles.css.js';
import customCssProps from '../../../lib/components/internal/generated/custom-css-properties';
import { KeyCode } from '../../internal/keycode';
import { useVisualRefresh } from '../../../lib/components/internal/hooks/use-visual-mode';

jest.mock('@cloudscape-design/component-toolkit', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit'),
Expand Down Expand Up @@ -252,64 +250,6 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => {
});
});

describe('Classic only features', () => {
beforeEach(() => {
(useVisualRefresh as jest.Mock).mockReturnValue(false);
});
afterEach(() => {
(useVisualRefresh as jest.Mock).mockReset();
});

test(`should toggle single drawer on click of container`, () => {
const { wrapper } = renderComponent(
<AppLayout toolsHide={true} drawers={[testDrawer]} ariaLabels={{ drawers: 'Drawers' }} />
);
fireEvent.click(screen.getByLabelText('Drawers'));
expect(wrapper.findActiveDrawer()).toBeTruthy();
fireEvent.click(screen.getByLabelText('Drawers'));
expect(wrapper.findActiveDrawer()).toBeFalsy();
});

test(`should not toggle many drawers on click of container`, () => {
const { wrapper } = renderComponent(
<AppLayout toolsHide={true} drawers={manyDrawers} ariaLabels={{ drawers: 'Drawers' }} />
);
fireEvent.click(screen.getByLabelText('Drawers'));
expect(wrapper.findActiveDrawer()).toBeFalsy();
});

test('renders roles only when aria labels are not provided', () => {
const { wrapper } = renderComponent(<AppLayout navigationHide={true} drawers={[testDrawerWithoutLabels]} />);
const drawersAside = within(wrapper.findByClassName(drawerStyles['drawer-closed'])!.getElement()).getByRole(
'region'
);

expect(wrapper.findDrawerTriggerById(testDrawer.id)!.getElement()).not.toHaveAttribute('aria-label');
expect(drawersAside).not.toHaveAttribute('aria-label');
expect(wrapper.findByClassName(drawerStyles['drawer-triggers-wrapper'])!.getElement()).toHaveAttribute(
'role',
'toolbar'
);
});

test('renders roles and aria labels when provided', () => {
const { wrapper } = renderComponent(<AppLayout drawers={[testDrawer]} ariaLabels={{ drawers: 'Drawers' }} />);
const drawersAside = within(wrapper.findByClassName(drawerStyles['drawer-closed'])!.getElement()).getByRole(
'region'
);

expect(wrapper.findDrawerTriggerById('security')!.getElement()).toHaveAttribute(
'aria-label',
'Security trigger button'
);
expect(drawersAside).toHaveAttribute('aria-label', 'Drawers');
expect(wrapper.findByClassName(drawerStyles['drawer-triggers-wrapper'])!.getElement()).toHaveAttribute(
'role',
'toolbar'
);
});
});

describeEachAppLayout({ themes: ['refresh', 'refresh-toolbar'], sizes: ['desktop'] }, ({ theme }) => {
const styles = theme === 'refresh' ? visualRefreshStyles : toolbarStyles;
test('renders roles only when aria labels are not provided', () => {
Expand Down
4 changes: 0 additions & 4 deletions src/app-layout/__tests__/header-variant.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import { describeEachAppLayout, renderComponent } from './utils';
import visualRefreshStyles from '../../../lib/components/app-layout/visual-refresh/styles.css.js';
import toolbarSkeletonStyles from '../../../lib/components/app-layout/visual-refresh-toolbar/skeleton/styles.css.js';

jest.mock('../../../lib/components/internal/hooks/use-visual-mode', () => ({
useVisualRefresh: jest.fn().mockReturnValue(false),
}));

jest.mock('../../../lib/components/internal/hooks/use-mobile', () => ({
useMobile: jest.fn().mockReturnValue(false),
}));
Expand Down
12 changes: 0 additions & 12 deletions src/app-layout/__tests__/split-panel.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import AppLayout from '../../../lib/components/app-layout';
import { AppLayoutProps } from '../../../lib/components/app-layout/interfaces';
import SplitPanel from '../../../lib/components/split-panel';
import { KeyCode } from '../../../lib/components/internal/keycode';
import { useVisualRefresh } from '../../../lib/components/internal/hooks/use-visual-mode';
import { describeEachAppLayout, renderComponent, splitPanelI18nStrings } from './utils';
import applayoutTools from '../../../lib/components/app-layout/visual-refresh/styles.selectors.js';
import { AppLayoutWrapper } from '../../../lib/components/test-utils/dom';
Expand All @@ -30,10 +29,6 @@ const fakeComputedStyle: Window['getComputedStyle'] = (...args) => {
return result;
};

jest.mock('../../../lib/components/internal/hooks/use-visual-mode', () => ({
useVisualRefresh: jest.fn().mockReturnValue(false),
}));

jest.mock('@cloudscape-design/component-toolkit/internal', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit/internal'),
isMotionDisabled: jest.fn().mockReturnValue(true),
Expand Down Expand Up @@ -262,13 +257,6 @@ describeEachAppLayout({ sizes: ['desktop'] }, ({ theme }) => {
});

describe('Visual refresh only features', () => {
beforeEach(() => {
(useVisualRefresh as jest.Mock).mockReturnValue(true);
});
afterEach(() => {
(useVisualRefresh as jest.Mock).mockReset();
});

function isDrawersBarDisplayed(wrapper: AppLayoutWrapper) {
return !!wrapper.findByClassName(applayoutTools['has-tools-form']);
}
Expand Down
9 changes: 1 addition & 8 deletions src/app-layout/__tests__/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import AppLayout, { AppLayoutProps } from '../../../lib/components/app-layout';
import customCssProps from '../../../lib/components/internal/generated/custom-css-properties';
import { useMobile } from '../../../lib/components/internal/hooks/use-mobile';
import { useVisualRefresh } from '../../../lib/components/internal/hooks/use-visual-mode';
import { SplitPanelProps } from '../../../lib/components/split-panel';
import createWrapper, { AppLayoutWrapper, ElementWrapper } from '../../../lib/components/test-utils/dom';

Expand All @@ -22,10 +21,6 @@
useMobile: jest.fn().mockReturnValue(true),
}));

jest.mock('../../../lib/components/internal/hooks/use-visual-mode', () => ({
useVisualRefresh: jest.fn().mockReturnValue(false),
}));

jest.mock('@cloudscape-design/component-toolkit/internal', () => ({
...jest.requireActual('@cloudscape-design/component-toolkit/internal'),
isMotionDisabled: jest.fn().mockReturnValue(true),
Expand Down Expand Up @@ -53,7 +48,7 @@
type AppLayoutTestSuite = (config: { theme: Theme; size: Size }) => void;

const defaultTestConfig: AppLayoutTestConfig = {
themes: ['classic', 'refresh', 'refresh-toolbar'],
themes: ['refresh', 'refresh-toolbar'],
sizes: ['desktop', 'mobile'],
};

Expand All @@ -70,17 +65,15 @@
describe(`Theme=${theme}, Size=${size}`, () => {
beforeEach(() => {
(useMobile as jest.Mock).mockReturnValue(size === 'mobile');
(useVisualRefresh as jest.Mock).mockReturnValue(theme !== 'classic');
setGlobalFlag('appLayoutWidget', theme === 'refresh-toolbar');
});
afterEach(() => {
(useMobile as jest.Mock).mockReset();
(useVisualRefresh as jest.Mock).mockReset();
setGlobalFlag('appLayoutWidget', undefined);
});
test('mocks applied correctly', () => {
const { wrapper } = renderComponent(<AppLayout />);
expect(!!wrapper.matches(`.${visualRefreshStyles.layout}`)).toEqual(theme === 'refresh');

Check failure on line 76 in src/app-layout/__tests__/utils.tsx

View workflow job for this annotation

GitHub Actions / build / build

Theme=refresh

expect(received).toEqual(expected) // deep equality Expected: true Received: false at Object.<anonymous> (src/app-layout/__tests__/utils.tsx:76:71)

Check failure on line 76 in src/app-layout/__tests__/utils.tsx

View workflow job for this annotation

GitHub Actions / build / build

Theme=refresh

expect(received).toEqual(expected) // deep equality Expected: true Received: false at Object.<anonymous> (src/app-layout/__tests__/utils.tsx:76:71)

Check failure on line 76 in src/app-layout/__tests__/utils.tsx

View workflow job for this annotation

GitHub Actions / build / build

Theme=refresh

expect(received).toEqual(expected) // deep equality Expected: true Received: false at Object.<anonymous> (src/app-layout/__tests__/utils.tsx:76:71)

Check failure on line 76 in src/app-layout/__tests__/utils.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components unit tests

Theme=refresh

expect(received).toEqual(expected) // deep equality Expected: true Received: false at Object.<anonymous> (src/app-layout/__tests__/utils.tsx:76:71)

Check failure on line 76 in src/app-layout/__tests__/utils.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components unit tests

Theme=refresh

expect(received).toEqual(expected) // deep equality Expected: true Received: false at Object.<anonymous> (src/app-layout/__tests__/utils.tsx:76:71)

Check failure on line 76 in src/app-layout/__tests__/utils.tsx

View workflow job for this annotation

GitHub Actions / dry-run / Components unit tests

Theme=refresh

expect(received).toEqual(expected) // deep equality Expected: true Received: false at Object.<anonymous> (src/app-layout/__tests__/utils.tsx:76:71)
expect(!!wrapper.matches(`.${visualRefreshToolbarStyles.root}`)).toEqual(theme === 'refresh-toolbar');
expect(!!wrapper.findByClassName(testutilStyles['mobile-bar'])).toEqual(size === 'mobile');
});
Expand Down
Loading
Loading