-
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-1268 Implemented tests for metadata header
- Loading branch information
Showing
11 changed files
with
177 additions
and
31 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
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,58 @@ | ||
import { Component, ViewChild } from '@angular/core'; | ||
import { TestBed, async, ComponentFixture } from '@angular/core/testing'; | ||
import { MockI18nModule } from '../../../../testing/i18n.stub'; | ||
import { MetadataVersion } from '../model/version'; | ||
import { MetadataHeaderComponent } from './metadata-header.component'; | ||
|
||
@Component({ | ||
template: ` | ||
<metadata-header | ||
[isEnabled]="isEnabled" | ||
[version]="version" | ||
[versionNumber]="versionNumber" | ||
[isCurrent]="isCurrent" | ||
></metadata-header> | ||
` | ||
}) | ||
class TestHostComponent { | ||
@ViewChild(MetadataHeaderComponent) | ||
public componentUnderTest: MetadataHeaderComponent; | ||
|
||
isEnabled = true; | ||
|
||
version: MetadataVersion = { | ||
id: 'foo', | ||
creator: 'foobar', | ||
date: new Date().toDateString() | ||
}; | ||
versionNumber = 1; | ||
isCurrent = false; | ||
} | ||
|
||
describe('Metadata Header Component', () => { | ||
|
||
let fixture: ComponentFixture<TestHostComponent>; | ||
let instance: TestHostComponent; | ||
let app: MetadataHeaderComponent; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
MockI18nModule | ||
], | ||
declarations: [ | ||
MetadataHeaderComponent, | ||
TestHostComponent | ||
] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(TestHostComponent); | ||
instance = fixture.componentInstance; | ||
app = instance.componentUnderTest; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should accept a property 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
2 changes: 1 addition & 1 deletion
2
ui/src/app/metadata/configuration/container/metadata-options.component.html
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
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,70 @@ | ||
import { reducer } from './history.reducer'; | ||
import * as fromHistory from './history.reducer'; | ||
import * as actions from '../action/history.action'; | ||
import { MetadataHistory } from '../model/history'; | ||
|
||
describe('History Reducer', () => { | ||
|
||
const baseState = fromHistory.initialState; | ||
|
||
const history: MetadataHistory = { | ||
versions: [ | ||
{ | ||
id: '1', | ||
date: new Date().toLocaleDateString(), | ||
creator: 'foo' | ||
}, | ||
{ | ||
id: '2', | ||
date: new Date().toDateString(), | ||
creator: 'foo' | ||
} | ||
] | ||
}; | ||
|
||
describe('undefined action', () => { | ||
it('should return the default state', () => { | ||
const result = reducer(undefined, {} as any); | ||
|
||
expect(result).toEqual(fromHistory.initialState); | ||
}); | ||
}); | ||
|
||
describe('SET_HISTORY action', () => { | ||
it('should set the state metadata model', () => { | ||
const action = new actions.SetHistory(history); | ||
const result = reducer(fromHistory.initialState, action); | ||
|
||
expect(Object.keys(result.entities)).toEqual(['1', '2']); | ||
}); | ||
}); | ||
|
||
describe('SELECT_VERSION action', () => { | ||
it('should set the state metadata model', () => { | ||
const action = new actions.SelectVersion('1'); | ||
const result = reducer(baseState, action); | ||
|
||
expect(result).toEqual({ ...baseState, selectedVersionId: '1' }); | ||
}); | ||
}); | ||
|
||
describe('CLEAR action', () => { | ||
it('should clear the state and reset to initial state', () => { | ||
const action = new actions.ClearHistory(); | ||
const result = reducer({ | ||
...baseState, | ||
...history | ||
}, action); | ||
|
||
expect(result).toEqual(baseState); | ||
}); | ||
}); | ||
|
||
describe('selector functions', () => { | ||
describe('getSelectedId', () => { | ||
it('should return the selected version id', () => { | ||
expect(fromHistory.getSelectedVersionId({ ...baseState, selectedVersionId: '1' })).toBe('1'); | ||
}); | ||
}); | ||
}); | ||
}); |
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
3 changes: 2 additions & 1 deletion
3
ui/src/app/metadata/configuration/service/configuration.service.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