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

Allow the user to Convert unembeddable URLs to links and try embedding again #12095

Merged
merged 4 commits into from
Nov 22, 2018

Conversation

notnownikki
Copy link
Member

@notnownikki notnownikki commented Nov 20, 2018

Description

On the UI that tells the user that the URL could not be embedded, this adds a button to convert the URL to a paragraph block with a link, and a button to attempt the embedding again.

How has this been tested?

Try to embed a URL that can't be embedded, press the new "Convert to link" button. Press the "Try again" button and you should see the embed proxy request again.

Screenshots

Types of changes

New feature

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • My code has proper inline documentation.

@jasmussen
Copy link
Contributor

Before:

screenshot 2018-11-20 at 12 21 25

After:

screenshot 2018-11-20 at 12 26 32

In this case I just put the button inside the same paragraph as the error, and added a linebreak. I think it's fine to do, and it fixes the issue. Nice work! 👍 👍

@notnownikki notnownikki requested a review from a team November 21, 2018 09:37
@notnownikki notnownikki added this to the 4.6 milestone Nov 21, 2018
@notnownikki
Copy link
Member Author

@jasmussen thank you!

@jasmussen
Copy link
Contributor

jasmussen commented Nov 21, 2018

🙇 — and thank you!

@notnownikki notnownikki changed the title Allow the user to Convert unembeddable URLs to links Allow the user to Convert unembeddable URLs to links and try embedding again Nov 21, 2018
@notnownikki
Copy link
Member Author

Updated and added the "Try again" button to retry the embed.

* @param {string} buttonText The text that appears on the button to click.
*/
export async function clickButton( buttonText ) {
const button = await page.waitForXPath( `//button[contains(text(), '${ buttonText }')]` );
Copy link
Member

Choose a reason for hiding this comment

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

It might be nice to have a way to scope this button somehow. Some buttons can have very general name and have multiple instances.

Copy link
Member Author

Choose a reason for hiding this comment

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

Perhaps this just needs to go inline in the test? It gets tricky when you're matching the inner text of something too.

Copy link
Member

Choose a reason for hiding this comment

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

We can iterate on it later. It should be still useful in some cases as is.

I'm only worried about that because we are planning to expose shared code for e2e tests in npm package. That means we will have to maintain all those utils :)

// when we try to process the same request twice.
interceptionInitialized = true;
await page.setRequestInterception( true );
page.on( 'request', async ( request ) => {
Copy link
Member

Choose a reason for hiding this comment

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

https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#class-page

I see page.once in this section. Could that be used instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

once is for responding to an event once, not only registering a handler once, unfortunately, and we want our handler to be there for all requests.

Copy link
Member

Choose a reason for hiding this comment

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

we want our handler to be there for all requests.

All requests... within a particular file of tests? Or the entire suite?

To me, this request mocking should only take place for the duration of the tests where it's applicable. It seems we're missing a critical "tear down" step, which risks lingering test state inadvertently affecting other test files.

@gziolo gziolo added [Block] Embed Affects the Embed Block [Type] Enhancement A suggestion for improvement. labels Nov 22, 2018
Copy link
Member

@gziolo gziolo left a comment

Choose a reason for hiding this comment

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

It works great in my testing. I tried the following:

  • go offline, paste link and click try again after going online
  • paste unknow Twitter link, paste GitHub link and convert from embed to link

Great work @notnownikki, thanks 🙇

if ( mock.match( request ) ) {
await mock.onRequestMatch( request );
return;
if ( ! interceptionInitialized ) {
Copy link
Member

Choose a reason for hiding this comment

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

What if two test files each want to set up their own response mocks? Wouldn't this singleton boolean global only allow the first set of mocks to "win"?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Embed Affects the Embed Block [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants