Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nii Yeboah committed Oct 4, 2019
1 parent b390b21 commit dfd5c7d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 15 deletions.
9 changes: 4 additions & 5 deletions test/accessibility.html
Original file line number Diff line number Diff line change
Expand Up @@ -324,16 +324,15 @@
expect(input.getAttribute('aria-describedby')).to.equal(`${helperText.id} ${err.id}`);
});

it('should have aria-describedby with helper text and error message if slotted helper is set and input invalid', function(done) {
it('should have aria-describedby with helper text and error message if slotted helper is set and input invalid', function() {
const tf = fixture(`${el}-with-slotted-helper`);
const input = tf.inputElement;
const err = tf.root.querySelector('[part=error-message]');
const helperText = tf.root.querySelector('[part=helper-text]');
const evt = new CustomEvent('slotchange');
tf.validate();
setTimeout(() => {
expect(input.getAttribute('aria-describedby')).to.equal(`${helperText.id} ${err.id}`);
done();
}, 1);
tf.shadowRoot.querySelector('[name="helper"]').dispatchEvent(evt);
expect(input.getAttribute('aria-describedby')).to.equal(`${helperText.id} ${err.id}`);
});

it('should have appropriate aria-live attribute', function() {
Expand Down
23 changes: 13 additions & 10 deletions test/text-field.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,12 @@
});

describe(`binding ${condition}`, function() {
function dispatchHelperSlotChange() {
// Workaround not to use timeouts
const evt = new CustomEvent('slotchange');
textField.shadowRoot.querySelector('[name="helper"]').dispatchEvent(evt);
}

it('default value should be empty string', function() {
expect(textField.value).to.be.equal('');
});
Expand Down Expand Up @@ -355,29 +361,26 @@
expect(textField.hasAttribute('has-helper')).to.be.true;
});

it('text-field with slotted helper updates has-helper attribute', function(done) {
it('text-field with slotted helper updates has-helper attribute', function() {
const textFieldSlottedHelper = fixture('default-with-slotted-helper');
setTimeout(() => {
expect(textFieldSlottedHelper.hasAttribute('has-helper')).to.be.true;
done();
}, 1);
dispatchHelperSlotChange();
expect(textFieldSlottedHelper.hasAttribute('has-helper')).to.be.true;
});

it('setting helper with slot updates has-helper attribute', function(done) {
it('setting helper with slot updates has-helper attribute', function() {
const helper = document.createElement('div');
helper.setAttribute('slot', 'helper');
helper.textContent = 'foo';
textField.appendChild(helper);
setTimeout(() => {
expect(textField.hasAttribute('has-helper')).to.be.true;
done();
}, 1);
dispatchHelperSlotChange();
expect(textField.hasAttribute('has-helper')).to.be.true;
});

it('removing slotted helper removes has-helper attribute', function(done) {
const textFieldSlottedHelper = fixture('default-with-slotted-helper');
const helper = textFieldSlottedHelper.querySelector('[slot="helper"]');
textFieldSlottedHelper.removeChild(helper);
// dispatchHelperSlotChange does not work with this test
setTimeout(() => {
expect(textFieldSlottedHelper.hasAttribute('has-helper')).to.be.false;
done();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions test/visual/vaadin-text-field/text-field-3.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

window.addEventListener('WebComponentsReady', function() {
setTimeout(function() {
if (theme !== 'lumo') {
document.getElementById('lumo').setAttribute('hidden', '');
}
window.ShadyDOM && window.ShadyDOM.flush(); // Force DOM composition
window.webComponentsAreReady = true; // Checked in gemini before capture callback
});
Expand Down Expand Up @@ -52,6 +55,9 @@
<p>
<vaadin-text-field label="Label" helper-text="Helper" invalid error-message="Error"></vaadin-text-field>
<vaadin-text-field helper-text="Helper" value="value"></vaadin-text-field>
<p id="lumo">
<vaadin-text-field label="Label" helper-text="Helper" invalid error-message="Error" theme="helper-above-field"></vaadin-text-field>
<vaadin-text-field helper-text="Helper" value="value" theme="helper-above-field"></vaadin-text-field>
</fieldset>
</form>

Expand Down

0 comments on commit dfd5c7d

Please sign in to comment.