|
| 1 | +import { expect } from '@vaadin/chai-plugins'; |
| 2 | +import { fixtureSync, nextRender } from '@vaadin/testing-helpers'; |
| 3 | +import './not-animated-styles.js'; |
| 4 | +import '@vaadin/side-nav/src/vaadin-side-nav-item.js'; |
| 5 | +import { Tooltip } from '@vaadin/tooltip/src/vaadin-tooltip.js'; |
| 6 | +import { mouseenter, mouseleave } from '@vaadin/tooltip/test/helpers.js'; |
| 7 | + |
| 8 | +describe('side-nav-item with tooltip', () => { |
| 9 | + let item, tooltip, tooltipOverlay, srOnly; |
| 10 | + |
| 11 | + before(() => { |
| 12 | + Tooltip.setDefaultFocusDelay(0); |
| 13 | + Tooltip.setDefaultHoverDelay(0); |
| 14 | + Tooltip.setDefaultHideDelay(0); |
| 15 | + }); |
| 16 | + |
| 17 | + beforeEach(async () => { |
| 18 | + item = fixtureSync(` |
| 19 | + <vaadin-side-nav-item path="/parent"> |
| 20 | + Parent |
| 21 | + <vaadin-tooltip slot="tooltip" text="Tooltip text"></vaadin-tooltip> |
| 22 | + <vaadin-side-nav-item path="/parent/child" slot="children">Child</vaadin-side-nav-item> |
| 23 | + </vaadin-side-nav-item> |
| 24 | + `); |
| 25 | + await nextRender(); |
| 26 | + tooltip = item.querySelector('vaadin-tooltip'); |
| 27 | + tooltipOverlay = tooltip.shadowRoot.querySelector('vaadin-tooltip-overlay'); |
| 28 | + srOnly = item.shadowRoot.querySelector('.sr-only'); |
| 29 | + }); |
| 30 | + |
| 31 | + it('should set tooltip target to the item content part', () => { |
| 32 | + expect(tooltip.target).to.equal(item.$.content); |
| 33 | + }); |
| 34 | + |
| 35 | + it('should set tooltip ariaTarget to null', () => { |
| 36 | + expect(tooltip.ariaTarget).to.be.null; |
| 37 | + }); |
| 38 | + |
| 39 | + it('should set aria-hidden: none on the tooltip', () => { |
| 40 | + expect(tooltip.getAttribute('aria-hidden')).to.equal('true'); |
| 41 | + }); |
| 42 | + |
| 43 | + it('should toggle tooltip on item content mouseenter', () => { |
| 44 | + mouseenter(item.$.content); |
| 45 | + expect(tooltipOverlay.opened).to.be.true; |
| 46 | + |
| 47 | + mouseleave(item.$.content); |
| 48 | + expect(tooltipOverlay.opened).to.be.false; |
| 49 | + }); |
| 50 | + |
| 51 | + it('should not show tooltip on child item mouseenter', async () => { |
| 52 | + item.click(); |
| 53 | + const child = item.querySelector('vaadin-side-nav-item'); |
| 54 | + mouseenter(child.$.content); |
| 55 | + await nextRender(); |
| 56 | + expect(tooltipOverlay.opened).to.be.not.ok; |
| 57 | + }); |
| 58 | + |
| 59 | + it('should use tooltip text for the sr-only element text content', async () => { |
| 60 | + expect(srOnly.textContent).to.equal(tooltip.text); |
| 61 | + |
| 62 | + tooltip.text = 'Other text'; |
| 63 | + await nextRender(); |
| 64 | + |
| 65 | + expect(srOnly.textContent).to.equal('Other text'); |
| 66 | + }); |
| 67 | + |
| 68 | + it('should use tooltip generator for the sr-only element text content', async () => { |
| 69 | + expect(srOnly.textContent).to.equal(tooltip.text); |
| 70 | + |
| 71 | + tooltip.generator = () => 'Other text'; |
| 72 | + await nextRender(); |
| 73 | + |
| 74 | + expect(srOnly.textContent).to.equal('Other text'); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should clear the sr-only element content when tooltip is removed', async () => { |
| 78 | + tooltip.remove(); |
| 79 | + await nextRender(); |
| 80 | + |
| 81 | + expect(srOnly.textContent).to.equal(''); |
| 82 | + }); |
| 83 | +}); |
0 commit comments