Skip to content

Commit

Permalink
fixed input coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
RCopeland committed Dec 5, 2018
1 parent 0d93f1c commit 303b48f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/spark-core/tests/requiredTick.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@ describe('requiredTextInput UI Events tests', () => {
expect(errorContainer.textContent).eql('This field is required.');
});

it('should run validation on focusout', () => {
event = new window.Event('focusout');
inputContainer.dispatchEvent(event);
expect(errorContainer.textContent).eql('This field is required.');
});

it('should mark valid when input is triggered with a value', () => {
radio1.checked = true;
event = new window.Event('change');
Expand Down
13 changes: 10 additions & 3 deletions packages/spark-core/tests/setInvalidSelect.tests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global document describe before it */
/* global document describe beforeEach it */
import { expect } from 'chai';
import setInvalidSelect from '../utilities/validation/setInvalidSelect';

Expand All @@ -9,7 +9,7 @@ describe('setInvalidSelect tests', () => {
let option2;
let errorContainer;

before(() => {
beforeEach(() => {
inputContainer = document.createElement('div');
inputContainer.setAttribute('data-sprk-required', 'select');
errorContainer = document.createElement('span');
Expand All @@ -25,15 +25,22 @@ describe('setInvalidSelect tests', () => {
select.appendChild(option2);

inputContainer.appendChild(select);
inputContainer.appendChild(errorContainer);
});

it('should set the errorContainer text', () => {
inputContainer.appendChild(errorContainer);
const error = 'This is an error message';
setInvalidSelect(inputContainer, error);
expect(errorContainer.textContent).eql(error);
});

it('should not error if there is no errorContainer', () => {
setInvalidSelect(inputContainer, 'oops.');
expect(select.getAttribute('aria-invalid')).eql('true');
});

it('should support overriding the error message', () => {
inputContainer.appendChild(errorContainer);
const defaultError = 'This is an error message';
const newError = 'This is my custom error.';
inputContainer.setAttribute('data-sprk-input-invalid-content', newError);
Expand Down
11 changes: 8 additions & 3 deletions packages/spark-core/tests/setValidSelect.tests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global document describe before it */
/* global document describe beforeEach it */
import { expect } from 'chai';
import setValidSelect from '../utilities/validation/setValidSelect';

Expand All @@ -9,7 +9,7 @@ describe('setValidSelect tests', () => {
let option2;
let errorContainer;

before(() => {
beforeEach(() => {
inputContainer = document.createElement('div');
inputContainer.setAttribute('data-sprk-required', 'select');
errorContainer = document.createElement('span');
Expand All @@ -26,11 +26,16 @@ describe('setValidSelect tests', () => {
select.appendChild(option2);

inputContainer.appendChild(select);
inputContainer.appendChild(errorContainer);
});

it('should empty the error container', () => {
inputContainer.appendChild(errorContainer);
setValidSelect(inputContainer);
expect(errorContainer.textContent).eql('');
});

it('should not error if there is no error container', () => {
setValidSelect(inputContainer);
expect(select.getAttribute('aria-invalid')).eql('false');
});
});
11 changes: 8 additions & 3 deletions packages/spark-core/tests/setValidTick.tests.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* global document describe before it */
/* global document describe beforeEach it */
import { expect } from 'chai';
import setValidTick from '../utilities/validation/setValidTick';

Expand All @@ -10,7 +10,7 @@ describe('setValidTick tests', () => {
let radio2;
let errorContainer;

before(() => {
beforeEach(() => {
inputContainer = document.createElement('div');
inputContainer.setAttribute('data-sprk-required', 'tick');
errorContainer = document.createElement('span');
Expand All @@ -34,11 +34,16 @@ describe('setValidTick tests', () => {

inputContainer.appendChild(selectionContainer1);
inputContainer.appendChild(selectionContainer2);
inputContainer.appendChild(errorContainer);
});

it('should empty the error container', () => {
inputContainer.appendChild(errorContainer);
setValidTick(inputContainer);
expect(errorContainer.textContent).eql('');
});

it('should not error if there is no error container', () => {
setValidTick(inputContainer);
expect(inputContainer.querySelector('.sprk-b-ErrorContainer')).eql(null);
});
});

0 comments on commit 303b48f

Please sign in to comment.