Skip to content

Commit

Permalink
Pulling in roberts test name changes
Browse files Browse the repository at this point in the history
  • Loading branch information
oatkiller authored and jonathan-buttner committed Sep 3, 2020
1 parent e97352c commit 97e14dd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,13 @@ interface Metadata {
}

/**
* A simple mock dataAccessLayer possible that returns a tree with 0 ancestors and 2 direct children. 1 related event is returned. The parameter to `entities` is ignored.
* A mock DataAccessLayer that will return an origin in two children. The `entity` response will be empty unless
* `awesome_index` is passed in the indices array.
*/
export function handleNoIndices(): { dataAccessLayer: DataAccessLayer; metadata: Metadata } {
export function noAncestorsTwoChildenInIndexCalledAwesomeIndex(): {
dataAccessLayer: DataAccessLayer;
metadata: Metadata;
} {
const metadata: Metadata = {
databaseDocumentID: '_id',
entityIDs: { origin: 'origin', firstChild: 'firstChild', secondChild: 'secondChild' },
Expand Down Expand Up @@ -82,6 +86,7 @@ export function handleNoIndices(): { dataAccessLayer: DataAccessLayer; metadata:
* Get entities matching a document.
*/
entities({ indices }): Promise<ResolverEntityIndex> {
// Only return values if the `indices` array contains exactly `'awesome_index'`
if (indices.length === 1 && indices[0] === 'awesome_index') {
return Promise.resolve([{ entity_id: metadata.entityIDs.origin }]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ export function equal(param1: TreeFetcherParameters, param2?: TreeFetcherParamet
if (param1.databaseDocumentID !== param2.databaseDocumentID) {
return false;
}
return arrayEqual(param1.indices, param2.indices);
return arraysContainTheSameElements(param1.indices, param2.indices);
}

function arrayEqual(first: unknown[], second: unknown[]): boolean {
function arraysContainTheSameElements(first: unknown[], second: unknown[]): boolean {
if (first === second) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { handleNoIndices } from '../data_access_layer/mocks/no_indices_two_children';
import { noAncestorsTwoChildenInIndexCalledAwesomeIndex } from '../data_access_layer/mocks/no_ancestors_two_children_in_index_called_awesome_index';
import { noAncestorsTwoChildren } from '../data_access_layer/mocks/no_ancestors_two_children';
import { Simulator } from '../test_utilities/simulator';
// Extend jest with a custom matcher
Expand All @@ -20,10 +20,13 @@ let entityIDs: { origin: string; firstChild: string; secondChild: string };
// the resolver component instance ID, used by the react code to distinguish piece of global state from those used by other resolver instances
const resolverComponentInstanceID = 'resolverComponentInstanceID';

describe('Resolver, initially no indices', () => {
describe("Resolver, when rendered with the `indices` prop set to `[]` and the `databaseDocumentID` prop set to `_id`, and when the document is found in an index called 'awesome_index'", () => {
beforeEach(async () => {
// create a mock data access layer
const { metadata: dataAccessLayerMetadata, dataAccessLayer } = handleNoIndices();
const {
metadata: dataAccessLayerMetadata,
dataAccessLayer,
} = noAncestorsTwoChildenInIndexCalledAwesomeIndex();

// save a reference to the entity IDs exposed by the mock data layer
entityIDs = dataAccessLayerMetadata.entityIDs;
Expand All @@ -40,7 +43,7 @@ describe('Resolver, initially no indices', () => {
});
});

it(`should retrieve no process nodes when the indices was an empty array`, async () => {
it('should render no processes', async () => {
await expect(
simulator.map(() => ({
processes: simulator.processNodeElements().length,
Expand All @@ -50,9 +53,8 @@ describe('Resolver, initially no indices', () => {
});
});

describe('Resolver, when indices are used', () => {
describe("when rerendered with the `indices` prop set to `['awesome_index'`]", () => {
beforeEach(async () => {
// awesome_index is checked in the handleNoIndices function
simulator.indices = ['awesome_index'];
});
// Combining assertions here for performance. Unfortunately, Enzyme + jsdom + React is slow.
Expand Down

0 comments on commit 97e14dd

Please sign in to comment.