Skip to content

Commit

Permalink
Merge pull request #380 from atmire/improved-test-coverage-and-typedoc
Browse files Browse the repository at this point in the history
Improved test coverage and TypeDoc
  • Loading branch information
tdonohue committed Apr 15, 2019
2 parents f54a3a4 + 2425386 commit 96155e5
Show file tree
Hide file tree
Showing 12 changed files with 403 additions and 65 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,24 @@ import { PaginatedList } from '../../../core/data/paginated-list';
import { BitstreamFormat } from '../../../core/registry/mock-bitstream-format.model';
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';

/**
* This component renders a list of bitstream formats
*/
@Component({
selector: 'ds-bitstream-formats',
templateUrl: './bitstream-formats.component.html'
})
export class BitstreamFormatsComponent {

/**
* A paginated list of bitstream formats to be shown on the page
*/
bitstreamFormats: Observable<RemoteData<PaginatedList<BitstreamFormat>>>;

/**
* The current pagination configuration for the page
* Currently simply renders all bitstream formats
*/
config: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
id: 'registry-bitstreamformats-pagination',
pageSize: 10000
Expand All @@ -22,11 +33,18 @@ export class BitstreamFormatsComponent {
this.updateFormats();
}

/**
* When the page is changed, make sure to update the list of bitstreams to match the new page
* @param event The page change event
*/
onPageChange(event) {
this.config.currentPage = event;
this.updateFormats();
}

/**
* Method to update the bitstream formats that are shown
*/
private updateFormats() {
this.bitstreamFormats = this.registryService.getBitstreamFormats(this.config);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const MetadataRegistryActionTypes = {

/* tslint:disable:max-classes-per-file */
/**
* Used to collapse the sidebar
* Used to edit a metadata schema in the metadata registry
*/
export class MetadataRegistryEditSchemaAction implements Action {
type = MetadataRegistryActionTypes.EDIT_SCHEMA;
Expand All @@ -41,12 +41,15 @@ export class MetadataRegistryEditSchemaAction implements Action {
}

/**
* Used to expand the sidebar
* Used to cancel the editing of a metadata schema in the metadata registry
*/
export class MetadataRegistryCancelSchemaAction implements Action {
type = MetadataRegistryActionTypes.CANCEL_EDIT_SCHEMA;
}

/**
* Used to select a single metadata schema in the metadata registry
*/
export class MetadataRegistrySelectSchemaAction implements Action {
type = MetadataRegistryActionTypes.SELECT_SCHEMA;

Expand All @@ -57,6 +60,9 @@ export class MetadataRegistrySelectSchemaAction implements Action {
}
}

/**
* Used to deselect a single metadata schema in the metadata registry
*/
export class MetadataRegistryDeselectSchemaAction implements Action {
type = MetadataRegistryActionTypes.DESELECT_SCHEMA;

Expand All @@ -67,12 +73,15 @@ export class MetadataRegistryDeselectSchemaAction implements Action {
}
}

/**
* Used to deselect all metadata schemas in the metadata registry
*/
export class MetadataRegistryDeselectAllSchemaAction implements Action {
type = MetadataRegistryActionTypes.DESELECT_ALL_SCHEMA;
}

/**
* Used to collapse the sidebar
* Used to edit a metadata field in the metadata registry
*/
export class MetadataRegistryEditFieldAction implements Action {
type = MetadataRegistryActionTypes.EDIT_FIELD;
Expand All @@ -85,12 +94,15 @@ export class MetadataRegistryEditFieldAction implements Action {
}

/**
* Used to expand the sidebar
* Used to cancel the editing of a metadata field in the metadata registry
*/
export class MetadataRegistryCancelFieldAction implements Action {
type = MetadataRegistryActionTypes.CANCEL_EDIT_FIELD;
}

/**
* Used to select a single metadata field in the metadata registry
*/
export class MetadataRegistrySelectFieldAction implements Action {
type = MetadataRegistryActionTypes.SELECT_FIELD;

Expand All @@ -101,6 +113,9 @@ export class MetadataRegistrySelectFieldAction implements Action {
}
}

/**
* Used to deselect a single metadata field in the metadata registry
*/
export class MetadataRegistryDeselectFieldAction implements Action {
type = MetadataRegistryActionTypes.DESELECT_FIELD;

Expand All @@ -111,6 +126,9 @@ export class MetadataRegistryDeselectFieldAction implements Action {
}
}

/**
* Used to deselect all metadata fields in the metadata registry
*/
export class MetadataRegistryDeselectAllFieldAction implements Action {
type = MetadataRegistryActionTypes.DESELECT_ALL_FIELD;
}
Expand All @@ -120,6 +138,7 @@ export class MetadataRegistryDeselectAllFieldAction implements Action {
/**
* Export a type alias of all actions in this action group
* so that reducers can easily compose action types
* These are all the actions to perform on the metadata registry state
*/
export type MetadataRegistryAction
= MetadataRegistryEditSchemaAction
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
import {
MetadataRegistryCancelFieldAction,
MetadataRegistryCancelSchemaAction, MetadataRegistryDeselectAllFieldAction,
MetadataRegistryDeselectAllSchemaAction, MetadataRegistryDeselectFieldAction,
MetadataRegistryDeselectSchemaAction, MetadataRegistryEditFieldAction,
MetadataRegistryEditSchemaAction, MetadataRegistrySelectFieldAction,
MetadataRegistrySelectSchemaAction
} from './metadata-registry.actions';
import { metadataRegistryReducer, MetadataRegistryState } from './metadata-registry.reducers';
import { MetadataSchema } from '../../../core/metadata/metadataschema.model';
import { MetadataField } from '../../../core/metadata/metadatafield.model';

class NullAction extends MetadataRegistryEditSchemaAction {
type = null;
constructor() {
super(undefined);
}
}

const schema: MetadataSchema = Object.assign(new MetadataSchema(),
{
id: 'schema-id',
self: 'http://rest.self/schema/dc',
prefix: 'dc',
namespace: 'http://dublincore.org/documents/dcmi-terms/'
});

const schema2: MetadataSchema = Object.assign(new MetadataSchema(),
{
id: 'another-schema-id',
self: 'http://rest.self/schema/dcterms',
prefix: 'dcterms',
namespace: 'http://purl.org/dc/terms/'
});

const field: MetadataField = Object.assign(new MetadataField(),
{
id: 'author-field-id',
self: 'http://rest.self/field/author',
element: 'contributor',
qualifier: 'author',
scopeNote: 'Author of an item',
schema: schema
});

const field2: MetadataField = Object.assign(new MetadataField(),
{
id: 'title-field-id',
self: 'http://rest.self/field/title',
element: 'title',
qualifier: null,
scopeNote: 'Title of an item',
schema: schema
});

const initialState: MetadataRegistryState = {
editSchema: null,
selectedSchemas: [],
editField: null,
selectedFields: []
};

const editState: MetadataRegistryState = {
editSchema: schema,
selectedSchemas: [],
editField: field,
selectedFields: []
};

const selectState: MetadataRegistryState = {
editSchema: null,
selectedSchemas: [schema2],
editField: null,
selectedFields: [field2]
};

const moreSelectState: MetadataRegistryState = {
editSchema: null,
selectedSchemas: [schema, schema2],
editField: null,
selectedFields: [field, field2]
};

describe('metadataRegistryReducer', () => {

it('should return the current state when no valid actions have been made', () => {
const state = initialState;
const action = new NullAction();
const newState = metadataRegistryReducer(state, action);

expect(newState).toEqual(state);
});

it('should start with an the initial state', () => {
const state = initialState;
const action = new NullAction();
const initState = metadataRegistryReducer(undefined, action);

expect(initState).toEqual(state);
});

it('should update the current state to change the editSchema to a new schema when MetadataRegistryEditSchemaAction is dispatched', () => {
const state = editState;
const action = new MetadataRegistryEditSchemaAction(schema2);
const newState = metadataRegistryReducer(state, action);

expect(newState.editSchema).toEqual(schema2);
});

it('should update the current state to remove the editSchema from the state when MetadataRegistryCancelSchemaAction is dispatched', () => {
const state = editState;
const action = new MetadataRegistryCancelSchemaAction();
const newState = metadataRegistryReducer(state, action);

expect(newState.editSchema).toEqual(null);
});

it('should update the current state to add a given schema to the selectedSchemas when MetadataRegistrySelectSchemaAction is dispatched', () => {
const state = selectState;
const action = new MetadataRegistrySelectSchemaAction(schema);
const newState = metadataRegistryReducer(state, action);

expect(newState.selectedSchemas).toContain(schema);
expect(newState.selectedSchemas).toContain(schema2);
});

it('should update the current state to remove a given schema to the selectedSchemas when MetadataRegistryDeselectSchemaAction is dispatched', () => {
const state = selectState;
const action = new MetadataRegistryDeselectSchemaAction(schema2);
const newState = metadataRegistryReducer(state, action);

expect(newState.selectedSchemas).toEqual([]);
});

it('should update the current state to remove a given schema to the selectedSchemas when MetadataRegistryDeselectAllSchemaAction is dispatched', () => {
const state = selectState;
const action = new MetadataRegistryDeselectAllSchemaAction();
const newState = metadataRegistryReducer(state, action);

expect(newState.selectedSchemas).toEqual([]);
});

it('should update the current state to change the editField to a new field when MetadataRegistryEditFieldAction is dispatched', () => {
const state = editState;
const action = new MetadataRegistryEditFieldAction(field2);
const newState = metadataRegistryReducer(state, action);

expect(newState.editField).toEqual(field2);
});

it('should update the current state to remove the editField from the state when MetadataRegistryCancelFieldAction is dispatched', () => {
const state = editState;
const action = new MetadataRegistryCancelFieldAction();
const newState = metadataRegistryReducer(state, action);

expect(newState.editField).toEqual(null);
});

it('should update the current state to add a given field to the selectedFields when MetadataRegistrySelectFieldAction is dispatched', () => {
const state = selectState;
const action = new MetadataRegistrySelectFieldAction(field);
const newState = metadataRegistryReducer(state, action);

expect(newState.selectedFields).toContain(field);
expect(newState.selectedFields).toContain(field2);
});

it('should update the current state to remove a given field to the selectedFields when MetadataRegistryDeselectFieldAction is dispatched', () => {
const state = selectState;
const action = new MetadataRegistryDeselectFieldAction(field2);
const newState = metadataRegistryReducer(state, action);

expect(newState.selectedFields).toEqual([]);
});

it('should update the current state to remove a given field to the selectedFields when MetadataRegistryDeselectAllFieldAction is dispatched', () => {
const state = selectState;
const action = new MetadataRegistryDeselectAllFieldAction();
const newState = metadataRegistryReducer(state, action);

expect(newState.selectedFields).toEqual([]);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import {
import { MetadataField } from '../../../core/metadata/metadatafield.model';

/**
* The auth state.
* @interface State
* The metadata registry state.
* @interface MetadataRegistryState
*/
export interface MetadataRegistryState {
editSchema: MetadataSchema;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@ import { Component, EventEmitter, Input, OnDestroy, OnInit, Output } from '@angu
import { MetadataSchema } from '../../../../core/metadata/metadataschema.model';
import {
DynamicFormControlModel,
DynamicFormGroupModel,
DynamicFormLayout,
DynamicInputModel
} from '@ng-dynamic-forms/core';
import { FormGroup } from '@angular/forms';
import { RegistryService } from '../../../../core/registry/registry.service';
import { FormBuilderService } from '../../../../shared/form/builder/form-builder.service';
import { Observable } from 'rxjs/internal/Observable';
import { MetadataField } from '../../../../core/metadata/metadatafield.model';
import { take } from 'rxjs/operators';
import { TranslateService } from '@ngx-translate/core';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
import { BrowseEntrySearchOptions } from '../../core/browse/browse-entry-search-options.model';
import { combineLatest as observableCombineLatest } from 'rxjs/internal/observable/combineLatest';
import { RemoteData } from '../../core/data/remote-data';
import { PaginatedList } from '../../core/data/paginated-list';
import { Item } from '../../core/shared/item.model';
import { hasValue, isNotEmpty } from '../../shared/empty.util';
import { ActivatedRoute, Router } from '@angular/router';
Expand Down

0 comments on commit 96155e5

Please sign in to comment.