test(validators): validatorName instead of name

This commit is contained in:
Hzunax 2020-07-09 15:16:46 +02:00
parent 3ef736bacf
commit 83f0b112aa
7 changed files with 22 additions and 24 deletions

View file

@ -423,7 +423,7 @@ export const ValidateMixin = dedupeMixin(
if (!validationStates[v.type]) { if (!validationStates[v.type]) {
validationStates[v.type] = {}; validationStates[v.type] = {};
} }
validationStates[v.type][v.constructor.name] = true; validationStates[v.type][v.constructor.validatorName] = true;
}); });
this.validationStates = validationStates; this.validationStates = validationStates;

View file

@ -294,7 +294,7 @@ export function runValidateMixinSuite(customConfig) {
} }
static get validatorName() { static get validatorName() {
return 'isCat'; return 'IsCat';
} }
} }

View file

@ -240,7 +240,7 @@ export function runValidateMixinFeedbackPart() {
} }
render() { render() {
return html`Custom for ${this.feedbackData[0].validator.constructor.name}`; return html`Custom for ${this.feedbackData[0].validator.constructor.validatorName}`;
} }
}, },
); );

View file

@ -348,9 +348,8 @@ describe('<lion-field>', () => {
}); });
it('should not run validation when disabled', async () => { it('should not run validation when disabled', async () => {
const HasX = class extends Validator { const HasX = class extends Validator {
constructor() { static get validatorName() {
super(); return 'HasX';
this.name = 'HasX';
} }
execute(value) { execute(value) {
@ -385,9 +384,8 @@ describe('<lion-field>', () => {
it('should remove validation when disabled state toggles', async () => { it('should remove validation when disabled state toggles', async () => {
const HasX = class extends Validator { const HasX = class extends Validator {
constructor() { static get validatorName() {
super(); return 'HasX';
this.name = 'HasX';
} }
execute(value) { execute(value) {

View file

@ -13,7 +13,7 @@ describe('Date Validation', () => {
it('provides new isDate() to allow only dates', () => { it('provides new isDate() to allow only dates', () => {
let isEnabled; let isEnabled;
const validator = new IsDate(); const validator = new IsDate();
expect(validator.constructor.name).to.equal('IsDate'); expect(validator.constructor.validatorName).to.equal('IsDate');
isEnabled = validator.execute(new Date()); isEnabled = validator.execute(new Date());
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;
@ -28,7 +28,7 @@ describe('Date Validation', () => {
it('provides new minDate(x) to allow only dates after min', () => { it('provides new minDate(x) to allow only dates after min', () => {
let isEnabled; let isEnabled;
const validator = new MinDate(new Date('2018/02/02')); const validator = new MinDate(new Date('2018/02/02'));
expect(validator.constructor.name).to.equal('MinDate'); expect(validator.constructor.validatorName).to.equal('MinDate');
isEnabled = validator.execute(new Date('2018-02-03')); isEnabled = validator.execute(new Date('2018-02-03'));
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;
@ -46,7 +46,7 @@ describe('Date Validation', () => {
it('provides maxDate() to allow only dates before max', () => { it('provides maxDate() to allow only dates before max', () => {
let isEnabled; let isEnabled;
const validator = new MaxDate(new Date('2018/02/02')); const validator = new MaxDate(new Date('2018/02/02'));
expect(validator.constructor.name).to.equal('MaxDate'); expect(validator.constructor.validatorName).to.equal('MaxDate');
isEnabled = validator.execute(new Date('2018-02-01')); isEnabled = validator.execute(new Date('2018-02-01'));
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;
@ -67,7 +67,7 @@ describe('Date Validation', () => {
min: new Date('2018/02/02'), min: new Date('2018/02/02'),
max: new Date('2018/02/04'), max: new Date('2018/02/04'),
}); });
expect(validator.constructor.name).to.equal('MinMaxDate'); expect(validator.constructor.validatorName).to.equal('MinMaxDate');
isEnabled = validator.execute(new Date('2018/02/03')); isEnabled = validator.execute(new Date('2018/02/03'));
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;
@ -88,7 +88,7 @@ describe('Date Validation', () => {
it('provides new IsDateDisabled() to disable dates matching specified condition', () => { it('provides new IsDateDisabled() to disable dates matching specified condition', () => {
let isDisabled; let isDisabled;
const validator = new IsDateDisabled(d => d.getDate() === 3); const validator = new IsDateDisabled(d => d.getDate() === 3);
expect(validator.constructor.name).to.equal('IsDateDisabled'); expect(validator.constructor.validatorName).to.equal('IsDateDisabled');
isDisabled = validator.execute(new Date('2018/02/04')); isDisabled = validator.execute(new Date('2018/02/04'));
expect(isDisabled).to.be.false; expect(isDisabled).to.be.false;

View file

@ -11,7 +11,7 @@ describe('Number Validation', () => {
it('provides new IsNumber() to allow only numbers', () => { it('provides new IsNumber() to allow only numbers', () => {
let isEnabled; let isEnabled;
const validator = new IsNumber(); const validator = new IsNumber();
expect(validator.constructor.name).to.equal('IsNumber'); expect(validator.constructor.validatorName).to.equal('IsNumber');
isEnabled = validator.execute(4); isEnabled = validator.execute(4);
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;
@ -26,7 +26,7 @@ describe('Number Validation', () => {
it('provides new MinNumber(x) to allow only numbers longer then min', () => { it('provides new MinNumber(x) to allow only numbers longer then min', () => {
let isEnabled; let isEnabled;
const validator = new MinNumber(3); const validator = new MinNumber(3);
expect(validator.constructor.name).to.equal('MinNumber'); expect(validator.constructor.validatorName).to.equal('MinNumber');
isEnabled = validator.execute(3); isEnabled = validator.execute(3);
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;
@ -38,7 +38,7 @@ describe('Number Validation', () => {
it('provides new MaxNumber(x) to allow only number shorter then max', () => { it('provides new MaxNumber(x) to allow only number shorter then max', () => {
let isEnabled; let isEnabled;
const validator = new MaxNumber(3); const validator = new MaxNumber(3);
expect(validator.constructor.name).to.equal('MaxNumber'); expect(validator.constructor.validatorName).to.equal('MaxNumber');
isEnabled = validator.execute(3); isEnabled = validator.execute(3);
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;
@ -50,7 +50,7 @@ describe('Number Validation', () => {
it('provides new MinMaxNumber({ min: x, max: y}) to allow only numbers between min and max', () => { it('provides new MinMaxNumber({ min: x, max: y}) to allow only numbers between min and max', () => {
let isEnabled; let isEnabled;
const validator = new MinMaxNumber({ min: 2, max: 4 }); const validator = new MinMaxNumber({ min: 2, max: 4 });
expect(validator.constructor.name).to.equal('MinMaxNumber'); expect(validator.constructor.validatorName).to.equal('MinMaxNumber');
isEnabled = validator.execute(2); isEnabled = validator.execute(2);
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;

View file

@ -14,7 +14,7 @@ describe('String Validation', () => {
it('provides new IsString() to allow only strings', () => { it('provides new IsString() to allow only strings', () => {
let isEnabled; let isEnabled;
const validator = new IsString(); const validator = new IsString();
expect(validator.constructor.name).to.equal('IsString'); expect(validator.constructor.validatorName).to.equal('IsString');
isEnabled = validator.execute('foo'); isEnabled = validator.execute('foo');
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;
@ -29,7 +29,7 @@ describe('String Validation', () => {
it('provides new EqualsLength(x) to allow only a specific string length', () => { it('provides new EqualsLength(x) to allow only a specific string length', () => {
let isEnabled; let isEnabled;
const validator = new EqualsLength(3); const validator = new EqualsLength(3);
expect(validator.constructor.name).to.equal('EqualsLength'); expect(validator.constructor.validatorName).to.equal('EqualsLength');
isEnabled = validator.execute('foo'); isEnabled = validator.execute('foo');
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;
@ -44,7 +44,7 @@ describe('String Validation', () => {
it('provides new MinLength(x) to allow only strings longer then min', () => { it('provides new MinLength(x) to allow only strings longer then min', () => {
let isEnabled; let isEnabled;
const validator = new MinLength(3); const validator = new MinLength(3);
expect(validator.constructor.name).to.equal('MinLength'); expect(validator.constructor.validatorName).to.equal('MinLength');
isEnabled = validator.execute('foo'); isEnabled = validator.execute('foo');
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;
@ -56,7 +56,7 @@ describe('String Validation', () => {
it('provides new MaxLength(x) to allow only strings shorter then max', () => { it('provides new MaxLength(x) to allow only strings shorter then max', () => {
let isEnabled; let isEnabled;
const validator = new MaxLength(3); const validator = new MaxLength(3);
expect(validator.constructor.name).to.equal('MaxLength'); expect(validator.constructor.validatorName).to.equal('MaxLength');
isEnabled = validator.execute('foo'); isEnabled = validator.execute('foo');
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;
@ -68,7 +68,7 @@ describe('String Validation', () => {
it('provides new MinMaxValidator({ min: x, max: y}) to allow only strings between min and max', () => { it('provides new MinMaxValidator({ min: x, max: y}) to allow only strings between min and max', () => {
let isEnabled; let isEnabled;
const validator = new MinMaxLength({ min: 2, max: 4 }); const validator = new MinMaxLength({ min: 2, max: 4 });
expect(validator.constructor.name).to.equal('MinMaxLength'); expect(validator.constructor.validatorName).to.equal('MinMaxLength');
isEnabled = validator.execute('foo'); isEnabled = validator.execute('foo');
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;
@ -83,7 +83,7 @@ describe('String Validation', () => {
it('provides new IsEmail() to allow only valid email formats', () => { it('provides new IsEmail() to allow only valid email formats', () => {
let isEnabled; let isEnabled;
const validator = new IsEmail(); const validator = new IsEmail();
expect(validator.constructor.name).to.equal('IsEmail'); expect(validator.constructor.validatorName).to.equal('IsEmail');
isEnabled = validator.execute('foo@bar.com'); isEnabled = validator.execute('foo@bar.com');
expect(isEnabled).to.be.false; expect(isEnabled).to.be.false;