Skip to content

Commit

Permalink
feat(tabs): add test coverage, remove unused property from component …
Browse files Browse the repository at this point in the history
…class
  • Loading branch information
monkeyjabs authored and Westbrook committed Feb 16, 2023
1 parent d104b52 commit 9933ad8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
7 changes: 2 additions & 5 deletions packages/tabs/src/TabsOverflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ governing permissions and limitations under the License.
*/
import {
CSSResultArray,
ElementSize,
html,
PropertyValues,
SizedMixin,
Expand Down Expand Up @@ -72,14 +71,12 @@ export class TabsOverflow extends SizedMixin(SpectrumElement) {
super.firstUpdated(changes);
// enable scroll event
this.scrollContent[0]?.setAttribute('enableTabsScroll', '');
this.size = (this.scrollContent[0]?.getAttribute('size') ||
'm') as ElementSize;
this.resizeController.observe(this.overflowContainer);
}

private async _handleSlotChange(): Promise<void> {
const [tabsElement] = this.scrollContent;
await tabsElement.updateComplete;
await tabsElement?.updateComplete;
this._updateScrollState();
}

Expand Down Expand Up @@ -107,7 +104,7 @@ export class TabsOverflow extends SizedMixin(SpectrumElement) {
const [tabsElement] = this.scrollContent;

const dist = tabsElement.clientWidth * 0.5;
const left = currentTarget?.classList?.contains('left-scroll')
const left = currentTarget.classList.contains('left-scroll')
? -dist
: dist;
tabsElement.scrollTabs(left, 'smooth');
Expand Down
23 changes: 19 additions & 4 deletions packages/tabs/test/tabs-overflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,17 +130,32 @@ describe('TabsOverflow', () => {
'.right-scroll'
) as ActionButton;

leftButton.click();
leftButton.dispatchEvent(new Event('click', {}));

const tabsEl = spTabsOverflows.querySelector('sp-tab') as Tab;
const initialLeft = tabsEl.getBoundingClientRect().left;
rightButton.click();
rightButton.dispatchEvent(new Event('click', {}));
await elementUpdated(el);
rightButton.click();
rightButton.dispatchEvent(new Event('click', {}));
await elementUpdated(el);
rightButton.click();
rightButton.dispatchEvent(new Event('click', {}));
await elementUpdated(el);
const finalLeft = tabsEl.getBoundingClientRect().left;
expect(finalLeft).to.be.lessThanOrEqual(initialLeft);
});

it('should fail properly if slot is not sp-tabs', async () => {
const el = await fixture<TabsOverflow>(
html`
<sp-tabs-overflow>
<div>Some div</div>
</sp-tabs-overflow>
`
);

await elementUpdated(el);
const slot = el.shadowRoot.querySelector('slot');
const slotContent = slot?.assignedElements() || '';
expect(slotContent[0].toString()).to.not.contains('Tabs');
});
});

0 comments on commit 9933ad8

Please sign in to comment.