From 9f22a1e4d63afbec58acdf7506e33152c4f855c0 Mon Sep 17 00:00:00 2001 From: "J. Diogo Oliveira" Date: Mon, 7 Feb 2022 07:25:25 +0000 Subject: [PATCH] PR comment #3 --- packages/grid/test/tree-toggle.test.js | 167 ------------------------- 1 file changed, 167 deletions(-) delete mode 100644 packages/grid/test/tree-toggle.test.js diff --git a/packages/grid/test/tree-toggle.test.js b/packages/grid/test/tree-toggle.test.js deleted file mode 100644 index 1e8137ca428..00000000000 --- a/packages/grid/test/tree-toggle.test.js +++ /dev/null @@ -1,167 +0,0 @@ -import { expect } from '@esm-bundle/chai'; -import { click, fixtureSync } from '@vaadin/testing-helpers'; -import sinon from 'sinon'; -import '@vaadin/polymer-legacy-adapter/template-renderer.js'; -import '../vaadin-grid.js'; -import '../vaadin-grid-tree-toggle.js'; -import '../vaadin-grid-tree-column.js'; -import { flushGrid, getBodyCellContent } from './helpers.js'; - -describe('tree toggle', () => { - let toggle; - - describe('default', () => { - beforeEach(() => { - toggle = fixtureSync(''); - }); - - describe('properties', () => { - it('should have leaf false by default', () => { - expect(toggle.leaf).to.not.be.ok; - }); - - it('should have expanded false by default', () => { - expect(toggle.expanded).to.not.be.ok; - }); - - it('should not toggle on click if leaf', () => { - toggle.leaf = true; - - const clickEvent = click(toggle); - expect(toggle.expanded).to.not.be.ok; - expect(clickEvent.defaultPrevented).to.be.false; - }); - - it('should toggle on click', () => { - let clickEvent = click(toggle); - expect(toggle.expanded).to.be.true; - expect(clickEvent.defaultPrevented).to.be.true; - - clickEvent = click(toggle); - expect(toggle.expanded).to.be.false; - expect(clickEvent.defaultPrevented).to.be.true; - }); - - it('should notify for expanded on toggle', () => { - const spy = sinon.spy(); - toggle.addEventListener('expanded-changed', spy); - - click(toggle); - - expect(spy.callCount).to.equal(1); - - toggle.removeEventListener('expanded-changed', spy); - }); - }); - - describe('level', () => { - it('should have level zero by default', () => { - expect(toggle.level).to.equal(0); - }); - - it('should have zero spacer width by default', () => { - const spacer = toggle.shadowRoot.querySelector('#level-spacer'); - expect(spacer.getBoundingClientRect().width).to.equal(0); - }); - - it('should increase spacer width for each level step', () => { - const spacer = toggle.shadowRoot.querySelector('#level-spacer'); - let prevWidth = 0; - for (let i = 1; i < 3; i++) { - toggle.level = i; - const width = spacer.getBoundingClientRect().width; - expect(width).to.be.gt(prevWidth); - prevWidth = width; - } - }); - }); - - describe('DOM', () => { - it('should have default slot', () => { - const slot = toggle.shadowRoot.querySelector('slot:not([name])'); - expect(slot).to.be.ok; - }); - - it('should have toggle shadow part', () => { - expect(toggle.shadowRoot.querySelector(`[part~="toggle"]`)).to.not.be.null; - }); - }); - }); - - describe('with content', () => { - beforeEach(() => { - toggle = fixtureSync(` - -
foo
-
- `); - }); - - it('should not toggle on internal focusable click', () => { - const clickEvent = click(toggle.querySelector('input')); - expect(toggle.expanded).to.be.false; - expect(clickEvent.defaultPrevented).to.be.false; - }); - - it('should toggle on internal non-focusable element click', () => { - const clickEvent = click(toggle.querySelector('div')); - expect(toggle.expanded).to.be.true; - expect(clickEvent.defaultPrevented).to.be.true; - }); - }); - - describe('tree column', () => { - let grid, column, toggle; - - beforeEach(() => { - grid = fixtureSync(` - - - - `); - column = grid.querySelector('vaadin-grid-tree-column'); - grid.dataProvider = (params, cb) => { - cb([{ name: 'foo', hasChildren: true }], 1); - }; - flushGrid(grid); - toggle = getBodyCellContent(grid, 0, 0).firstElementChild; - }); - - it('should be empty', () => { - expect(toggle.textContent.trim()).to.be.empty; - }); - - it('should not be empty', () => { - column.path = 'name'; - expect(toggle.textContent.trim()).to.equal('foo'); - }); - - it('should be a leaf', () => { - expect(toggle.leaf).to.be.true; - }); - - it('should have the default level', () => { - expect(toggle.level).to.equal(0); - }); - - it('should have a higher level', () => { - column.itemHasChildrenPath = 'hasChildren'; - toggle.expanded = true; - const childToggle = getBodyCellContent(grid, 1, 0).firstElementChild; - expect(childToggle.level).to.equal(1); - }); - - it('should not be a leaf', () => { - column.itemHasChildrenPath = 'hasChildren'; - expect(toggle.leaf).to.be.false; - }); - - it('should ignore a custom renderer', () => { - column.renderer = (root) => { - root.innerHTML = 'cell'; - }; - - expect(getBodyCellContent(grid, 0, 0).firstElementChild).to.equal(toggle); - }); - }); -});