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

Jconabree/issue 3873 talon exports #3874

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
2 changes: 1 addition & 1 deletion packages/pagebuilder/lib/ContentTypes/Banner/banner.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Button from '@magento/venia-ui/lib/components/Button/button';
import resolveLinkProps from '@magento/peregrine/lib/util/resolveLinkProps';
import { Link, useHistory } from 'react-router-dom';
import resourceUrl from '@magento/peregrine/lib/util/makeUrl';
import useIntersectionObserver from '@magento/peregrine/lib/hooks/useIntersectionObserver';
import { useIntersectionObserver } from '@magento/peregrine/lib/hooks/useIntersectionObserver';
import { useMediaQuery } from '@magento/peregrine/lib/hooks/useMediaQuery';
import handleHtmlContentClick from '../../handleHtmlContentClick';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { mockSetPageLoading } from '@magento/peregrine/lib/context/app';
import { mockSetComponentMap } from '@magento/peregrine/lib/context/rootComponents';

import { getRootComponent } from '../../talons/MagentoRoute/helpers';
import useDelayedTransition from '../useDelayedTransition';
import { useDelayedTransition } from '../useDelayedTransition';

// jest.mock('react');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useAppContext } from '../../context/app';
import useInternalLink, { SHIMMER_TYPE_SUFFIX } from '../useInternalLink';
import { useInternalLink, SHIMMER_TYPE_SUFFIX } from '../useInternalLink';

jest.mock('../../context/app', () => ({
useAppContext: jest.fn()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect } from 'react';

import { createTestInstance } from '@magento/peregrine';
import useIntersectionObserver from '../useIntersectionObserver';
import { useIntersectionObserver } from '../useIntersectionObserver';

const log = jest.fn();

Expand Down
2 changes: 1 addition & 1 deletion packages/peregrine/lib/hooks/__tests__/useScript.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { act, renderHook } from '@testing-library/react-hooks';

import useScript from '../useScript';
import { useScript } from '../useScript';

describe('#useScript', () => {
it('returns idle if script not provided', () => {
Expand Down
4 changes: 1 addition & 3 deletions packages/peregrine/lib/hooks/useDelayedTransition.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { getRootComponent } from '../talons/MagentoRoute/helpers';

const DELAY_MESSAGE_PREFIX = 'DELAY:';

const useDelayedTransition = () => {
export const useDelayedTransition = () => {
const { pathname } = useLocation();
const history = useHistory();
const client = useApolloClient();
Expand Down Expand Up @@ -123,5 +123,3 @@ const useDelayedTransition = () => {
};
}, [client, resolveUrlQuery, setComponentMap, setPageLoading]);
};

export default useDelayedTransition;
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useGoogleReCaptcha } from '../useGoogleReCaptcha';
jest.mock('@magento/peregrine/lib/hooks/useScript', () => {
return {
__esModule: true,
default: jest.fn().mockImplementation(() => {
useScript: jest.fn().mockImplementation(() => {
return 'ready';
})
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useCallback, useEffect, useState } from 'react';
import { useQuery } from '@apollo/client';

import useScript from '@magento/peregrine/lib/hooks/useScript';
import { useScript } from '@magento/peregrine/lib/hooks/useScript';
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';

import defaultOperations from './googleReCaptchaConfig.gql';
Expand Down
2 changes: 1 addition & 1 deletion packages/peregrine/lib/hooks/useInternalLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAppContext } from '../context/app';

export const SHIMMER_TYPE_SUFFIX = '_SHIMMER';

export default rootType => {
export const useInternalLink = rootType => {
const [, appApi] = useAppContext();
const { actions: appActions } = appApi;
const { setNextRootComponent } = appActions;
Expand Down
2 changes: 1 addition & 1 deletion packages/peregrine/lib/hooks/useIntersectionObserver.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export default () => {
export const useIntersectionObserver = () => {
if (typeof IntersectionObserver === 'undefined') {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/peregrine/lib/hooks/useIsInViewport.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useEffect, useState } from 'react';

import useIntersectionObserver from '@magento/peregrine/lib/hooks/useIntersectionObserver';
import { useIntersectionObserver } from '@magento/peregrine/lib/hooks/useIntersectionObserver';

export const useIsInViewport = props => {
const { elementRef, renderOnce = true } = props;
Expand Down
2 changes: 1 addition & 1 deletion packages/peregrine/lib/hooks/useScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { useState, useEffect } from 'react';
*
* @returns {string} - returns one of the possible status: "idle", "loading", "ready" or "error"
*/
export default src => {
export const useScript = src => {
// Keep track of script status ("idle", "loading", "ready", "error")
const [status, setStatus] = useState(src ? 'loading' : 'idle');
useEffect(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@ jest.mock('@apollo/client', () => {
};
});

jest.mock('../../../hooks/useInternalLink', () =>
jest.fn(() => ({
jest.mock('../../../hooks/useInternalLink', () => ({
useInternalLink: jest.fn(() => ({
setShimmerType: jest.fn()
}))
);
}));

const storeConfigResponse = {
data: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo } from 'react';
import { useQuery } from '@apollo/client';
import useInternalLink from '../../hooks/useInternalLink';
import { useInternalLink } from '../../hooks/useInternalLink';

import mergeOperations from '../../util/shallowMerge';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const props = {

const log = jest.fn();

jest.mock('../../../hooks/useInternalLink', () =>
jest.fn(() => ({
jest.mock('../../../hooks/useInternalLink', () => ({
useInternalLink: jest.fn(() => ({
setShimmerType: jest.fn()
}))
);
}));

const Component = props => {
const talonProps = useCategoryTile(props);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* Deprecated in PWA-12.1.0*/

import { useMemo } from 'react';
import useInternalLink from '../../hooks/useInternalLink';
import { useInternalLink } from '../../hooks/useInternalLink';

const previewImageSize = 480;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { createTestInstance } from '@magento/peregrine';
import { useQuery } from '@apollo/client';
import useContactLink from '../useContactLink';
import { useContactLink } from '../useContactLink';

jest.mock('@apollo/client', () => ({
useQuery: jest.fn()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { createTestInstance } from '@magento/peregrine';

import { useMutation, useQuery } from '@apollo/client';
import useContactPage from '../useContactPage';
import { useContactPage } from '../useContactPage';

/*
* Mocks.
Expand Down
4 changes: 2 additions & 2 deletions packages/peregrine/lib/talons/ContactPage/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { default as useContactPage } from './useContactPage';
export { default as useContactLink } from './useContactLink';
export { useContactPage } from './useContactPage';
export { useContactLink } from './useContactLink';
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useQuery } from '@apollo/client';
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
import DEFAULT_OPERATIONS from './contactUs.gql';

export default (props = {}) => {
export const useContactLink = (props = {}) => {
const { getStoreConfigQuery } = mergeOperations(
DEFAULT_OPERATIONS,
props.operations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useMutation, useQuery } from '@apollo/client';
import mergeOperations from '@magento/peregrine/lib/util/shallowMerge';
import DEFAULT_OPERATIONS from './contactUs.gql';

export default props => {
export const useContactPage = props => {
const { cmsBlockIdentifiers = [], operations } = props;
const {
contactMutation,
Expand Down
2 changes: 1 addition & 1 deletion packages/peregrine/lib/talons/Gallery/useGalleryItem.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { isSupportedProductType as isSupported } from '@magento/peregrine/lib/util/isSupportedProductType';
import { useEventingContext } from '@magento/peregrine/lib/context/eventing';
import { useCallback, useEffect, useRef } from 'react';
import useIntersectionObserver from '@magento/peregrine/lib/hooks/useIntersectionObserver';
import { useIntersectionObserver } from '@magento/peregrine/lib/hooks/useIntersectionObserver';

export const useGalleryItem = (props = {}) => {
const [, { dispatch }] = useEventingContext();
Expand Down
8 changes: 5 additions & 3 deletions packages/peregrine/lib/talons/Link/__tests__/useLink.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useRef } from 'react';
import { act, create } from 'react-test-renderer';
import { useLazyQuery } from '@apollo/client';
import useLink from '../useLink';
import useIntersectionObserver from '../../../hooks/useIntersectionObserver';
import { useLink } from '../useLink';
import { useIntersectionObserver } from '../../../hooks/useIntersectionObserver';

jest.mock('react', () => {
const react = jest.requireActual('react');
Expand Down Expand Up @@ -34,7 +34,9 @@ jest.mock('../../../util/makeUrl', () =>
})
);

jest.mock('../../../hooks/useIntersectionObserver');
jest.mock('../../../hooks/useIntersectionObserver', () => ({
useIntersectionObserver: jest.fn()
}));

const mockIntersectionObserve = jest.fn();
const mockIntersectionUnobserve = jest.fn();
Expand Down
6 changes: 2 additions & 4 deletions packages/peregrine/lib/talons/Link/useLink.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { useEffect, useRef } from 'react';
import { useLazyQuery } from '@apollo/client';
import useIntersectionObserver from '../../hooks/useIntersectionObserver';
import { useIntersectionObserver } from '../../hooks/useIntersectionObserver';
import resourceUrl from '../../util/makeUrl';
import mergeOperations from '../../util/shallowMerge';
import DEFAULT_OPERATIONS from '../MagentoRoute/magentoRoute.gql';

const useLink = (props, passedOperations = {}) => {
export const useLink = (props, passedOperations = {}) => {
const { innerRef: originalRef, to } = props;
const shouldPrefetch = props.prefetchType || props.shouldPrefetch;
const operations = shouldPrefetch
Expand Down Expand Up @@ -65,5 +65,3 @@ const useLink = (props, passedOperations = {}) => {
ref: elementRef
};
};

export default useLink;
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ jest.mock('react-router-dom', () => ({
useLocation: jest.fn(() => ({ pathname: '/venia-tops.html' }))
}));

jest.mock('../../../hooks/useInternalLink', () =>
jest.fn(() => ({
jest.mock('../../../hooks/useInternalLink', () => ({
useInternalLink: jest.fn(() => ({
setShimmerType: jest.fn().mockName('onNavigate')
}))
);
}));

jest.mock('../../../hooks/useEventListener', () => ({
useEventListener: jest.fn()
Expand Down
2 changes: 1 addition & 1 deletion packages/peregrine/lib/talons/MegaMenu/useMegaMenu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { useMemo, useState, useCallback, useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import useInternalLink from '../../hooks/useInternalLink';
import { useInternalLink } from '../../hooks/useInternalLink';

import { useQuery } from '@apollo/client';
import { useEventListener } from '../../hooks/useEventListener';
Expand Down
2 changes: 1 addition & 1 deletion packages/peregrine/lib/talons/Navigation/useNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useAppContext } from '../../context/app';
import { useCatalogContext } from '../../context/catalog';
import { useUserContext } from '../../context/user';
import { useAwaitQuery } from '../../hooks/useAwaitQuery';
import useInternalLink from '../../hooks/useInternalLink';
import { useInternalLink } from '../../hooks/useInternalLink';

import DEFAULT_OPERATIONS from './navigation.gql';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { act, create } from 'react-test-renderer';
import { useAppContext } from '../../../context/app';
import usePageLoadingIndicator from '../usePageLoadingIndicator';
import { usePageLoadingIndicator } from '../usePageLoadingIndicator';

jest.mock('../../../context/app', () => {
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useAppContext } from '../../context/app';

const GROUP_LOADING_DELAY = 750;

export default () => {
export const usePageLoadingIndicator = () => {
const [{ isPageLoading }] = useAppContext();
const doneTimeoutRef = useRef();
const [loadingState, setLoadingState] = useState('off');
Expand Down
4 changes: 3 additions & 1 deletion packages/venia-ui/lib/components/App/__tests__/app.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ jest.mock('../../Navigation', () => 'Navigation');
jest.mock('../../Routes', () => 'Routes');
jest.mock('../../ToastContainer', () => 'ToastContainer');
jest.mock('@magento/peregrine/lib/hooks/useDelayedTransition', () => {
return jest.fn();
return {
useDelayedTransition: jest.fn()
};
});

const mockAddToast = jest.fn();
Expand Down
2 changes: 1 addition & 1 deletion packages/venia-ui/lib/components/App/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useIntl } from 'react-intl';
import { array, func, shape, string } from 'prop-types';

import { useToasts } from '@magento/peregrine';
import useDelayedTransition from '@magento/peregrine/lib/hooks/useDelayedTransition';
import { useDelayedTransition } from '@magento/peregrine/lib/hooks/useDelayedTransition';
import { useApp } from '@magento/peregrine/lib/talons/App/useApp';

import globalCSS from '../../index.module.css';
Expand Down
14 changes: 8 additions & 6 deletions packages/venia-ui/lib/components/Link/__tests__/link.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React from 'react';
import { act, create } from 'react-test-renderer';
import { Link as RouterLink } from 'react-router-dom';
import useLink from '@magento/peregrine/lib/talons/Link/useLink';
import { useLink } from '@magento/peregrine/lib/talons/Link/useLink';
import Link from '../link';

jest.mock('@magento/peregrine/lib/talons/Link/useLink', () => {
return jest.fn(({ innerRef }) => {
return {
ref: innerRef
};
});
return {
useLink: jest.fn(({ innerRef }) => {
return {
ref: innerRef
};
})
};
});

jest.mock('react-router-dom', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/venia-ui/lib/components/Link/link.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { Link as RouterLink } from 'react-router-dom';
import { bool } from 'prop-types';
import useLink from '@magento/peregrine/lib/talons/Link/useLink';
import { useLink } from '@magento/peregrine/lib/talons/Link/useLink';

/**
* @kind functional component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { act, create } from 'react-test-renderer';
import usePageLoadingIndicator from '@magento/peregrine/lib/talons/PageLoadingIndicator/usePageLoadingIndicator';
import { usePageLoadingIndicator } from '@magento/peregrine/lib/talons/PageLoadingIndicator/usePageLoadingIndicator';
import PageLoadingIndicator from '../pageLoadingIndicator';

jest.mock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { shape, string, bool } from 'prop-types';
import { useStyle } from '../../classify';
import defaultClasses from './pageLoadingIndicator.module.css';
import usePageLoadingIndicator from '@magento/peregrine/lib/talons/PageLoadingIndicator/usePageLoadingIndicator';
import { usePageLoadingIndicator } from '@magento/peregrine/lib/talons/PageLoadingIndicator/usePageLoadingIndicator';

const PageLoadingIndicator = props => {
const classes = useStyle(defaultClasses, props.classes);
Expand Down