diff --git a/src/components/Banner/Banner.tsx b/src/components/Banner/Banner.tsx index 4205471d11d..221830160b4 100644 --- a/src/components/Banner/Banner.tsx +++ b/src/components/Banner/Banner.tsx @@ -22,7 +22,7 @@ import ButtonGroup from '../ButtonGroup'; import UnstyledLink from '../UnstyledLink'; import Icon from '../Icon'; -import WithinContentContext from '../WithinContentContext'; +import {WithinContentContext} from '../../utilities/within-content-context'; import styles from './Banner.scss'; diff --git a/src/components/Banner/tests/Banner.test.tsx b/src/components/Banner/tests/Banner.test.tsx index 162febf9bb9..cc1593382d3 100644 --- a/src/components/Banner/tests/Banner.test.tsx +++ b/src/components/Banner/tests/Banner.test.tsx @@ -12,7 +12,7 @@ import {mountWithAppProvider} from 'test-utilities/legacy'; import {BannerContext} from 'utilities/banner-context'; import {Button, Icon, UnstyledLink, Heading} from 'components'; import Banner from '..'; -import WithinContentContext from '../../WithinContentContext'; +import {WithinContentContext} from '../../../utilities/within-content-context'; describe('', () => { it('renders a title', () => { diff --git a/src/components/Card/Card.tsx b/src/components/Card/Card.tsx index 3d7e835209f..270e5aa4f6a 100644 --- a/src/components/Card/Card.tsx +++ b/src/components/Card/Card.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {classNames} from '../../utilities/css'; import ButtonGroup from '../ButtonGroup'; -import WithinContentContext from '../WithinContentContext'; +import {WithinContentContext} from '../../utilities/within-content-context'; import {DisableableAction, ComplexAction} from '../../types'; import ActionList from '../ActionList'; import Button, {buttonFrom} from '../Button'; diff --git a/src/components/Card/tests/Card.test.tsx b/src/components/Card/tests/Card.test.tsx index 36aaa960e27..2a9c17c2e57 100644 --- a/src/components/Card/tests/Card.test.tsx +++ b/src/components/Card/tests/Card.test.tsx @@ -5,7 +5,7 @@ import { findByTestID, } from 'test-utilities/legacy'; import {Card, Badge, Button, Popover, ActionList} from 'components'; -import WithinContentContext from '../../WithinContentContext'; +import {WithinContentContext} from '../../../utilities/within-content-context'; import {Section} from '../components'; describe('', () => { diff --git a/src/components/ContextualSaveBar/tests/ContextualSaveBar.test.tsx b/src/components/ContextualSaveBar/tests/ContextualSaveBar.test.tsx index 9baf5f06e99..426dd23c3eb 100644 --- a/src/components/ContextualSaveBar/tests/ContextualSaveBar.test.tsx +++ b/src/components/ContextualSaveBar/tests/ContextualSaveBar.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {mount} from 'enzyme'; import {mountWithAppProvider} from 'test-utilities/legacy'; import ContextualSaveBar from '../ContextualSaveBar'; -import {FrameContext, createFrameContext} from '../../Frame'; +import {createFrameContext} from '../../Frame'; describe('', () => { const props = { @@ -17,11 +17,9 @@ describe('', () => { removeContextualSaveBar: jest.fn(), }); - mountWithAppProvider( - - - , - ); + mountWithAppProvider(, { + context: {frame: mockFrameContext}, + }); expect(mockFrameContext.setContextualSaveBar).toHaveBeenCalledWith({ ...props, }); @@ -33,11 +31,9 @@ describe('', () => { removeContextualSaveBar: jest.fn(), }); - const frame = mountWithAppProvider( - - - , - ); + const frame = mountWithAppProvider(, { + context: {frame: mockFrameContext}, + }); expect(mockFrameContext.removeContextualSaveBar).not.toHaveBeenCalled(); frame.unmount(); expect(mockFrameContext.removeContextualSaveBar).toHaveBeenCalled(); @@ -49,11 +45,9 @@ describe('', () => { removeContextualSaveBar: jest.fn(), }); - const frame = mountWithAppProvider( - - - , - ); + const frame = mountWithAppProvider(, { + context: {frame: mockFrameContext}, + }); const newProps = { saveAction: {content: 'Save', onAction: noop, loading: true}, discardAction: {content: 'Discard', onAction: noop}, @@ -74,11 +68,9 @@ describe('', () => { removeContextualSaveBar: jest.fn(), }); - const frame = mountWithAppProvider( - - - , - ); + const frame = mountWithAppProvider(, { + context: {frame: mockFrameContext}, + }); expect(mockFrameContext.setContextualSaveBar).toHaveBeenCalledTimes(1); const newProps = {...props}; diff --git a/src/components/DropZone/components/FileUpload/tests/FileUpload.test.tsx b/src/components/DropZone/components/FileUpload/tests/FileUpload.test.tsx index 26cd1630784..a8f3e6d8035 100755 --- a/src/components/DropZone/components/FileUpload/tests/FileUpload.test.tsx +++ b/src/components/DropZone/components/FileUpload/tests/FileUpload.test.tsx @@ -102,18 +102,4 @@ describe('', () => { fileUpload.setProps({children: }); expect(fileUpload.find(TextStyle).text()).toBe('or drop files to upload'); }); - - it('does not use default action title and hint when props are changed', () => { - const actionTitle = 'Add file title'; - const actionHint = 'or drop files to upload hint'; - const fileUpload = mountWithAppProvider( - - - , - ); - - fileUpload.setProps({actionTitle, actionHint}); - - expect(fileUpload.props()).toStrictEqual({actionTitle, actionHint}); - }); }); diff --git a/src/components/Loading/tests/Loading.test.tsx b/src/components/Loading/tests/Loading.test.tsx index 0d28e7c1982..3a43ddf1635 100644 --- a/src/components/Loading/tests/Loading.test.tsx +++ b/src/components/Loading/tests/Loading.test.tsx @@ -1,7 +1,7 @@ import React from 'react'; import {Loading as AppBridgeLoading} from '@shopify/app-bridge/actions'; import {mountWithAppProvider} from 'test-utilities/legacy'; -import {FrameContext, createFrameContext} from '../../Frame'; +import {createFrameContext} from '../../Frame'; import Loading from '../Loading'; @@ -15,11 +15,7 @@ describe('', () => { startLoading: jest.fn(), }); - mountWithAppProvider( - - - , - ); + mountWithAppProvider(, {context: {frame: mockFrameContext}}); expect(mockFrameContext.startLoading).toHaveBeenCalled(); }); @@ -27,11 +23,9 @@ describe('', () => { const mockFrameContext = createFrameContext({ stopLoading: jest.fn(), }); - const frame = mountWithAppProvider( - - - , - ); + const frame = mountWithAppProvider(, { + context: {frame: mockFrameContext}, + }); expect(mockFrameContext.stopLoading).not.toHaveBeenCalled(); frame.unmount(); diff --git a/src/components/Modal/Modal.tsx b/src/components/Modal/Modal.tsx index 71b1c24e9d9..5d48e9d87c0 100644 --- a/src/components/Modal/Modal.tsx +++ b/src/components/Modal/Modal.tsx @@ -5,7 +5,7 @@ import {write} from '@shopify/javascript-utilities/fastdom'; import {focusFirstFocusableNode} from '@shopify/javascript-utilities/focus'; import {createUniqueIDFactory} from '@shopify/javascript-utilities/other'; import {Modal as AppBridgeModal} from '@shopify/app-bridge/actions'; -import WithinContentContext from '../WithinContentContext'; +import {WithinContentContext} from '../../utilities/within-content-context'; import {wrapWithComponent} from '../../utilities/components'; import {transformActions} from '../../utilities/app-bridge-transformers'; diff --git a/src/components/Modal/tests/Modal.test.tsx b/src/components/Modal/tests/Modal.test.tsx index 3b366020a94..1924518db16 100644 --- a/src/components/Modal/tests/Modal.test.tsx +++ b/src/components/Modal/tests/Modal.test.tsx @@ -6,7 +6,7 @@ import {Badge, Spinner, Portal, Scrollable} from 'components'; import {Footer, Dialog} from '../components'; import Modal from '../Modal'; -import WithinContentContext from '../../WithinContentContext'; +import {WithinContentContext} from '../../../utilities/within-content-context'; jest.mock('../../../utilities/app-bridge-transformers', () => ({ ...require.requireActual('../../../utilities/app-bridge-transformers'), diff --git a/src/components/Navigation/Navigation.tsx b/src/components/Navigation/Navigation.tsx index e0e3d355120..da12449cb0c 100644 --- a/src/components/Navigation/Navigation.tsx +++ b/src/components/Navigation/Navigation.tsx @@ -2,7 +2,7 @@ import React from 'react'; import Scrollable from '../Scrollable'; -import WithinContentContext from '../WithinContentContext'; +import {WithinContentContext} from '../../utilities/within-content-context'; import NavigationContext from './context'; import {Section, Item} from './components'; import {SectionType} from './types'; diff --git a/src/components/Navigation/tests/Navigation.test.tsx b/src/components/Navigation/tests/Navigation.test.tsx index 6cf1c0b9c98..58dbf664cc7 100644 --- a/src/components/Navigation/tests/Navigation.test.tsx +++ b/src/components/Navigation/tests/Navigation.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {mountWithAppProvider} from 'test-utilities/legacy'; import Navigation from '../Navigation'; import NavigationContext from '../context'; -import WithinContentContext from '../../WithinContentContext'; +import {WithinContentContext} from '../../../utilities/within-content-context'; describe('', () => { it('mounts', () => { diff --git a/src/components/ResourceList/components/FilterControl/tests/FilterControl.test.tsx b/src/components/ResourceList/components/FilterControl/tests/FilterControl.test.tsx index 613d700bcd3..cb30f8b9f46 100644 --- a/src/components/ResourceList/components/FilterControl/tests/FilterControl.test.tsx +++ b/src/components/ResourceList/components/FilterControl/tests/FilterControl.test.tsx @@ -303,13 +303,9 @@ describe('', () => { , ); - const expectedLocalizedLabel = filterControl.app.polaris.intl.translate( - 'Polaris.ResourceList.DateSelector.FilterLabelForValue.past_week', - ); - const firstTag = filterControl.find(Tag).at(0); expect(firstTag.text()).toBe( - `${filter.label} ${filter.operatorText} ${expectedLocalizedLabel}`, + `${filter.label} ${filter.operatorText} in the last week`, ); }); @@ -338,15 +334,8 @@ describe('', () => { , ); - const expectedLocalizedLabel = filterControl.app.polaris.intl.translate( - 'Polaris.ResourceList.DateSelector.FilterLabelForValue.on_or_after', - { - date: new Date(selectedDate.replace(/-/g, '/')).toLocaleDateString(), - }, - ); - const firstTag = filterControl.find(Tag).at(0); - expect(firstTag.text()).toBe(`${filter.label} ${expectedLocalizedLabel}`); + expect(firstTag.text()).toBe(`${filter.label} after 9/16/2018`); }); it('renders the provided localized applied filter string when filter is a FilterDateSelector with maximum date predicate (on or before)', () => { @@ -373,15 +362,8 @@ describe('', () => { , ); - const expectedLocalizedLabel = filterControl.app.polaris.intl.translate( - 'Polaris.ResourceList.DateSelector.FilterLabelForValue.on_or_before', - { - date: new Date(selectedDate.replace(/-/g, '/')).toLocaleDateString(), - }, - ); - const firstTag = filterControl.find(Tag).at(0); - expect(firstTag.text()).toBe(`${filter.label} ${expectedLocalizedLabel}`); + expect(firstTag.text()).toBe(`${filter.label} before 9/16/2018`); }); it('renders applied filter value when filter is a FilterDateSelector with invalid date predicate', () => { @@ -408,15 +390,8 @@ describe('', () => { , ); - const expectedLocalizedLabel = filterControl.app.polaris.intl.translate( - 'Polaris.ResourceList.DateSelector.FilterLabelForValue.on_or_before', - { - date: selectedDate, - }, - ); - const firstTag = filterControl.find(Tag).at(0); - expect(firstTag.text()).toBe(`${filter.label} ${expectedLocalizedLabel}`); + expect(firstTag.text()).toBe(`${filter.label} before INVALID`); }); it('renders the provided applied filter string when filter uses operators with filter label', () => { diff --git a/src/components/Toast/tests/Toast.test.tsx b/src/components/Toast/tests/Toast.test.tsx index 3fd6ab5e6c4..fb8246ef489 100644 --- a/src/components/Toast/tests/Toast.test.tsx +++ b/src/components/Toast/tests/Toast.test.tsx @@ -2,7 +2,7 @@ import React from 'react'; import {Toast as AppBridgeToast} from '@shopify/app-bridge/actions'; import {mountWithAppProvider} from 'test-utilities/legacy'; import Toast from '../Toast'; -import {FrameContext, createFrameContext} from '../../Frame'; +import {createFrameContext} from '../../Frame'; describe('', () => { beforeEach(() => { @@ -15,11 +15,9 @@ describe('', () => { }); const props = {content: 'Image uploaded', onDismiss: noop}; - mountWithAppProvider( - - - , - ); + mountWithAppProvider(, { + context: {frame: mockFrameContext}, + }); expect(mockFrameContext.showToast).toHaveBeenCalledWith( expect.objectContaining({id: expect.any(String), ...props}), @@ -32,9 +30,8 @@ describe('', () => { }); const frame = mountWithAppProvider( - - - , + , + {context: {frame: mockFrameContext}}, ); expect(mockFrameContext.hideToast).not.toHaveBeenCalled(); diff --git a/src/components/WithinContentContext/context.tsx b/src/components/WithinContentContext/context.tsx deleted file mode 100644 index 771510e97ba..00000000000 --- a/src/components/WithinContentContext/context.tsx +++ /dev/null @@ -1,5 +0,0 @@ -import React from 'react'; - -const WithinContentContext = React.createContext(false); - -export default WithinContentContext; diff --git a/src/components/WithinContentContext/index.ts b/src/components/WithinContentContext/index.ts deleted file mode 100644 index 825fa6fde14..00000000000 --- a/src/components/WithinContentContext/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import WithinContentContext from './context'; - -export default WithinContentContext; diff --git a/src/components/index.ts b/src/components/index.ts index 62e644a2805..942d23c8679 100644 --- a/src/components/index.ts +++ b/src/components/index.ts @@ -272,6 +272,8 @@ export {default as TextField, Props as TextFieldProps} from './TextField'; export {default as TextStyle, Props as TextStyleProps} from './TextStyle'; +export {default as ThemeProvider} from './ThemeProvider'; + export {default as Thumbnail, Props as ThumbnailProps} from './Thumbnail'; export {default as Toast} from './Toast'; @@ -290,5 +292,3 @@ export { default as VisuallyHidden, Props as VisuallyHiddenProps, } from './VisuallyHidden'; - -export {default as WithinContentContext} from './WithinContentContext'; diff --git a/src/index.ts b/src/index.ts index 5683a63f6b2..6a17820e25e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -5,4 +5,11 @@ export * from './types'; export * from './components'; export {UnstyledLinkProps, LinkLikeComponent} from './utilities/link'; -export {createPolarisContext} from './utilities/create-polaris-context'; +export { + ScrollLockManagerContext as _SECRET_INTERNAL_SCROLL_LOCK_MANAGER_CONTEXT, +} from './utilities/scroll-lock-manager'; +export { + WithinContentContext as _SECRET_INTERNAL_WITHIN_CONTENT_CONTEXT, +} from './utilities/within-content-context'; + +export {PolarisTestProvider} from './test-utilities/PolarisTestProvider'; diff --git a/src/test-utilities/PolarisTestProvider.tsx b/src/test-utilities/PolarisTestProvider.tsx new file mode 100644 index 00000000000..7d83466ed42 --- /dev/null +++ b/src/test-utilities/PolarisTestProvider.tsx @@ -0,0 +1,68 @@ +import React from 'react'; +// eslint-disable-next-line shopify/strict-component-boundaries +import {FrameContext} from '../components/Frame'; +import {createThemeContext, ThemeProviderContext} from '../utilities/theme'; +import { + ScrollLockManager, + ScrollLockManagerContext, +} from '../utilities/scroll-lock-manager'; +import {StickyManager, StickyManagerContext} from '../utilities/sticky-manager'; +import {AppBridgeContext} from '../utilities/app-bridge'; +import {I18n, I18nContext} from '../utilities/i18n'; +import translations from '../../locales/en.json'; +import {Link, LinkContext} from '../utilities/link'; +import {ReturnedContext} from './types'; + +export interface Props extends Partial { + children: React.ReactElement; + strict?: boolean; +} + +export function PolarisTestProvider({ + strict, + children, + themeProvider = createThemeContext(), + frame = { + showToast: noop, + hideToast: noop, + setContextualSaveBar: noop, + removeContextualSaveBar: noop, + startLoading: noop, + stopLoading: noop, + }, + intl = new I18n(translations), + scrollLockManager = new ScrollLockManager(), + stickyManager = new StickyManager(), + appBridge = null, + link = new Link(undefined), + ...props +}: Props) { + const childWithProps = + Object.keys(props).length > 0 + ? React.cloneElement(children, props) + : children; + + const Wrapper = strict ? React.StrictMode : React.Fragment; + + return ( + + + + + + + + + {childWithProps} + + + + + + + + + ); +} + +function noop() {} diff --git a/src/test-utilities/legacy.tsx b/src/test-utilities/legacy.tsx index bfebc6b2db3..44129fe5916 100644 --- a/src/test-utilities/legacy.tsx +++ b/src/test-utilities/legacy.tsx @@ -2,28 +2,20 @@ import {ReactWrapper, CommonWrapper, mount} from 'enzyme'; import React from 'react'; import {noop} from '@shopify/javascript-utilities/other'; import {ClientApplication} from '@shopify/app-bridge'; -import {I18n, I18nContext, TranslationDictionary} from '../utilities/i18n'; +import {I18n, TranslationDictionary} from '../utilities/i18n'; import {get} from '../utilities/get'; import {merge} from '../utilities/merge'; import {PolarisContext} from '../components/types'; import {DeepPartial} from '../types'; import translations from '../../locales/en.json'; -import {createPolarisContext} from '../utilities/create-polaris-context'; // eslint-disable-next-line shopify/strict-component-boundaries -import {FrameContext, FrameContextType} from '../components/Frame'; -import { - createThemeContext, - ThemeProviderContextType, - ThemeProviderContext, -} from '../utilities/theme'; -import { - ScrollLockManager, - ScrollLockManagerContext, -} from '../utilities/scroll-lock-manager'; -import {StickyManager, StickyManagerContext} from '../utilities/sticky-manager'; -import {AppBridgeContext} from '../utilities/app-bridge'; -import {Link, LinkContext, LinkLikeComponent} from '../utilities/link'; +import {FrameContextType} from '../components/Frame'; +import {createThemeContext, ThemeProviderContextType} from '../utilities/theme'; +import {ScrollLockManager} from '../utilities/scroll-lock-manager'; +import {StickyManager} from '../utilities/sticky-manager'; +import {Link, LinkLikeComponent} from '../utilities/link'; +import {PolarisTestProvider} from './PolarisTestProvider'; export type AnyWrapper = ReactWrapper | CommonWrapper; @@ -86,7 +78,6 @@ function updateRoot(wrapper: AnyWrapper) { } type AppContext = { - polaris: PolarisContext; intl: I18n; scrollLockManager: ScrollLockManager; stickyManager: StickyManager; @@ -119,10 +110,6 @@ export function mountWithAppProvider

( ): PolarisContextReactWrapper { const {context: ctx = {}} = options; - const polarisDefault = createPolarisContext({i18n: translations}); - const polaris = - (ctx.polaris && merge(polarisDefault, ctx.polaris)) || polarisDefault; - const intlTranslations = (ctx.intl && merge(translations, ctx.intl)) || translations; const intl = new I18n(intlTranslations); @@ -151,7 +138,6 @@ export function mountWithAppProvider

( const appBridge = ctx.appBridge || null; const context: AppContext = { - polaris, themeProvider, frame, intl, @@ -174,40 +160,13 @@ export function polarisContextReactWrapper( element: React.ReactElement

, {app}: AppContextOptions, ): PolarisContextReactWrapper { - function TestProvider

(props: P) { - let content: React.ReactNode = element; - - if (Object.keys(props).length > 0) { - content = React.cloneElement(React.Children.only(element), props); - } - - return ( - - - - - - - - {content} - - - - - - - - ); - } + const appBridge: any = app.appBridge; - const wrapper = mount(); - - Object.defineProperty(wrapper, 'app', { - enumerable: true, - writable: false, - configurable: false, - value: app, - }); + const wrapper = mount( + + {element} + , + ); return wrapper as PolarisContextReactWrapper; } diff --git a/src/test-utilities/react-testing.tsx b/src/test-utilities/react-testing.tsx index 30a4c336670..cbd9602ed58 100644 --- a/src/test-utilities/react-testing.tsx +++ b/src/test-utilities/react-testing.tsx @@ -1,104 +1,23 @@ import React from 'react'; import {createMount} from '@shopify/react-testing'; import {ClientApplication} from '@shopify/app-bridge'; -import {createPolarisContext} from '../utilities/create-polaris-context'; -// eslint-disable-next-line shopify/strict-component-boundaries -import {FrameContext, FrameContextType} from '../components/Frame'; -import { - createThemeContext, - ThemeProviderContextType, - ThemeProviderContext, -} from '../utilities/theme'; -import { - ScrollLockManager, - ScrollLockManagerContext, -} from '../utilities/scroll-lock-manager'; -import {StickyManager, StickyManagerContext} from '../utilities/sticky-manager'; -import { - createAppBridge, - AppBridgeContext, - AppBridgeOptions, -} from '../utilities/app-bridge'; -import {I18n, I18nContext, TranslationDictionary} from '../utilities/i18n'; +import {createThemeContext} from '../utilities/theme'; +import {ScrollLockManager} from '../utilities/scroll-lock-manager'; +import {StickyManager} from '../utilities/sticky-manager'; +import {createAppBridge} from '../utilities/app-bridge'; +import {I18n} from '../utilities/i18n'; import translations from '../../locales/en.json'; -import {PolarisContext} from '../components/types'; import {DeepPartial} from '../types'; import {merge} from '../utilities/merge'; -import {Link, LinkContext, LinkLikeComponent} from '../utilities/link'; +import {Link} from '../utilities/link'; +import {PolarisTestProvider} from './PolarisTestProvider'; +import {ComplexProviders, SimpleProviders, ReturnedContext} from './types'; -interface ComplexProviders { - polaris: PolarisContext; - themeProvider: ThemeProviderContextType; - frame: FrameContextType; -} - -interface SimpleProvidersWithSameReturn { - scrollLockManager: ScrollLockManager; - stickyManager: StickyManager; -} -interface SimpleProvidersWithAltReturn { - intl: TranslationDictionary | TranslationDictionary[]; - appBridge: AppBridgeOptions; - link: LinkLikeComponent; -} -type SimpleProviders = SimpleProvidersWithSameReturn & - SimpleProvidersWithAltReturn; - -type ReturnedContext = ComplexProviders & - SimpleProvidersWithSameReturn & { - intl: I18n; - appBridge: ClientApplication<{}> | null; - link: Link; - }; type Options = DeepPartial & Partial; type Context = ReturnedContext; -interface Props extends ReturnedContext { - children: React.ReactElement; -} - -function noop() {} - -export function TestProvider({ - children, - polaris, - themeProvider, - frame, - intl, - scrollLockManager, - stickyManager, - appBridge, - link, - ...props -}: Props) { - const childWithProps = - Object.keys(props).length > 0 - ? React.cloneElement(children, props) - : children; - - return ( - - - - - - - - - {childWithProps} - - - - - - - - - ); -} export const mountWithContext = createMount({ context({ - polaris, themeProvider, frame, intl, @@ -107,11 +26,6 @@ export const mountWithContext = createMount({ appBridge, link, }) { - const polarisContextDefault = createPolarisContext(); - const polarisContext = - (polaris && merge(polarisContextDefault, polaris)) || - polarisContextDefault; - const intlTranslations = (intl && merge(translations, intl)) || translations; const intlContext = new I18n(intlTranslations); @@ -150,7 +64,6 @@ export const mountWithContext = createMount({ const linkContext = new Link(link); return { - polaris: polarisContext, themeProvider: themeProviderContext, frame: frameContext, intl: intlContext, @@ -163,7 +76,6 @@ export const mountWithContext = createMount({ render( element, { - polaris, themeProvider, frame, intl, @@ -174,8 +86,7 @@ export const mountWithContext = createMount({ }, ) { return ( - ({ link={link} > {element} - + ); }, }); + +function noop() {} diff --git a/src/test-utilities/tests/PolarisTestProvider.test.tsx b/src/test-utilities/tests/PolarisTestProvider.test.tsx new file mode 100644 index 00000000000..c91234eefa8 --- /dev/null +++ b/src/test-utilities/tests/PolarisTestProvider.test.tsx @@ -0,0 +1,25 @@ +import React from 'react'; +import {mount} from '@shopify/react-testing'; +import {PolarisTestProvider} from '../PolarisTestProvider'; + +describe('PolarisTestProvider', () => { + it("doesn't render in strict mode by default", () => { + const polarisTestProvider = mount( + +

Hello
+ , + ); + + expect(polarisTestProvider).not.toContainReactComponent(React.StrictMode); + }); + + it('renders in strict mode with strict', () => { + const polarisTestProvider = mount( + +
Hello
+
, + ); + + expect(polarisTestProvider).toContainReactComponent(React.StrictMode); + }); +}); diff --git a/src/test-utilities/tests/react-testing.test.tsx b/src/test-utilities/tests/react-testing.test.tsx deleted file mode 100644 index 49a4fca35ff..00000000000 --- a/src/test-utilities/tests/react-testing.test.tsx +++ /dev/null @@ -1,38 +0,0 @@ -import React from 'react'; -import {mount} from '@shopify/react-testing'; -import {createThemeContext} from 'utilities/theme'; -import {ScrollLockManager} from 'utilities/scroll-lock-manager'; -import {StickyManager} from 'utilities/sticky-manager'; -import {I18n} from 'utilities/i18n'; -import {Link} from 'utilities/link'; -import {TestProvider} from '../react-testing'; -import {createPolarisContext} from '../../utilities/create-polaris-context'; - -describe('TestProvider', () => { - it('renders in strict mode', () => { - const testProvider = mount( - -
Polaris
-
, - ); - expect(testProvider).toContainReactComponent(React.StrictMode); - }); -}); - -function noop() {} diff --git a/src/test-utilities/types.ts b/src/test-utilities/types.ts new file mode 100644 index 00000000000..6843e6e2720 --- /dev/null +++ b/src/test-utilities/types.ts @@ -0,0 +1,33 @@ +import {ClientApplication} from '@shopify/app-bridge'; +// eslint-disable-next-line shopify/strict-component-boundaries +import {FrameContextType} from '../components/Frame'; +import {ThemeProviderContextType} from '../utilities/theme'; +import {ScrollLockManager} from '../utilities/scroll-lock-manager'; +import {StickyManager} from '../utilities/sticky-manager'; +import {AppBridgeOptions} from '../utilities/app-bridge'; +import {I18n, TranslationDictionary} from '../utilities/i18n'; +import {Link, LinkLikeComponent} from '../utilities/link'; + +export interface ComplexProviders { + themeProvider: ThemeProviderContextType; + frame: FrameContextType; +} + +export interface SimpleProvidersWithSameReturn { + scrollLockManager: ScrollLockManager; + stickyManager: StickyManager; +} +export interface SimpleProvidersWithAltReturn { + intl: TranslationDictionary | TranslationDictionary[]; + appBridge: AppBridgeOptions; + link: LinkLikeComponent; +} +export type SimpleProviders = SimpleProvidersWithSameReturn & + SimpleProvidersWithAltReturn; + +export type ReturnedContext = ComplexProviders & + SimpleProvidersWithSameReturn & { + intl: I18n; + appBridge: ClientApplication<{}> | null; + link: Link; + }; diff --git a/src/utilities/app-bridge/context.tsx b/src/utilities/app-bridge/context.tsx index acf2b3feb0d..d5d6e96b5ab 100644 --- a/src/utilities/app-bridge/context.tsx +++ b/src/utilities/app-bridge/context.tsx @@ -1,6 +1,6 @@ -import {createContext} from 'react'; +import React from 'react'; import {ClientApplication} from '@shopify/app-bridge'; -export const AppBridgeContext = createContext | null>( +export const AppBridgeContext = React.createContext | null>( null, ); diff --git a/src/utilities/banner-context.tsx b/src/utilities/banner-context.tsx index 2222625db81..eba581b998d 100644 --- a/src/utilities/banner-context.tsx +++ b/src/utilities/banner-context.tsx @@ -1,3 +1,3 @@ import React from 'react'; -export const BannerContext = React.createContext(false); +export const BannerContext = React.createContext(false); diff --git a/src/utilities/i18n/context.tsx b/src/utilities/i18n/context.tsx index faa7b8695a8..ecaec109511 100644 --- a/src/utilities/i18n/context.tsx +++ b/src/utilities/i18n/context.tsx @@ -1,4 +1,4 @@ -import {createContext} from 'react'; +import React from 'react'; import {I18n} from './I18n'; -export const I18nContext = createContext(new I18n({})); +export const I18nContext = React.createContext(new I18n({})); diff --git a/src/utilities/link/context.tsx b/src/utilities/link/context.tsx index 7243944ffca..8679714bc4b 100644 --- a/src/utilities/link/context.tsx +++ b/src/utilities/link/context.tsx @@ -1,4 +1,4 @@ -import {createContext} from 'react'; +import React from 'react'; import {Link} from './link'; -export const LinkContext = createContext(new Link()); +export const LinkContext = React.createContext(new Link()); diff --git a/src/utilities/scroll-lock-manager/context.tsx b/src/utilities/scroll-lock-manager/context.tsx index 2904d254152..3702930bdf9 100644 --- a/src/utilities/scroll-lock-manager/context.tsx +++ b/src/utilities/scroll-lock-manager/context.tsx @@ -1,6 +1,6 @@ -import {createContext} from 'react'; +import React from 'react'; import {ScrollLockManager} from './scroll-lock-manager'; -export const ScrollLockManagerContext = createContext( +export const ScrollLockManagerContext = React.createContext( null, ); diff --git a/src/utilities/sticky-manager/context.tsx b/src/utilities/sticky-manager/context.tsx index c543596880b..df6eb977cdc 100644 --- a/src/utilities/sticky-manager/context.tsx +++ b/src/utilities/sticky-manager/context.tsx @@ -1,4 +1,6 @@ -import {createContext} from 'react'; +import React from 'react'; import {StickyManager} from './sticky-manager'; -export const StickyManagerContext = createContext(null); +export const StickyManagerContext = React.createContext( + null, +); diff --git a/src/utilities/within-content-context.tsx b/src/utilities/within-content-context.tsx new file mode 100644 index 00000000000..7c42af29a83 --- /dev/null +++ b/src/utilities/within-content-context.tsx @@ -0,0 +1,3 @@ +import React from 'react'; + +export const WithinContentContext = React.createContext(false);