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

test for jest conversion #767

Merged
merged 4 commits into from
Dec 21, 2021
Merged

test for jest conversion #767

merged 4 commits into from
Dec 21, 2021

Conversation

jywarren
Copy link
Member

@jywarren jywarren commented Dec 21, 2021

Working from these for triggering the event without jQuery:

Sourcing syntax from this: https://github.com/publiclab/PublicLab.Editor/blob/main/test/ui-testing/bold.test.js

Trying to convert this Jasmine test:

it("Publish button is enabled", function() {
// Check initially that Publish button is disabled.
expect($('.ple-publish').prop('disabled')).toBe(true);
// Add title.
$('.ple-module-title input').val('A title');
$('.ple-module-title input').keydown();
// Check final state of Publish button.
expect($('.ple-publish').prop('disabled')).toBe(false);
});

@gitpod-io
Copy link

gitpod-io bot commented Dec 21, 2021


test('Publish button is enabled', () => {
// Check initially that Publish button is disabled.
expect(await page.evaluate(() => document.querySelector('.ple-textarea').disabled).toBe(true);
Copy link
Member Author

Choose a reason for hiding this comment

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

What's odd is that I thought we use the /Bootstrap class/ disabled to set the disabled state on this. I don't know how that interacts with the HTML attribute -- the difference is:

<i class="disabled"></i> (Bootstrap CSS)
<i disabled></i> (HTML)

So we may need to disambiguate how this is working, possibly by manually testing the jquery $('.ple-publish').prop('disabled') vs. just el.disabled.

@jywarren
Copy link
Member Author

OK - so i think that's right:


  ● Publish button › Publish button is enabled

    expect(received).toBe(expected) // Object.is equality

    Expected: true
    Received: false

      10 |   test('Publish button is enabled', async () => {
      11 |     // Check initially that Publish button is disabled.    
    > 12 |     expect(await page.evaluate(() => document.querySelector('.ple-textarea').disabled)).toBe(true);
         |                                                                                         ^
      13 |     // Add title.
      14 |     await page.evaluate(() => {
      15 |       document.querySelector('.ple-module-title input').value = 'A title'

We should try this: document.querySelector('.ple-publish').style.includes('disabled'));

oh wait. First we should be checking ple-publish and not ple-textarea! Doh!

@jywarren
Copy link
Member Author

That worked! @NARUDESIGNS 🎉

So, maybe what we should do is to look closely at the old test vs. this new one. And to come up with a little bit of helpful documentation (even just a short checklist) for how to do this kind of test conversion successfully. It looks like a combination of:

  • .evaluate()
  • adding async
  • switching to non-jQuery functions

Does that sound right?

@jywarren
Copy link
Member Author

Would you like to try that for an additional test file now? I'll merge this. I hope this'll get us moving now! Thanks Paul, for your patience!!!

@jywarren jywarren merged commit e0f5972 into main Dec 21, 2021
@jywarren
Copy link
Member Author

Ah, and we should add to the checklist - removing the tests from the Jasmine files. So when we finish all conversions, we'll have no more Jasmine tests!

@NARUDESIGNS
Copy link
Collaborator

Wow awesome!
I took some time to rest my head after our meeting. I can't wait to see those tests turn green!!!
I'd have a look at it tomorrow, it's 11pm here right now.
Thank you @jywarren you are amazing! 🔥 🔥 🔥

// Add title.
await page.evaluate(() => {
document.querySelector('.ple-module-title input').value = 'A title';
document.querySelector('.ple-module-title input').dispatchEvent(new KeyboardEvent('keydown', { "code": "9" })); // random key
});
// Check final state of Publish button.
expect(await page.evaluate(() => document.querySelector('.ple-textarea').disabled)).toBe(false);
expect(await page.evaluate(() => document.querySelector('.ple-publish').disabled)).toBe(false);
});
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @jywarren I noticed you didn't add the timeout variable here. Is this part of the new change or is it something you missed out?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I was able to set it globally on the first few lines and so didn't need to set it per-test.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, interesting, actually on checking, I am not setting the timeout. I think that means we could remove that line, actually.

For reference, I'm stuck on a related issue (going past the timeout limit in this case) in this test publiclab/image-sequencer#2026

https://github.com/publiclab/image-sequencer/blob/58eb3ef6b1caba88aaf217d93ec085a14765d8aa/test/ui-2/test/OverlayInput.test.js#L1-L12

That actually is globally setting timeout. But here I think i just removed it and for the purposes of our test it wasn't needed. I think the default timeout is 5 or 10 seconds? So i guess that's enough for this.

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

Successfully merging this pull request may close these issues.

2 participants