mirror of
https://github.com/vale981/Vulcan
synced 2025-03-06 10:01:40 -05:00
44 lines
2.2 KiB
JavaScript
44 lines
2.2 KiB
JavaScript
import { extractCollectionInfo, extractFragmentInfo } from '../lib/modules/containers/handleOptions';
|
|
import expect from 'expect';
|
|
|
|
describe('vulcan-core/containers', function () {
|
|
describe('handleOptions', function () {
|
|
const expectedCollectionName = 'COLLECTION_NAME';
|
|
const expectedCollection = { options: { expectedCollectionName } };
|
|
it('get collectionName from collection', function () {
|
|
const options = { collection: expectedCollection };
|
|
const { collection, collectionName } = extractCollectionInfo(options);
|
|
expect(collection).toEqual(expectedCollection);
|
|
expect(collectionName).toEqual(expectedCollectionName);
|
|
});
|
|
it('get collection from collectioName', function () {
|
|
// MOCK getCollection
|
|
const options = { collectionName: expectedCollectionName };
|
|
const { collection, collectionName } = extractCollectionInfo(options);
|
|
expect(collection).toEqual(expectedCollection);
|
|
expect(collectionName).toEqual(expectedCollectionName);
|
|
});
|
|
const expectedFragmentName = 'FRAGMENT_NAME';
|
|
const expectedFragment = { definitions: [{ name: { value: expectedFragmentName } }] };
|
|
it('get fragment from fragmentName', function () {
|
|
// MOCK getCollection
|
|
const options = { fragmentName: expectedFragmentName };
|
|
const { fragment, fragmentName } = extractFragmentInfo(options);
|
|
expect(fragment).toEqual(expectedFragment);
|
|
expect(fragmentName).toEqual(expectedFragmentName);
|
|
});
|
|
it('get fragmentName from fragment', function () {
|
|
const options = { fragment: expectedFragment };
|
|
const { fragment, fragmentName } = extractFragmentInfo(options);
|
|
expect(fragment).toEqual(expectedFragment);
|
|
expect(fragmentName).toEqual(expectedFragmentName);
|
|
});
|
|
it('get fragmentName and fragment from collectionName', function () {
|
|
// if options does not contain fragment, we get the collection default fragment based on its name
|
|
const options = {};
|
|
const { fragment, fragmentName } = extractFragmentInfo(options, expectedCollectionName);
|
|
expect(fragment).toEqual(expectedFragment);
|
|
expect(fragmentName).toEqual(expectedFragmentName);
|
|
});
|
|
});
|
|
});
|