Skip to content

Commit

Permalink
Updated unit tests, improved coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Sep 27, 2019
1 parent 45711c5 commit 40feb8a
Show file tree
Hide file tree
Showing 15 changed files with 471 additions and 147 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ describe('Metadata Configuration Component', () => {
}));

describe('edit method', () => {
it('should call router.navigate', () => {
spyOn(router, 'navigate');
it('should call onEdit.emit', () => {
spyOn(app.onEdit, 'emit');
app.edit('foo');
expect(router.navigate).toHaveBeenCalled();
expect(app.onEdit.emit).toHaveBeenCalled();
});
});

Expand Down
118 changes: 3 additions & 115 deletions ui/src/app/metadata/configuration/reducer/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,143 +1,31 @@
import {
getConfigurationSectionsFn,
getConfigurationModelNameFn,
getConfigurationModelEnabledFn,
assignValueToProperties,
getLimitedPropertiesFn,
getConfigurationModelTypeFn,
getSelectedVersionNumberFn,
getSelectedIsCurrentFn
} from './index';
import { SCHEMA as schema } from '../../../../testing/form-schema.stub';

import { Metadata } from '../../domain/domain.type';
import { MockMetadataWizard } from '../../../../testing/mockMetadataWizard';

describe('Configuration Reducer', () => {
const model = {
name: 'foo',
serviceEnabled: true,
foo: {
bar: 'bar',
baz: 'baz'
},
list: [
'super',
'cool'
]
};

const props = [
{
id: 'name',
items: null,
name: 'label.metadata-provider-name-dashboard-display-only',
properties: [],
type: 'string',
value: null,
widget: { id: 'string', help: 'message.must-be-unique' }
},
{
id: 'serviceEnabled',
items: null,
name: 'serviceEnabled',
properties: [],
type: 'string',
value: null,
widget: { id: 'select', disabled: true }
},
{
id: 'foo',
items: null,
name: 'foo',
type: 'object',
properties: [
{
id: 'bar',
name: 'bar',
type: 'string',
properties: []
},
{
id: 'baz',
name: 'baz',
type: 'string',
properties: []
}
]
},
{
id: 'list',
name: 'list',
type: 'array',
items: {
type: 'string'
},
widget: {
id: 'datalist',
data: [
{ key: 'super', label: 'super' },
{ key: 'cool', label: 'cool' },
{ key: 'notcool', label: 'notcool' }
]
}
}
];

const definition = MockMetadataWizard;

describe('getConfigurationSectionsFn', () => {
it('should parse the schema, definition, and model into a MetadataConfiguration', () => {
const config = getConfigurationSectionsFn([model], definition, schema);
expect(config.sections).toBeDefined();
});
});

describe('getConfigurationModelNameFn function', () => {
it('should return the name attribute', () => {
expect(getConfigurationModelNameFn({ serviceProviderName: 'foo' } as Metadata)).toBe('foo');
expect(getConfigurationModelNameFn({ name: 'bar' } as Metadata)).toBe('bar');
expect(getConfigurationModelNameFn(null)).toBe(false);
expect(getConfigurationModelNameFn(null)).toBe('');
});
});

describe('getConfigurationModelEnabledFn function', () => {
it('should return the name attribute', () => {
it('should return the enabled attribute', () => {
expect(getConfigurationModelEnabledFn({ serviceEnabled: true } as Metadata)).toBe(true);
expect(getConfigurationModelEnabledFn({ enabled: true } as Metadata)).toBe(true);
expect(getConfigurationModelEnabledFn(null)).toBe(false);
});
});

describe('assignValueToProperties function', () => {
it('should assign appropriate values to the given schema properties', () => {
const assigned = assignValueToProperties([model], props, definition);
expect(assigned[0].value).toEqual(['foo']);
expect(assigned[1].value).toEqual([true]);
});

it('should assign differences when passed multiple models', () => {
const assigned = assignValueToProperties([model, {
...model,
name: 'bar',
list: [
'super',
'notcool'
]
}], props, definition);
expect(assigned[0].differences).toBe(true);
});
});

describe('getLimitedPropertiesFn function', () => {
it('should filter properties without differences', () => {
const assigned = assignValueToProperties([model, {
...model,
name: 'bar'
}], props, definition);
expect(getLimitedPropertiesFn(assigned).length).toBe(1);
});
});

describe('getConfigurationModelTypeFn function ', () => {
it('should return provider type if the object has an @type property', () => {
const md = { '@type': 'FilebackedHttpMetadataResolver' } as Metadata;
Expand Down
24 changes: 1 addition & 23 deletions ui/src/app/metadata/configuration/reducer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import * as fromVersion from './version.reducer';
import * as fromRestore from './restore.reducer';
import * as fromFilter from './filter.reducer';

import * as utils from '../../domain/utility/configuration';
import { getConfigurationSectionsFn } from './utilities';
import { getConfigurationSectionsFn, getLimitedPropertiesFn } from './utilities';
import { getModel } from '../../../wizard/reducer';
import { getInCollectionFn } from '../../domain/domain.util';
import { Metadata } from '../../domain/domain.type';

import * as fromResolver from '../../resolver/reducer';
import * as fromProvider from '../../provider/reducer';
import { SectionProperty } from '../model/section';

export interface ConfigurationState {
configuration: fromConfiguration.State;
Expand Down Expand Up @@ -136,26 +134,6 @@ export const getComparisonConfigurationCount = createSelector(getComparisonConfi

export const getViewChangedOnly = createSelector(getCompareState, fromCompare.getViewChangedOnly);

export const getLimitedPropertiesFn = (properties: SectionProperty[]) => {
return ([
...properties
.filter(p => p.differences)
.map(p => {
const parsed = { ...p };
if (p.widget && p.widget.data) {
parsed.widget = {
...p.widget,
data: p.widget.data.filter(item => item.differences)
};
}
if (p.properties) {
parsed.properties = getLimitedPropertiesFn(p.properties);
}
return parsed;
})
]);
};

export const getLimitedConfigurationsFn = (configurations, limited) => configurations ? ({
...configurations,
sections: limited ? configurations.sections :
Expand Down
120 changes: 120 additions & 0 deletions ui/src/app/metadata/configuration/reducer/utilities.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import {
getConfigurationSectionsFn,
getLimitedPropertiesFn,
assignValueToProperties
} from './utilities';

import { SCHEMA as schema } from '../../../../testing/form-schema.stub';
import { MockMetadataWizard } from '../../../../testing/mockMetadataWizard';

describe('config reducer utilities', () => {

const model = {
name: 'foo',
serviceEnabled: true,
foo: {
bar: 'bar',
baz: 'baz'
},
list: [
'super',
'cool'
]
};

const props = [
{
id: 'name',
items: null,
name: 'label.metadata-provider-name-dashboard-display-only',
properties: [],
type: 'string',
value: null,
widget: { id: 'string', help: 'message.must-be-unique' }
},
{
id: 'serviceEnabled',
items: null,
name: 'serviceEnabled',
properties: [],
type: 'string',
value: null,
widget: { id: 'select', disabled: true }
},
{
id: 'foo',
items: null,
name: 'foo',
type: 'object',
properties: [
{
id: 'bar',
name: 'bar',
type: 'string',
properties: []
},
{
id: 'baz',
name: 'baz',
type: 'string',
properties: []
}
]
},
{
id: 'list',
name: 'list',
type: 'array',
items: {
type: 'string'
},
widget: {
id: 'datalist',
data: [
{ key: 'super', label: 'super' },
{ key: 'cool', label: 'cool' },
{ key: 'notcool', label: 'notcool' }
]
}
}
];

const definition = MockMetadataWizard;

describe('assignValueToProperties function', () => {
it('should assign appropriate values to the given schema properties', () => {
const assigned = assignValueToProperties([model], props, definition);
expect(assigned[0].value).toEqual(['foo']);
expect(assigned[1].value).toEqual([true]);
});

it('should assign differences when passed multiple models', () => {
const assigned = assignValueToProperties([model, {
...model,
name: 'bar',
list: [
'super',
'notcool'
]
}], props, definition);
expect(assigned[0].differences).toBe(true);
});
});

describe('getLimitedPropertiesFn function', () => {
it('should filter properties without differences', () => {
const assigned = assignValueToProperties([model, {
...model,
name: 'bar'
}], props, definition);
expect(getLimitedPropertiesFn(assigned).length).toBe(1);
});
});

describe('getConfigurationSectionsFn', () => {
it('should parse the schema, definition, and model into a MetadataConfiguration', () => {
const config = getConfigurationSectionsFn([model], definition, schema);
expect(config.sections).toBeDefined();
});
});
});
21 changes: 21 additions & 0 deletions ui/src/app/metadata/configuration/reducer/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { MetadataConfiguration } from '../model/metadata-configuration';
import { WizardStep } from '../../../wizard/model';
import * as utils from '../../domain/utility/configuration';
import { getSplitSchema } from '../../../wizard/reducer';
import { SectionProperty } from '../model/section';

export const getConfigurationSectionsFn = (models, definition, schema): MetadataConfiguration => {
return !definition || !schema || !models ? null :
Expand Down Expand Up @@ -82,3 +83,23 @@ export const assignValueToProperties = (models, properties, definition: any): an
}
});
};

export const getLimitedPropertiesFn = (properties: SectionProperty[]) => {
return ([
...properties
.filter(p => p.differences)
.map(p => {
const parsed = { ...p };
if (p.widget && p.widget.data) {
parsed.widget = {
...p.widget,
data: p.widget.data.filter(item => item.differences)
};
}
if (p.properties) {
parsed.properties = getLimitedPropertiesFn(p.properties);
}
return parsed;
})
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { of } from 'rxjs';
import { MetadataProviderService } from '../../domain/service/provider.service';
import { Metadata } from '../../domain/domain.type';
import { SCHEMA } from '../../../../testing/form-schema.stub';
import { getConfigurationSectionsFn } from '../reducer';
import { getConfigurationSectionsFn } from '../reducer/utilities';

describe(`Configuration Service`, () => {

Expand Down
14 changes: 14 additions & 0 deletions ui/src/app/metadata/domain/component/wizard-summary.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<div class="row">
<div class="col-xl-6 col-xs-12" *ngFor="let sections of columns">
<section class="px-3" *ngFor="let section of sections; let i = index;">
<button (click)="gotoPage(section.id)" class="tag tag-success tag-sm my-4 text-left"
[attr.aria-label]="section.label | translate">
<span class="index">{{ section.pageNumber }}</span>
<translate-i18n [key]="section.label">{{ section.label }}</translate-i18n>
</button>
<ng-container *ngFor="let prop of section.properties">
<summary-property [property]="prop"></summary-property>
</ng-container>
</section>
</div>
</div>
Loading

0 comments on commit 40feb8a

Please sign in to comment.