-
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 #2034 from woocommerce/release/2.5.1
release 2.5.1
- Loading branch information
Showing
68 changed files
with
2,505 additions
and
356 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,19 @@ | ||
name: 'Merge the release to develop' | ||
run-name: Merge the released `${{ github.head_ref }}` from `trunk` to `develop` | ||
|
||
# **What it does**: Merges trunk to develop after `release/*` is merged to `trunk`. | ||
# **Why we have it**: To automate the release process and follow git-flow. | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- closed | ||
branches: | ||
- trunk | ||
|
||
jobs: | ||
automerge_trunk: | ||
name: Automerge released trunk | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: woocommerce/grow/automerge-released-trunk@actions-v1 |
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,12 @@ | ||
{ | ||
"phpVersion": "8.0", | ||
"plugins": [ | ||
"https://downloads.wordpress.org/plugin/woocommerce.latest-stable.zip", | ||
"https://github.com/WP-API/Basic-Auth/archive/master.zip", | ||
"." | ||
], | ||
"lifecycleScripts": { | ||
"afterStart": "./tests/e2e/bin/test-env-setup.sh", | ||
"afterClean": "./tests/e2e/bin/test-env-setup.sh" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import '@testing-library/jest-dom'; | ||
import { screen, render, act } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import AdaptiveForm from './adaptive-form'; | ||
|
||
const alwaysValid = () => ( {} ); | ||
|
||
const delayOneSecond = () => new Promise( ( r ) => setTimeout( r, 1000 ) ); | ||
|
||
describe( 'AdaptiveForm', () => { | ||
it( 'Should have `formContext.adapter` with functions and initial states', () => { | ||
const children = jest.fn(); | ||
|
||
render( | ||
<AdaptiveForm validate={ alwaysValid }>{ children }</AdaptiveForm> | ||
); | ||
|
||
const formContextSchema = expect.objectContaining( { | ||
adapter: expect.objectContaining( { | ||
isSubmitting: false, | ||
isSubmitted: false, | ||
submitter: null, | ||
validationRequestCount: 0, | ||
requestedShowValidation: false, | ||
showValidation: expect.any( Function ), | ||
hideValidation: expect.any( Function ), | ||
} ), | ||
} ); | ||
|
||
expect( children ).toHaveBeenLastCalledWith( formContextSchema ); | ||
} ); | ||
|
||
it( 'Should provide `isSubmitting` and `isSubmitted` states via adapter', async () => { | ||
const inspect = jest.fn(); | ||
|
||
render( | ||
<AdaptiveForm validate={ alwaysValid } onSubmit={ delayOneSecond }> | ||
{ ( formContext ) => { | ||
const { isSubmitting, isSubmitted } = formContext.adapter; | ||
inspect( isSubmitting, isSubmitted ); | ||
|
||
return <button onClick={ formContext.handleSubmit } />; | ||
} } | ||
</AdaptiveForm> | ||
); | ||
|
||
expect( inspect ).toHaveBeenLastCalledWith( false, false ); | ||
|
||
await act( async () => { | ||
return userEvent.click( screen.getByRole( 'button' ) ); | ||
} ); | ||
|
||
expect( inspect ).toHaveBeenLastCalledWith( true, false ); | ||
|
||
await act( async () => { | ||
jest.runOnlyPendingTimers(); | ||
} ); | ||
|
||
expect( inspect ).toHaveBeenLastCalledWith( false, true ); | ||
} ); | ||
|
||
it( 'Should be able to signal failed submission to reset `isSubmitting` and `isSubmitted` states', async () => { | ||
const inspect = jest.fn(); | ||
|
||
const onSubmit = ( values, enhancer ) => { | ||
enhancer.signalFailedSubmission(); | ||
return delayOneSecond(); | ||
}; | ||
|
||
render( | ||
<AdaptiveForm validate={ alwaysValid } onSubmit={ onSubmit }> | ||
{ ( formContext ) => { | ||
const { isSubmitting, isSubmitted } = formContext.adapter; | ||
inspect( isSubmitting, isSubmitted ); | ||
|
||
return <button onClick={ formContext.handleSubmit } />; | ||
} } | ||
</AdaptiveForm> | ||
); | ||
|
||
await act( async () => { | ||
return userEvent.click( screen.getByRole( 'button' ) ); | ||
} ); | ||
|
||
expect( inspect ).toHaveBeenLastCalledWith( true, false ); | ||
|
||
await act( async () => { | ||
jest.runOnlyPendingTimers(); | ||
} ); | ||
|
||
expect( inspect ).toHaveBeenLastCalledWith( false, false ); | ||
} ); | ||
|
||
it( 'Should provide the element triggering the form submission via `submitter` until the processing is completed', async () => { | ||
const inspectOnSubmit = jest.fn(); | ||
const inspectSubmitter = jest.fn(); | ||
|
||
render( | ||
<AdaptiveForm validate={ alwaysValid } onSubmit={ inspectOnSubmit }> | ||
{ ( formContext ) => { | ||
inspectSubmitter( formContext.adapter.submitter ); | ||
|
||
return ( | ||
<> | ||
<button onClick={ formContext.handleSubmit }> | ||
A | ||
</button> | ||
|
||
<button onClick={ formContext.handleSubmit }> | ||
B | ||
</button> | ||
</> | ||
); | ||
} } | ||
</AdaptiveForm> | ||
); | ||
|
||
const [ buttonA, buttonB ] = screen.getAllByRole( 'button' ); | ||
|
||
expect( inspectOnSubmit ).toHaveBeenCalledTimes( 0 ); | ||
|
||
await act( async () => { | ||
return userEvent.click( buttonA ); | ||
} ); | ||
|
||
expect( inspectSubmitter ).toHaveBeenCalledWith( buttonA ); | ||
expect( inspectSubmitter ).toHaveBeenLastCalledWith( null ); | ||
expect( inspectOnSubmit ).toHaveBeenCalledTimes( 1 ); | ||
expect( inspectOnSubmit ).toHaveBeenLastCalledWith( | ||
{}, | ||
expect.objectContaining( { submitter: buttonA } ) | ||
); | ||
|
||
inspectSubmitter.mockClear(); | ||
|
||
await act( async () => { | ||
return userEvent.click( buttonB ); | ||
} ); | ||
|
||
expect( inspectSubmitter ).toHaveBeenCalledWith( buttonB ); | ||
expect( inspectSubmitter ).toHaveBeenLastCalledWith( null ); | ||
expect( inspectOnSubmit ).toHaveBeenCalledTimes( 2 ); | ||
expect( inspectOnSubmit ).toHaveBeenLastCalledWith( | ||
{}, | ||
expect.objectContaining( { submitter: buttonB } ) | ||
); | ||
} ); | ||
|
||
it( 'Should be able to accumulate and reset the validation request count and requested state', async () => { | ||
const inspect = jest.fn(); | ||
|
||
render( | ||
<AdaptiveForm validate={ alwaysValid }> | ||
{ ( { adapter } ) => { | ||
inspect( | ||
adapter.requestedShowValidation, | ||
adapter.validationRequestCount | ||
); | ||
|
||
return ( | ||
<> | ||
<button onClick={ adapter.showValidation }> | ||
request | ||
</button> | ||
|
||
<button onClick={ adapter.hideValidation }> | ||
reset | ||
</button> | ||
</> | ||
); | ||
} } | ||
</AdaptiveForm> | ||
); | ||
|
||
const requestButton = screen.getByRole( 'button', { name: 'request' } ); | ||
const resetButton = screen.getByRole( 'button', { name: 'reset' } ); | ||
|
||
expect( inspect ).toHaveBeenLastCalledWith( false, 0 ); | ||
|
||
await userEvent.click( requestButton ); | ||
|
||
expect( inspect ).toHaveBeenLastCalledWith( true, 1 ); | ||
|
||
await userEvent.click( requestButton ); | ||
|
||
expect( inspect ).toHaveBeenLastCalledWith( true, 2 ); | ||
|
||
await userEvent.click( resetButton ); | ||
|
||
expect( inspect ).toHaveBeenLastCalledWith( false, 0 ); | ||
} ); | ||
} ); |
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
Oops, something went wrong.