EmilStenstrom / django-components

Create simple reusable template components in Django.
MIT License
953 stars 59 forks source link

Tests refactor: Move from template files to inline templates #470

Closed EmilStenstrom closed 2 weeks ago

EmilStenstrom commented 2 weeks ago

It might be just me (please disagree in the comments), but I'm finding it hard to look at many of the tests, and understand what the tests are testing. To do it, you first look at the test, then at the component it's defining, then at the template file it's referencing. This is OK I guess, but I'm slowing finding it more and more annoying as we add more tests.

Idea: Could we make each test function self-containing, with very few external references? I would be fine if we duplicate some code between tests here; sharing code between tests is likely not a good idea anyways.

Suggestion:

  1. Move all the template code from external files to inline templates in the component definition
  2. Move all components from classes defined outside of the test function to inline classes defined in the function.

The goal with these changes would be to be able to look at a test, and immediately understand what it's testing, without having to look stuff up in several different places.

JuroOravec commented 2 weeks ago

Totally agree!

JuroOravec commented 2 weeks ago

Gave it a go at https://github.com/EmilStenstrom/django-components/pull/474