-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Add the authorization Step for the Application Passwords #96891
Merged
+466
−5
Merged
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
f9ae282
Add the authorization Step for the Application Passwords
valterlorran a045d7b
Add the notice when the authorization is request and add the texts
valterlorran 5aacf80
Apply the style to the component
valterlorran 904a860
Added the submit logic for the new step
valterlorran fb0316c
Add the tests
valterlorran 228b6f3
Add the action to skip the error on storing the credentials
valterlorran e7c3fd6
Add the redirect to the fallback step
valterlorran 0349e4f
Fix the authorizationUrl parameter name
valterlorran 4a0deb8
Try fix the errors
valterlorran 93a7874
Fix tests
valterlorran f213398
Add the back button logic
valterlorran 0aa14a1
Fix the from param
valterlorran bff33e2
Fix design issues
valterlorran 0ce0f81
Fix button test
valterlorran e55dca2
We should encode the success_url to allow the source site to redirect…
valterlorran 8b8ca48
Fix the authorizationUrl parameter
valterlorran File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add the tests
- Loading branch information
commit fb0316c343c974de55a3d67023ace4b450b5fa36
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
...repository/site-migration-application-password-authorization/components/authorization.tsx
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,58 @@ | ||
import { NextButton } from '@automattic/onboarding'; | ||
import { check, Icon } from '@wordpress/icons'; | ||
import { useTranslate } from 'i18n-calypso'; | ||
|
||
const AuthorizationBenefits = ( { benefits }: { benefits: string[] } ) => { | ||
return ( | ||
<div className="site-migration-application-password-authorization__benefits"> | ||
{ benefits.map( ( benefit, index ) => ( | ||
<div | ||
className="site-migration-application-password-authorization__benefits-item" | ||
key={ index } | ||
> | ||
<div className="site-migration-application-password-authorization__benefits-item-icon"> | ||
<Icon icon={ check } size={ 20 } /> | ||
</div> | ||
<span>{ benefit }</span> | ||
</div> | ||
) ) } | ||
</div> | ||
); | ||
}; | ||
|
||
interface AuthorizationProps { | ||
onShareCredentialsClick: () => void; | ||
onAuthorizationClick: () => void; | ||
} | ||
|
||
const Authorization = ( { onShareCredentialsClick, onAuthorizationClick }: AuthorizationProps ) => { | ||
const translate = useTranslate(); | ||
return ( | ||
<div className="site-migration-application-password-authorization__authorization"> | ||
<div> | ||
<NextButton onClick={ onAuthorizationClick }>{ translate( 'Authorize' ) }</NextButton> | ||
</div> | ||
<div> | ||
<button | ||
className="button navigation-link step-container__navigation-link has-underline is-borderless" | ||
type="button" | ||
onClick={ onShareCredentialsClick } | ||
> | ||
{ translate( 'Share credentials instead' ) } | ||
</button> | ||
</div> | ||
<div className="site-migration-application-password-authorization__benefits-container"> | ||
<h3>{ translate( "Here's what else you're getting" ) }</h3> | ||
<AuthorizationBenefits | ||
benefits={ [ | ||
translate( 'Uninterrupted service throughout the entire migration experience.' ), | ||
translate( 'Unmatched reliability with 99.999% uptime and unmetered traffic.' ), | ||
translate( 'Round-the-clock security monitoring and DDoS protection.' ), | ||
] } | ||
/> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Authorization; |
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
...ternals/steps-repository/site-migration-application-password-authorization/test/index.tsx
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 @@ | ||
/** | ||
* @jest-environment jsdom | ||
*/ | ||
import { screen, waitFor } from '@testing-library/react'; | ||
import userEvent from '@testing-library/user-event'; | ||
import nock from 'nock'; | ||
import React from 'react'; | ||
import wpcomRequest from 'wpcom-proxy-request'; | ||
import { useSiteSlugParam } from 'calypso/landing/stepper/hooks/use-site-slug-param'; | ||
import SiteMigrationApplicationPasswordAuthorization from '..'; | ||
import { StepProps } from '../../../types'; | ||
import { RenderStepOptions, mockStepProps, renderStep } from '../../test/helpers'; | ||
|
||
const render = ( props?: Partial< StepProps >, renderOptions?: RenderStepOptions ) => { | ||
const combinedProps = { ...mockStepProps( props ) }; | ||
return renderStep( | ||
<SiteMigrationApplicationPasswordAuthorization { ...combinedProps } />, | ||
renderOptions | ||
); | ||
}; | ||
|
||
jest.mock( 'wpcom-proxy-request', () => jest.fn() ); | ||
jest.mock( 'calypso/landing/stepper/hooks/use-site-slug-param' ); | ||
|
||
( useSiteSlugParam as jest.Mock ).mockImplementation( () => 'site-url.wordpress.com' ); | ||
|
||
const { getByRole, getByTestId, findByText } = screen; | ||
|
||
describe( 'SiteMigrationApplicationPasswordAuthorization', () => { | ||
beforeAll( () => nock.disableNetConnect() ); | ||
it( 'renders the loading state when the authorization is successful and the application password is not yet stored', async () => { | ||
( wpcomRequest as jest.Mock ).mockImplementation( () => new Promise( () => {} ) ); | ||
|
||
const initialEntry = | ||
'/step?authorization_url=https://example.com&user_login=test&password=test'; | ||
render( {}, { initialEntry } ); | ||
|
||
await waitFor( () => { | ||
expect( getByTestId( 'loading-ellipsis' ) ).toBeVisible(); | ||
} ); | ||
} ); | ||
|
||
it( 'redirects to the next step when the application password is stored', async () => { | ||
const submit = jest.fn(); | ||
const initialEntry = | ||
'/step?authorization_url=https://example.com&user_login=test&password=test'; | ||
|
||
( wpcomRequest as jest.Mock ).mockResolvedValue( { | ||
status: 200, | ||
body: { | ||
data: { status: 200 }, | ||
}, | ||
} ); | ||
|
||
render( { navigation: { submit } }, { initialEntry } ); | ||
await waitFor( () => { | ||
expect( submit ).toHaveBeenCalledWith( { action: 'migration-started' } ); | ||
} ); | ||
} ); | ||
|
||
it( 'renders the error state when the application password fails to be stored', async () => { | ||
( wpcomRequest as jest.Mock ).mockRejectedValue( { | ||
status: 500, | ||
body: { | ||
code: 'no_ticket_found', | ||
message: 'No migration ticket found.', | ||
data: { status: 500 }, | ||
}, | ||
} ); | ||
|
||
const initialEntry = | ||
'/step?authorization_url=https://example.com&user_login=test&password=test'; | ||
render( {}, { initialEntry } ); | ||
|
||
const errorMessage = await findByText( /We couldn't complete the authorization./ ); | ||
|
||
await waitFor( () => { | ||
expect( errorMessage ).toBeVisible(); | ||
} ); | ||
} ); | ||
|
||
it( 'renders the alert notice when the authorization is rejected', async () => { | ||
const submit = jest.fn(); | ||
const initialEntry = '/step?authorization_url=https://example.com&success=false'; | ||
render( { navigation: { submit } }, { initialEntry } ); | ||
|
||
const errorMessage = await findByText( | ||
/We can't start your migration without your authorization. Please authorize WordPress.com in your WP Admin or share your credentials./ | ||
); | ||
|
||
await waitFor( () => { | ||
expect( errorMessage ).toBeVisible(); | ||
} ); | ||
} ); | ||
|
||
it( 'the authorization button redirects to the source URL when clicked', async () => { | ||
const submit = jest.fn(); | ||
const authorizationUrl = 'https://example.com/authorization.php'; | ||
const initialEntry = `/step?authorization_url=${ authorizationUrl }`; | ||
render( { navigation: { submit } }, { initialEntry } ); | ||
|
||
await userEvent.click( getByRole( 'button', { name: 'Authorize' } ) ); | ||
|
||
expect( submit ).toHaveBeenCalledWith( { action: 'authorization', authorizationUrl } ); | ||
} ); | ||
|
||
it( 'the share credentials button redirects to the fallback credentials step', async () => { | ||
const submit = jest.fn(); | ||
const initialEntry = '/step?authorization_url=https://example.com'; | ||
render( { navigation: { submit } }, { initialEntry } ); | ||
|
||
await userEvent.click( getByRole( 'button', { name: 'Share credentials instead' } ) ); | ||
|
||
expect( submit ).toHaveBeenCalledWith( { action: 'fallback-credentials' } ); | ||
} ); | ||
} ); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where this strings added to the string freeze PR we where using for having translations ready earliear?