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

External Media: Add API unit tests #15988

Merged
merged 7 commits into from
Jun 10, 2020

Conversation

obenland
Copy link
Member

@obenland obenland commented May 28, 2020

Adds unit tests for external media API endpoints.

Changes proposed in this Pull Request:

  • Adds unit tests for external media API endpoints

Is this a new feature or does it add/remove features to an existing part of Jetpack?

  • Part of a new feature that allows users access to a free image library and their Google Photos account from within blocks.

Does this pull request change what data or activity we track or use?

No.

Testing instructions:

To run unit tests:

  • Follow setup guidelines if you don't have unit tests set up yet.
  • The /copy endpoint test is being skipped at the moment.
  • Run phpunit --filter WP_Test_WPCOM_REST_API_V2_Endpoint_External_Media.

Proposed changelog entry for your changes:

Not necessary

@obenland obenland added [Feature] WPCOM API [Feature] WP REST API [Extension] External Media Extend all block editor media tools to support external providers labels May 28, 2020
@obenland obenland self-assigned this May 28, 2020
@jetpackbot
Copy link

jetpackbot commented May 28, 2020

Warnings
⚠️

pre-commit hook was skipped for one or more commits

This is an automated check which relies on PULL_REQUEST_TEMPLATE. We encourage you to follow that template as it helps Jetpack maintainers do their job. If you think 'Testing instructions' or 'Proposed changelog entry' are not needed for your PR - please explain why you think so. Thanks for cooperation 🤖

E2E results is available here (for debugging purposes): https://jetpack-e2e-dashboard.herokuapp.com/pr-15988

Generated by 🚫 dangerJS against 3b4a5f5

@obenland
Copy link
Member Author

@jeherve Attempting to make #15717 somewhat easier to review, I split out the API endpoint and added unit test (to make it easier to test without a client).

I've not had much luck creating a test for the image sideload endpoint. Not sure how to best mock an external image. Do you happen to have any advice or pointers there? Or is it fine to skip for now?

How can I tell Codeclimate about the added test coverage?

@obenland obenland marked this pull request as ready for review June 1, 2020 20:26
@obenland obenland requested a review from a team June 1, 2020 20:26
@obenland obenland added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] In Progress labels Jun 1, 2020
@obenland obenland force-pushed the add/external-media-endpoint branch from 10ace2e to 8589b5d Compare June 1, 2020 21:54
@jeherve jeherve added this to the 8.7 milestone Jun 2, 2020
@obenland
Copy link
Member Author

obenland commented Jun 2, 2020

Closing in favor of merging #15717.

@obenland obenland closed this Jun 2, 2020
@obenland obenland deleted the add/external-media-endpoint branch June 2, 2020 14:52
@obenland obenland restored the add/external-media-endpoint branch June 2, 2020 17:10
@obenland obenland reopened this Jun 2, 2020
@obenland obenland changed the base branch from master to feature/external-media June 2, 2020 17:10
@obenland obenland force-pushed the add/external-media-endpoint branch from 8589b5d to f91b759 Compare June 2, 2020 17:14
@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello obenland! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer, review, and approve D44304-code before merging this PR. Thank you!
This revision will be updated with each commit to this PR

@obenland obenland changed the title External Media: Add API endpoint External Media: Add API unit tests Jun 2, 2020
@obenland obenland added [Status] Needs Team Review and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Jun 2, 2020
@obenland obenland requested review from a team and removed request for a team June 2, 2020 17:16
@obenland
Copy link
Member Author

obenland commented Jun 2, 2020

@jeherve How do you feel about introducing skipped tests?

@obenland obenland force-pushed the add/external-media-endpoint branch from f91b759 to 32765ff Compare June 2, 2020 19:20
@jeherve
Copy link
Member

jeherve commented Jun 4, 2020

How do you feel about introducing skipped tests?

I think that'd be fine for now, but maybe add a comment in there explaining the things you've tried and how that turned out, or maybe a link to a comment here with more details? This may help the next person who looks at this, and save them some time in their investigation?

@obenland
Copy link
Member Author

obenland commented Jun 4, 2020

I was able to make the image copy test work with bunch of filter modifications. Feels fragile, but maybe that's just how it needs to be when we're trying to test an endpoint for a remote image with a local file. 🤷‍♂️

All tests are 🟢 now, though!

@obenland obenland merged commit 036c342 into feature/external-media Jun 10, 2020
@obenland obenland deleted the add/external-media-endpoint branch June 10, 2020 17:49
obenland added a commit that referenced this pull request Jun 24, 2020
* [not verified] Add External media endpoint

* [not verified] Add unit tests

* [not verified] Add class coverage info

* Simplify schema

* Fix image copy test

* Use local image

* Remove duplicate file ending

Props @frontdevde.
obenland added a commit that referenced this pull request Jun 25, 2020
* External Media: Render Media after authentication (#16044)

See #15717 (review)

* [not verified] Handle 401 responses (#16041)

See #15717 (review)

* External Media: Better reflect accepted media types (#16071)

* External Media: Account for multiple images (#16077)

See #16071 (comment)

* External Media: Fix Modal focus loss on arrow keypress (#16055)

Co-authored-by: Marek Hrabe <marekhrabe@me.com>

* External Media: Add API unit tests (#15988)

* [not verified] Add External media endpoint

* [not verified] Add unit tests

* [not verified] Add class coverage info

* Simplify schema

* Fix image copy test

* Use local image

* Remove duplicate file ending

Props @frontdevde.

* External Media: Improve Insert Flow (#16081)

* [not verified] # This is a combination of 5 commits.

External Media: Improve Insert Flow

See #15867

Remove unused import

Lock pointer events when copying
This prevents a UX issue where user can still interact with the modal content while the "Inserting..." request is pending.

Announce Inserting action along with alt text of selected images.

Update modal headers to reflect status

Props @jancavan.

* External Media: Fix mobile modal size (#16098)

* External Media: Improve Insert Flow

See #15867

* Remove unused import

* Lock pointer events when copying
This prevents a UX issue where user can still interact with the modal content while the "Inserting..." request is pending.

* Announce Inserting action along with alt text of selected images.

* Fix mobile mobile width to take up the full available modal space

* Change is-copying to modifier instead of element to follow BEM syntax

Co-authored-by: Konstantin Obenland <obenland@gmx.de>
Co-authored-by: Bart <bartlomiej.kalisz@gmail.com>

* External Media: Loading and disabled states for the copying state (#16103)

* disable pagination while loading

* fade out all images when copying

* disable event handlers and mark as disabled when copying

* disable pexels search when copying

* disabled google filters when copying

* add text to copying indicator

* disable google photos view selector when copying

* [not verified] remove debugging condition

* Pass functions not booleans to event emitters

Co-authored-by: Konstantin Obenland <obenland@gmx.de>

* Removed :not() copying css state since they are the same modal now

* Reset focus to the modal after clicking Insert. Otherwise focus is reset to the body and focus needs to stay trapped within the modal.

* Cosmetically rearranging code order

* External Media: Screen Reader accessible states for Insert flow (#16113)

* Add visually hidden description for the external media modal to give improved screen reader instructions and communicate the copying state

* [not verified] Remove title attribute from grid images

* [not verified] Move Inserting Image... copy to before the image so it is announced first.

* Separate-out description and element id

Helps with keeping describedby id in sync

Co-authored-by: Konstantin Obenland <obenland@gmx.de>

Co-authored-by: Jerry Jones <jones.jeremydavid@gmail.com>
Co-authored-by: Bart <bartlomiej.kalisz@gmail.com>
Co-authored-by: Marek Hrabe <marekhrabe@me.com>

* External Media: Restore focus on modal close (#16102)

* External Media: Disable for existing galleries (#16176)

* External Media: Disable for existing galleries
* Update comment

* External Media: Improve upload permission check (#16185)

* Use `value` to disable for existing galleries

`addToGallery` is not used by all gallery-type blocks, like tiled-gallery or slideshow.

Props @jeherve.

Co-authored-by: Bart Kalisz <bartlomiej.kalisz@gmail.com>
Co-authored-by: Marek Hrabe <marekhrabe@me.com>
Co-authored-by: Jerry Jones <jones.jeremydavid@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Extension] External Media Extend all block editor media tools to support external providers [Feature] WP REST API [Feature] WPCOM API Touches WP.com Files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants