Skip to content
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

Hides jetpack during onboarding if already connected #2516

Conversation

dsawardekar
Copy link
Collaborator

@dsawardekar dsawardekar commented Aug 9, 2024

Changes proposed in this Pull Request:

This PR improves the plugin setup process by conditionally hiding the WP.com account connection card when the store is already connected to WP.com.

Closes: #2487

Screenshots:

Disconnected:
image

Connected:
image

Settings:
image

Detailed test instructions:

  1. Switch to this branch, and rebuild the plugin with npm run build
  2. With Jetpack not connected, go to the onboarding flow.
  • You should see the WP.com / Jetpack Connection Card
  1. Connect Jetpack, and then refresh the page to restart the onboarding steps
  • The WP.com / Jetpack Connection Card should be hidden
  1. Verify that the WP.com card is still shown on the settings tab.

You can use the below code in an mu-plugin to temporarily test this by toggling the active state to 'yes' / 'no'.

add_filter( 'rest_pre_echo_response', function( $result, $server, $request ) {
	if ( '/wc/gla/jetpack/connected' === $request->get_route() ) {
		$result['active'] = 'no';
	}

	return $result;
}, 10, 3 );

Additional details:

Update - Hides WP.com card if already connected

To run the e2e tests for the onboarding process you can use,

$ npm run test:e2e -- tests/e2e/specs/setup-mc/step-1-accounts.test.js'

This PR also includes some refactoring of the E2E test playwright utilities to avoid relying on nth-child locations for account cards, now that the WP.com account card will not be displayed in some scenarios.

Changelog entry

Update - Hides WordPress.com account connection setting from the onboarding flow if already connected.

@github-actions github-actions bot added the changelog: update Big changes to something that wasn't broken. label Aug 9, 2024
Copy link

codecov bot commented Aug 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 63.8%. Comparing base (f398161) to head (ecd25fc).
Report is 149 commits behind head on feature/2458-streamline-onboarding.

Additional details and impacted files

Impacted file tree graph

@@                           Coverage Diff                           @@
##             feature/2458-streamline-onboarding   #2516      +/-   ##
=======================================================================
- Coverage                                  64.5%   63.8%    -0.7%     
=======================================================================
  Files                                       795     326     -469     
  Lines                                     22844    5086   -17758     
  Branches                                   1220    1229       +9     
=======================================================================
- Hits                                      14739    3247   -11492     
+ Misses                                     7938    1672    -6266     
  Partials                                    167     167              
Flag Coverage Δ
js-unit-tests 63.8% <ø> (+0.3%) ⬆️
php-unit-tests ?

Flags with carried forward coverage won't be shown. Click here to find out more.

see 479 files with indirect coverage changes

@joemcgill joemcgill linked an issue Aug 9, 2024 that may be closed by this pull request
4 tasks
@dsawardekar dsawardekar self-assigned this Aug 12, 2024
@dsawardekar dsawardekar marked this pull request as ready for review August 12, 2024 04:18
Copy link
Collaborator

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks right to me. One small code quality nitpick, but it looks like it's functioning correctly. 👍🏻

@@ -101,6 +101,8 @@ const SetupAccounts = ( props ) => {
* and the whole page would display this AppSpinner, which is not desired.
*/
const isLoadingJetpack = ! jetpack;
const isJetpackInactive = jetpack?.active !== 'yes';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: There are a couple other places below where we are checking for the jetpack.active value (e.g., isLoadingGoogle and isGoogleAccountDisabled. Let's consolidate all of this logic by updating those references to make use of the new variable you're adding here. For readability, I'd also suggest making the variable isJetpackActive rather than inactive, to avoid the double negative when checking for ! isJetpackInactive, ex:

const isJetpackActive = jetpack?.active === 'yes';

// ...etc.

{ ! isJetPackActive && ( <WPComAccountCard /> ) }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@dsawardekar
Copy link
Collaborator Author

@joemcgill I've refactored the code per the feedback. Also confirmed that settings still show the card, AC is also updated to reflect this. Back to you for another review.

Copy link
Collaborator

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @dsawardekar. The updates all look good to me. I tried running the e2e tests locally with these changes and noticed that this would require quite a few updates to the existing test suite, since many of the existing playwright tests depend on finding HTML elements in a particular order in the screen.

I went ahead and opened a follow-up PR that addresses those issues so you can review how these were previously set up.

Once you've taken a look, let's merge that PR into this branch prior to passing to QA for review.

@dsawardekar
Copy link
Collaborator Author

Thanks, @joemcgill . I've merged the PR, and updated the AC to remove the non-mocking based instructions.

Copy link
Collaborator

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @dsawardekar. Looks good to me.

@ankitguptaindia
Copy link
Member

@joemcgill, I have reviewed the PR and found it to be functioning as described ✅. However, I came across a use case where I would appreciate your feedback:

Current Behavior: When a user completes the onboarding flow, the WordPress.com card is hidden if Jetpack is connected, and the status is displayed as "connected" on the plugin’s Settings tab.

Use Case: The button on the Settings screen labelled "Disconnect from all accounts" suggests that clicking it will disconnect all accounts, including the WordPress.com account. Furthermore, when the user clicks this button, a confirmation message (e.g., "I understand that I am disconnecting any WordPress.com account...") appears, reinforcing that the WordPress.com account will be disconnected.

Given this, a user might expect the WordPress.com card to reappear on the onboarding screen when they restart the plugin setup. However, with the current implementation, the WordPress.com card does not appear on the first screen of the onboarding steps after all accounts have been disconnected.

This discrepancy between the expected behaviour and the label/button details could cause some confusion for users.

Recording.794.mp4
Disconnection Screens

image

image


Additional Note: I tested the same flow with the stable build and found that, when the user disconnects all accounts and restarts the onboarding journey, the WordPress.com card appears on the onboarding screen with a "CONNECTED" status.

Screenshot

image

@joemcgill
Copy link
Collaborator

Thanks @ankitguptaindia! Re:

Use Case: The button on the Settings screen labelled "Disconnect from all accounts" suggests that clicking it will disconnect all accounts, including the WordPress.com account. Furthermore, when the user clicks this button, a confirmation message (e.g., "I understand that I am disconnecting any WordPress.com account...") appears, reinforcing that the WordPress.com account will be disconnected.

This behavior is something that both @dsawardekar and I noticed as well. This seems to be the current behavior in the develop branch and not something related to the changes made here. I'm going to create a new issue to address this.

@joemcgill
Copy link
Collaborator

@eason9487 this one is ready for your review.

Copy link
Member

@eason9487 eason9487 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the work and the change in SetupAccounts looks good.

Left a few suggestions for the e2e test. It would be great if unused methods could be removed.

tests/e2e/specs/setup-mc/step-1-accounts.test.js Outdated Show resolved Hide resolved
tests/e2e/utils/pages/setup-mc/step-1-set-up-accounts.js Outdated Show resolved Hide resolved
tests/e2e/utils/pages/setup-mc/step-1-set-up-accounts.js Outdated Show resolved Hide resolved
tests/e2e/utils/pages/setup-mc/step-1-set-up-accounts.js Outdated Show resolved Hide resolved
tests/e2e/utils/pages/setup-mc/step-1-set-up-accounts.js Outdated Show resolved Hide resolved
const isLoadingGoogleMCAccount =
google?.active === 'yes' && scope.gmcRequired && ! googleMCAccount;

if ( isLoadingJetpack || isLoadingGoogle || isLoadingGoogleMCAccount ) {
return <AppSpinner />;
}

const isGoogleAccountDisabled = jetpack?.active !== 'yes';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement! Thanks!

@joemcgill
Copy link
Collaborator

Re: #2516 (comment)

Use Case: The button on the Settings screen labelled "Disconnect from all accounts" suggests that clicking it will disconnect all accounts, including the WordPress.com account. Furthermore, when the user clicks this button, a confirmation message (e.g., "I understand that I am disconnecting any WordPress.com account...") appears, reinforcing that the WordPress.com account will be disconnected.

This behavior is something that both @dsawardekar and I noticed as well. This seems to be the current behavior in the develop branch and not something related to the changes made here. I'm going to create a new issue to address this.

I'm no longer seeing this behavior today and the WP.com connection is being disconnected correctly when clicking "Disconnect all accounts" so this may have been due to a local configuration issue.

@dsawardekar
Copy link
Collaborator Author

@joemcgill PR updated, back to you for CR.

RE: Disconnection

I'm still seeing the disconnection issue. It appears to disconnect correctly, but shows an error on the FE. But if you refresh the page, everything except the Jetpack connection has disconnected. I'm currently using the jetpack REST override to reset the state. If there is a better way, please let me know.

Comment on lines 143 to 145
await expect(
page.getByRole( 'button', { name: 'Connect' } ).first()
).toBeEnabled();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this assertion once the once the previous suggestion is updated.

Suggested change
await expect(
page.getByRole( 'button', { name: 'Connect' } ).first()
).toBeEnabled();

Copy link
Collaborator

@joemcgill joemcgill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates

Copy link
Member

@eason9487 eason9487 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the update for e2e tests! LGTM.

@joemcgill joemcgill changed the base branch from develop to feature/2458-streamline-onboarding August 22, 2024 13:56
@joemcgill joemcgill merged commit 0bb6163 into feature/2458-streamline-onboarding Aug 22, 2024
7 checks passed
@joemcgill joemcgill deleted the update/2487-hide-jetpack-if-already-connected-onboarding branch August 22, 2024 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog: update Big changes to something that wasn't broken.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Onboarding: Hide WP.com connection card if already connected
4 participants