-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix-qit-security
- Loading branch information
Showing
77 changed files
with
3,099 additions
and
443 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Call a function when an element is available in the DOM. | ||
* | ||
* @param {string} selector The selector to look for. | ||
* @param {Function} callable fThe function to call when the element is available. | ||
* @param {Array} params The parameters to pass to the callable function. | ||
*/ | ||
export function callWhenElementIsAvailable( selector, callable, params = [] ) { | ||
const checkoutBlock = document.querySelector( | ||
'[data-block-name="woocommerce/checkout"]' | ||
); | ||
|
||
if ( ! checkoutBlock ) { | ||
return; | ||
} | ||
|
||
const observer = new MutationObserver( ( mutationList, obs ) => { | ||
if ( document.querySelector( selector ) ) { | ||
// Element found, run the function and disconnect the observer. | ||
callable( ...params ); | ||
obs.disconnect(); | ||
} | ||
} ); | ||
|
||
observer.observe( checkoutBlock, { | ||
childList: true, | ||
subtree: true, | ||
} ); | ||
} |
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
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
73 changes: 73 additions & 0 deletions
73
client/components/webhook-description/__tests__/index.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,73 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { WebhookDescription } from '..'; | ||
import { useAccount } from 'wcstripe/data/account'; | ||
import useWebhookStateMessage from 'wcstripe/settings/account-details/use-webhook-state-message'; | ||
|
||
jest.mock( 'wcstripe/data/account', () => ( { | ||
useAccount: jest.fn(), | ||
} ) ); | ||
|
||
jest.mock( 'wcstripe/settings/account-details/use-webhook-state-message' ); | ||
|
||
beforeEach( () => { | ||
useAccount.mockReturnValue( { | ||
data: { webhook_url: 'example.com' }, | ||
} ); | ||
} ); | ||
|
||
describe( 'WebhookDescription', () => { | ||
it( 'regular message (not a warning), no information component', () => { | ||
useWebhookStateMessage.mockImplementation( () => { | ||
return { | ||
message: 'Some message', | ||
requestStatus: 'success', | ||
refreshMessage: jest.fn(), | ||
}; | ||
} ); | ||
|
||
render( <WebhookDescription isWebhookSecretEntered={ true } /> ); | ||
|
||
expect( | ||
screen.queryByTestId( 'webhook-information' ) | ||
).not.toBeInTheDocument(); | ||
expect( | ||
screen.queryByTestId( 'warning-icon' ) | ||
).not.toBeInTheDocument(); | ||
} ); | ||
|
||
it( 'regular message (not a warning), with information component', () => { | ||
useWebhookStateMessage.mockImplementation( () => { | ||
return { | ||
message: 'Some message', | ||
requestStatus: 'success', | ||
refreshMessage: jest.fn(), | ||
}; | ||
} ); | ||
|
||
render( <WebhookDescription isWebhookSecretEntered={ false } /> ); | ||
|
||
expect( | ||
screen.queryByTestId( 'webhook-information' ) | ||
).toBeInTheDocument(); | ||
expect( | ||
screen.queryByTestId( 'warning-icon' ) | ||
).not.toBeInTheDocument(); | ||
} ); | ||
|
||
it( 'warning message, with information component', () => { | ||
useWebhookStateMessage.mockImplementation( () => { | ||
return { | ||
message: 'Warning: Some message', | ||
requestStatus: 'success', | ||
refreshMessage: jest.fn(), | ||
}; | ||
} ); | ||
|
||
render( <WebhookDescription isWebhookSecretEntered={ false } /> ); | ||
|
||
expect( | ||
screen.queryByTestId( 'webhook-information' ) | ||
).toBeInTheDocument(); | ||
expect( screen.queryByTestId( 'warning-icon' ) ).toBeInTheDocument(); | ||
} ); | ||
} ); |
Oops, something went wrong.