Skip to content

Commit

Permalink
test: cleanup and fix helper focus tests (#2256)
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan authored Jul 21, 2021
1 parent 2eb6148 commit 4923156
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 30 deletions.
5 changes: 2 additions & 3 deletions packages/vaadin-checkbox/test/checkbox-group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,13 +508,12 @@ describe('slot focus', () => {
</vaadin-checkbox-group>
`);
group._observer.flush();
group.focus();
helper = group.querySelector('[slot="helper"]');
});

it('should not get focus after click', () => {
const spy = sinon.spy(group, 'focus');
helper.click();

expect(group.hasAttribute('focused')).to.be.false;
expect(spy.called).to.be.false;
});
});
7 changes: 2 additions & 5 deletions packages/vaadin-custom-field/test/helper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,16 @@ describe('helper text', () => {
beforeEach(() => {
field = fixtureSync(`
<vaadin-custom-field>
<input type="text" />
<input type="text" slot="helper" />
<input type="text" />
<input type="text" slot="helper" />
</vaadin-custom-field>
`);
helper = field.querySelector('[slot="helper"]');
field.focus();
});

it('should not focus the field on helper click', () => {
const spy = sinon.spy(field, 'focus');
helper.click();

expect(spy.called).to.be.false;
});
});
Expand Down
15 changes: 4 additions & 11 deletions packages/vaadin-text-field/test/text-area.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,18 +348,14 @@ describe('helper text', () => {
beforeEach(() => {
field = fixtureSync(`
<vaadin-text-area label="outer">
<vaadin-text-area label="inner" slot="helper">
<vaadin-text-area label="inner" slot="helper"></vaadin-text-area>
</vaadin-text-area>
<vaadin-text-area label="inner" slot="helper"></vaadin-text-area>
</vaadin-text-area>
`);
helper = field.querySelector('[slot="helper"]');
field.focus();
});

it('helper should get focus when clicked', () => {
const spy = sinon.spy(field, 'focus');

helper.click();
expect(spy.called).to.be.false;
});
Expand All @@ -369,17 +365,14 @@ describe('helper text', () => {
let field, helper;

beforeEach(() => {
field = fixtureSync(`
<vaadin-text-area label='text-field' helper-text='helper-text'>
</vaadin-text-area>
`);

field = fixtureSync('<vaadin-text-area helper-text="helper-text"></vaadin-text-area>');
helper = field.shadowRoot.querySelector('[part="helper-text"]');
});

it('should not get focus when helper text is clicked', () => {
const spy = sinon.spy(field, 'focus');
helper.click();
expect(field.hasAttribute('focused')).to.be.false;
expect(spy.called).to.be.false;
});
});
});
14 changes: 3 additions & 11 deletions packages/vaadin-text-field/test/text-field.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -614,15 +614,13 @@ describe('helper slot', () => {
});
});

describe('nested helper', () => {
describe('slotted helper', () => {
let field, helper;

beforeEach(() => {
field = fixtureSync(`
<vaadin-text-field label="outer">
<vaadin-text-field label="inner" slot="helper">
<vaadin-text-field label="inner" slot="helper"></vaadin-text-field>
</vaadin-text-field>
<vaadin-text-field label="inner" slot="helper"></vaadin-text-field>
</vaadin-text-field>
`);
helper = field.querySelector('[slot="helper"]');
Expand All @@ -631,7 +629,6 @@ describe('helper slot', () => {
it('helper should get focus when clicked', () => {
const spy = sinon.spy(field, 'focus');
helper.click();

expect(spy.called).to.be.false;
});
});
Expand All @@ -640,18 +637,13 @@ describe('helper slot', () => {
let field, helper;

beforeEach(() => {
field = fixtureSync(`
<vaadin-text-field label='text-field' helper-text='helper-text'>
</vaadin-text-field>
`);

field = fixtureSync('<vaadin-text-field helper-text="helper-text"></vaadin-text-field>');
helper = field.shadowRoot.querySelector('[part="helper-text"]');
});

it('should not get focus when helper text is only text', () => {
const spy = sinon.spy(field, 'focus');
helper.click();

expect(spy.called).to.be.false;
});
});
Expand Down

0 comments on commit 4923156

Please sign in to comment.