-
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.
- Loading branch information
Showing
7 changed files
with
196 additions
and
9 deletions.
There are no files selected for viewing
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,60 @@ | ||
import { Component, ViewChild, Input } from '@angular/core'; | ||
import { TestBed, async, ComponentFixture } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { MetadataConfigurationComponent } from './metadata-configuration.component'; | ||
|
||
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { MetadataConfiguration } from '../model/metadata-configuration'; | ||
import { Property } from '../../domain/model/property'; | ||
import { MockI18nModule } from '../../../../testing/i18n.stub'; | ||
|
||
@Component({ | ||
selector: 'object-property', | ||
template: `` | ||
}) | ||
class ObjectPropertyComponent { | ||
@Input() property: Property; | ||
} | ||
|
||
@Component({ | ||
template: ` | ||
<metadata-configuration [configuration]="configuration"></metadata-configuration> | ||
` | ||
}) | ||
class TestHostComponent { | ||
@ViewChild(MetadataConfigurationComponent) | ||
public componentUnderTest: MetadataConfigurationComponent; | ||
|
||
configuration: MetadataConfiguration = {sections: []}; | ||
} | ||
|
||
describe('Metadata Configuration Component', () => { | ||
|
||
let fixture: ComponentFixture<TestHostComponent>; | ||
let instance: TestHostComponent; | ||
let app: MetadataConfigurationComponent; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NgbDropdownModule, | ||
MockI18nModule, | ||
RouterTestingModule | ||
], | ||
declarations: [ | ||
MetadataConfigurationComponent, | ||
ObjectPropertyComponent, | ||
TestHostComponent | ||
], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(TestHostComponent); | ||
instance = fixture.componentInstance; | ||
app = instance.componentUnderTest; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should accept a configuration input', async(() => { | ||
expect(app).toBeTruthy(); | ||
})); | ||
}); |
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
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,64 @@ | ||
import { Component, ViewChild, Input } from '@angular/core'; | ||
import { TestBed, async, ComponentFixture } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { StoreModule, combineReducers } from '@ngrx/store'; | ||
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; | ||
|
||
import { MetadataConfiguration } from '../model/metadata-configuration'; | ||
import { ConfigurationComponent } from './configuration.component'; | ||
import * as fromConfiguration from '../reducer'; | ||
import { MockI18nModule } from '../../../../testing/i18n.stub'; | ||
|
||
@Component({ | ||
selector: 'metadata-configuration', | ||
template: `` | ||
}) | ||
class MetadataConfigurationComponent { | ||
@Input() configuration: MetadataConfiguration; | ||
} | ||
|
||
@Component({ | ||
template: ` | ||
<configuration-page></configuration-page> | ||
` | ||
}) | ||
class TestHostComponent { | ||
@ViewChild(ConfigurationComponent) | ||
public componentUnderTest: ConfigurationComponent; | ||
|
||
configuration: MetadataConfiguration = { sections: [] }; | ||
} | ||
|
||
describe('Metadata Configuration Page Component', () => { | ||
|
||
let fixture: ComponentFixture<TestHostComponent>; | ||
let instance: TestHostComponent; | ||
let app: ConfigurationComponent; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NgbDropdownModule, | ||
StoreModule.forRoot({ | ||
'metadata-configuration': combineReducers(fromConfiguration.reducers), | ||
}), | ||
MockI18nModule, | ||
RouterTestingModule | ||
], | ||
declarations: [ | ||
ConfigurationComponent, | ||
MetadataConfigurationComponent, | ||
TestHostComponent | ||
], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(TestHostComponent); | ||
instance = fixture.componentInstance; | ||
app = instance.componentUnderTest; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should load metadata objects', async(() => { | ||
expect(app).toBeTruthy(); | ||
})); | ||
}); |
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
51 changes: 51 additions & 0 deletions
51
ui/src/app/metadata/configuration/reducer/configuration.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,51 @@ | ||
import { reducer } from './configuration.reducer'; | ||
import * as fromConfig from './configuration.reducer'; | ||
import * as actions from '../action/configuration.action'; | ||
import { MetadataSourceEditor } from '../../domain/model/wizards/metadata-source-editor'; | ||
import { SCHEMA } from '../../../../testing/form-schema.stub'; | ||
import { MetadataResolver } from '../../domain/model'; | ||
|
||
describe('Configuration Reducer', () => { | ||
const initialState: fromConfig.State = { ...fromConfig.initialState }; | ||
|
||
describe('undefined action', () => { | ||
it('should return the default state', () => { | ||
const result = reducer(undefined, {} as any); | ||
|
||
expect(result).toEqual(initialState); | ||
}); | ||
}); | ||
|
||
describe('SET_DEFINITION action', () => { | ||
it('should set the state definition', () => { | ||
const definition = new MetadataSourceEditor(); | ||
const action = new actions.SetDefinition(definition); | ||
const result = reducer(initialState, action); | ||
|
||
expect(result).toEqual({ ...initialState, definition }); | ||
}); | ||
}); | ||
|
||
describe('SET_SCHEMA action', () => { | ||
it('should set the state schema', () => { | ||
const action = new actions.SetSchema(SCHEMA); | ||
const result = reducer(initialState, action); | ||
|
||
expect(result).toEqual({ ...initialState, schema: SCHEMA }); | ||
}); | ||
}); | ||
|
||
describe('SET_METADATA action', () => { | ||
it('should set the state metadata model', () => { | ||
const model: MetadataResolver = { | ||
id: 'foo', | ||
serviceProviderName: 'foo', | ||
'@type': 'MetadataResolver' | ||
}; | ||
const action = new actions.SetMetadata(model as MetadataResolver); | ||
const result = reducer(initialState, action); | ||
|
||
expect(result).toEqual({ ...initialState, model }); | ||
}); | ||
}); | ||
}); |
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,19 @@ | ||
import { getConfigurationSectionsFn } from './index'; | ||
import { SCHEMA as schema } from '../../../../testing/form-schema.stub'; | ||
import { MetadataSourceEditor } from '../../domain/model/wizards/metadata-source-editor'; | ||
|
||
describe('Configuration Reducer', () => { | ||
const model = { | ||
name: 'foo', | ||
'@type': 'MetadataResolver' | ||
}; | ||
|
||
const definition = new MetadataSourceEditor(); | ||
|
||
describe('getConfigurationSectionsFn', () => { | ||
it('should parse the schema, definition, and model into a MetadataConfiguration', () => { | ||
const config = getConfigurationSectionsFn(model, definition, schema); | ||
expect(config.sections).toBeDefined(); | ||
}); | ||
}); | ||
}); |
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