Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: bump test-runner, improve coverage #59

Merged
merged 1 commit into from
Jan 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@
"@polymer/iron-component-page": "^4.0.0",
"@polymer/iron-test-helpers": "^3.0.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"@web/dev-server": "~0.0.25",
"@web/test-runner": "^0.10.0",
"@web/test-runner-saucelabs": "^0.1.3",
"@web/dev-server": "^0.1.5",
"@web/test-runner": "^0.12.6",
"@web/test-runner-saucelabs": "^0.4.0",
"eslint": "^7.14.0",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
Expand Down
200 changes: 121 additions & 79 deletions test/item-mixin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,108 +47,150 @@ describe('vaadin-item-mixin', () => {
`);
});

it('should not have focused attribute when not focused', () => {
expect(item.hasAttribute('focused')).to.be.false;
});
describe('selected', () => {
it('should set selected to false by default', () => {
expect(item.selected).to.be.false;
});

it('should have focused attribute when focused', () => {
fire(item, 'focus');
expect(item.hasAttribute('focused')).to.be.true;
});
it('should reflect selected to attribute', () => {
item.selected = true;
expect(item.hasAttribute('selected')).to.be.true;
});

it('should not have focused attribute when blurred', () => {
fire(item, 'focus');
fire(item, 'blur');
expect(item.hasAttribute('focused')).to.be.false;
it('should set aria-selected attribute', () => {
item.selected = true;
expect(item.getAttribute('aria-selected')).to.equal('true');
});
});

it('should have active attribute on mousedown', () => {
fire(item, 'mousedown');
expect(item.hasAttribute('active')).to.be.true;
expect(item._mousedown).to.be.true;
});
describe('disabled', () => {
it('should set disabled to false by default', () => {
expect(item.disabled).to.be.false;
});

it('should not have active attribute after mouseup', () => {
fire(item, 'mousedown');
fire(item, 'mouseup');
expect(item.hasAttribute('active')).to.be.false;
expect(item._mousedown).to.be.false;
});
it('should reflect disabled to attribute', () => {
item.disabled = true;
expect(item.hasAttribute('disabled')).to.be.true;
});

it('should have active attribute on space down', () => {
spaceDown(item);
expect(item.hasAttribute('active')).to.be.true;
});
it('should set selected to false when disabled', () => {
item.selected = true;
space(item);
item.disabled = true;
expect(item.selected).to.be.false;
});

it('should not have active attribute after space up', () => {
spaceDown(item);
spaceUp(item);
expect(item.hasAttribute('active')).to.be.false;
it('should have aria-disabled when disabled', () => {
item.disabled = true;
expect(item.getAttribute('aria-disabled')).to.equal('true');
item.disabled = false;
expect(item.getAttribute('aria-disabled')).to.be.null;
});
});

it('should not have active attribute when disconnected from the DOM', () => {
spaceDown(item);
item.parentNode.removeChild(item);
expect(item.hasAttribute('active')).to.be.false;
});
describe('focused', () => {
it('should not have focused attribute when not focused', () => {
expect(item.hasAttribute('focused')).to.be.false;
});

it('should not have focus-ring if not focused', () => {
expect(item.hasAttribute('focus-ring')).to.be.false;
});
it('should have focused attribute when focused', () => {
fire(item, 'focus');
expect(item.hasAttribute('focused')).to.be.true;
});

it('should not have focus-ring attribute when not focused with keyboard', () => {
item.click();
expect(item.hasAttribute('focus-ring')).to.be.false;
it('should not have focused attribute when blurred', () => {
fire(item, 'focus');
fire(item, 'blur');
expect(item.hasAttribute('focused')).to.be.false;
});
});

it('should have focus-ring attribute when focused with keyboard', () => {
fire(item, 'focus');
expect(item.hasAttribute('focus-ring')).to.be.true;
});
describe('active', () => {
it('should have active attribute on mousedown', () => {
fire(item, 'mousedown');
expect(item.hasAttribute('active')).to.be.true;
expect(item._mousedown).to.be.true;
});

it('should not have focus-ring after blur', () => {
fire(item, 'focus');
fire(item, 'blur');
expect(item.hasAttribute('focus-ring')).to.be.false;
});
it('should not have active attribute after mouseup', () => {
fire(item, 'mousedown');
fire(item, 'mouseup');
expect(item.hasAttribute('active')).to.be.false;
expect(item._mousedown).to.be.false;
});

it('set this._mousedown to false if mouseup was outside', () => {
fire(item, 'mousedown');
expect(item._mousedown).to.be.true;
fire(document, 'mouseup');
expect(item._mousedown).to.be.false;
});
it('should have active attribute on space down', () => {
spaceDown(item);
expect(item.hasAttribute('active')).to.be.true;
});

it('should set selected to false when disabled', () => {
item.selected = true;
space(item);
item.disabled = true;
expect(item.selected).to.be.false;
});
it('should not have active attribute after space up', () => {
spaceDown(item);
spaceUp(item);
expect(item.hasAttribute('active')).to.be.false;
});

it('should have aria-disabled when disabled', () => {
item.disabled = true;
expect(item.getAttribute('aria-disabled')).to.equal('true');
item.disabled = false;
expect(item.getAttribute('aria-disabled')).to.be.null;
it('should not have active attribute when disconnected from the DOM', () => {
spaceDown(item);
item.parentNode.removeChild(item);
expect(item.hasAttribute('active')).to.be.false;
});
});

it('should fire click event when it is selected with keyboard', () => {
const clickSpy = sinon.spy();
item.addEventListener('click', clickSpy);
enter(item);
expect(clickSpy.calledOnce).to.be.true;
describe('focus-ring', () => {
it('should not have focus-ring if not focused', () => {
expect(item.hasAttribute('focus-ring')).to.be.false;
});

it('should not have focus-ring attribute when not focused with keyboard', () => {
item.click();
expect(item.hasAttribute('focus-ring')).to.be.false;
});

it('should have focus-ring attribute when focused with keyboard', () => {
fire(item, 'focus');
expect(item.hasAttribute('focus-ring')).to.be.true;
});

it('should not have focus-ring after blur', () => {
fire(item, 'focus');
fire(item, 'blur');
expect(item.hasAttribute('focus-ring')).to.be.false;
});
});

it('should not fire click event if keyup does not happen after a keydown in the element', () => {
const clickSpy = sinon.spy();
item.addEventListener('click', clickSpy);
spaceUp(item);
expect(clickSpy.called).to.be.false;
describe('interaction', () => {
it('set this._mousedown to false if mouseup was outside', () => {
fire(item, 'mousedown');
expect(item._mousedown).to.be.true;
fire(document, 'mouseup');
expect(item._mousedown).to.be.false;
});

it('should fire click event when activated with Enter', () => {
const clickSpy = sinon.spy();
item.addEventListener('click', clickSpy);
enter(item);
expect(clickSpy.calledOnce).to.be.true;
});

it('should not fire click event if keyup does not happen after a keydown in the element', () => {
const clickSpy = sinon.spy();
item.addEventListener('click', clickSpy);
spaceUp(item);
expect(clickSpy.called).to.be.false;
});
});

it('should have value property', () => {
expect(item.value).to.be.equal('foo');
describe('value', () => {
it('should have value property', () => {
expect(item.value).to.be.equal('foo');
});

it('should not reflect value to attribute', () => {
item.value = 'bar';
expect(item.getAttribute('value')).to.be.equal('foo');
});
});
});

Expand Down
4 changes: 4 additions & 0 deletions test/item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ describe('vaadin-item', () => {
item = fixtureSync('<vaadin-item>label</vaadin-item>');
});

it('should have a valid version number', () => {
expect(item.constructor.version).to.match(/^(\d+\.)?(\d+\.)?(\d+)(-(alpha|beta)\d+)?$/);
});

it('should extend item-mixin', () => {
expect(item._hasVaadinItemMixin).to.be.true;
});
Expand Down
6 changes: 3 additions & 3 deletions web-test-runner.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const config = {
coverageConfig: {
include: ['**/src/*'],
threshold: {
statements: 99,
statements: 100,
branches: 85,
functions: 94,
lines: 99
functions: 100,
lines: 100
}
}
};
Expand Down