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: simplify validation tests #253

Merged
merged 1 commit into from
Jul 5, 2023
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
120 changes: 20 additions & 100 deletions test/spec/components/Feel.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,7 @@ describe('<FeelField>', function() {
it('should set valid', function() {

// given
const validate = (v) => {
if (v === 'bar') {
return 'error';
}
};
const validate = () => null;

const result = createFeelField({ container, validate });

Expand All @@ -212,11 +208,7 @@ describe('<FeelField>', function() {
it('should set invalid', function() {

// given
const validate = (v) => {
if (v === 'bar') {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelField({ container, validate });

Expand All @@ -234,11 +226,7 @@ describe('<FeelField>', function() {
it('should keep showing invalid value', function() {

// given
const validate = (v) => {
if (v === 'bar') {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelField({ container, validate });

Expand All @@ -256,11 +244,7 @@ describe('<FeelField>', function() {
it('should show error message', function() {

// given
const validate = (v) => {
if (v === 'bar') {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelField({ container, validate });

Expand All @@ -282,11 +266,7 @@ describe('<FeelField>', function() {

// given
const setValueSpy = sinon.spy();
const validate = (v) => {
if (v === 'bar') {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelField({ container, validate, setValue: setValueSpy });

Expand Down Expand Up @@ -691,11 +671,7 @@ describe('<FeelField>', function() {
it('should set valid', function() {

// given
const validate = (v) => {
if (v === 3) {
return 'error';
}
};
const validate = () => null;

const result = createFeelNumber({ container, validate });

Expand All @@ -714,11 +690,7 @@ describe('<FeelField>', function() {
it('should set invalid', function() {

// given
const validate = (v) => {
if (v === 3) {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelNumber({ container, validate });

Expand All @@ -736,11 +708,7 @@ describe('<FeelField>', function() {
it('should keep showing invalid value', function() {

// given
const validate = (v) => {
if (v === 3) {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelNumber({ container, validate });

Expand All @@ -758,11 +726,7 @@ describe('<FeelField>', function() {
it('should show error message', function() {

// given
const validate = (v) => {
if (v === 3) {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelNumber({ container, validate });

Expand All @@ -784,11 +748,7 @@ describe('<FeelField>', function() {

// given
const setValueSpy = sinon.spy();
const validate = (v) => {
if (v === 3) {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelNumber({ container, validate, setValue: setValueSpy });

Expand Down Expand Up @@ -1151,11 +1111,7 @@ describe('<FeelField>', function() {
it('should set valid', function() {

// given
const validate = (v) => {
if (v === 'bar') {
return 'error';
}
};
const validate = () => null;

const result = createFeelTextArea({ container, validate });

Expand All @@ -1174,11 +1130,7 @@ describe('<FeelField>', function() {
it('should set invalid', function() {

// given
const validate = (v) => {
if (v === 'bar') {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelTextArea({ container, validate });

Expand All @@ -1196,11 +1148,7 @@ describe('<FeelField>', function() {
it('should keep showing invalid value', function() {

// given
const validate = (v) => {
if (v === 'bar') {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelTextArea({ container, validate });

Expand All @@ -1218,11 +1166,7 @@ describe('<FeelField>', function() {
it('should show error message', function() {

// given
const validate = (v) => {
if (v === 'bar') {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelTextArea({ container, validate });

Expand All @@ -1244,11 +1188,7 @@ describe('<FeelField>', function() {

// given
const setValueSpy = sinon.spy();
const validate = (v) => {
if (v === 'bar') {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelTextArea({ container, validate, setValue: setValueSpy });

Expand Down Expand Up @@ -2013,11 +1953,7 @@ describe('<FeelField>', function() {
it('should set valid', function() {

// given
const validate = (v) => {
if (v === 'bar') {
return 'error';
}
};
const validate = () => null;

const result = createFeelField({ container, validate, feel: 'required' });

Expand All @@ -2038,11 +1974,7 @@ describe('<FeelField>', function() {
it('should set invalid', async function() {

// given
const validate = (v) => {
if (v === '=bar') {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelField({ container, validate, feel: 'required' });

Expand All @@ -2065,11 +1997,7 @@ describe('<FeelField>', function() {
it('should keep showing invalid value', function() {

// given
const validate = (v) => {
if (v === '=bar') {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelField({ container, validate, feel: 'required' });

Expand All @@ -2089,11 +2017,7 @@ describe('<FeelField>', function() {
it('should show error message', async function() {

// given
const validate = (v) => {
if (v === '=bar') {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelField({ container, validate, feel: 'required' });

Expand All @@ -2119,11 +2043,7 @@ describe('<FeelField>', function() {

// given
const setValueSpy = sinon.spy();
const validate = (v) => {
if (v === '=bar') {
return 'error';
}
};
const validate = () => 'error';

const result = createFeelTextArea({ container, validate, setValue: setValueSpy, feel: 'required' });

Expand Down
44 changes: 12 additions & 32 deletions test/spec/components/NumberField.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,7 @@ describe('<NumberField>', function() {
it('should set valid', function() {

// given
const validate = (v) => {
if (v % 2 !== 0) {
return 'should be even';
}
};
const validate = () => null;

const result = createNumberField({ container, validate });

Expand All @@ -221,7 +217,7 @@ describe('<NumberField>', function() {
const input = domQuery('.bio-properties-panel-input', entry);

// when
changeInput(input, 2);
changeInput(input, 1);

// then
expect(isValid(entry)).to.be.true;
Expand All @@ -231,19 +227,15 @@ describe('<NumberField>', function() {
it('should set invalid', function() {

// given
const validate = (v) => {
if (v % 2 !== 0) {
return 'should be even';
}
};
const validate = () => 'error';

const result = createNumberField({ container, validate });

const entry = domQuery('.bio-properties-panel-entry', result.container);
const input = domQuery('.bio-properties-panel-input', entry);

// when
changeInput(input, 3);
changeInput(input, 1);

// then
expect(isValid(entry)).to.be.false;
Expand All @@ -253,58 +245,46 @@ describe('<NumberField>', function() {
it('should keep showing invalid value', function() {

// given
const validate = (v) => {
if (v % 2 !== 0) {
return 'should be even';
}
};
const validate = () => 'error';

const result = createNumberField({ container, validate });

const entry = domQuery('.bio-properties-panel-entry', result.container);
const input = domQuery('.bio-properties-panel-input', entry);

// when
changeInput(input, 3);
changeInput(input, 1);

// then
expect(input.value).to.eql('3');
expect(input.value).to.eql('1');
});


it('should show error message', function() {

// given
const validate = (v) => {
if (v % 2 !== 0) {
return 'should be even';
}
};
const validate = () => 'error';

const result = createNumberField({ container, validate });

const entry = domQuery('.bio-properties-panel-entry', result.container);
const input = domQuery('.bio-properties-panel-input', entry);

// when
changeInput(input, 3);
changeInput(input, 1);

const error = domQuery('.bio-properties-panel-error', entry);

// then
expect(error).to.exist;
expect(error.innerText).to.eql('should be even');
expect(error.innerText).to.eql('error');
});


it('should pass error to `setValue`', function() {

// given
const validate = (v) => {
if (v % 2 !== 0) {
return 'should be even';
}
};
const validate = () => 'error';

const setValueSpy = sinon.spy();

Expand All @@ -315,7 +295,7 @@ describe('<NumberField>', function() {
changeInput(entry, 1);

// then
expect(setValueSpy).to.have.been.calledWith(1, 'should be even');
expect(setValueSpy).to.have.been.calledWith(1, 'error');
});

});
Expand Down
Loading