|
230 | 230 | MockInteractions.keyDownOn(target || grid.shadowRoot.activeElement, 113, [], 'F2');
|
231 | 231 | }
|
232 | 232 |
|
| 233 | + function mouseDown(target) { |
| 234 | + const event = new CustomEvent('mousedown', {bubbles: true, cancelable: true, composed: true}); |
| 235 | + target.dispatchEvent(event); |
| 236 | + } |
| 237 | + |
| 238 | + function mouseUp(target) { |
| 239 | + const event = new CustomEvent('mouseup', {bubbles: true, cancelable: true, composed: true}); |
| 240 | + target.dispatchEvent(event); |
| 241 | + } |
| 242 | + |
233 | 243 | function getFirstHeaderCell() {
|
234 | 244 | return grid.$.header.children[0].children[0];
|
235 | 245 | }
|
|
1914 | 1924 |
|
1915 | 1925 | expect(spy.calledOnce).to.be.true;
|
1916 | 1926 | });
|
| 1927 | + |
| 1928 | + // Separate test suite for Chrome, where we use a workaround to dispatch |
| 1929 | + // cell-focus on mouse up |
| 1930 | + const isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor); |
| 1931 | + (isChrome ? describe : describe.skip)('chrome', () => { |
| 1932 | + it('should dispatch cell-focus on mouse up on cell content', () => { |
| 1933 | + const spy = sinon.spy(); |
| 1934 | + grid.addEventListener('cell-focus', spy); |
| 1935 | + |
| 1936 | + // Mouse down and release on cell content element |
| 1937 | + const cell = getRowFirstCell(0); |
| 1938 | + mouseDown(cell._content); |
| 1939 | + mouseUp(cell._content); |
| 1940 | + expect(spy.calledOnce).to.be.true; |
| 1941 | + }); |
| 1942 | + |
| 1943 | + it('should dispatch cell-focus on mouse up on cell content, when grid is in shadow DOM', () => { |
| 1944 | + const spy = sinon.spy(); |
| 1945 | + grid.addEventListener('cell-focus', spy); |
| 1946 | + |
| 1947 | + // Move grid into a shadow DOM |
| 1948 | + const container = document.createElement('div'); |
| 1949 | + document.body.appendChild(container); |
| 1950 | + container.attachShadow({mode: 'open'}); |
| 1951 | + container.shadowRoot.appendChild(grid); |
| 1952 | + |
| 1953 | + // Mouse down and release on cell content element |
| 1954 | + const cell = getRowFirstCell(0); |
| 1955 | + mouseDown(cell._content); |
| 1956 | + mouseUp(cell._content); |
| 1957 | + expect(spy.calledOnce).to.be.true; |
| 1958 | + }); |
| 1959 | + |
| 1960 | + it('should dispatch cell-focus on mouse up within cell content', () => { |
| 1961 | + const spy = sinon.spy(); |
| 1962 | + grid.addEventListener('cell-focus', spy); |
| 1963 | + |
| 1964 | + // Mouse down and release on cell content child |
| 1965 | + const cell = getRowFirstCell(0); |
| 1966 | + const contentSpan = document.createElement('span'); |
| 1967 | + cell._content.appendChild(contentSpan); |
| 1968 | + |
| 1969 | + mouseDown(contentSpan); |
| 1970 | + mouseUp(contentSpan); |
| 1971 | + expect(spy.calledOnce).to.be.true; |
| 1972 | + }); |
| 1973 | + |
| 1974 | + // Regression test for https://github.com/vaadin/flow-components/issues/2863 |
| 1975 | + it('should not dispatch cell-focus on mouse up outside of cell', () => { |
| 1976 | + const spy = sinon.spy(); |
| 1977 | + grid.addEventListener('cell-focus', spy); |
| 1978 | + |
| 1979 | + mouseDown(getRowFirstCell(0)._content); |
| 1980 | + mouseUp(document.body); |
| 1981 | + expect(spy.calledOnce).to.be.false; |
| 1982 | + }); |
| 1983 | + }); |
1917 | 1984 | });
|
1918 | 1985 | });
|
1919 | 1986 |
|
|
0 commit comments