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

[ASScrollNode] Fix small bugs and add unit tests #637

Merged
merged 11 commits into from
Dec 1, 2017

Conversation

nguyenhuy
Copy link
Member

@nguyenhuy nguyenhuy commented Oct 24, 2017

  • Currently, ASScrollNode's calculated size is based on its parent size. However, there are cases in which the size range passed to the scroll node to calculate a layout against doesn't include the parent size. In such cases, we should clamp the parent size against the size range to make sure the range is always respected.
  • When scrollable directions change, invalidate the calculated layout because these directions affect the size range that is used to calculate the content's layout.
  • Add unit tests to cover these bugs and other common use cases.

Copy link
Member

@Adlai-Holler Adlai-Holler left a comment

Choose a reason for hiding this comment

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

Beautiful! Comments and unit tests and useful fixes 💯

subnodeSizeRange = sizeRange;
subnodeSizeRange.max.width = CGFLOAT_MAX;

XCTAssertTrue(ASSizeRangeEqualToSizeRange(_subnode.constrainedSizeForCalculatedLayout, subnodeSizeRange));
Copy link
Member

Choose a reason for hiding this comment

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

Nit: Let's use ASXCTAssertEqualSizeRanges and ASXCTAssertEqualSizes where possible, so that we get better error messages. Import ASXCTExtensions.h to get 'em.

_subnode.style.preferredSize = subnodeSize;

ASLayout *layout = [_scrollNode layoutThatFits:sizeRange parentSize:parentSize];
[_scrollNode layout];
Copy link
Member

Choose a reason for hiding this comment

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

Another nit: I prefer to name ivars without underscores in unit test files. It makes things more readable and it's usually safe since a new instance is created for each test method.

Copy link
Contributor

@maicki maicki left a comment

Choose a reason for hiding this comment

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

Thanks <3

@ghost
Copy link

ghost commented Oct 26, 2017

🚫 CI failed with log

Copy link
Member

@appleguy appleguy left a comment

Choose a reason for hiding this comment

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

Great to see improvements in test code. Thank you, @nguyenhuy !

ASLayout *layout = [scrollNode layoutThatFits:sizeRange parentSize:parentSize];
[scrollNode layout];
ASLayout *layout = [self.scrollNode layoutThatFits:sizeRange parentSize:parentSize];
[self.scrollNode layout];
Copy link
Member

Choose a reason for hiding this comment

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

It seems better (perhaps) to call [scrollNode.layer layoutIfNeeded], to test the full layout stack as it is triggered in most apps?


ASSizeRange subnodeSizeRange = sizeRange;
subnodeSizeRange.max.height = CGFLOAT_MAX;
XCTAssertEqual(scrollNode.scrollableDirections, ASScrollDirectionVerticalDirections);
ASXCTAssertEqualSizeRanges(subnode.constrainedSizeForCalculatedLayout, subnodeSizeRange);
XCTAssertEqual(self.scrollNode.scrollableDirections, ASScrollDirectionVerticalDirections);
Copy link
Member

Choose a reason for hiding this comment

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

Rather than self. everywhere, using the ivar like _scrollNode would be more readable (especially in property chains & methods that use it a lot).

Copy link
Member

Choose a reason for hiding this comment

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

As a follow-up to this, I find that using non-underscored ivar names in test classes provides the best readability.

Since the object is destroyed after -tearDown is run, and since test classes usually have trivial accessors, direct ivar access is safe and convenient.

@nguyenhuy nguyenhuy merged commit bccde6c into TextureGroup:master Dec 1, 2017
bernieperez pushed a commit to AtomTickets/Texture that referenced this pull request Apr 25, 2018
* Add unit tests for ASScrollNode

* Make sure ASScrollNode's size is clamped against its size range

* Invalidate ASScrollNode's calculated layout if its scrollable directions changed

* Update comment

* Update CHANGELOG

* Address Adlai's comments
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.

None yet

4 participants