-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SHIBUI-1364 Tests for filter version list
- Loading branch information
Showing
3 changed files
with
179 additions
and
1 deletion.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
ui/src/app/metadata/configuration/component/filter-version-list.component.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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: ` | ||
| <filter-version-list | ||
| [filters]="filters" | ||
| (compare)="compare($event)"> | ||
| </filter-version-list> | ||
| ` | ||
| }) | ||
| class TestHostComponent { | ||
| @ViewChild(FilterVersionListComponent) | ||
| public componentUnderTest: FilterVersionListComponent; | ||
|
|
||
| filters: FilterConfiguration = TestData; | ||
|
|
||
| compare(versions: FilterComparison): void { } | ||
| } | ||
|
|
||
| describe('Filter Version List Component', () => { | ||
| let fixture: ComponentFixture<TestHostComponent>; | ||
| 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(); | ||
| }); | ||
| }); | ||
| */ | ||
| }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
ui/src/app/metadata/configuration/reducer/filter.reducer.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |