feat: add SplitLayout, Card and AvatarGroup testers - #197
Open
totally-not-ai[bot] wants to merge 3 commits into
Open
feat: add SplitLayout, Card and AvatarGroup testers#197totally-not-ai[bot] wants to merge 3 commits into
totally-not-ai[bot] wants to merge 3 commits into
Conversation
None of SplitLayout, Card or AvatarGroup had a @Tests-annotated ComponentTester, so LocatorProcessor emitted no *Locator and no find*() entry point for them and they had to be driven through raw component calls. SplitLayoutTester.dragSplitterTo(double) delivers a splitter-dragend DOM event with the flex-basis event data the browser sends, so the component recomputes its own splitter position and notifies drag end listeners, instead of the tester setting server-side state behind the component's back. CardTester and AvatarGroupTester are assertion-only: Card gets content accessors that reject the title and subtitle while a header component replaces them, and AvatarGroup reports the split between avatars and the overflow bubble derived from maxItemsVisible. Part of #181. Fixes #192
Document in dragSplitterTo() that the component rounds a dragged position to two decimals, and cover it with a value that does not round-trip exactly, so the behaviour is visible instead of surprising. Also cover the AvatarGroupTester branch where i18n is set but has no phrase for the current item count, add getTitle() to the hidden-card check, and drop the CsvSource row that repeated the maxItemsVisible clamp already covered by the preceding one.
Member
|
Is this the same as #196? |
Dragging a split fully closed or fully open is a legal drag, not an argument error, and only the rejected values either side of the range were pinned so far.
Contributor
Author
|
The differences, in case they decide it:
I have also taken the one test #196 had that was missing here — that dragging to |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SplitLayout, Card and AvatarGroup had no component tester, so tests had to drive them through raw component calls. This PR adds
SplitLayoutTester,CardTesterandAvatarGroupTester, so these three components now get a generated*Locatorand atest(...)entry point like every other supported component.Part of #181. Fixes #192
What changed
SplitLayoutTester—dragSplitterTo(double)fires a realsplitter-dragendDOM event carrying the same flex-basis event data the browser sends. The component then recomputes its own splitter position and notifies drag end listeners, instead of the tester writing server-side state behind the component's back. Also exposes the splitter position and the primary/secondary components.CardTester— assertion-only. The title and subtitle accessors throw when a header component is set, because the header replaces them and that text is not on screen. Also exposes header, header prefix/suffix, media and footer components.AvatarGroupTester— assertion-only. Reports the split between visible avatars and the overflow bubble, derived frommaxItemsVisible(the overflow avatar takes one slot, and the group never drops below two avatars). Also gives the accessible "active users" label with{count}filled in.TesterWrappersgets the three matchingtest(...)overloads, and the README tester count goes from 65+ to 70+.Because there is no browser and no layout,
AvatarGroupTestercannot apply the extra truncation the component does when avatars do not fit the available width.Use case
An app has a master-detail view built on
SplitLayout, and it stores the splitter position the user drags to so the view reopens the same way. A developer wants a fast unit test that the position is really saved, without starting a browser.The same style works for assertions on a card or an avatar group:
API Changes
4 classes affected, 3 new classes, 20 methods added, none removed or changed.
com.vaadin.flow.component.splitlayout.SplitLayoutTester
com.vaadin.flow.component.card.CardTester
com.vaadin.flow.component.avatar.AvatarGroupTester
com.vaadin.browserless.TesterWrappers
Test summary
dragSplitterTo(30)sets the splitter position to 30 and fires exactly one drag end event withisFromClient() == true33.333reports33.330and100are accepted;-0.5and100.5throwIllegalArgumentExceptiondragSplitterTothrowIllegalStateExceptionwhen the layout is hiddendragSplitterToon a disabled layoutensureComponentIsUsablealso covers disabled, but only the hidden case is pinnedCardTester: it must not report content the header replacedgetTitleAsText()returns the text title (empty string when unset);getTitle()returns the title component, ornullfor a text titlegetFooterComponents()returns footer components in insertion order, empty list when there is no footerIllegalStateExceptionwhen the card is hiddenmaxItemsVisibleexceeded, items split into visible avatars and trailing overflow items, with the right+Nabbreviation; a max of 0 or 1 behaves as 2maxItemsVisible(or one not reached), all items are visible and the abbreviation isnullgetActiveUsersLabel()substitutes{count}, uses the singular phrase for one item, and returnsnullwhen no i18n is set or the phrase for the current count is missingIllegalStateExceptionwhen the group is hiddenTest methods added on this branch:
SplitLayoutTesterTest.dragSplitterTo_updatesPositionAndNotifiesListener→ 1SplitLayoutTesterTest.dragSplitterTo_positionSetOnServer_isReplacedByTheDraggedPosition→ 2SplitLayoutTesterTest.dragSplitterTo_positionWithMoreThanTwoDecimals_isRoundedByComponent→ 3SplitLayoutTesterTest.dragSplitterTo_positionAtRangeEnds_isAccepted→ 4SplitLayoutTesterTest.dragSplitterTo_positionOutsideRange_throws→ 4SplitLayoutTesterTest.dragSplitterTo_layoutHidden_throws→ 5SplitLayoutTesterTest.accessors_layoutHidden_throw→ 5SplitLayoutTesterTest.getSplitterPosition_neverPositioned_returnsNull→ 2SplitLayoutTesterTest.getPrimaryAndSecondaryComponent_returnSplitContents→ 9 (split contents)SplitLayoutTesterTest.getPrimaryComponent_emptyLayout_returnsNull→ 9 (empty splits)CardTesterTest.titleAndSubtitle_headerSet_throw→ 7CardTesterTest.getTitleAsText_returnsTitle,getTitleAsText_noTitleSet_returnsEmptyString,getTitle_titleSetAsComponent_returnsComponent,getTitle_titleSetAsText_returnsNull→ 8CardTesterTest.getSubtitle_returnsSubtitleComponent,headerAccessors_returnHeaderComponents,getHeader_noHeaderSet_returnsNull,getMedia_returnsMediaComponent→ 8 (accessor pass-through)CardTesterTest.getFooterComponents_returnsComponentsInOrder,getFooterComponents_emptyFooter_returnsEmptyList→ 9CardTesterTest.accessors_cardHidden_throw→ 10AvatarGroupTesterTest.maxItemsVisibleExceeded_itemsSplitBetweenAvatarsAndOverflow→ 11AvatarGroupTesterTest.noMaxItemsVisible_allItemsVisibleAndNoOverflow,maxItemsVisibleNotReached_allItemsVisible,getItems_returnsAllItems→ 12AvatarGroupTesterTest.getActiveUsersLabel_manyUsers_countIsSubstituted,getActiveUsersLabel_oneUser_usesSingularPhrase,getActiveUsersLabel_noI18nSet_returnsNull,getActiveUsersLabel_phraseMissingForCurrentCount_returnsNull→ 13AvatarGroupTesterTest.accessors_groupHidden_throw→ 14Left untested on purpose: the generated
*Locatorclasses andfind*()methods, which come from the existingLocatorProcessorand are covered by its own tests; and the threeTesterWrappers.test(...)overloads, which every test above goes through anyway.