-
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-1267 Updated unit test coverage
- Loading branch information
Showing
9 changed files
with
335 additions
and
14 deletions.
There are no files selected for viewing
115 changes: 115 additions & 0 deletions
115
ui/src/app/metadata/configuration/component/array-property.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,115 @@ | ||
import { Component, ViewChild, Input } from '@angular/core'; | ||
import { TestBed, async, ComponentFixture } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
import { NgbDropdownModule, NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { Property } from '../../domain/model/property'; | ||
import { MockI18nModule } from '../../../../testing/i18n.stub'; | ||
import { SCHEMA } from '../../../../testing/form-schema.stub'; | ||
import { getStepProperty } from '../../domain/utility/configuration'; | ||
import { ArrayPropertyComponent } from './array-property.component'; | ||
import { AttributesService } from '../../domain/service/attributes.service'; | ||
import { MockAttributeService } from '../../../../testing/attributes.stub'; | ||
import { of } from 'rxjs'; | ||
|
||
@Component({ | ||
template: ` | ||
<array-property [property]="property"></array-property> | ||
` | ||
}) | ||
class TestHostComponent { | ||
@ViewChild(ArrayPropertyComponent) | ||
public componentUnderTest: ArrayPropertyComponent; | ||
|
||
property: Property = getStepProperty(SCHEMA.properties.list, { | ||
name: 'foo', | ||
type: 'baz', | ||
description: 'foo bar baz', | ||
list: [] | ||
}, SCHEMA.definitions); | ||
|
||
setProperty(property: Property): void { | ||
this.property = property; | ||
} | ||
} | ||
|
||
describe('Array Property Component', () => { | ||
|
||
let fixture: ComponentFixture<TestHostComponent>; | ||
let instance: TestHostComponent; | ||
let app: ArrayPropertyComponent; | ||
let service: AttributesService; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NgbPopoverModule, | ||
MockI18nModule, | ||
RouterTestingModule | ||
], | ||
declarations: [ | ||
ArrayPropertyComponent, | ||
TestHostComponent | ||
], | ||
providers: [ | ||
{ provide: AttributesService, useClass: MockAttributeService } | ||
] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(TestHostComponent); | ||
instance = fixture.componentInstance; | ||
app = instance.componentUnderTest; | ||
service = TestBed.get(AttributesService); | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should accept a property input', async(() => { | ||
expect(app).toBeTruthy(); | ||
})); | ||
|
||
describe('attributeList$ getter', () => { | ||
it('should return an empty list when no data or dataUrl is set', () => { | ||
app.attributeList$.subscribe((list) => { | ||
expect(list).toEqual([]); | ||
}); | ||
}); | ||
it('should return a list of data items from the schema', () => { | ||
const datalist = [ | ||
{ key: 'foo', label: 'foo' }, | ||
{ key: 'bar', label: 'bar' }, | ||
{ key: 'baz', label: 'baz' }, | ||
]; | ||
instance.setProperty({ | ||
...instance.property, | ||
widget: { | ||
id: 'datalist', | ||
data: datalist | ||
} | ||
}); | ||
fixture.detectChanges(); | ||
app.attributeList$.subscribe(list => { | ||
expect(list).toEqual(datalist); | ||
}); | ||
}); | ||
|
||
it('should call the attribute service with a provided dataUrl', () => { | ||
const datalist = [ | ||
{ key: 'foo', label: 'foo' }, | ||
{ key: 'bar', label: 'bar' }, | ||
{ key: 'baz', label: 'baz' }, | ||
]; | ||
spyOn(service, 'query').and.returnValue(of(datalist)); | ||
instance.setProperty({ | ||
...instance.property, | ||
widget: { | ||
id: 'datalist', | ||
dataUrl: '/foo' | ||
} | ||
}); | ||
fixture.detectChanges(); | ||
app.attributeList$.subscribe(list => { | ||
expect(list).toEqual(datalist); | ||
}); | ||
}); | ||
}); | ||
}); |
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
69 changes: 69 additions & 0 deletions
69
ui/src/app/metadata/configuration/component/configuration-property.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,69 @@ | ||
import { Component, ViewChild, Input } from '@angular/core'; | ||
import { TestBed, async, ComponentFixture } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
import { NgbDropdownModule, NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { Property } from '../../domain/model/property'; | ||
import { MockI18nModule } from '../../../../testing/i18n.stub'; | ||
import { SCHEMA } from '../../../../testing/form-schema.stub'; | ||
import { getStepProperties, getStepProperty } from '../../domain/utility/configuration'; | ||
import { ConfigurationPropertyComponent } from './configuration-property.component'; | ||
|
||
@Component({ | ||
template: ` | ||
<configuration-property [property]="property"></configuration-property> | ||
` | ||
}) | ||
class TestHostComponent { | ||
@ViewChild(ConfigurationPropertyComponent) | ||
public componentUnderTest: ConfigurationPropertyComponent; | ||
|
||
property: Property = getStepProperty(SCHEMA.properties.name, { | ||
name: 'foo', | ||
type: 'baz', | ||
description: 'foo bar baz' | ||
}, SCHEMA.definitions); | ||
} | ||
|
||
describe('Configuration Property Component', () => { | ||
|
||
let fixture: ComponentFixture<TestHostComponent>; | ||
let instance: TestHostComponent; | ||
let app: ConfigurationPropertyComponent; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NgbPopoverModule, | ||
MockI18nModule, | ||
RouterTestingModule | ||
], | ||
declarations: [ | ||
ConfigurationPropertyComponent, | ||
TestHostComponent | ||
] | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(TestHostComponent); | ||
instance = fixture.componentInstance; | ||
app = instance.componentUnderTest; | ||
fixture.detectChanges(); | ||
})); | ||
|
||
it('should accept a property input', async(() => { | ||
expect(app).toBeTruthy(); | ||
})); | ||
|
||
describe('getKeys method', () => { | ||
it('should return the property`s child keys', () => { | ||
expect(app.getKeys({ properties: { foo: 'bar', baz: 'bar' } })).toEqual(['foo', 'baz']); | ||
}); | ||
}); | ||
|
||
describe('getItemType method', () => { | ||
it('should return the item`s type', () => { | ||
expect(app.getItemType({ widget: { id: 'string' } } as Property)).toBe('string'); | ||
expect(app.getItemType({} as Property)).toBe('default'); | ||
}); | ||
}); | ||
}); |
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
60 changes: 60 additions & 0 deletions
60
ui/src/app/metadata/configuration/component/object-property.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,60 @@ | ||
import { Component, ViewChild, Input } from '@angular/core'; | ||
import { TestBed, async, ComponentFixture } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
import { NgbDropdownModule, NgbPopoverModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { Property } from '../../domain/model/property'; | ||
import { MockI18nModule } from '../../../../testing/i18n.stub'; | ||
import { ObjectPropertyComponent } from './object-property.component'; | ||
import { SCHEMA } from '../../../../testing/form-schema.stub'; | ||
import { getStepProperties, getStepProperty } from '../../domain/utility/configuration'; | ||
import { PrimitivePropertyComponent } from './primitive-property.component'; | ||
import { ArrayPropertyComponent } from './array-property.component'; | ||
|
||
@Component({ | ||
template: ` | ||
<object-property [property]="property"></object-property> | ||
` | ||
}) | ||
class TestHostComponent { | ||
@ViewChild(ObjectPropertyComponent) | ||
public componentUnderTest: ObjectPropertyComponent; | ||
|
||
property: Property = getStepProperty(SCHEMA.properties.name, { | ||
name: 'foo', | ||
type: 'baz', | ||
description: 'foo bar baz' | ||
}, SCHEMA.definitions); | ||
} | ||
|
||
describe('Object Property Component', () => { | ||
|
||
let fixture: ComponentFixture<TestHostComponent>; | ||
let instance: TestHostComponent; | ||
let app: ObjectPropertyComponent; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NgbPopoverModule, | ||
MockI18nModule, | ||
RouterTestingModule | ||
], | ||
declarations: [ | ||
ObjectPropertyComponent, | ||
PrimitivePropertyComponent, | ||
ArrayPropertyComponent, | ||
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
60 changes: 60 additions & 0 deletions
60
ui/src/app/metadata/configuration/component/primitive-property.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,60 @@ | ||
import { Component, ViewChild, Input } from '@angular/core'; | ||
import { TestBed, async, ComponentFixture } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
|
||
import { NgbDropdownModule } from '@ng-bootstrap/ng-bootstrap'; | ||
import { Property } from '../../domain/model/property'; | ||
import { MockI18nModule } from '../../../../testing/i18n.stub'; | ||
import { PrimitivePropertyComponent } from './primitive-property.component'; | ||
|
||
@Component({ | ||
template: ` | ||
<primitive-property [property]="property"></primitive-property> | ||
` | ||
}) | ||
class TestHostComponent { | ||
@ViewChild(PrimitivePropertyComponent) | ||
public componentUnderTest: PrimitivePropertyComponent; | ||
|
||
property: Property = { | ||
title: 'foo', | ||
type: 'string', | ||
name: 'foo', | ||
value: ['bar'], | ||
items: null, | ||
properties: null, | ||
widget: { | ||
id: 'string' | ||
} | ||
}; | ||
} | ||
|
||
describe('Primitive Property Component', () => { | ||
|
||
let fixture: ComponentFixture<TestHostComponent>; | ||
let instance: TestHostComponent; | ||
let app: PrimitivePropertyComponent; | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
NgbDropdownModule, | ||
MockI18nModule, | ||
RouterTestingModule | ||
], | ||
declarations: [ | ||
PrimitivePropertyComponent, | ||
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