-
Notifications
You must be signed in to change notification settings - Fork 11
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
feat(slider, range-slider): add pin feature (VIV-1611) #1736
Conversation
44e3d0c
to
5e5e7c4
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1736 +/- ##
===========================================
Coverage 100.00% 100.00%
===========================================
Files 123 342 +219
Lines 1562 6195 +4633
Branches 108 772 +664
===========================================
+ Hits 1562 6195 +4633
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
d229e53
to
9a89dc9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
Thanks for this split and work well done.
Because now I understand that popup
is our "facade" for floatingUI
it makes much more sense.
3 comments and we're done here :)
it('should not continuously update position with requestAnimationFrame when false', async () => { | ||
element.anchor = anchor; | ||
await elementUpdated(element); | ||
jest.spyOn(window, 'requestAnimationFrame'); | ||
|
||
element.open = true; | ||
|
||
expect(window.requestAnimationFrame).toHaveBeenCalledTimes( | ||
RAF_CALLS_FROM_SETTING_ATTRIBUTE | ||
); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is unclear to me what we are testing.
In the first test we call element.open = true;
and it uses rAF
once.
In the 2nd test, we call element.open = true;
and it uses rAF
twice.
Question is - why should it change only twice?
Looking at the floatingUI
code it seems like what it does is keep updating the position as long as it keeps changing. Which seems to be the way things are going. So IMO the tests should be:
- Mock rAF implementation to change the position on every call 3 or 4 times and then stabilize it
- Show that rAF is called once when the prop is false and 3 or 4 times when the prop is true
- Show that rAF is called once when the position doesn't change even when the prop is true
WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With animationFrame it should continuously update the position with rAF.
After some thought, I think this test is kind of bad either way. Popup shouldn't really test how many times rAF is called or whether floatingUI works correctly.
All I really care about is that it passes the argument to floatingUI, which has it's own tests.
So maybe we should change it back to the original?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not believe so.
We do care about the amount of times rAF is called.
Floating UI is an implementation detail. You can implement this on your own or switch library - the tests should still pass :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, maybe, but unit tests shouldn't test dependencies for correctness like that.
I really don't care how many times rAF gets called, only that the flag gets passed.
If we replace floatingUI with something, this code needs updating which I'm fine with
Also, all the other tests in this file do not test floatingUI either. Either all them should or none
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are not testing dependencies for correctness. The fact you are using Floating UI is irrelevant. It is an implementation detail. We are testing the outcome of this - so if we removed floating UI or the corresponding code that implements this API, the test should fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated the test now to test that it continuously calls rAF. However the test is still bad and doesn't really test anything at all
If I change the test further to test that it actually updates position I end up testing floatingUI through popup...
Testing the outcome is not always what you want to do. E.g. when you have some code that sends an email, you don't want to test that it sends an actual email. Just that it calls some other code that is responsible for sending emails.
I'd argue that it's the same here. It's not popups job to calculate positions and keep them up to date, so we just verify that calls the code that is responsible for that
@@ -61,7 +93,7 @@ export class Popup extends FoundationElement { | |||
open = false; | |||
openChanged(_: boolean, newValue: boolean): void { | |||
newValue ? this.$emit('vwc-popup:open') : this.$emit('vwc-popup:close'); | |||
this.#updateAutoUpdate(); | |||
DOM.queueUpdate(() => this.#updateAutoUpdate()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now I see that the reason we have 1 rAF
in the case animationFrame
is false.
I gather a few things from this:
- If we delete the
DOM.queueupdate
and leave just theautoUpdate
all tests are passing. It is either irrelevant or it should be tested in theopen
tests.should update position in the next animation frame
or something like that. - This explains why when we set
animationFrame
to false, we get onerAF
call. So I'd might change theanimationFrame
property's name to something more meaningful likesoftPositionAnimation
orsmoothPositionAnimation
orgradualPositionAnimation
. WDYT?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this change has nothing to do with animationFrame or its tests
If you delete it, the ui tests will fail. The reason is that it is wrong to call autoUpdate before open has changed in the the DOM, because floatingUI requires the floating element to be measurable. Which it isn't if open is false (display: none
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then why not add a small unit test for it?
It should autoUpdate after open
changed (e.g. after elementUpdated
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, I added some tests for open
* @internal | ||
*/ | ||
animationFrameChanged() { | ||
this.#updateAutoUpdate(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateAutoUpdate
is not a descriptive name ;)
Wouldn't updatePopupParmeters
be more descriptive?
I'm open for other names as well :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mhm, I don't think the name is that bad. Anyway, I would say that is out of scope of this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... it made me read the function in order to just understand what it does, which makes it a bad name (always take the weak link as your test case - and I'm the weak link here ;) ).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, maybe there is a better name but this review is already getting very big so I want to focus only the things actually in the PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This review has only 4 comments ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't assigned myself and saw that @YonatanKra reviewed. Adding only one comment
Co-authored-by: Yonatan Kra <yonatan.kra@vonage.com>
* feat(slider): add pin feature (VIV-1611) * Update libs/components/src/lib/slider/slider.spec.ts * Rename internals * Add test for thumb mouse down * Move dragging into thumb * Refactor visible popup tests * Add test for placement strategy * Add test clicking on track while disabled * Clarify code * Refactor tests * Split tests * Add pin feature to range slider
No description provided.