-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2523 from woocommerce/release/2.8.2
Release 2.8.2
- Loading branch information
Showing
36 changed files
with
1,133 additions
and
435 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
js/src/components/enable-new-product-sync-notice.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import '@testing-library/jest-dom'; | ||
import { render } from '@testing-library/react'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import useGoogleMCAccount from '.~/hooks/useGoogleMCAccount'; | ||
import EnableNewProductSyncNotice from './enable-new-product-sync-notice'; | ||
|
||
jest.mock( '.~/hooks/useGoogleMCAccount' ); | ||
|
||
describe( 'Enable New Product Sync Notice', () => { | ||
it( 'should render the notice if the account has not switched to new product sync', () => { | ||
useGoogleMCAccount.mockImplementation( () => { | ||
return { | ||
hasFinishedResolution: true, | ||
googleMCAccount: { | ||
notification_service_enabled: true, | ||
wpcom_rest_api_status: null, | ||
}, | ||
}; | ||
} ); | ||
|
||
const { getByText, getByRole } = render( | ||
<EnableNewProductSyncNotice /> | ||
); | ||
|
||
expect( | ||
getByText( | ||
'We will soon transition to a new and improved method for synchronizing product data with Google.' | ||
) | ||
).toBeInTheDocument(); | ||
|
||
const button = getByRole( 'button', { | ||
name: /Get early access/i, | ||
} ); | ||
|
||
expect( button ).toBeEnabled(); | ||
} ); | ||
it( 'should not render the notice if the account has switched to new product sync', () => { | ||
useGoogleMCAccount.mockImplementation( () => { | ||
return { | ||
hasFinishedResolution: true, | ||
googleMCAccount: { | ||
notification_service_enabled: true, | ||
wpcom_rest_api_status: 'approved', | ||
}, | ||
}; | ||
} ); | ||
|
||
const { queryByText, queryByRole } = render( | ||
<EnableNewProductSyncNotice /> | ||
); | ||
|
||
expect( | ||
queryByText( | ||
'We will soon transition to a new and improved method for synchronizing product data with Google.' | ||
) | ||
).not.toBeInTheDocument(); | ||
|
||
expect( | ||
queryByRole( 'button', { name: /Get early access/i } ) | ||
).not.toBeInTheDocument(); | ||
} ); | ||
it( 'should not render the notice if the notification service is not enabled', () => { | ||
useGoogleMCAccount.mockImplementation( () => { | ||
return { | ||
hasFinishedResolution: true, | ||
googleMCAccount: { | ||
notification_service_enabled: false, | ||
wpcom_rest_api_status: 'approved', | ||
}, | ||
}; | ||
} ); | ||
|
||
const { queryByText, queryByRole } = render( | ||
<EnableNewProductSyncNotice /> | ||
); | ||
|
||
expect( | ||
queryByText( | ||
'We will soon transition to a new and improved method for synchronizing product data with Google.' | ||
) | ||
).not.toBeInTheDocument(); | ||
|
||
expect( | ||
queryByRole( 'button', { name: /Get early access/i } ) | ||
).not.toBeInTheDocument(); | ||
} ); | ||
|
||
it( 'should not render the notice if googleMCAccount is undefined because the google account is not connected or missing scopes', () => { | ||
useGoogleMCAccount.mockImplementation( () => { | ||
return { | ||
hasFinishedResolution: true, | ||
googleMCAccount: undefined, | ||
}; | ||
} ); | ||
|
||
const { queryByText, queryByRole } = render( | ||
<EnableNewProductSyncNotice /> | ||
); | ||
|
||
expect( | ||
queryByText( | ||
'We will soon transition to a new and improved method for synchronizing product data with Google.' | ||
) | ||
).not.toBeInTheDocument(); | ||
|
||
expect( | ||
queryByRole( 'button', { name: /Get early access/i } ) | ||
).not.toBeInTheDocument(); | ||
} ); | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import apiFetch from '@wordpress/api-fetch'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { useAppDispatch } from '.~/data'; | ||
|
||
jest.mock( '@wordpress/api-fetch', () => { | ||
const impl = jest.fn().mockName( '@wordpress/api-fetch' ); | ||
impl.use = jest.fn().mockName( 'apiFetch.use' ); | ||
return impl; | ||
} ); | ||
|
||
describe( 'createAdsCampaign', () => { | ||
let navigatorGetter; | ||
|
||
const mockFetch = jest | ||
.fn() | ||
.mockResolvedValue( { targeted_locations: [ 'ES' ] } ); | ||
|
||
beforeEach( () => { | ||
jest.clearAllMocks(); | ||
apiFetch.mockImplementation( ( args ) => { | ||
return mockFetch( args ); | ||
} ); | ||
|
||
navigatorGetter = jest.spyOn( window.navigator, 'userAgent', 'get' ); | ||
} ); | ||
|
||
it( 'If the user agent is not set to wc-ios or wc-android, the label should default to wc-web', async () => { | ||
const { result } = renderHook( () => useAppDispatch() ); | ||
|
||
await result.current.createAdsCampaign( 100, [ 'ES' ] ); | ||
|
||
expect( mockFetch ).toHaveBeenCalledTimes( 1 ); | ||
expect( mockFetch ).toHaveBeenCalledWith( { | ||
path: '/wc/gla/ads/campaigns', | ||
method: 'POST', | ||
data: { | ||
amount: 100, | ||
targeted_locations: [ 'ES' ], | ||
label: 'wc-web', | ||
}, | ||
} ); | ||
} ); | ||
|
||
it( 'If the user agent is set to wc-ios the label should be wc-ios', async () => { | ||
navigatorGetter.mockReturnValue( | ||
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 wc-ios/19.7.1' | ||
); | ||
|
||
const { result } = renderHook( () => useAppDispatch() ); | ||
|
||
await result.current.createAdsCampaign( 100, [ 'ES' ] ); | ||
|
||
expect( mockFetch ).toHaveBeenCalledTimes( 1 ); | ||
expect( mockFetch ).toHaveBeenCalledWith( { | ||
path: '/wc/gla/ads/campaigns', | ||
method: 'POST', | ||
data: { | ||
amount: 100, | ||
targeted_locations: [ 'ES' ], | ||
label: 'wc-ios', | ||
}, | ||
} ); | ||
} ); | ||
|
||
it( 'If the user agent is set to wc-android the label should be wc-android', async () => { | ||
navigatorGetter.mockReturnValue( | ||
'Mozilla/5.0 (iPhone; CPU iPhone OS 17_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 wc-android/19.7.1' | ||
); | ||
|
||
const { result } = renderHook( () => useAppDispatch() ); | ||
|
||
await result.current.createAdsCampaign( 100, [ 'ES' ] ); | ||
|
||
expect( mockFetch ).toHaveBeenCalledTimes( 1 ); | ||
expect( mockFetch ).toHaveBeenCalledWith( { | ||
path: '/wc/gla/ads/campaigns', | ||
method: 'POST', | ||
data: { | ||
amount: 100, | ||
targeted_locations: [ 'ES' ], | ||
label: 'wc-android', | ||
}, | ||
} ); | ||
} ); | ||
} ); |
Oops, something went wrong.