-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: restore template logic and tests
- Loading branch information
1 parent
6095519
commit c5516bc
Showing
5 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
39 changes: 39 additions & 0 deletions
39
packages/combo-box/test/fixtures/mock-combo-box-light-template-wrapper.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js'; | ||
import '../vaadin-combo-box-light.js'; | ||
|
||
class MockComboBoxLightTemplateWrapper extends PolymerElement { | ||
static get template() { | ||
return html` | ||
<vaadin-combo-box-light id="comboBox" items="[[items]]"> | ||
<vaadin-text-field></vaadin-text-field> | ||
<template> | ||
<div>index: [[index]]</div> | ||
<div>item: [[item]]</div> | ||
<div>selected: [[selected]]</div> | ||
<div>focused: [[focused]]</div> | ||
<div>parentProperty: [[parentProperty]]</div> | ||
<div>parentProperty.foo: [[parentProperty.foo]]</div> | ||
<div>parentMethod: [[parentMethod()]]</div> | ||
<button on-click="parentEventHandler"></button> | ||
</template> | ||
</vaadin-combo-box-light> | ||
`; | ||
} | ||
|
||
static get properties() { | ||
return { | ||
items: Array | ||
}; | ||
} | ||
|
||
parentMethod() { | ||
return 'quux'; | ||
} | ||
|
||
parentEventHandler() { | ||
// do nothing | ||
} | ||
} | ||
|
||
customElements.define('mock-combo-box-light-template-wrapper', MockComboBoxLightTemplateWrapper); |
37 changes: 37 additions & 0 deletions
37
packages/combo-box/test/fixtures/mock-combo-box-template-wrapper.js
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { PolymerElement, html } from '@polymer/polymer/polymer-element.js'; | ||
import '../vaadin-combo-box.js'; | ||
|
||
class MockComboBoxTemplateWrapper extends PolymerElement { | ||
static get template() { | ||
return html` | ||
<vaadin-combo-box id="comboBox" items="[[items]]"> | ||
<template> | ||
<div>index: [[index]]</div> | ||
<div>item: [[item]]</div> | ||
<div>selected: [[selected]]</div> | ||
<div>focused: [[focused]]</div> | ||
<div>parentProperty: [[parentProperty]]</div> | ||
<div>parentProperty.foo: [[parentProperty.foo]]</div> | ||
<div>parentMethod: [[parentMethod()]]</div> | ||
<button on-click="parentEventHandler"></button> | ||
</template> | ||
</vaadin-combo-box> | ||
`; | ||
} | ||
|
||
static get properties() { | ||
return { | ||
items: Array | ||
}; | ||
} | ||
|
||
parentMethod() { | ||
return 'quux'; | ||
} | ||
|
||
parentEventHandler() { | ||
// do nothing | ||
} | ||
} | ||
|
||
customElements.define('mock-combo-box-template-wrapper', MockComboBoxTemplateWrapper); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import { expect } from '@esm-bundle/chai'; | ||
import sinon from 'sinon'; | ||
import { fixtureSync, keyDownOn } from '@vaadin/testing-helpers'; | ||
import { flush } from '@polymer/polymer/lib/utils/flush.js'; | ||
import '@vaadin/vaadin-template-renderer'; | ||
import './fixtures/mock-combo-box-template-wrapper.js'; | ||
import './fixtures/mock-combo-box-light-template-wrapper.js'; | ||
|
||
describe('item template', () => { | ||
let wrapper, comboBox, firstItem; | ||
|
||
['combo-box' /*'combo-box-light'*/].forEach((name) => { | ||
describe(name, () => { | ||
beforeEach(() => { | ||
wrapper = fixtureSync(`<mock-${name}-template-wrapper></mock-${name}-template-wrapper>`); | ||
comboBox = wrapper.$.comboBox; | ||
comboBox.items = ['foo', 'bar']; | ||
comboBox.open(); | ||
|
||
flush(); | ||
firstItem = comboBox.$.overlay._selector.querySelector('vaadin-combo-box-item'); | ||
}); | ||
|
||
it('should render items using template', () => { | ||
expect(firstItem.shadowRoot.innerHTML).to.contain('item: foo'); | ||
}); | ||
|
||
it('should have index property', () => { | ||
expect(firstItem.shadowRoot.innerHTML).to.contain('index: 0'); | ||
}); | ||
|
||
it('should have selected property', () => { | ||
expect(firstItem.shadowRoot.innerHTML).to.contain('selected: false'); | ||
}); | ||
|
||
it('should update selected property', () => { | ||
comboBox.value = 'foo'; | ||
expect(firstItem.shadowRoot.innerHTML).to.contain('selected: true'); | ||
}); | ||
|
||
it('should have focused property', () => { | ||
expect(firstItem.shadowRoot.innerHTML).to.contain('focused: false'); | ||
}); | ||
|
||
it('should update focused property', () => { | ||
keyDownOn(comboBox.inputElement, 40); // Press arrow down key | ||
expect(firstItem.shadowRoot.innerHTML).to.contain('focused: true'); | ||
}); | ||
|
||
it('should forward parent properties', () => { | ||
wrapper.parentProperty = 'qux'; | ||
expect(firstItem.shadowRoot.innerHTML).to.contain('parentProperty: qux'); | ||
}); | ||
|
||
it('should forward parent paths', () => { | ||
wrapper.parentProperty = { foo: '' }; | ||
wrapper.set('parentProperty.foo', 'bar'); | ||
expect(firstItem.shadowRoot.innerHTML).to.contain('parentProperty.foo: bar'); | ||
}); | ||
|
||
it('should support computed bindings in parent scope', () => { | ||
expect(firstItem.shadowRoot.innerHTML).to.contain('parentMethod: quux'); | ||
}); | ||
|
||
it('should support event handlers in parent scope', () => { | ||
const spy = sinon.spy(wrapper, 'parentEventHandler'); | ||
firstItem.shadowRoot.querySelector('button').click(); | ||
expect(spy.calledOnce).to.be.true; | ||
}); | ||
|
||
it('should have content part wrapping template', () => { | ||
const content = firstItem.shadowRoot.querySelector('[part="content"]'); | ||
expect(content.querySelector('button').parentElement).to.equal(content); | ||
}); | ||
|
||
it('should have block style for the content part', () => { | ||
const content = firstItem.shadowRoot.querySelector('[part="content"]'); | ||
expect(getComputedStyle(content).display).to.equal('block'); | ||
}); | ||
|
||
it('should preserve and propagate dir to the items', () => { | ||
comboBox.close(); | ||
comboBox.setAttribute('dir', 'ltr'); | ||
comboBox.open(); | ||
expect(firstItem.getAttribute('dir')).to.eql('ltr'); | ||
}); | ||
}); | ||
}); | ||
}); |