PDF: Remove legacy view & add tests#257
Conversation
|
Thanks for the pull request, @Kelketek! This repository is currently maintained by Once you've gone through the following steps feel free to tag them in a comment and let them know that your changes are ready for engineering review. 🔘 Get product approvalIf you haven't already, check this list to see if your contribution needs to go through the product review process.
🔘 Provide contextTo help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:
🔘 Get a green buildIf one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green. DetailsWhere can I find more information?If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources: When can I expect my changes to be merged?Our goal is to get community contributions seen and reviewed as efficiently as possible. However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:
💡 As a result it may take up to several weeks or months to complete a review and merge your PR. |
3f30cc1 to
7ec98e1
Compare
|
@kdmccormick I could use your advice (and perhaps preliminary review) here. As requested, I've added JS tests for the PDF block. I noted the following:
The other blocks do work currently, right? How are they ensuring their files are built before serving them? Am I taking a totally backward approach? |
dad29e5 to
672ef99
Compare
|
@kdmccormick Nevermind-- decided not to have the bootstrapper built, nor use the 'public' folder, and instead only add tests rather than a build system for the general case, since it's not really necessary here anyway. |
|
@kdmccormick Oh, and-- ready for you :) |
samuelallan72
left a comment
There was a problem hiding this comment.
On a clean clone, the tests fail with:
node:fs:1350
const result = binding.mkdir(
^
Error: ENOENT: no such file or directory, mkdir '/home/samuel/proj/opencraft/xblocks-core/xblocks_contrib/video/public/js'
I don't think this is related to this PR though, since this is for the video xblock. These tests pass if I manually created that dir. Although it passes in CI, so I'm not sure what I missed here.
Please see other comments/questions inline. :)
| const tag = document.createElement('div') | ||
| tag.setAttribute('data-testid', 'jquery-loaded') | ||
| document.body.appendChild(tag) | ||
| clearInterval(id) |
There was a problem hiding this comment.
The scope of id is in the parent, so it's available to the child. const allows shadowing and global access if the name is defined higher. It prevents polluting outer scopes and redefinition, though.
Try this in your browser console:
const id = setInterval(() => console.log(id), 100)There was a problem hiding this comment.
@Kelketek that's so weird! I knew about the scopes, but it felt weird that it was fine accessing the variable that was defined here (after or at the same time as the function was defined). I see that this also works which feels even more wrong:
const id = setInterval(() => console.log(foo), 100)
const foo = "hello";
🤔 🤔
There was a problem hiding this comment.
@samuelallan72 Does it seems less weird if it's a function?
const doThing = () => {
scream()
setTimeout(() => doThing(), 100)
}
function scream () {
console.log("AHHHH!")
}
doThing()There was a problem hiding this comment.
@Kelketek ah yes, that does seem less weird. Nice. :) I guess this is usual recursion, but just looked weird to me in this context. 👍
| "scripts": { | ||
| "setup": "playwright install", | ||
| "check": "tsc --noEmit", | ||
| "test": "npm run build && vitest run", |
There was a problem hiding this comment.
Does the build subcommand call need to be there? Currently it fails for me because there's no build subcommand. (not sure why it succeeds in CI)
There was a problem hiding this comment.
Nope, I forgot to replace it with check and only tested test-ci after I did it there.
| @@ -1,58 +0,0 @@ | |||
| {% load i18n %} | |||
There was a problem hiding this comment.
Does this then drop support for openedx < ulmo?
There was a problem hiding this comment.
< Verawood. The included PDF feature only arrived in Verawood, and had the MFE editing when Verawood was cut. It didn't have it when initially merged, which means no release has had the included PDF block with the backend-rendered editor enabled. Only master has had it briefly.
It is possible to override use of the PDF block with one of the older versions, though, if you need to.
| return new Promise((resolve) => setTimeout(resolve, ms)); | ||
| } | ||
|
|
||
| const waitFor = async <T>(func: () => T, timeout: number = 1000) => { |
There was a problem hiding this comment.
vitest includes a waitFor function: https://vitest.dev/api/vi.html#vi-waitfor . Can we use that instead of implementing our own?
There was a problem hiding this comment.
Ah! I thought it was only available in testing-library, and I didn't want to add an entire library for one function.
| document.body.appendChild(block) | ||
| } | ||
|
|
||
| const loadJsPayload = async (path: string, id?: string) => { |
There was a problem hiding this comment.
Could you add a comment about why we need this kind of loading? I found it confusing.
|
@samuelallan72 This is ready for another look. Thanks! |
|
(please link to https://tasks.opencraft.com/browse/BB-10571 from the PR description :) )
|
|
@kdmccormick Went ahead and got it an internal review here, which it's passed. Could you take a look? |
|
@kdmccormick Do you have an idea when you'll be able to take a look at this? Thanks! |
| @@ -0,0 +1,19 @@ | |||
| { | |||
There was a problem hiding this comment.
It looks like the other blocks in this repo have a package.json for the block itself (not just the tests) and then use devDependencies to declare tests deps. Does that pattern seem reasonable to follow here, too? The setup script would become something like setup-tests
There was a problem hiding this comment.
@kdmccormick The other blocks have an assets directory where the package.json is defined, and then that builds out and sticks the assets in the public directory, which is .gitignored. Then Karma serves the files from there to run its tests. This is a lot of indirection and doesn't quite make it clear what the scope of the script is-- it gave me the impression that we were building the JS using npm and then eventually serving that in production somehow, but I couldn't find any mechanism for doing that, unless you're aware of one?
Vitest doesn't require this additional 'build to asset directory' step, so the kind of hopping around with directories isn't needed.
Additionally, we're not building any assets for the PDF block. I attempted to build the bootstrap script from there, but there wasn't a good TypeScript config that would work consistently with the kind of in-browser stuff it does-- especially not with newer versions.
There's one JS file, which only serves as a bootstrap point. If and when we need to start building JS for display of the PDF block, I'd suggest we tackle any reconciliation then, as the build is likely to be significantly different to how we do it for other blocks.
There was a problem hiding this comment.
Thanks, that all makes sense. Do you mind calling it npm run setup-tests or something that makes it's clear that it's just installing test deps?
I believe what's actually happening for the other blocks is that they get shoved into the openedx-platform static asset build (not great) and that the static asset build here is just for tests. This is something we've been meaning to untangle.
kdmccormick
left a comment
There was a problem hiding this comment.
LGTM pending my suggestion about setup -> setup-tests
3e61b9f to
58501dd
Compare
Description
This merge request adds tests for the PDF Block initializer. It also removes the backend rendered studio view now that the authoring MFE directly supports PDF blocks.
Supporting information
Link to other information about the change, such as Jira issues, GitHub issues, or Discourse discussions.
Be sure to check they are publicly readable, or if not, repeat the information here.
Testing instructions
OPENEDX_EXTRA_PIP_REQUIREMENTSwith atutor dev launchafterwardpdfto the advanced modules list for a coursenpm run setupand thennpm run test. Verify the output shows the PDF block tests (they're likely last)Other information
Closes #170
Merge checklist:
Check off if complete or not applicable: