From 03d3b2449e9a13c447fdff2861eb4b66f3ee24c3 Mon Sep 17 00:00:00 2001 From: Ryan Mathis Date: Fri, 30 Nov 2018 08:56:11 -0700 Subject: [PATCH] SHIBUI-996 Fixed issue with filter validation --- .../model/entity-attributes.filter.spec.ts | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/ui/src/app/metadata/filter/model/entity-attributes.filter.spec.ts b/ui/src/app/metadata/filter/model/entity-attributes.filter.spec.ts index ba27a427d..f21b2db4b 100644 --- a/ui/src/app/metadata/filter/model/entity-attributes.filter.spec.ts +++ b/ui/src/app/metadata/filter/model/entity-attributes.filter.spec.ts @@ -1,8 +1,37 @@ import { EntityAttributesFilter } from './entity-attributes.filter'; describe('Entity Attributes filter form', () => { - it('should return an empty object for validators', () => { - expect(EntityAttributesFilter.getValidators()).toEqual({}); + describe('getValidators', () => { + it('should return an empty object for validators', () => { + expect(Object.keys(EntityAttributesFilter.getValidators())).toEqual([ + '/', + '/name' + ]); + }); + + describe('name `/name` validator', () => { + const validators = EntityAttributesFilter.getValidators(['foo', 'bar']); + + it('should return an invalid object when provided values are invalid based on name', () => { + expect(validators['/name']('foo', { path: '/name' })).toBeDefined(); + }); + + it('should return null when provided values are valid based on name', () => { + expect(validators['/name']('baz', { path: '/name' })).toBeNull(); + }); + }); + + describe('parent `/` validator', () => { + const validators = EntityAttributesFilter.getValidators(['foo', 'bar']); + + it('should return a list of child errors', () => { + expect(validators['/']({ name: 'foo' }, { path: '/name' }, {}).length).toBe(1); + }); + + it('should ignore properties that don\'t exist a list of child errors', () => { + expect(validators['/']({ foo: 'bar' }, { path: '/foo' }, {})).toBeUndefined(); + }); + }); }); describe('transformer', () => {