Skip to content

Commit

Permalink
SHIBUI-799 Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Dec 7, 2018
1 parent 901e848 commit f5a2f04
Show file tree
Hide file tree
Showing 9 changed files with 92 additions and 76 deletions.
26 changes: 2 additions & 24 deletions backend/src/main/resources/nameid-filter.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
<div class="col-md-12">
<span class="display-6">
<i class="fa fa-fw fa-gears"></i>&nbsp;&nbsp;
<translate-i18n key="label.edit-filter">Edit Filter</translate-i18n> {{ type$ | async }}
<ng-container *ngIf="type$ | async">
<translate-i18n key="label.edit-filter">Edit Filter</translate-i18n>&ndash; {{ type$ | async }}
</ng-container>
</span>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EditFilterComponent>;
let store: Store<fromFilter.State>;
let instance: EditFilterComponent;
Expand All @@ -25,8 +25,7 @@ describe('New Metadata Filter Page', () => {
FormBuilder,
NgbPopoverConfig,
NavigatorService,
SchemaService,
{ provide: WidgetRegistry, useClass: DefaultWidgetRegistry }
SchemaService
],
imports: [
StoreModule.forRoot({
Expand All @@ -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', () => {
Expand All @@ -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();
});
});
Expand All @@ -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);
});
});
Expand Down
5 changes: 2 additions & 3 deletions ui/src/app/metadata/filter/container/edit-filter.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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 => {
Expand All @@ -80,8 +81,6 @@ export class EditFilterComponent {
this.preview(parameters.id);
}
};

this.type$ = this.model$.pipe(map(f => f['@type']));
}

save(): void {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
});
43 changes: 43 additions & 0 deletions ui/src/app/metadata/filter/model/nameid.filter.spec.ts
Original file line number Diff line number Diff line change
@@ -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({});
});
});
});
31 changes: 28 additions & 3 deletions ui/src/app/metadata/filter/model/nameid.filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,34 @@ import { MetadataFilter } from '../../domain/model';
export const NameIDFilter: FormDefinition<MetadataFilter> = {
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,
Expand Down
34 changes: 0 additions & 34 deletions ui/src/app/metadata/filter/reducer/filter.reducer.spec.ts
Original file line number Diff line number Diff line change
@@ -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',
Expand Down Expand Up @@ -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());
Expand Down
7 changes: 7 additions & 0 deletions ui/src/app/metadata/filter/reducer/search.reducer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down

0 comments on commit f5a2f04

Please sign in to comment.