-
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
11 changed files
with
168 additions
and
69 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
2 changes: 1 addition & 1 deletion
2
ui/src/app/metadata/configuration/reducer/configuration.reducer.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
63 changes: 63 additions & 0 deletions
63
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { TestBed, async, inject } from '@angular/core/testing'; | ||
import { HttpClientModule, HttpRequest } from '@angular/common/http'; | ||
import { HttpTestingController, HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { MetadataConfigurationService, PATHS } from './configuration.service'; | ||
import { FileBackedHttpMetadataProviderEditor } from '../../provider/model'; | ||
import { MetadataSourceEditor } from '../../domain/model/wizards/metadata-source-editor'; | ||
|
||
describe(`Attributes Service`, () => { | ||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
HttpClientModule, | ||
HttpClientTestingModule | ||
], | ||
providers: [ | ||
MetadataConfigurationService | ||
] | ||
}); | ||
}); | ||
|
||
describe('find method', () => { | ||
it(`should send an expected GET request`, async(inject([MetadataConfigurationService, HttpTestingController], | ||
(service: MetadataConfigurationService, backend: HttpTestingController) => { | ||
const type = 'resolver'; | ||
const id = 'foo'; | ||
service.find(id, type).subscribe(); | ||
backend.expectOne((req: HttpRequest<any>) => { | ||
return req.url === `${service.base}/${PATHS[type]}/${id}` | ||
&& req.method === 'GET'; | ||
}, `GET metadata by id and type`); | ||
} | ||
))); | ||
}); | ||
|
||
describe('loadSchema method', () => { | ||
it(`should send an expected GET request`, async(inject([MetadataConfigurationService, HttpTestingController], | ||
(service: MetadataConfigurationService, backend: HttpTestingController) => { | ||
const path = '/foo.json'; | ||
service.loadSchema(path).subscribe(); | ||
backend.expectOne((req: HttpRequest<any>) => { | ||
return req.url === `${path}` | ||
&& req.method === 'GET'; | ||
}, `GET schema by path`); | ||
} | ||
))); | ||
}); | ||
|
||
describe('getDefinition method', () => { | ||
it(`should retrieve the editor definition by model type`, async(inject([MetadataConfigurationService, HttpTestingController], | ||
(service: MetadataConfigurationService, backend: HttpTestingController) => { | ||
const def = service.getDefinition('FileBackedHttpMetadataResolver'); | ||
expect(def).toBe(FileBackedHttpMetadataProviderEditor); | ||
} | ||
))); | ||
|
||
it(`should instantiate an editor for resolvers`, async(inject([MetadataConfigurationService], | ||
(service: MetadataConfigurationService) => { | ||
const def = service.getDefinition('foo'); | ||
expect(def instanceof MetadataSourceEditor).toBe(true); | ||
} | ||
))); | ||
}); | ||
}); |
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,62 @@ | ||
import { getStepProperties, getDefinition, getPropertyItemSchema, getStepProperty } from './configuration'; | ||
import * as utils from './configuration'; | ||
import { SCHEMA } from '../../../../testing/form-schema.stub'; | ||
|
||
describe('domain utility functions', () => { | ||
describe('getStepProperties function', () => { | ||
it('should return an empty array of schema or schema.properties is not defined', () => { | ||
expect(getStepProperties(null, {})).toEqual([]); | ||
expect(getStepProperties({}, {})).toEqual([]); | ||
}); | ||
|
||
it('should return a formatted list of properties', () => { | ||
expect(getStepProperties(SCHEMA, {}).length).toBe(2); | ||
}); | ||
}); | ||
|
||
describe('getDefinitions method', () => { | ||
it('should retrieve the definitions from the json schema', () => { | ||
const definition = { | ||
id: 'foo', | ||
title: 'bar', | ||
description: 'baz', | ||
type: 'string' | ||
}; | ||
expect(getDefinition('/foo/bar', {bar: definition})).toBe(definition); | ||
}); | ||
}); | ||
|
||
describe('getPropertyItemSchema method', () => { | ||
it('should return null if no items are provided', () => { | ||
expect(getPropertyItemSchema(null, SCHEMA.definitions)).toBeNull(); | ||
}); | ||
it('should retrieve the definitions from the items schema', () => { | ||
expect(getPropertyItemSchema({$ref: 'description'}, SCHEMA.definitions)).toBe(SCHEMA.definitions.description); | ||
}); | ||
it('should return the item itself if no $ref', () => { | ||
let item = {}; | ||
expect(getPropertyItemSchema(item, SCHEMA.definitions)).toBe(item); | ||
}); | ||
}); | ||
|
||
describe('getStepProperty method', () => { | ||
const model = { | ||
name: 'foo', | ||
type: 'bar', | ||
description: 'baz' | ||
}; | ||
it('should return null if no items are provided', () => { | ||
expect(getStepProperty(null, null, SCHEMA.definitions)).toBeNull(); | ||
}); | ||
|
||
it('should retrieve the property $ref definition if available', () => { | ||
const property = getStepProperty( | ||
{ $ref: 'description' }, | ||
model, | ||
SCHEMA.definitions | ||
); | ||
expect(property.type).toBe('string'); | ||
}); | ||
}); | ||
}); | ||
|
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