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
3 changes: 0 additions & 3 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: major
Type: removed

Remove the deprecated `GlobalNotices` component, `useGlobalNotices` hook and `globalNoticesStore`; use `@wordpress/notices` directly.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion projects/js-packages/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ export { default as MarkedLines } from './components/marked-lines/index.tsx';
export { default as DetailsViewer } from './components/details-viewer/index.tsx';
export { default as SidebarFooter } from './components/sidebar-footer/index.tsx';
export type { SidebarFooterProps } from './components/sidebar-footer/types.ts';
export * from './components/global-notices/index.ts';
export * from './components/navigator-modal/index.tsx';
6 changes: 0 additions & 6 deletions projects/js-packages/components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@
"types": "./build/components/checkbox-card/index.d.ts",
"default": "./build/components/checkbox-card/index.js"
},
"./global-notices": {
"jetpack:src": "./components/global-notices/index.ts",
"types": "./build/components/global-notices/index.d.ts",
"default": "./build/components/global-notices/index.js"
},
"./gravatar": {
"jetpack:src": "./components/gravatar/index.tsx",
"types": "./build/components/gravatar/index.d.ts",
Expand Down Expand Up @@ -133,7 +128,6 @@
"@wordpress/element": "10.1.0",
"@wordpress/i18n": "7.1.0",
"@wordpress/icons": "20.0.0",
"@wordpress/notices": "6.1.0",
"@wordpress/theme": "4.0.0",
"@wordpress/ui": "0.26.0",
"clsx": "2.1.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ const bulkEvent = () =>
.filter( ( [ name ] ) => name === 'jetpack_myjetpack_features_bulk_action' )
.at( -1 )?.[ 1 ];

jest.mock( '@automattic/jetpack-components', () => ( {
useGlobalNotices: () => ( { createSuccessNotice: mockSuccess, createErrorNotice: jest.fn() } ),
} ) );

jest.mock( '@automattic/jetpack-shared-stores', () => ( { store: 'modules-store' } ) );
jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) );

// A proxy rather than a spread: the real module's exports are read lazily, since spreading it
// here copies them before its circular imports have settled.
jest.mock( '@wordpress/data', () => {
const actual = jest.requireActual( '@wordpress/data' );
const useDispatch = () => ( { fetchModules: () => Promise.resolve( true ) } );
const useDispatch = () => ( {
fetchModules: () => Promise.resolve( true ),
createSuccessNotice: mockSuccess,
createErrorNotice: jest.fn(),
} );
return new Proxy( actual, {
get: ( target, key ) => ( key === 'useDispatch' ? useDispatch : target[ key ] ),
} );
Expand Down Expand Up @@ -90,7 +91,9 @@ describe( 'FeatureList with the bulk switch', () => {
await userEvent.click( screen.getByRole( 'checkbox', { name: 'Select boost' } ) );
await userEvent.click( screen.getByRole( 'button', { name: 'Activate' } ) );

await waitFor( () => expect( mockSuccess ).toHaveBeenCalledWith( '2 features activated.' ) );
await waitFor( () =>
expect( mockSuccess ).toHaveBeenCalledWith( '2 features activated.', { type: 'snackbar' } )
);
expect( mockApiFetch ).toHaveBeenCalledTimes( 1 );
expect( mockApiFetch ).toHaveBeenCalledWith(
expect.objectContaining( {
Expand Down Expand Up @@ -123,7 +126,9 @@ describe( 'FeatureList with the bulk switch', () => {
await userEvent.click( screen.getByRole( 'checkbox', { name: 'Select all features' } ) );
await userEvent.click( screen.getByRole( 'button', { name: 'Activate' } ) );

await waitFor( () => expect( mockSuccess ).toHaveBeenCalledWith( '3 features activated.' ) );
await waitFor( () =>
expect( mockSuccess ).toHaveBeenCalledWith( '3 features activated.', { type: 'snackbar' } )
);
expect( mockApiFetch ).toHaveBeenCalledWith(
expect.objectContaining( {
data: { active: true, modules: [ 'monitor', 'markdown' ], plugins: [ 'akismet' ] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ let mockResolved = true;
let mockFailed = false;

jest.mock( '@wordpress/api-fetch' );
jest.mock( '@automattic/jetpack-components', () => ( {
useGlobalNotices: () => ( { createSuccessNotice: jest.fn(), createErrorNotice: jest.fn() } ),
} ) );
jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) );
jest.mock( '@automattic/jetpack-script-data', () => ( {
getScriptData: () => ( { myJetpack: { offlineFeatures: mockOfflineSeed.current } } ),
Expand All @@ -36,6 +33,8 @@ jest.mock( '@automattic/jetpack-connection/use-connection-error-notice', () => (
jest.mock( '@wordpress/data', () => ( {
useDispatch: () => ( {
fetchModules: mockFetchModules,
createSuccessNotice: jest.fn(),
createErrorNotice: jest.fn(),
} ),
useSelect: ( selector: ( select: unknown ) => unknown ) =>
selector( () => ( {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ const mockFetchModules = jest.fn();

jest.mock( '@wordpress/api-fetch' );

jest.mock( '@automattic/jetpack-components', () => ( {
useGlobalNotices: () => ( { createSuccessNotice: mockSuccess, createErrorNotice: mockError } ),
} ) );

jest.mock( '@automattic/jetpack-shared-stores', () => ( { store: 'modules-store' } ) );
jest.mock( '@wordpress/notices', () => ( { store: 'core/notices' } ) );

jest.mock( '@wordpress/data', () => ( {
select: () => ( { hasFinishedResolution: () => false } ),
useDispatch: () => ( { fetchModules: mockFetchModules } ),
useDispatch: () => ( {
fetchModules: mockFetchModules,
createSuccessNotice: mockSuccess,
createErrorNotice: mockError,
} ),
} ) );

const mockApiFetch = apiFetch as unknown as jest.Mock;
Expand Down Expand Up @@ -142,7 +142,7 @@ describe( 'useBulkFeatureSwitch', () => {
method: 'POST',
data: { active: true, modules: [ 'stats' ], plugins: [ 'akismet' ] },
} );
expect( mockSuccess ).toHaveBeenCalledWith( '2 features activated.' );
expect( mockSuccess ).toHaveBeenCalledWith( '2 features activated.', { type: 'snackbar' } );
expect( mockError ).not.toHaveBeenCalled();
} );

Expand Down Expand Up @@ -219,8 +219,10 @@ describe( 'useBulkFeatureSwitch', () => {
)
);

expect( mockSuccess ).toHaveBeenCalledWith( '1 feature deactivated.' );
expect( mockError ).toHaveBeenCalledWith( 'akismet feature: This plugin runs the page.' );
expect( mockSuccess ).toHaveBeenCalledWith( '1 feature deactivated.', { type: 'snackbar' } );
expect( mockError ).toHaveBeenCalledWith( 'akismet feature: This plugin runs the page.', {
type: 'snackbar',
} );
} );

it( 'resolves to the features that failed, so they can be kept for a retry', async () => {
Expand Down Expand Up @@ -266,7 +268,9 @@ describe( 'useBulkFeatureSwitch', () => {
);

expect( mockError ).toHaveBeenCalledTimes( 1 );
expect( mockError ).toHaveBeenCalledWith( `akismet feature, boost feature: ${ reason }` );
expect( mockError ).toHaveBeenCalledWith( `akismet feature, boost feature: ${ reason }`, {
type: 'snackbar',
} );
expect( mockSuccess ).not.toHaveBeenCalled();
} );

Expand All @@ -277,7 +281,7 @@ describe( 'useBulkFeatureSwitch', () => {

await act( () => result.current.bulk.run( [ moduleState( 'stats', 'inactive' ) ], true ) );

expect( mockError ).toHaveBeenCalledWith( 'Server error.' );
expect( mockError ).toHaveBeenCalledWith( 'Server error.', { type: 'snackbar' } );
expect( mockSuccess ).not.toHaveBeenCalled();
expect( result.current.requested ).toEqual( {} );
} );
Expand Down
Loading
Loading