Fix VideoPress block test cases#5916
Conversation
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.
src/test/videopress/edit.js
Outdated
| post_id: 1, | ||
| duration: 2803, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
For now, I'd prefer to keep them as-is and only focus on the fixes, if that makes sense.
Absolutely. 🚀
There was a problem hiding this comment.
I've just applied this suggestion via 68a1ccd.
| { | ||
| request: { | ||
| path: `/wpcom/v2/videopress/${ guid }/check-ownership/${ postID }`, | ||
| method: 'GET', | ||
| }, | ||
| response: { | ||
| 'video-belong-to-site': belongsToSite, | ||
| }, | ||
| }, |
There was a problem hiding this comment.
We need to mock this response, otherwise, some of the block settings like the title will be locked.
src/test/videopress/edit.js
Outdated
| post_id: 1, | ||
| duration: 2803, |
There was a problem hiding this comment.
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.
Fixes the JSDoc type of `isVideoPrivate` and `isSitePrivate` params. Co-authored-by: David Calhoun <github@davidcalhoun.me>
|
Wanna run full suite of Android and iOS UI tests? Click here and 'Approve' CI job! |
| // 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} /-->"`; |
There was a problem hiding this comment.
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.
gutenberg-mobile/src/test/videopress/local-helpers/utils.js
Lines 203 to 229 in 68a1ccd
| } | ||
| return { | ||
| privacySetting: isVideoPrivate ? 1 : 0, | ||
| isPrivate, |
There was a problem hiding this comment.
Sorry I didn't notice before 🤦 , but this should be:
isPrivate: isVideoPrivate,
I'll push a fix directly in the base branch (4349216) 💨
This PR aims to fix the failures in #5874 related to unit tests.
ci/circleci: Test Androidci/circleci: Test iOSWe could omit the rest as they will be solved in other PRs.
To test:
npm run test.Alternatively, we could rely on the CI job that runs the unit tests.
PR submission checklist: