From f5a2f04d8dbe497b41133601c0d6c1979a95cb38 Mon Sep 17 00:00:00 2001 From: Ryan Mathis Date: Fri, 7 Dec 2018 13:06:40 -0700 Subject: [PATCH] SHIBUI-799 Fixed tests --- .../main/resources/nameid-filter.schema.json | 26 +---------- .../container/edit-filter.component.html | 4 +- .../container/edit-filter.component.spec.ts | 14 +++--- .../filter/container/edit-filter.component.ts | 5 +-- .../model/entity-attributes.filter.spec.ts | 4 +- .../filter/model/nameid.filter.spec.ts | 43 +++++++++++++++++++ .../metadata/filter/model/nameid.filter.ts | 31 +++++++++++-- .../filter/reducer/filter.reducer.spec.ts | 34 --------------- .../filter/reducer/search.reducer.spec.ts | 7 +++ 9 files changed, 92 insertions(+), 76 deletions(-) create mode 100644 ui/src/app/metadata/filter/model/nameid.filter.spec.ts diff --git a/backend/src/main/resources/nameid-filter.schema.json b/backend/src/main/resources/nameid-filter.schema.json index cb8a30410..461a9a39b 100644 --- a/backend/src/main/resources/nameid-filter.schema.json +++ b/backend/src/main/resources/nameid-filter.schema.json @@ -117,30 +117,8 @@ "default": false }, "formats": { - "$ref": "#/definitions/NameIdFormatList" + "$ref": "#/definitions/nameIdFormats" } }, - "definitions": { - "NameIdFormatList": { - "title": "label.nameid-format-to-send", - "placeholder": "label.nameid-format", - "description": "tooltip.nameid-format", - "type": "array", - "uniqueItems": true, - "items": { - "type": "string", - "minLength": 1, - "maxLength": 255, - "widget": { - "id": "datalist", - "data": [ - "urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified", - "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress", - "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent", - "urn:oasis:names:tc:SAML:2.0:nameid-format:transient" - ] - } - } - } - } + "definitions": {} } \ No newline at end of file diff --git a/ui/src/app/metadata/filter/container/edit-filter.component.html b/ui/src/app/metadata/filter/container/edit-filter.component.html index 7f2908762..0cf1e5129 100644 --- a/ui/src/app/metadata/filter/container/edit-filter.component.html +++ b/ui/src/app/metadata/filter/container/edit-filter.component.html @@ -5,7 +5,9 @@
   - Edit Filter {{ type$ | async }} + + Edit Filter– {{ type$ | async }} +
diff --git a/ui/src/app/metadata/filter/container/edit-filter.component.spec.ts b/ui/src/app/metadata/filter/container/edit-filter.component.spec.ts index b38fb4256..8f7060c27 100644 --- a/ui/src/app/metadata/filter/container/edit-filter.component.spec.ts +++ b/ui/src/app/metadata/filter/container/edit-filter.component.spec.ts @@ -12,7 +12,7 @@ import { SchemaService } from '../../../schema-form/service/schema.service'; import { HttpClientModule } from '@angular/common/http'; import { MockI18nModule } from '../../../../testing/i18n.stub'; -describe('New Metadata Filter Page', () => { +describe('Edit Metadata Filter Page', () => { let fixture: ComponentFixture; let store: Store; let instance: EditFilterComponent; @@ -25,8 +25,7 @@ describe('New Metadata Filter Page', () => { FormBuilder, NgbPopoverConfig, NavigatorService, - SchemaService, - { provide: WidgetRegistry, useClass: DefaultWidgetRegistry } + SchemaService ], imports: [ StoreModule.forRoot({ @@ -48,7 +47,7 @@ describe('New Metadata Filter Page', () => { instance = fixture.componentInstance; store = TestBed.get(Store); - spyOn(store, 'dispatch').and.callThrough(); + spyOn(store, 'dispatch'); }); it('should compile', () => { @@ -66,9 +65,9 @@ describe('New Metadata Filter Page', () => { }); describe('preview method', () => { - it('should dispatch a cancel changes action', () => { + it('should dispatch a preview action', () => { fixture.detectChanges(); - instance.cancel(); + instance.preview('foo'); expect(store.dispatch).toHaveBeenCalled(); }); }); @@ -77,21 +76,18 @@ describe('New Metadata Filter Page', () => { it('should set the isValid property to true', () => { fixture.detectChanges(); instance.statusChangeSubject.next({value: []}); - fixture.detectChanges(); expect(instance.isValid).toBe(true); }); it('should set the isValid property to true if value is undefined', () => { fixture.detectChanges(); instance.statusChangeSubject.next({value: null}); - fixture.detectChanges(); expect(instance.isValid).toBe(true); }); it('should set the isValid property to false', () => { fixture.detectChanges(); instance.statusChangeSubject.next({ value: [{control: 'foo'}] }); - fixture.detectChanges(); expect(instance.isValid).toBe(false); }); }); diff --git a/ui/src/app/metadata/filter/container/edit-filter.component.ts b/ui/src/app/metadata/filter/container/edit-filter.component.ts index 696de845a..a4ee5f3a4 100644 --- a/ui/src/app/metadata/filter/container/edit-filter.component.ts +++ b/ui/src/app/metadata/filter/container/edit-filter.component.ts @@ -11,7 +11,7 @@ import { UpdateFilterRequest } from '../action/collection.action'; import { CancelCreateFilter, UpdateFilterChanges } from '../action/filter.action'; import { PreviewEntity } from '../../domain/action/entity.action'; import { EntityAttributesFilterEntity } from '../../domain/entity'; -import { shareReplay, map, withLatestFrom, filter, switchMap } from 'rxjs/operators'; +import { shareReplay, map, withLatestFrom, filter, switchMap, startWith, defaultIfEmpty } from 'rxjs/operators'; @Component({ selector: 'edit-filter-page', @@ -55,6 +55,7 @@ export class EditFilterComponent { ); this.isSaving$ = this.store.select(fromFilter.getCollectionSaving); this.model$ = this.store.select(fromFilter.getSelectedFilter); + this.type$ = this.model$.pipe(map(f => f && f.hasOwnProperty('@type') ? f['@type'] : '')); this.valueChangeEmitted$.subscribe(changes => this.store.dispatch(new UpdateFilterChanges(changes.value))); this.statusChangeEmitted$.subscribe(valid => { @@ -80,8 +81,6 @@ export class EditFilterComponent { this.preview(parameters.id); } }; - - this.type$ = this.model$.pipe(map(f => f['@type'])); } save(): void { 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 f21b2db4b..53e3630c8 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 @@ -35,9 +35,9 @@ describe('Entity Attributes filter form', () => { }); describe('transformer', () => { - it('should not modify the object', () => { + it('should add modify the object', () => { expect(EntityAttributesFilter.formatter({})).toEqual({}); - expect(EntityAttributesFilter.parser({})).toEqual({}); + expect(EntityAttributesFilter.parser({}).relyingPartyOverrides).toBeDefined(); }); }); }); diff --git a/ui/src/app/metadata/filter/model/nameid.filter.spec.ts b/ui/src/app/metadata/filter/model/nameid.filter.spec.ts new file mode 100644 index 000000000..f366ca90a --- /dev/null +++ b/ui/src/app/metadata/filter/model/nameid.filter.spec.ts @@ -0,0 +1,43 @@ +import { NameIDFilter } from './nameid.filter'; + +describe('NameID Format filter form', () => { + describe('getValidators', () => { + it('should return an empty object for validators', () => { + expect(Object.keys(NameIDFilter.getValidators())).toEqual([ + '/', + '/name' + ]); + }); + + describe('name `/name` validator', () => { + const validators = NameIDFilter.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 = NameIDFilter.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', () => { + it('should add modify the object', () => { + expect(NameIDFilter.formatter({})).toEqual({}); + expect(NameIDFilter.parser({})).toEqual({}); + }); + }); +}); diff --git a/ui/src/app/metadata/filter/model/nameid.filter.ts b/ui/src/app/metadata/filter/model/nameid.filter.ts index f98a92eae..d03d66c3e 100644 --- a/ui/src/app/metadata/filter/model/nameid.filter.ts +++ b/ui/src/app/metadata/filter/model/nameid.filter.ts @@ -4,9 +4,34 @@ import { MetadataFilter } from '../../domain/model'; export const NameIDFilter: FormDefinition = { label: 'NameIDFilter', type: 'NameIDFormat', - schema: 'assets/schema/filter/nameid.schema.json', - getValidators(): any { - const validators = {}; + schema: '/api/ui/NameIdFormatFilter', + getValidators(namesList: string[] = []): any { + const validators = { + '/': (value, property, form_current) => { + let errors; + // iterate all customer + Object.keys(value).forEach((key) => { + const item = value[key]; + const validatorKey = `/${key}`; + const validator = validators.hasOwnProperty(validatorKey) ? validators[validatorKey] : null; + const error = validator ? validator(item, { path: `/${key}` }, form_current) : null; + if (error) { + errors = errors || []; + errors.push(error); + } + }); + return errors; + }, + '/name': (value, property, form) => { + const err = namesList.indexOf(value) > -1 ? { + code: 'INVALID_NAME', + path: `#${property.path}`, + message: 'message.name-must-be-unique', + params: [value] + } : null; + return err; + } + }; return validators; }, parser: (changes: any): MetadataFilter => changes, diff --git a/ui/src/app/metadata/filter/reducer/filter.reducer.spec.ts b/ui/src/app/metadata/filter/reducer/filter.reducer.spec.ts index bd7e71514..229478811 100644 --- a/ui/src/app/metadata/filter/reducer/filter.reducer.spec.ts +++ b/ui/src/app/metadata/filter/reducer/filter.reducer.spec.ts @@ -1,22 +1,8 @@ import { reducer, initialState as snapshot } from './filter.reducer'; import * as fromFilter from './filter.reducer'; import { SelectId, LoadEntityPreviewSuccess, UpdateFilterChanges, FilterActionTypes, CancelCreateFilter } from '../action/filter.action'; -import { SearchActionTypes } from '../action/search.action'; - -import { - ClearSearch -} from '../action/search.action'; - -import { - FilterCollectionActionTypes, - AddFilterRequest, - UpdateFilterRequest, - AddFilterSuccess, - UpdateFilterSuccess -} from '../action/collection.action'; import { MDUI } from '../../domain/model'; import { MetadataFilter } from '../../domain/model'; -import { EntityAttributesFilterEntity } from '../../domain/entity/filter/entity-attributes-filter'; const mdui: MDUI = { displayName: 'foo', @@ -61,26 +47,6 @@ describe('Filter Reducer', () => { expect(result.changes.filterEnabled).toBe(false); }); }); - - describe(`${FilterCollectionActionTypes.ADD_FILTER_SUCCESS} action`, () => { - it('should set saving to true', () => { - const result = reducer(snapshot, new AddFilterSuccess(new EntityAttributesFilterEntity())); - expect(result).toEqual(fromFilter.initialState); - }); - }); - describe(`${FilterCollectionActionTypes.UPDATE_FILTER_SUCCESS} action`, () => { - it('should set saving to true', () => { - const update = {id: 'foo', changes: new EntityAttributesFilterEntity({id: 'foo'})}; - const result = reducer(snapshot, new UpdateFilterSuccess(update)); - expect(result).toEqual(fromFilter.initialState); - }); - }); - describe(`${SearchActionTypes.CLEAR_SEARCH} action`, () => { - it('should set saving to true', () => { - const result = reducer(snapshot, new ClearSearch()); - expect(result).toEqual(fromFilter.initialState); - }); - }); describe(`${FilterActionTypes.CANCEL_CREATE_FILTER} action`, () => { it('should set saving to true', () => { const result = reducer(snapshot, new CancelCreateFilter()); diff --git a/ui/src/app/metadata/filter/reducer/search.reducer.spec.ts b/ui/src/app/metadata/filter/reducer/search.reducer.spec.ts index f778451da..4b18f91f4 100644 --- a/ui/src/app/metadata/filter/reducer/search.reducer.spec.ts +++ b/ui/src/app/metadata/filter/reducer/search.reducer.spec.ts @@ -90,6 +90,13 @@ describe('Filter Reducer', () => { }); }); + describe(`${SearchActionTypes.CLEAR_SEARCH} action`, () => { + it('should set saving to true', () => { + const result = reducer(snapshot, new ClearSearch()); + expect(result).toEqual(fromFilter.initialState); + }); + }); + describe('selector methods', () => { describe('getViewMore', () => { it('should return the state viewMore', () => {