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

Comments Query Loop - Add e2e tests for the block #39502

Merged
merged 19 commits into from
Mar 28, 2022

Conversation

cbravobernal
Copy link
Contributor

@cbravobernal cbravobernal commented Mar 16, 2022

What?

We are adding e2e and unit tests for the Comments Query Loop block.

Why

To prevent future changes that could make the pagination comments link bug happen again. Also to prevent code that would break the Comments Query Loop block insertion.

How

We are adding the block using both the inserter and the shortcode /comments query loop.
Also, we fixed a bug on #39227 where, as the cpage query var was not defined in a specific case, the "Older Comments" and "Newer Comments" were not working. This PR also adds unit testing for those lines of code.

@github-actions
Copy link

github-actions bot commented Mar 16, 2022

Size Change: 0 B

Total Size: 1.21 MB

ℹ️ View Unchanged
Filename Size
build/a11y/index.min.js 993 B
build/admin-manifest/index.min.js 1.24 kB
build/annotations/index.min.js 2.77 kB
build/api-fetch/index.min.js 2.27 kB
build/autop/index.min.js 2.15 kB
build/blob/index.min.js 487 B
build/block-directory/index.min.js 6.49 kB
build/block-directory/style-rtl.css 1.01 kB
build/block-directory/style.css 1.01 kB
build/block-editor/default-editor-styles-rtl.css 378 B
build/block-editor/default-editor-styles.css 378 B
build/block-editor/index.min.js 147 kB
build/block-editor/style-rtl.css 15.4 kB
build/block-editor/style.css 15.4 kB
build/block-library/blocks/archives/editor-rtl.css 61 B
build/block-library/blocks/archives/editor.css 60 B
build/block-library/blocks/archives/style-rtl.css 65 B
build/block-library/blocks/archives/style.css 65 B
build/block-library/blocks/audio/editor-rtl.css 150 B
build/block-library/blocks/audio/editor.css 150 B
build/block-library/blocks/audio/style-rtl.css 111 B
build/block-library/blocks/audio/style.css 111 B
build/block-library/blocks/audio/theme-rtl.css 125 B
build/block-library/blocks/audio/theme.css 125 B
build/block-library/blocks/avatar/editor-rtl.css 59 B
build/block-library/blocks/avatar/editor.css 59 B
build/block-library/blocks/block/editor-rtl.css 161 B
build/block-library/blocks/block/editor.css 161 B
build/block-library/blocks/button/editor-rtl.css 445 B
build/block-library/blocks/button/editor.css 445 B
build/block-library/blocks/button/style-rtl.css 560 B
build/block-library/blocks/button/style.css 560 B
build/block-library/blocks/buttons/editor-rtl.css 292 B
build/block-library/blocks/buttons/editor.css 292 B
build/block-library/blocks/buttons/style-rtl.css 275 B
build/block-library/blocks/buttons/style.css 275 B
build/block-library/blocks/calendar/style-rtl.css 207 B
build/block-library/blocks/calendar/style.css 207 B
build/block-library/blocks/categories/editor-rtl.css 84 B
build/block-library/blocks/categories/editor.css 83 B
build/block-library/blocks/categories/style-rtl.css 79 B
build/block-library/blocks/categories/style.css 79 B
build/block-library/blocks/code/style-rtl.css 103 B
build/block-library/blocks/code/style.css 103 B
build/block-library/blocks/code/theme-rtl.css 124 B
build/block-library/blocks/code/theme.css 124 B
build/block-library/blocks/columns/editor-rtl.css 108 B
build/block-library/blocks/columns/editor.css 108 B
build/block-library/blocks/columns/style-rtl.css 406 B
build/block-library/blocks/columns/style.css 406 B
build/block-library/blocks/comment-author-avatar/editor-rtl.css 125 B
build/block-library/blocks/comment-author-avatar/editor.css 125 B
build/block-library/blocks/comment-template/style-rtl.css 127 B
build/block-library/blocks/comment-template/style.css 127 B
build/block-library/blocks/comments-pagination-numbers/editor-rtl.css 123 B
build/block-library/blocks/comments-pagination-numbers/editor.css 121 B
build/block-library/blocks/comments-pagination/editor-rtl.css 222 B
build/block-library/blocks/comments-pagination/editor.css 209 B
build/block-library/blocks/comments-pagination/style-rtl.css 235 B
build/block-library/blocks/comments-pagination/style.css 231 B
build/block-library/blocks/comments-query-loop/editor-rtl.css 95 B
build/block-library/blocks/comments-query-loop/editor.css 95 B
build/block-library/blocks/cover/editor-rtl.css 546 B
build/block-library/blocks/cover/editor.css 547 B
build/block-library/blocks/cover/style-rtl.css 1.56 kB
build/block-library/blocks/cover/style.css 1.56 kB
build/block-library/blocks/embed/editor-rtl.css 293 B
build/block-library/blocks/embed/editor.css 293 B
build/block-library/blocks/embed/style-rtl.css 417 B
build/block-library/blocks/embed/style.css 417 B
build/block-library/blocks/embed/theme-rtl.css 124 B
build/block-library/blocks/embed/theme.css 124 B
build/block-library/blocks/file/editor-rtl.css 300 B
build/block-library/blocks/file/editor.css 300 B
build/block-library/blocks/file/style-rtl.css 255 B
build/block-library/blocks/file/style.css 255 B
build/block-library/blocks/file/view.min.js 353 B
build/block-library/blocks/freeform/editor-rtl.css 2.44 kB
build/block-library/blocks/freeform/editor.css 2.44 kB
build/block-library/blocks/gallery/editor-rtl.css 961 B
build/block-library/blocks/gallery/editor.css 964 B
build/block-library/blocks/gallery/style-rtl.css 1.51 kB
build/block-library/blocks/gallery/style.css 1.51 kB
build/block-library/blocks/gallery/theme-rtl.css 122 B
build/block-library/blocks/gallery/theme.css 122 B
build/block-library/blocks/group/editor-rtl.css 159 B
build/block-library/blocks/group/editor.css 159 B
build/block-library/blocks/group/style-rtl.css 57 B
build/block-library/blocks/group/style.css 57 B
build/block-library/blocks/group/theme-rtl.css 78 B
build/block-library/blocks/group/theme.css 78 B
build/block-library/blocks/heading/style-rtl.css 114 B
build/block-library/blocks/heading/style.css 114 B
build/block-library/blocks/html/editor-rtl.css 332 B
build/block-library/blocks/html/editor.css 333 B
build/block-library/blocks/image/editor-rtl.css 731 B
build/block-library/blocks/image/editor.css 730 B
build/block-library/blocks/image/style-rtl.css 529 B
build/block-library/blocks/image/style.css 535 B
build/block-library/blocks/image/theme-rtl.css 124 B
build/block-library/blocks/image/theme.css 124 B
build/block-library/blocks/latest-comments/style-rtl.css 284 B
build/block-library/blocks/latest-comments/style.css 284 B
build/block-library/blocks/latest-posts/editor-rtl.css 199 B
build/block-library/blocks/latest-posts/editor.css 198 B
build/block-library/blocks/latest-posts/style-rtl.css 447 B
build/block-library/blocks/latest-posts/style.css 446 B
build/block-library/blocks/list/style-rtl.css 94 B
build/block-library/blocks/list/style.css 94 B
build/block-library/blocks/media-text/editor-rtl.css 266 B
build/block-library/blocks/media-text/editor.css 263 B
build/block-library/blocks/media-text/style-rtl.css 493 B
build/block-library/blocks/media-text/style.css 490 B
build/block-library/blocks/more/editor-rtl.css 431 B
build/block-library/blocks/more/editor.css 431 B
build/block-library/blocks/navigation-link/editor-rtl.css 708 B
build/block-library/blocks/navigation-link/editor.css 706 B
build/block-library/blocks/navigation-link/style-rtl.css 94 B
build/block-library/blocks/navigation-link/style.css 94 B
build/block-library/blocks/navigation-submenu/editor-rtl.css 299 B
build/block-library/blocks/navigation-submenu/editor.css 299 B
build/block-library/blocks/navigation-submenu/view.min.js 375 B
build/block-library/blocks/navigation/editor-rtl.css 2.03 kB
build/block-library/blocks/navigation/editor.css 2.04 kB
build/block-library/blocks/navigation/style-rtl.css 1.89 kB
build/block-library/blocks/navigation/style.css 1.88 kB
build/block-library/blocks/navigation/view.min.js 2.85 kB
build/block-library/blocks/nextpage/editor-rtl.css 395 B
build/block-library/blocks/nextpage/editor.css 395 B
build/block-library/blocks/page-list/editor-rtl.css 363 B
build/block-library/blocks/page-list/editor.css 363 B
build/block-library/blocks/page-list/style-rtl.css 175 B
build/block-library/blocks/page-list/style.css 175 B
build/block-library/blocks/paragraph/editor-rtl.css 157 B
build/block-library/blocks/paragraph/editor.css 157 B
build/block-library/blocks/paragraph/style-rtl.css 273 B
build/block-library/blocks/paragraph/style.css 273 B
build/block-library/blocks/post-author/style-rtl.css 175 B
build/block-library/blocks/post-author/style.css 176 B
build/block-library/blocks/post-comments-form/style-rtl.css 446 B
build/block-library/blocks/post-comments-form/style.css 446 B
build/block-library/blocks/post-comments/style-rtl.css 521 B
build/block-library/blocks/post-comments/style.css 521 B
build/block-library/blocks/post-excerpt/editor-rtl.css 73 B
build/block-library/blocks/post-excerpt/editor.css 73 B
build/block-library/blocks/post-excerpt/style-rtl.css 69 B
build/block-library/blocks/post-excerpt/style.css 69 B
build/block-library/blocks/post-featured-image/editor-rtl.css 721 B
build/block-library/blocks/post-featured-image/editor.css 721 B
build/block-library/blocks/post-featured-image/style-rtl.css 153 B
build/block-library/blocks/post-featured-image/style.css 153 B
build/block-library/blocks/post-template/editor-rtl.css 99 B
build/block-library/blocks/post-template/editor.css 98 B
build/block-library/blocks/post-template/style-rtl.css 323 B
build/block-library/blocks/post-template/style.css 323 B
build/block-library/blocks/post-terms/style-rtl.css 73 B
build/block-library/blocks/post-terms/style.css 73 B
build/block-library/blocks/post-title/style-rtl.css 80 B
build/block-library/blocks/post-title/style.css 80 B
build/block-library/blocks/preformatted/style-rtl.css 103 B
build/block-library/blocks/preformatted/style.css 103 B
build/block-library/blocks/pullquote/editor-rtl.css 198 B
build/block-library/blocks/pullquote/editor.css 198 B
build/block-library/blocks/pullquote/style-rtl.css 370 B
build/block-library/blocks/pullquote/style.css 370 B
build/block-library/blocks/pullquote/theme-rtl.css 167 B
build/block-library/blocks/pullquote/theme.css 167 B
build/block-library/blocks/query-pagination-numbers/editor-rtl.css 122 B
build/block-library/blocks/query-pagination-numbers/editor.css 121 B
build/block-library/blocks/query-pagination/editor-rtl.css 221 B
build/block-library/blocks/query-pagination/editor.css 211 B
build/block-library/blocks/query-pagination/style-rtl.css 234 B
build/block-library/blocks/query-pagination/style.css 231 B
build/block-library/blocks/query/editor-rtl.css 131 B
build/block-library/blocks/query/editor.css 132 B
build/block-library/blocks/quote/style-rtl.css 201 B
build/block-library/blocks/quote/style.css 201 B
build/block-library/blocks/quote/theme-rtl.css 223 B
build/block-library/blocks/quote/theme.css 226 B
build/block-library/blocks/read-more/style-rtl.css 132 B
build/block-library/blocks/read-more/style.css 132 B
build/block-library/blocks/rss/editor-rtl.css 202 B
build/block-library/blocks/rss/editor.css 204 B
build/block-library/blocks/rss/style-rtl.css 289 B
build/block-library/blocks/rss/style.css 288 B
build/block-library/blocks/search/editor-rtl.css 165 B
build/block-library/blocks/search/editor.css 165 B
build/block-library/blocks/search/style-rtl.css 397 B
build/block-library/blocks/search/style.css 398 B
build/block-library/blocks/search/theme-rtl.css 64 B
build/block-library/blocks/search/theme.css 64 B
build/block-library/blocks/separator/editor-rtl.css 140 B
build/block-library/blocks/separator/editor.css 140 B
build/block-library/blocks/separator/style-rtl.css 233 B
build/block-library/blocks/separator/style.css 233 B
build/block-library/blocks/separator/theme-rtl.css 194 B
build/block-library/blocks/separator/theme.css 194 B
build/block-library/blocks/shortcode/editor-rtl.css 474 B
build/block-library/blocks/shortcode/editor.css 474 B
build/block-library/blocks/site-logo/editor-rtl.css 759 B
build/block-library/blocks/site-logo/editor.css 759 B
build/block-library/blocks/site-logo/style-rtl.css 181 B
build/block-library/blocks/site-logo/style.css 181 B
build/block-library/blocks/site-tagline/editor-rtl.css 86 B
build/block-library/blocks/site-tagline/editor.css 86 B
build/block-library/blocks/site-title/editor-rtl.css 84 B
build/block-library/blocks/site-title/editor.css 84 B
build/block-library/blocks/social-link/editor-rtl.css 177 B
build/block-library/blocks/social-link/editor.css 177 B
build/block-library/blocks/social-links/editor-rtl.css 674 B
build/block-library/blocks/social-links/editor.css 673 B
build/block-library/blocks/social-links/style-rtl.css 1.37 kB
build/block-library/blocks/social-links/style.css 1.36 kB
build/block-library/blocks/spacer/editor-rtl.css 332 B
build/block-library/blocks/spacer/editor.css 332 B
build/block-library/blocks/spacer/style-rtl.css 48 B
build/block-library/blocks/spacer/style.css 48 B
build/block-library/blocks/table/editor-rtl.css 471 B
build/block-library/blocks/table/editor.css 472 B
build/block-library/blocks/table/style-rtl.css 481 B
build/block-library/blocks/table/style.css 481 B
build/block-library/blocks/table/theme-rtl.css 188 B
build/block-library/blocks/table/theme.css 188 B
build/block-library/blocks/tag-cloud/style-rtl.css 226 B
build/block-library/blocks/tag-cloud/style.css 227 B
build/block-library/blocks/template-part/editor-rtl.css 235 B
build/block-library/blocks/template-part/editor.css 235 B
build/block-library/blocks/template-part/theme-rtl.css 101 B
build/block-library/blocks/template-part/theme.css 101 B
build/block-library/blocks/text-columns/editor-rtl.css 95 B
build/block-library/blocks/text-columns/editor.css 95 B
build/block-library/blocks/text-columns/style-rtl.css 166 B
build/block-library/blocks/text-columns/style.css 166 B
build/block-library/blocks/verse/style-rtl.css 87 B
build/block-library/blocks/verse/style.css 87 B
build/block-library/blocks/video/editor-rtl.css 571 B
build/block-library/blocks/video/editor.css 572 B
build/block-library/blocks/video/style-rtl.css 173 B
build/block-library/blocks/video/style.css 173 B
build/block-library/blocks/video/theme-rtl.css 124 B
build/block-library/blocks/video/theme.css 124 B
build/block-library/common-rtl.css 934 B
build/block-library/common.css 932 B
build/block-library/editor-rtl.css 10 kB
build/block-library/editor.css 10 kB
build/block-library/index.min.js 171 kB
build/block-library/reset-rtl.css 474 B
build/block-library/reset.css 474 B
build/block-library/style-rtl.css 11.2 kB
build/block-library/style.css 11.2 kB
build/block-library/theme-rtl.css 689 B
build/block-library/theme.css 694 B
build/block-serialization-default-parser/index.min.js 1.12 kB
build/block-serialization-spec-parser/index.min.js 2.83 kB
build/blocks/index.min.js 46.8 kB
build/components/index.min.js 223 kB
build/components/style-rtl.css 14.9 kB
build/components/style.css 14.9 kB
build/compose/index.min.js 11.2 kB
build/core-data/index.min.js 14.3 kB
build/customize-widgets/index.min.js 11.2 kB
build/customize-widgets/style-rtl.css 1.39 kB
build/customize-widgets/style.css 1.39 kB
build/data-controls/index.min.js 663 B
build/data/index.min.js 8.34 kB
build/date/index.min.js 32 kB
build/deprecated/index.min.js 518 B
build/dom-ready/index.min.js 336 B
build/dom/index.min.js 4.53 kB
build/edit-navigation/index.min.js 16.1 kB
build/edit-navigation/style-rtl.css 4.04 kB
build/edit-navigation/style.css 4.05 kB
build/edit-post/classic-rtl.css 546 B
build/edit-post/classic.css 547 B
build/edit-post/index.min.js 29.9 kB
build/edit-post/style-rtl.css 7.07 kB
build/edit-post/style.css 7.07 kB
build/edit-site/index.min.js 45.4 kB
build/edit-site/style-rtl.css 7.6 kB
build/edit-site/style.css 7.58 kB
build/edit-widgets/index.min.js 16.5 kB
build/edit-widgets/style-rtl.css 4.4 kB
build/edit-widgets/style.css 4.39 kB
build/editor/index.min.js 38.4 kB
build/editor/style-rtl.css 3.71 kB
build/editor/style.css 3.71 kB
build/element/index.min.js 4.29 kB
build/escape-html/index.min.js 548 B
build/format-library/index.min.js 6.62 kB
build/format-library/style-rtl.css 571 B
build/format-library/style.css 571 B
build/hooks/index.min.js 1.66 kB
build/html-entities/index.min.js 454 B
build/i18n/index.min.js 3.79 kB
build/is-shallow-equal/index.min.js 535 B
build/keyboard-shortcuts/index.min.js 1.83 kB
build/keycodes/index.min.js 1.41 kB
build/list-reusable-blocks/index.min.js 1.75 kB
build/list-reusable-blocks/style-rtl.css 838 B
build/list-reusable-blocks/style.css 838 B
build/media-utils/index.min.js 2.94 kB
build/notices/index.min.js 957 B
build/nux/index.min.js 2.12 kB
build/nux/style-rtl.css 751 B
build/nux/style.css 749 B
build/plugins/index.min.js 1.98 kB
build/preferences/index.min.js 1.2 kB
build/primitives/index.min.js 949 B
build/priority-queue/index.min.js 611 B
build/react-i18n/index.min.js 704 B
build/react-refresh-entry/index.min.js 8.44 kB
build/react-refresh-runtime/index.min.js 7.31 kB
build/redux-routine/index.min.js 2.69 kB
build/reusable-blocks/index.min.js 2.24 kB
build/reusable-blocks/style-rtl.css 256 B
build/reusable-blocks/style.css 256 B
build/rich-text/index.min.js 11.1 kB
build/server-side-render/index.min.js 1.61 kB
build/shortcode/index.min.js 1.52 kB
build/token-list/index.min.js 668 B
build/url/index.min.js 1.99 kB
build/vendors/react-dom.min.js 38.5 kB
build/vendors/react.min.js 4.34 kB
build/viewport/index.min.js 1.08 kB
build/warning/index.min.js 280 B
build/widgets/index.min.js 7.21 kB
build/widgets/style-rtl.css 1.16 kB
build/widgets/style.css 1.16 kB
build/wordcount/index.min.js 1.07 kB

compressed-size-action

@cbravobernal
Copy link
Contributor Author

Right now all e2e tests are not working I guess due to Quick Edit and other JS broken on .org 😢

So we will wait for it to be fixed so we can keep working on them.

@cbravobernal cbravobernal force-pushed the add/comments-query-loop-e2e-tests branch from df7a662 to 98529c2 Compare March 17, 2022 17:32
@ockham
Copy link
Contributor

ockham commented Mar 17, 2022

The e2e test is currently failing with

TimeoutError: waiting for XPath `//button//span[contains(text(), 'Comment Query')]` failed: timeout 30000ms exceeded
    at new WaitTask (/home/runner/work/gutenberg/gutenberg/node_modules/puppeteer-core/src/common/DOMWorld.ts:813:28)
    at DOMWorld.waitForXPath (/home/runner/work/gutenberg/gutenberg/node_modules/puppeteer-core/src/common/DOMWorld.ts:702:22)
    at Frame.waitForXPath (/home/runner/work/gutenberg/gutenberg/node_modules/puppeteer-core/src/common/FrameManager.ts:1303:47)
    at Page.page [as waitForXPath] (/home/runner/work/gutenberg/gutenberg/node_modules/puppeteer-core/src/common/Page.ts:3269:29)
    at insertBlock (/home/runner/work/gutenberg/gutenberg/packages/e2e-test-utils/build/@wordpress/e2e-test-utils/src/inserter.js:165:29)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at Object.<anonymous> (/home/runner/work/gutenberg/gutenberg/packages/e2e-tests/specs/experiments/comments-query.test.js:23:3)

Looking at the test artifacts (available from the same page), there's a few screenshots that indicate that the block can't seem to be found in the inserter 🤔

Comment Query block insertion 2022-03-17T17-58-28

I think this could be due to a non-FSE theme being active (I can repro that behavior locally). So I think we might need to activate an FSE theme for this to work first. The tests in this directory should provide some inspiration; we might also consider moving our new test there, since it's kinda related to the Site Editor 🤔

@cbravobernal cbravobernal force-pushed the add/comments-query-loop-e2e-tests branch from c2ed98b to 7a3ab6c Compare March 18, 2022 17:11
@cbravobernal cbravobernal marked this pull request as ready for review March 18, 2022 18:14
Comment on lines 21 to 22
// We won't select the option that we updated and will also remove some
// _transient options that seem to change at every update.
Copy link
Contributor

@ockham ockham Mar 18, 2022

Choose a reason for hiding this comment

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

Stray comment? 😅

Suggested change
// We won't select the option that we updated and will also remove some
// _transient options that seem to change at every update.

Comment on lines 20 to 25
it( 'Comment Query block insertion', async () => {
// We won't select the option that we updated and will also remove some
// _transient options that seem to change at every update.
await insertBlock( 'Comments Query Loop' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
Copy link
Contributor

Choose a reason for hiding this comment

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

While it gives some confidence that the block can be inserted, I'm a bit skeptical if we should have a test that really only checks for that. Each test means additional maintenance (when the implementation changes, and the test has to be updated accordingly).

This is especially true with snapshot tests; while convenient, snapshot tests aren't very "semantic" in expressing our expectations. And it's quite possible that the exact block markup changes frequently (e.g. a newline is removed or introduced -- changes that wouldn't even have any impact on the block behavior), and there's a risk that we get used to updating them blindly and start ignoring the actual snapshot contents.

Another question would be why the Comments Query block needs a test to cover its insertion more than other blocks (since not all of them test for that). We've seen one case when the block was gone from the inserter (#39415), so that's a fair argument.

Still, TBH, I'd remove the snapshot test. IMO, it'd be best to have an e2e test that covers some behavior that's fairly specific to the block, and ideally has already seen a regression; a test like that would require block insertion anyway, so we'd get test coverage for that "for free". (I thought that we needed a test for the scenario described here, but it seems like you've covered that now with a unit test?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is covered by a unit test, but, as you mention, is not so clear what is that test solving.
For that reason, maybe creating an e2e of this case scenario would be a better idea, the only cons is that we have to create a lot of new funcionalities:

  • Setting and getting discussion options (almost done)
  • Creating at least 3 comments on the post/page.
  • Checking different elements on the frontend.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that might be okay 🤔 Since this is covering a whole new area of Gutenberg (the Comments blocks), it makes sense that it requires us to introduce corresponding e2e helpers.

Setting and getting discussion options (almost done)

👍 🎉

Creating at least 3 comments on the post/page.

I guess we can start with a helper that creates one comment and allows to specify whether it's a reply to the post, or to a different comment.

We should probably ask ourselves whether we want to:

  1. Create those comments via the frontend, which will implicitly also test the frontend functionality of those blocks. It means that any e2e test relying on the util will break if any of those blocks break (probably a good thing), or change their behavior, in which case the util will need updating (potentially less good, since it means more maintenance); or
  2. Use the wp-admin Comments panel (i.e. wp-admin/edit-comments.php). This is going to be stabler as we don't expect it to change as much as Gutenberg and the new Comments blocks. But maybe we really want the "Create Comment" helper to work via the frontend, especially if we're adding more features that we want to cover? 🤔

Curious to hear your thoughts!

Checking different elements on the frontend.

There might be some precedent for this (but certainly not a lot), since it's a problem that doesn't just apply to the Comments blocks, but to FSE more generally. Maybe try looking in the Site Editor e2e tests directory.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Use the wp-admin Comments panel (i.e. wp-admin/edit-comments.php). This is going to be stabler as we don't expect it to change as much as Gutenberg and the new Comments blocks. But maybe we really want the "Create Comment" helper to work via the frontend, especially if we're adding more features that we want to cover?

I'm afraid there is no option to create comments from there 😢 . So I guess we have to go with option 1 (creating on the front).

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid there is no option to create comments from there 😢 . So I guess we have to go with option 1 (creating on the front).

Ah, oops 😅 Looks like I didn't pay close enough attention! Well, fewer decisions for us to make 😅

Comment on lines 16 to 17
await setOption( 'page_comments', true, 'options-discussion.php' );
await setOption( 'comments_per_page', '2', 'options-discussion.php' );
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like we're not really testing for any behavior based on these settings now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, at least while the unit test is the one that checks the pagination behavior. Let's make an e2e to check the navigation links and these settings and functions will be necessary.

Comment on lines 38 to 78
await setOption( 'page_comments', false, 'options-discussion.php' );
await setOption( 'comments_per_page', '50', 'options-discussion.php' );
Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines 26 to 85
it( 'can be created by typing "/comment query loop"', async () => {
// Create a list with the slash block shortcut.
await clickBlockAppender();
await page.keyboard.type( '/comments query loop' );
await page.waitForXPath(
`//*[contains(@class, "components-autocomplete__result") and contains(@class, "is-selected") and contains(text(), 'Comments Query Loop')]`
);
await page.keyboard.press( 'Enter' );
expect( await getEditedPostContent() ).toMatchSnapshot();
} );
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm afraid the same arguments as above apply 😕 It's a rather generic test that covers pretty standard block behavior -- the only reason it would fail that would be more or less specific to the Query Loop block is if it's not registered or otherwise broken. But as said above, we should cover block insertion as part of a test that covers a behavior that's more specific to the individual block (and we don't really need to cover different ways to insert the same block).

If we currently don't have any more block-specific tests (cause they're e.g. already covered by the unit test), I'd go as far as to suggest to remove them 😅

* @param {string} value The value to set the option to.
* @param {string} adminPage The url of the admin page to visit.
*
* @return {Promise<string>} The current value of the option.
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we're no longer returning any value from the helper function?

Copy link
Contributor Author

@cbravobernal cbravobernal Mar 21, 2022

Choose a reason for hiding this comment

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

Yes, we can add it if we ever need it, but yet I didn't find a case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's remove the JSDoc line it in case we don't actually return anything. I'd even lean towards removing it already so we don't forget about it; we can add it back later 🙂 YAGNI etc.

* @param {string} value The value to set the option to.
* @param {string} setting The option, used to get the option by id.
* @param {string} value The value to set the option to.
* @param {string} adminPage The url of the admin page to visit.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we mention the default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I forgot about that one 😓

$comment_query_max_num_pages = 5;
// We substract 1 because we created 1 comment at the beggining.
$post_comments_numbers = ( self::$per_page * $comment_query_max_num_pages ) - 1;
self::$comment_ids = self::factory()->comment->create_post_comments(
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems like we're not using self::$comment_ids anywhere?

Comment on lines 257 to 270
$this->assertEquals(
build_comment_query_vars_from_block( $block ),
array(
'orderby' => 'comment_date_gmt',
'order' => 'ASC',
'status' => 'approve',
'no_found_rows' => false,
'update_comment_meta_cache' => false,
'post_id' => self::$custom_post->ID,
'hierarchical' => 'threaded',
'number' => self::$per_page,
'paged' => $comment_query_max_num_pages,
)
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Some of these seem circumstantial (and not really impacted by our choice of settings). Would it make sense to only test for some select attributes, rather than the entire array?

E.g.

$actual = build_comment_query_vars_from_block( $block );
$this->assertEquals( $actual[ 'paged' ], $comment_query_max_num_pages);
// Etc

Comment on lines +225 to +170
/**
* Test that both "Older Comments" and "Newer Comments" are displayed in the correct order
* inside the Comment Query Loop when we enable pagination on Discussion Settings.
* In order to do that, it should exist a query var 'cpage' set with the $comment_args['paged'] value.
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

TBH without knowing much about build_comment_query_vars_from_block, pagination settings, and the cpage query arg and paged value, this is a lot to swallow 😅 It's not obvious to me how all these things are related to the correct order of "Older Comments" and "Newer Comments".

The test may have its value in covering the underlying implementation to ensure the desired behavior, but maybe it'd actually make sense to still add the e2e test to cover that behavior?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cbravobernal cbravobernal marked this pull request as draft March 21, 2022 11:49
@gziolo gziolo added [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Block] Comments Affects the Comments Block - formerly known as Comments Query Loop labels Mar 22, 2022
@cbravobernal cbravobernal force-pushed the add/comments-query-loop-e2e-tests branch from aea6688 to 3d12368 Compare March 25, 2022 08:07
}

// We check that there is a previous comments page link.
await page.waitForSelector( '.wp-block-comments-pagination-previous' );
Copy link
Contributor

@ockham ockham Mar 28, 2022

Choose a reason for hiding this comment

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

There's one minor issue with this: If the selector is not there, this will time out and throw an error -- i.e. we won't even make it to the assertion on the next line. This means that the assertion is kind of redundant.

So should we remove the assertion? No, since it's better to explicitly state our intent rather than implicitly.

Let's keep this as-is for now and merge it; I might file a follow-up to experiment with replacing the waitForSelector with waitForNavigation 🙂

Copy link
Contributor

Choose a reason for hiding this comment

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

Tentative diff for later:

diff --git a/packages/e2e-tests/specs/experiments/blocks/comments-query.test.js b/packages/e2e-tests/specs/experiments/blocks/comments-query.test.js
index 55c6b4b07a..d3b8c880a9 100644
--- a/packages/e2e-tests/specs/experiments/blocks/comments-query.test.js
+++ b/packages/e2e-tests/specs/experiments/blocks/comments-query.test.js
@@ -48,12 +48,13 @@ describe( 'Comment Query Loop', () => {
 				`This is an automated comment - ${ i }`
 			);
 			await pressKeyTimes( 'Tab', 1 );
-			await page.keyboard.press( 'Enter' );
-			await page.waitForNavigation();
+			await Promise.all( [
+				page.keyboard.press( 'Enter' ),
+				page.waitForNavigation( { waitUntil: 'networkidle0' } ),
+			] );
 		}
 
 		// We check that there is a previous comments page link.
-		await page.waitForSelector( '.wp-block-comments-pagination-previous' );
 		expect(
 			await page.$( '.wp-block-comments-pagination-previous' )
 		).not.toBeNull();
@@ -61,21 +62,25 @@ describe( 'Comment Query Loop', () => {
 			await page.$( '.wp-block-comments-pagination-next' )
 		).toBeNull();
 
-		await page.click( '.wp-block-comments-pagination-previous' );
+		await Promise.all( [
+			page.click( '.wp-block-comments-pagination-previous' ),
+			page.waitForNavigation( { waitUntil: 'networkidle0' } ),
+		] );
 
 		// We check that there are a previous and a next link.
-		await page.waitForSelector( '.wp-block-comments-pagination-previous' );
-		await page.waitForSelector( '.wp-block-comments-pagination-next' );
 		expect(
 			await page.$( '.wp-block-comments-pagination-previous' )
 		).not.toBeNull();
 		expect(
 			await page.$( '.wp-block-comments-pagination-next' )
 		).not.toBeNull();
-		await page.click( '.wp-block-comments-pagination-previous' );
+
+		await Promise.all( [
+			page.click( '.wp-block-comments-pagination-previous' ),
+			page.waitForNavigation( { waitUntil: 'networkidle0' } ),
+		] );
 
 		// We check that there is only have a next link
-		await page.waitForSelector( '.wp-block-comments-pagination-next' );
 		expect(
 			await page.$( '.wp-block-comments-pagination-previous' )
 		).toBeNull();

Copy link
Contributor

Choose a reason for hiding this comment

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

PR: #39818

Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

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

Thanks Carlos! LGTM! 🚢

Here's one note for a follow-up PR 🙂

BTW I just learned the other day that we now have an alternative way of writing e2e tests (using playwright, and generally using the REST API rather than wp-admin to change settings). We can give that a try some time, it might speed up e.g. comment creation.

@cbravobernal cbravobernal merged commit 7b28f7e into trunk Mar 28, 2022
@cbravobernal cbravobernal deleted the add/comments-query-loop-e2e-tests branch March 28, 2022 14:22
@github-actions github-actions bot added this to the Gutenberg 13.0 milestone Mar 28, 2022
@ockham
Copy link
Contributor

ockham commented Mar 28, 2022

BTW I just learned the other day that we now have an alternative way of writing e2e tests (using playwright, and generally using the REST API rather than wp-admin to change settings). We can give that a try some time, it might speed up e.g. comment creation.

PR draft: #39826

@gziolo
Copy link
Member

gziolo commented Apr 14, 2022

Can you have a look at the test failure on trunk:

https://github.com/WordPress/gutenberg/runs/6021185292?check_suite_focus=true

Screenshot 2022-04-14 at 12 19 55

Those blocks are no longer experimental, so the location of the test file should also get updated.

@ockham
Copy link
Contributor

ockham commented Apr 14, 2022

Since that test was re-run successfully, there are no test artifacts available from that test run.

However, this one has the same error (and wasn't re-run), so there are artifacts:

Pagination links are working as expected 2022-04-13T11-30-05

Looks like all comments are rendered on the same page, which explains why there are no pagination links shown. This means that setting the relevant comments pagination options doesn't seem to have worked in this test run 😕

@ockham
Copy link
Contributor

ockham commented Apr 14, 2022

I'm not quite sure why this is happening 😕 After all, setOption() makes sure that changed settings are properly submitted. I wonder if that's not waiting long enough after all?

Or maybe the page hasn't fully loaded when we try to focus the relevant field and change it? 🤔

@cbravobernal
Copy link
Contributor Author

Those blocks are no longer experimental, so the location of the test file should also get updated.

Or maybe the page hasn't fully loaded when we try to focus the relevant field and change it? 🤔

I created a PR to address:

  • Moving to stable.
  • Adding a wait for the option selector.

#40405

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Comments Affects the Comments Block - formerly known as Comments Query Loop [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants