From 9432f2c22b8ee31c9db77ee1a41bf6f33fe03a15 Mon Sep 17 00:00:00 2001 From: Ryan Mathis Date: Thu, 19 Sep 2019 10:05:46 -0700 Subject: [PATCH] SHIBUI-1364 Tests for filter version list --- .../filter-version-list.component.spec.ts | 85 +++++++++++++++++ .../metadata/configuration/model/version.ts | 2 +- .../reducer/filter.reducer.spec.ts | 93 +++++++++++++++++++ 3 files changed, 179 insertions(+), 1 deletion(-) create mode 100644 ui/src/app/metadata/configuration/component/filter-version-list.component.spec.ts create mode 100644 ui/src/app/metadata/configuration/reducer/filter.reducer.spec.ts diff --git a/ui/src/app/metadata/configuration/component/filter-version-list.component.spec.ts b/ui/src/app/metadata/configuration/component/filter-version-list.component.spec.ts new file mode 100644 index 000000000..8cb39402d --- /dev/null +++ b/ui/src/app/metadata/configuration/component/filter-version-list.component.spec.ts @@ -0,0 +1,85 @@ +import { Component, ViewChild } from '@angular/core'; +import { TestBed, ComponentFixture } from '@angular/core/testing'; +import { RouterTestingModule } from '@angular/router/testing'; + +import { MockI18nModule } from '../../../../testing/i18n.stub'; +import { FilterVersionListComponent } from './filter-version-list.component'; +import { FilterComparison } from '../model/compare'; +import { FilterConfiguration } from '../model/metadata-configuration'; + +export const TestData = { + dates: ['abc', '123'], + filters: [ + { + resourceId: 'foo', + name: 'Test 1', + type: 'EntityAttributesFilter', + comparable: false + }, + { + resourceId: 'bar', + name: 'Test 2', + type: 'EntityAttributesFilter', + comparable: false + } + ] +}; + +@Component({ + template: ` + + + ` +}) +class TestHostComponent { + @ViewChild(FilterVersionListComponent) + public componentUnderTest: FilterVersionListComponent; + + filters: FilterConfiguration = TestData; + + compare(versions: FilterComparison): void { } +} + +describe('Filter Version List Component', () => { + let fixture: ComponentFixture; + let instance: TestHostComponent; + let list: FilterVersionListComponent; + + beforeEach(() => { + TestBed.configureTestingModule({ + providers: [], + imports: [ + MockI18nModule, + RouterTestingModule + ], + declarations: [ + FilterVersionListComponent, + TestHostComponent + ], + }); + + fixture = TestBed.createComponent(TestHostComponent); + instance = fixture.componentInstance; + list = instance.componentUnderTest; + fixture.detectChanges(); + }); + + it('should compile', () => { + expect(list).toBeDefined(); + }); + + /* + describe('compareSelected', () => { + it('should emit an event with the selected filter data', () => { + list.selected = 'foo'; + fixture.detectChanges(); + spyOn(instance, 'compare'); + list.compareSelected(); + fixture.detectChanges(); + expect(instance.compare).toHaveBeenCalled(); + }); + }); + */ +}); diff --git a/ui/src/app/metadata/configuration/model/version.ts b/ui/src/app/metadata/configuration/model/version.ts index 5d1e1dac5..bba3c7ced 100644 --- a/ui/src/app/metadata/configuration/model/version.ts +++ b/ui/src/app/metadata/configuration/model/version.ts @@ -5,7 +5,7 @@ export interface MetadataVersion { } export interface FilterVersion { - id: string; + resourceId: string; name: string; type: string; comparable: boolean; diff --git a/ui/src/app/metadata/configuration/reducer/filter.reducer.spec.ts b/ui/src/app/metadata/configuration/reducer/filter.reducer.spec.ts new file mode 100644 index 000000000..228c705f1 --- /dev/null +++ b/ui/src/app/metadata/configuration/reducer/filter.reducer.spec.ts @@ -0,0 +1,93 @@ +import { reducer } from './filter.reducer'; +import * as fromFilterCompare from './filter.reducer'; +import { + SetFilterComparisonSchema, + ClearFilterComparison, + SetFilterComparisonDefinition, + CompareFilterVersions +} from '../action/filter.action'; +import { NameIDFilterConfiguration } from '../../filter/model/nameid-configuration.filter'; +import { Metadata } from '../../domain/domain.type'; + +describe('Filter Comparison Reducer', () => { + const initialState: fromFilterCompare.State = { ...fromFilterCompare.initialState }; + + describe('undefined action', () => { + it('should return the default state', () => { + const result = reducer(undefined, {} as any); + + expect(result).toEqual(initialState); + }); + }); + + describe('SET_SCHEMA action', () => { + it('should add the provided schema to the state', () => { + const schema = {type: 'object', properties: { foo: { type: 'string' } }}; + const action = new SetFilterComparisonSchema(schema); + const result = reducer(initialState, action); + expect(result.schema).toEqual(schema); + }); + }); + + describe('SET_DEFINITION action', () => { + it('should add the provided definition to the state', () => { + const definition = NameIDFilterConfiguration; + const action = new SetFilterComparisonDefinition(definition); + const result = reducer(initialState, action); + expect(result.definition).toEqual(definition); + }); + }); + + describe('COMPARE_FILTERS action', () => { + it('should add model information to the state', () => { + const request = { + modelId: 'foo', + modelType: 'EntityAttributesFilter', + models: [{}, {}] as Metadata[] + }; + const action = new CompareFilterVersions(request); + const result = reducer(initialState, action); + expect(result.modelId).toEqual(request.modelId); + expect(result.modelType).toEqual(request.modelType); + expect(result.models).toEqual(request.models); + }); + }); + + describe('CLEAR action', () => { + it('should reset to the initial state', () => { + const action = new ClearFilterComparison(); + const result = reducer(initialState, action); + expect(result).toEqual(initialState); + }); + }); + + describe('selector functions', () => { + describe('getModel', () => { + it('should retrieve the model from state', () => { + const models = [{}, {}] as Metadata[]; + expect(fromFilterCompare.getModelId({ ...initialState, modelId: 'foo' })).toBe('foo'); + expect(fromFilterCompare.getModelType({ ...initialState, modelType: 'foo' })).toBe('foo'); + expect(fromFilterCompare.getModels({ ...initialState, models })).toBe(models); + }); + }); + describe('getLoading', () => { + it('should retrieve the loading state', () => { + expect(fromFilterCompare.getLoading({ ...initialState, loading: true })).toBe(true); + }); + }); + + describe('getSchema', () => { + it('should retrieve the schema from state', () => { + const schema = {}; + expect(fromFilterCompare.getSchema({ ...initialState, schema })).toBe(schema); + }); + }); + + describe('getDefinition', () => { + it('should retrieve the definition from state', () => { + const definition = NameIDFilterConfiguration; + expect(fromFilterCompare.getDefinition({ ...initialState, definition })).toBe(NameIDFilterConfiguration); + }); + }); + }); +});