Skip to content

Adds unit and e2e tests for CopyrightWaiverStep Component #152

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

Merged
merged 10 commits into from
Apr 4, 2020
Merged

Adds unit and e2e tests for CopyrightWaiverStep Component #152

merged 10 commits into from
Apr 4, 2020

Conversation

JackieBinya
Copy link
Contributor

Fixes

Related #133 by @akmadian

Description

  • Adds unit tests
  • Adds e2e tests

Technical details

Tests

Screenshots

Checklist

  • [x ] My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the master branch of the repository.
  • My commit messages follow best practices.
  • [x ] My code follows the established code style of the repository.
  • [x ] I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@JackieBinya JackieBinya requested review from a team April 2, 2020 12:11
Copy link
Contributor

@obulat obulat left a comment

Choose a reason for hiding this comment

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

Thank you for contribution, @JackieBinya , it looks great!
Could you please run the linter on the file? After that, there are only two minor issues that I will comment on on the corresponding lines.

@JackieBinya
Copy link
Contributor Author

@obulat I have cleared the errors as advised in the review.
Well, I have an issue with the test coverage when I run npm run test, the results are in the screenshot below. Somehow lines 57, 58, 70,71 have not been tested in the unit tests in CopyrightWaiverStep.spec.js

Screenshot from 2020-04-02 17-04-58

After going through the logic what I realized was that the logic makes it seem like there are checkboxes where the user has an option to check not to agree OR not confirmed. But in reality, that's not the case the user can only check agree or confirm.
So I am in a situation where I'm stuck I don't have a checkbox I can check and trigger events on the else if statements on lines 57,58,70,71

@JackieBinya JackieBinya closed this Apr 2, 2020
@obulat
Copy link
Contributor

obulat commented Apr 2, 2020

Coverage shows that 4 lines are not covered. They have to do with the state when both checkboxes are checked, and the user 'deselects' one of them. Once you add tests for them, I will approve this PR.

@JackieBinya JackieBinya reopened this Apr 2, 2020
@obulat
Copy link
Contributor

obulat commented Apr 2, 2020

I guess you have already understood the answer to your question, but I will still write it just in case:

The user can check both checkboxes at first, but then go back and click on one of them again. If this happens, the CopyrightWaiverStep should not let the user proceed. So, if you set both props to true, and then click on them (setChecked(false)) and test for the emitted event, you will cover the remaining lines.

@JackieBinya
Copy link
Contributor Author

Hi, @obulat I have added the tests. But I had a problem with my Github account for some reason it was not showing all my pushed commits, hence the reason, I pushed the same commit twice.
Well in my implementation I used checkbox.trigger('change') instead of setChecked(false) Only because my github was not updating hence I was not able to see your recommendations. But despite that, I have tested the emitted events in the if-else block line 58&71. Coverage still says line 57 and 70 are yet to be checked. But overall coverage has improved.
Please check out the screenshot below.
Screenshot from 2020-04-02 23-36-05

In the meantime, I will try to write the e2e tests as I await your review.

@obulat
Copy link
Contributor

obulat commented Apr 3, 2020

Hi, @obulat I have added the tests. But I had a problem with my Github account for some reason it was not showing all my pushed commits, hence the reason, I pushed the same commit twice.

Actually, github was down about 7-8 hours ago, I think that's the reason for some problems you had. Don't worry!

Well in my implementation I used checkbox.trigger('change') instead of setChecked(false) Only because my github was not updating hence I was not able to see your recommendations. But despite that, I have tested the emitted events in the if-else block line 58&71. Coverage still says line 57 and 70 are yet to be checked. But overall coverage has improved.
Please check out the screenshot below.
Screenshot from 2020-04-02 23-36-05

I tried to figure it out, but I don't quite understand how that line can be untested, when we actually do get inside that condition, and the line after 'if' is executed.
However, I found a solution for how to cover those lines. In general, it is better to treat the code as a black box when you are testing it. So, it is better to approach it as a user clicking on a checkbox rather than a coder who knows how to set the props behind that checkbox. In this case, you set the agreed and confirmed properties in the beginning by using setData. Instead, you can set them to true by clicking both checkboxes. Then, to actually test 'unchecking', you can click on one of the checkboxes again. This way, those two lines get covered.

@JackieBinya
Copy link
Contributor Author

Hi, @obulat I have added the tests. But I had a problem with my Github account for some reason it was not showing all my pushed commits, hence the reason, I pushed the same commit twice.

Actually, github was down about 7-8 hours ago, I think that's the reason for some problems you had. Don't worry!

Well in my implementation I used checkbox.trigger('change') instead of setChecked(false) Only because my github was not updating hence I was not able to see your recommendations. But despite that, I have tested the emitted events in the if-else block line 58&71. Coverage still says line 57 and 70 are yet to be checked. But overall coverage has improved.
Please check out the screenshot below.
Screenshot from 2020-04-02 23-36-05

I tried to figure it out, but I don't quite understand how that line can be untested, when we actually do get inside that condition, and the line after 'if' is executed.
However, I found a solution for how to cover those lines. In general, it is better to treat the code as a black box when you are testing it. So, it is better to approach it as a user clicking on a checkbox rather than a coder who knows how to set the props behind that checkbox. In this case, you set the agreed and confirmed properties in the beginning by using setData. Instead, you can set them to true by clicking both checkboxes. Then, to actually test 'unchecking', you can click on one of the checkboxes again. This way, those two lines get covered.

Thank you so much for that pointer @obulat. It will forever change my approach to writing unit tests. Finally, I had my 'Aha' moment. I was familiar with the approach of treating logic/code as Blackbox but today I finally understood. Coverage is now at 100%

Screenshot from 2020-04-03 08-44-34

@obulat
Copy link
Contributor

obulat commented Apr 4, 2020

Thank you so much for that pointer @obulat. It will forever change my approach to writing unit tests. Finally, I had my 'Aha' moment. I was familiar with the approach of treating logic/code as Blackbox but today I finally understood.

Great! To be honest, I got this approach after reading the article from vuejsdevelopers.com on "Knowing what to test".

@obulat obulat merged commit a1875b4 into creativecommons:master Apr 4, 2020
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