Skip to content

Commit

Permalink
Tests for deaccession
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejritter committed Sep 9, 2024
1 parent 79ce526 commit 8afea63
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/specs/plugins/recordTypes/deaccession/advancedSearch.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import createConfigContext from '../../../../../src/helpers/createConfigContext';
import advancedSearch from '../../../../../src/plugins/recordTypes/deaccession/advancedSearch';

chai.should();

describe('deaccession record advanced search', () => {
const configContext = createConfigContext();

it('should contain a top level property `op`', () => {
advancedSearch(configContext).should.have.property('op');
});

it('should contain a top level property `value` that is an array', () => {
advancedSearch(configContext).should.have.property('value').that.is.an('array');
});
});
15 changes: 15 additions & 0 deletions test/specs/plugins/recordTypes/deaccession/columns.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import deaccessionRecordTypePluginFactory from '../../../../../src/plugins/recordTypes/deaccession';
import createColumns from '../../../../../src/plugins/recordTypes/deaccession/columns';
import createConfigContext from '../../../../../src/helpers/createConfigContext';

chai.should();

describe('deaccession record columns', () => {
const deaccessionRecordTypePlugin = deaccessionRecordTypePluginFactory({});
const configContext = createConfigContext(deaccessionRecordTypePlugin);
const columns = createColumns(configContext);

it('should have the correct shape', () => {
columns.should.have.property('default').that.is.an('object');
});
});
14 changes: 14 additions & 0 deletions test/specs/plugins/recordTypes/deaccession/forms/default.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Field from '../../../../../../src/components/record/Field';
import form from '../../../../../../src/plugins/recordTypes/deaccession/forms/default';
import createConfigContext from '../../../../../../src/helpers/createConfigContext';

chai.should();

describe('deaccession record default form', () => {
it('should be a Field', () => {
const configContext = createConfigContext();
const { template } = form(configContext);

template.type.should.equal(Field);
});
});
29 changes: 29 additions & 0 deletions test/specs/plugins/recordTypes/deaccession/index.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import deaccessionRecordTypePluginFactory from '../../../../../src/plugins/recordTypes/deaccession';
import createConfigContext from '../../../../../src/helpers/createConfigContext';

chai.should();

describe('deaccession record plugin', () => {
const config = {};
const deaccessionRecordTypePlugin = deaccessionRecordTypePluginFactory(config);
const configContext = createConfigContext(deaccessionRecordTypePlugin);

it('should have the correct shape', () => {
const pluginConfiguration = deaccessionRecordTypePlugin(configContext);

const {
recordTypes,
} = pluginConfiguration;

recordTypes.should.have.property('deaccession');

const deaccessionRecordType = recordTypes.deaccession;

deaccessionRecordType.should.have.property('title').that.is.a('function');
deaccessionRecordType.should.have.property('forms').that.is.an('object');
deaccessionRecordType.should.have.property('messages').that.is.an('object');
deaccessionRecordType.should.have.property('serviceConfig').that.is.an('object');

deaccessionRecordType.title().should.be.a('string');
});
});
17 changes: 17 additions & 0 deletions test/specs/plugins/recordTypes/deaccession/messages.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import messages from '../../../../../src/plugins/recordTypes/deaccession/messages';

chai.should();

describe('deaccession record messages', () => {
it('should contain properties with an id and defaultMessage properties', () => {
messages.should.be.an('object');

Object.keys(messages).forEach((deaccessionName) => {
const deaccessionMessages = messages[deaccessionName];

Object.keys(deaccessionMessages).forEach((name) => {
deaccessionMessages[name].should.contain.all.keys(['id', 'defaultMessage']);
});
});
});
});
13 changes: 13 additions & 0 deletions test/specs/plugins/recordTypes/deaccession/serviceConfig.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import serviceConfig from '../../../../../src/plugins/recordTypes/deaccession/serviceConfig';

chai.should();

describe('deaccession record serviceConfig', () => {
it('should have a servicePath property', () => {
serviceConfig.should.have.property('servicePath').that.is.a('string');
serviceConfig.should.have.property('serviceName').that.is.a('string');
serviceConfig.should.have.property('serviceType').that.is.a('string');
serviceConfig.should.have.property('objectName').that.is.a('string');
serviceConfig.should.have.property('documentName').that.is.a('string');
});
});
64 changes: 64 additions & 0 deletions test/specs/plugins/recordTypes/deaccession/title.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import Immutable from 'immutable';
import createTitleGetter from '../../../../../src/plugins/recordTypes/deaccession/title';
import createConfigContext from '../../../../../src/helpers/createConfigContext';

chai.should();

describe('deaccession record title', () => {
const configContext = createConfigContext();
const title = createTitleGetter(configContext);

it('should return the deaccession number and deaccessionTitle when both are present', () => {
const data = Immutable.fromJS({
document: {
'ns2:deaccessions_common': {
deaccessionNumber: 'DE',
// deaccessionTitle: 'Title',
},
},
});

title(data).should.equal('DE – Title');
});

it('should return the deaccession number only when the deaccessionTitle is missing', () => {
const data = Immutable.fromJS({
document: {
'ns2:deaccessions_common': {
deaccessionNumber: 'DE',
},
},
});

title(data).should.equal('DE');
});

it('should return the deaccessionTitle only when the deaccession number is missing', () => {
const data = Immutable.fromJS({
document: {
'ns2:deaccessions_common': {
// deaccessionTitle: 'Title',
},
},
});

title(data).should.equal('');
});

it('should return an empty string if no document is passed', () => {
title(null).should.equal('');
title(undefined).should.equal('');
});

it('should return an empty string if the common part is not present', () => {
const data = Immutable.fromJS({
document: {
'ns2:deaccessions_extension': {
deaccessionAltTitle: 'Alt deaccession title',
},
},
});

title(data).should.equal('');
});
});

0 comments on commit 8afea63

Please sign in to comment.