Skip to content

Additional tests for FlexboxLayout and FlexDirection#174

Merged
alice-i-cecile merged 6 commits intoDioxusLabs:mainfrom
mcrvaz:style-tests
Jun 19, 2022
Merged

Additional tests for FlexboxLayout and FlexDirection#174
alice-i-cecile merged 6 commits intoDioxusLabs:mainfrom
mcrvaz:style-tests

Conversation

@mcrvaz
Copy link
Copy Markdown
Contributor

@mcrvaz mcrvaz commented Jun 17, 2022

Objective

Continuing work towards #92.

Feedback wanted

The tests ended up being a little repetitive, although still simple. Would love some suggestions on how to make them more succinct.

Copy link
Copy Markdown
Collaborator

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

Everything else being equal, I'd rather use multiple asserts in a single test than the rstest macro.

It will be faster to build, and easier to refactor. For example I don't think that the flex_direction_is_row tests are any clearer or shorter using this syntax than with four asserts.

src/style.rs Outdated
#[rstest]
#[case(
FlexDirection::Row,
Rect { start: Dimension::Points(1.0), top: Dimension::Points(2.0), ..Default::default() },
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we use methods in these invocations? Because if so, we should consider creating some convenience methods to make using and testing these structs clearer.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can! I'll create some.

@alice-i-cecile
Copy link
Copy Markdown
Collaborator

Definitely like the direction we're moving in here; unit tests for the individual steps will make refactors much easier and because we're building to a spec these tests should be very stable.

@alice-i-cecile alice-i-cecile added the code quality Make the code cleaner or prettier. label Jun 17, 2022
@mcrvaz
Copy link
Copy Markdown
Contributor Author

mcrvaz commented Jun 17, 2022

So I've ended up removing all rtest macros, leaving only simple asserts. Also created some helpers functions as you suggested, it did clean up a lot. Let me know if there's something else to improve!
Now Clippy seems to be failling but I don't think it has anything to do with my changes here, so I'm uncertain if I should apply the suggested fixes?

src/style.rs Outdated
mod test_flexbox_layout {
use crate::style::*;

fn size_from_points(width: f32, height: f32) -> Size<Dimension> {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I kind of want these to be methods on Size / Rect / FlexboxLayout. Thoughts?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah I think that makes sense :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think that it works great for the Size and Rect, they're nice shortcurts, but I'm not sure if it's useful for FlexboxLayout.
It seems a bit arbitrary to have only from_align_self and from_align_items and even then, I'm not sure if it's a common use case. Would love to have some shorthand for initializing a default FlexboxLayout though.
So I would prefer any of those two options for FlexboxLayout:

  • Implement from_align_self, from_align_items and every other from_x
  • Don't implement any of them (I'm partial to this)

What do you guys think?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I vote for adding these convenience methods to Size and Rect, then we can skip any changes to FlexboxLayout for now then revisit later.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Great! I've added them and updated the tests. Let me know if there's anything I can improve.

@alice-i-cecile
Copy link
Copy Markdown
Collaborator

This is looking much better. CI failure isn't your fault (nightly got new lints); feel free to open a new PR applying the suggested fixes and I can merge that in first.

@Weibye Weibye mentioned this pull request Jun 18, 2022
Copy link
Copy Markdown
Collaborator

@Weibye Weibye left a comment

Choose a reason for hiding this comment

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

Awesome! These looks good to me, I've setup #175 to try to fix the clippy lints.

@alice-i-cecile
Copy link
Copy Markdown
Collaborator

I'll merge this once those methods are moved :)

@alice-i-cecile alice-i-cecile enabled auto-merge (squash) June 19, 2022 15:51
@alice-i-cecile alice-i-cecile merged commit 31c22f8 into DioxusLabs:main Jun 19, 2022
jkelleyrtp pushed a commit that referenced this pull request Oct 10, 2022
* Additional tests for FlexboxLayout and FlexDirection

* Refactoring FlexboxLayout and FlexDirection tests

* Adding helper functions to Size and Rect

Co-authored-by: Marcello Vaz <[email protected]>
Co-authored-by: Alice Cecile <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

code quality Make the code cleaner or prettier.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants