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

Unit tests for widgets #73

Open
5 of 14 tasks
lapp0 opened this issue Jul 23, 2021 · 0 comments
Open
5 of 14 tasks

Unit tests for widgets #73

lapp0 opened this issue Jul 23, 2021 · 0 comments
Labels
good first issue Good for newcomers
Milestone

Comments

@lapp0
Copy link
Collaborator

lapp0 commented Jul 23, 2021

Obvious unworkability not caught by tests #60 (comment)

We need to implement tests for the behavior for all widgets eventually. They can be tackled one at a time, pull requests needn't cover all of these.

These unit tests should mock out any calls to state_model or api. They also should only create an instance of the widget being tested, not the entirety of Nix-Gui.

Tests

Utilities:

https://github.com/pytest-dev/pytest-mock

https://docs.python.org/3/library/unittest.mock.html

field_widgets.py

  • For each non-Redirect widget create a single test function which does the following
  1. call __init__
  2. ensure current_value() is a sane default and works (e.g. BooleanField should be False)
  3. use pytest.mark.parameterize to call load_value()
  4. ensure current_value() is the passed value

For Null assert it's current_value is None,

UndefinedField -> Undefined,

NotImplementedField -> assert raises an exception

navbar.py

  • assert up_fn called when up is clicked (with mocked fn and check call)
  • assert set_lookup_key_fn(None) called when back is clicked
  • pass mocked set_lookup_key_fn
    • use qt to enter text into path_textbox and assert set_lookup_key_fn called with search key
    • use qt to enter text into search_textbox and assert set_lookup_key_fn called with search:text

navlist.py

  • ensure clicking an item in SearchResultListDisplay results in a call to self.set_option_path_callback

  • ensure clicking an item in StaticAttrsOf results in a call to self.set_option_path_callback

  • TODO: Need to complete Complete Implementation of ListOf #30 and DynamicAttrsOf Improvements #72 before writing tests for DynamicListOf and DynamicAttrsOf

option_display.py

  • load Undefined, ensure everything is hidden, undefined toggle is off
  • load defined value, ensure everything is shown
  • load defined value that can be an int, bool, or str. Ensure clicking each type changes the active widget in self.entry_stack, also ensure no Updates are created

Integration Tests (out of scope of the issue?)

search

  • load a search result

navlist.py

@lapp0 lapp0 added this to the V0.3 milestone Jul 27, 2021
@lapp0 lapp0 added the good first issue Good for newcomers label Oct 13, 2021
@lapp0 lapp0 changed the title Unit tests for all widgets Unit tests for widgets Oct 13, 2021
lapp0 pushed a commit that referenced this issue Dec 9, 2021
Unit tests for field widgets (Part of #73)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant