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

Fix VideoPress block test cases #5916

Merged
merged 9 commits into from
Jun 29, 2023

Conversation

fluiddot
Copy link
Contributor

@fluiddot fluiddot commented Jun 29, 2023

This PR aims to fix the failures in #5874 related to unit tests.

⚠️ It's expected that some of the CI jobs fails due to the RN upgrade. The jobs that this PR aims to fix are:

  • ci/circleci: Test Android
  • ci/circleci: Test iOS

We could omit the rest as they will be solved in other PRs.

To test:

  • Run the command: npm run test.
  • Observe that all tests pass.

Alternatively, we could rely on the CI job that runs the unit tests.

PR submission checklist:

  • I have considered adding unit tests where possible.
  • I have considered if this change warrants user-facing release notes more info and have added them to RELEASE-NOTES.txt if necessary.

Instead of using a constant for the block HTML, now we generate the HTML via the `generateBlockHTML` util.
This is needed to keep the same block attributes set via the block HTML generation.

Extract fetch mock metadata to a constant
The only change is that the video is now public when setting a caption. This has no impact in the testing logic.
@fluiddot fluiddot added the Testing Anything related to automated tests label Jun 29, 2023
@fluiddot fluiddot self-assigned this Jun 29, 2023
Comment on lines 46 to 47
post_id: 1,
duration: 2803,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These parameters are not really being tested but decided to include them to avoid updating the Jest snapshots. Especially, as updating snapshots usually makes the changes harder to review.

Copy link
Member

Choose a reason for hiding this comment

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

I have no objections to reviewing a snapshot change if it means the stored snapshot is more helpful or realistic. However, if these mocked parameters achieve a more realistic picture, then it makes sense to keep them IMO.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be honest, these parameters don't provide any value in the snapshot. They aren't meant to be updated in the test cases but since the VideoPress block updates settings automatically from the API when rendering the block, they are included. I'm happy with both options, but if including them in the tests gives a wrong impression of their usage, I can revert it.

Copy link
Member

Choose a reason for hiding this comment

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

I have no strong preference. I suppose I mostly wanted to convey that we should not be afraid of updating snapshots. If a given snapshot is too unwieldily to review, a more appropriate alternative may be forgoing snapshots altogether and asserting against specific outcomes, e.g. attributes within the snapshot.

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 have no strong preference. I suppose I mostly wanted to convey that we should not be afraid of updating snapshots.
Yep, I think in this case we can update the snapshots as we don't have that many to make the review complex 👍.

If a given snapshot is too unwieldily to review, a more appropriate alternative may be forgoing snapshots altogether and asserting against specific outcomes, e.g. attributes within the snapshot.

Good point. In general, I'd rather lean on snapshots to simplify test logic. But I agree that in some cases there's a good value on asserting specific outcomes. For these test cases, I'm hesitant about which one would fit better. For now, I'd prefer to keep them as-is and only focus on the fixes, if that makes sense.

Copy link
Member

Choose a reason for hiding this comment

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

For now, I'd prefer to keep them as-is and only focus on the fixes, if that makes sense.

Absolutely. 🚀

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've just applied this suggestion via 68a1ccd.

Comment on lines +254 to +262
{
request: {
path: `/wpcom/v2/videopress/${ guid }/check-ownership/${ postID }`,
method: 'GET',
},
response: {
'video-belong-to-site': belongsToSite,
},
},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to mock this response, otherwise, some of the block settings like the title will be locked.

@fluiddot fluiddot marked this pull request as ready for review June 29, 2023 15:50
Comment on lines 46 to 47
post_id: 1,
duration: 2803,
Copy link
Member

Choose a reason for hiding this comment

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

I have no objections to reviewing a snapshot change if it means the stored snapshot is more helpful or realistic. However, if these mocked parameters achieve a more realistic picture, then it makes sense to keep them IMO.

src/test/videopress/local-helpers/utils.js Outdated Show resolved Hide resolved
src/test/videopress/local-helpers/utils.js Outdated Show resolved Hide resolved
Fixes the JSDoc type of `isVideoPrivate` and `isSitePrivate` params.

Co-authored-by: David Calhoun <[email protected]>
@peril-wordpress-mobile
Copy link

peril-wordpress-mobile bot commented Jun 29, 2023

Wanna run full suite of Android and iOS UI tests? Click here and 'Approve' CI job!

@@ -1,39 +1,39 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Update VideoPress block's settings should update Playback Bar Color section's Dynamic color setting 1`] = `"<!-- wp:videopress/video {"title":"default-title-is-file-name","description":"","id":1,"guid":"AbCdEfGh","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":true,"duration":2803} /-->"`;
exports[`Update VideoPress block's settings should update Playback Bar Color section's Dynamic color setting 1`] = `"<!-- wp:videopress/video {"title":"default-title-is-file-name","description":"","id":34,"guid":"AbCdEfGh","privacySetting":2,"allowDownload":false,"rating":"G","isPrivate":true,"duration":1200} /-->"`;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The id and duration attributes have been modified due to using the default values specified in the util function (reference). They don't have an impact on the test cases, so we can omit them.

const postID = metadata?.post_id ?? 34;
return [
{
request: {
path: `/wpcom/v2/media/videopress-playback-jwt/${ guid }`,
method: 'POST',
body: {},
},
response: {
metadata_token: token,
},
},
{
request: {
path: isPrivate
? `/rest/v1.1/videos/${ guid }?metadata_token=${ token }`
: `/rest/v1.1/videos/${ guid }`,
credentials: 'omit',
global: true,
},
response: {
description: 'video-description',
post_id: postID,
guid,
private_enabled_for_site: false,
title: 'video-title',
duration: 1200,

@fluiddot fluiddot merged commit 4662b08 into upgrade/react-native-0.71.8 Jun 29, 2023
@fluiddot fluiddot deleted the fix/videopress-block-tests branch June 29, 2023 16:57
}
return {
privacySetting: isVideoPrivate ? 1 : 0,
isPrivate,
Copy link
Contributor Author

@fluiddot fluiddot Jun 29, 2023

Choose a reason for hiding this comment

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

Sorry I didn't notice before 🤦 , but this should be:

isPrivate: isVideoPrivate,

I'll push a fix directly in the base branch (4349216) 💨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Testing Anything related to automated tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants