Skip to content

Commit

Permalink
US 5 // Allow user to filter resources if they have path
Browse files Browse the repository at this point in the history
Signed-off-by: Dinika Saxena <[email protected]>
  • Loading branch information
Dinika committed Jul 4, 2023
1 parent 09091f6 commit 9d82891
Show file tree
Hide file tree
Showing 4 changed files with 366 additions and 104 deletions.
255 changes: 229 additions & 26 deletions src/subapps/dataExplorer/DataExplorer-utils.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
doesResourceContain,
getAllPaths,
isPathMissing,
checkPathExistence,
} from './PredicateSelector';

describe('DataExplorerSpec-Utils', () => {
Expand Down Expand Up @@ -82,7 +82,7 @@ describe('DataExplorerSpec-Utils', () => {
expect(receivedPaths).toEqual(expectedPaths);
});

it('returns true when top level property does not exist in resource', () => {
it('checks if path exists in resource', () => {
const resource = {
foo: 'some value',
nullValue: null,
Expand Down Expand Up @@ -121,45 +121,229 @@ describe('DataExplorerSpec-Utils', () => {
},
],
};
expect(isPathMissing(resource, 'bar')).toEqual(true);
expect(isPathMissing(resource, 'nullValue')).toEqual(false);
expect(isPathMissing(resource, 'undefinedValue')).toEqual(false);
expect(isPathMissing(resource, 'emptyString')).toEqual(false);
expect(isPathMissing(resource, 'emptyArray')).toEqual(false);
expect(isPathMissing(resource, 'emptyObject')).toEqual(false);
expect(checkPathExistence(resource, 'bar')).toEqual(false);
expect(checkPathExistence(resource, 'nullValue')).toEqual(true);
expect(checkPathExistence(resource, 'undefinedValue')).toEqual(true);
expect(checkPathExistence(resource, 'emptyString')).toEqual(true);
expect(checkPathExistence(resource, 'emptyArray')).toEqual(true);
expect(checkPathExistence(resource, 'emptyObject')).toEqual(true);

expect(isPathMissing(resource, 'foo')).toEqual(false);
expect(isPathMissing(resource, 'foo.xyz')).toEqual(true);
expect(isPathMissing(resource, 'foo.distribution')).toEqual(true);
expect(checkPathExistence(resource, 'foo')).toEqual(true);
expect(checkPathExistence(resource, 'foo.xyz')).toEqual(false);
expect(checkPathExistence(resource, 'foo.distribution')).toEqual(false);

expect(isPathMissing(resource, 'distribution')).toEqual(false);
expect(isPathMissing(resource, 'distribution.name')).toEqual(false);
expect(isPathMissing(resource, 'distribution.name.sillyname')).toEqual(
true
expect(checkPathExistence(resource, 'distribution')).toEqual(true);
expect(checkPathExistence(resource, 'distribution.name')).toEqual(true);
expect(checkPathExistence(resource, 'distribution.name.sillyname')).toEqual(
false
);
expect(
isPathMissing(resource, 'distribution.name.sillyname.pancake')
checkPathExistence(resource, 'distribution.name.sillyname.pancake')
).toEqual(false);
expect(
checkPathExistence(resource, 'distribution.name.label.pancake')
).toEqual(false);
expect(
checkPathExistence(resource, 'distribution.label.unofficial')
).toEqual(true); // TODO: Add opposite
expect(
checkPathExistence(resource, 'distribution.label.extended.prefix')
).toEqual(true);
expect(isPathMissing(resource, 'distribution.name.label.pancake')).toEqual(
true
expect(
checkPathExistence(resource, 'distribution.label.extended.suffix')
).toEqual(true); // Add opposite
expect(
checkPathExistence(resource, 'distribution.label.extended.notexisting')
).toEqual(false); // Add opposite
expect(checkPathExistence(resource, 'distribution.foo')).toEqual(false);
expect(checkPathExistence(resource, 'distribution.emptyArray')).toEqual(
false
);
expect(isPathMissing(resource, 'distribution.label.unofficial')).toEqual(
expect(
checkPathExistence(resource, 'distribution.label.emptyArray')
).toEqual(true);
expect(
checkPathExistence(resource, 'distribution.label.emptyString')
).toEqual(true); // Add opposite
});

it('check if path exists in resource with nested array', () => {
const resource = {
distribution: [
{
foo: 'foovalue',
filename: ['filename1'],
},
{
foo: 'foovalue',
},
],
objPath: {
filename: ['filename1'],
},
};
expect(
checkPathExistence(resource, 'distribution.filename', 'exists')
).toEqual(true);
expect(
checkPathExistence(resource, 'distribution.filename', 'does-not-exist')
).toEqual(true);
expect(
checkPathExistence(resource, 'objPath.filename', 'does-not-exist')
).toEqual(false);
expect(checkPathExistence(resource, 'objPath.filename', 'exists')).toEqual(
true
);
});

it('checks if path is missing in resource', () => {
const resource = {
foo: 'some value',
nullValue: null,
undefinedValue: undefined,
emptyString: '',
emptyArray: [],
emptyObject: {},
distribution: [
{
name: 'sally',
label: {
official: 'official',
unofficial: 'unofficial',
emptyArray: [],
emptyString: '',
extended: [{ prefix: '1', suffix: 2 }, { prefix: '1' }],
},
},
{
name: 'sally',
sillyname: 'soliloquy',
label: [
{
official: 'official',
emptyArray: [],
emptyString: '',
extended: [{ prefix: '1', suffix: 2 }, { prefix: '1' }],
},
{
official: 'official',
unofficial: 'unofficial',
emptyArray: [1],
extended: [{ prefix: '1', suffix: 2 }, { prefix: '1' }],
},
],
},
],
};
expect(checkPathExistence(resource, 'bar', 'does-not-exist')).toEqual(true);
expect(checkPathExistence(resource, 'nullValue', 'does-not-exist')).toEqual(
false
);
expect(
isPathMissing(resource, 'distribution.label.extended.prefix')
checkPathExistence(resource, 'undefinedValue', 'does-not-exist')
).toEqual(false);
expect(
isPathMissing(resource, 'distribution.label.extended.suffix')
).toEqual(true);
expect(isPathMissing(resource, 'distribution.foo')).toEqual(true);
expect(isPathMissing(resource, 'distribution.emptyArray')).toEqual(true);
expect(isPathMissing(resource, 'distribution.label.emptyArray')).toEqual(
checkPathExistence(resource, 'emptyString', 'does-not-exist')
).toEqual(false);
expect(
checkPathExistence(resource, 'emptyArray', 'does-not-exist')
).toEqual(false);
expect(
checkPathExistence(resource, 'emptyObject', 'does-not-exist')
).toEqual(false);

expect(checkPathExistence(resource, 'foo', 'does-not-exist')).toEqual(
false
);
expect(isPathMissing(resource, 'distribution.label.emptyString')).toEqual(
expect(checkPathExistence(resource, 'foo.xyz', 'does-not-exist')).toEqual(
true
);
expect(
checkPathExistence(resource, 'foo.distribution', 'does-not-exist')
).toEqual(true);

expect(
checkPathExistence(resource, 'distribution', 'does-not-exist')
).toEqual(false);
expect(
checkPathExistence(resource, 'distribution.name', 'does-not-exist')
).toEqual(false);
expect(
checkPathExistence(
resource,
'distribution.name.sillyname',
'does-not-exist'
)
).toEqual(true);
expect(
checkPathExistence(
resource,
'distribution.name.sillyname.pancake',
'does-not-exist'
)
).toEqual(true);
expect(
checkPathExistence(
resource,
'distribution.name.label.pancake',
'does-not-exist'
)
).toEqual(true);
expect(
checkPathExistence(
resource,
'distribution.label.unofficial',
'does-not-exist'
)
).toEqual(true);
expect(
checkPathExistence(
resource,
'distribution.label.official',
'does-not-exist'
)
).toEqual(false);
expect(
checkPathExistence(
resource,
'distribution.label.extended.prefix',
'does-not-exist'
)
).toEqual(false);
expect(
checkPathExistence(
resource,
'distribution.label.extended.suffix',
'does-not-exist'
)
).toEqual(true);
expect(
checkPathExistence(
resource,
'distribution.label.extended.notexisting',
'does-not-exist'
)
).toEqual(true);
expect(
checkPathExistence(resource, 'distribution.foo', 'does-not-exist')
).toEqual(true);
expect(
checkPathExistence(resource, 'distribution.emptyArray', 'does-not-exist')
).toEqual(true);
expect(
checkPathExistence(
resource,
'distribution.label.emptyArray',
'does-not-exist'
)
).toEqual(false);
expect(
checkPathExistence(
resource,
'distribution.label.emptyString',
'does-not-exist'
)
).toEqual(true);
});

it('checks if array strings can be checked for contains', () => {
Expand Down Expand Up @@ -301,4 +485,23 @@ describe('DataExplorerSpec-Utils', () => {
doesResourceContain(resource, 'distribution.filename', 'lly')
).toEqual(true);
});

it('checks if path exists in resource', () => {
const resource = {
distribution: [
{
name: 'sally',
filename: 'billy',
label: ['ChiPmunK'],
},
{
name: 'sally',
sillyname: 'soliloquy',
filename: 'bolly',
label: { foo: 'foovalut', bar: 'barvalue' },
},
],
};
expect(checkPathExistence(resource, 'topLevelNotExisting')).toEqual(false);
});
});
35 changes: 28 additions & 7 deletions src/subapps/dataExplorer/DataExplorer.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ import { render, screen, waitFor } from '../../utils/testUtil';
import { DataExplorer } from './DataExplorer';
import { AllProjects } from './ProjectSelector';
import { getColumnTitle } from './DataExplorerTable';
import { DEFAULT_OPTION, getAllPaths } from './PredicateSelector';
import {
CONTAINS,
DEFAULT_OPTION,
DOES_NOT_EXIST,
EXISTS,
getAllPaths,
} from './PredicateSelector';

describe('DataExplorer', () => {
const server = setupServer(
Expand Down Expand Up @@ -73,7 +79,6 @@ describe('DataExplorer', () => {
const expectRowCountToBe = async (expectedRowsCount: number) => {
return await waitFor(() => {
const rows = visibleTableRows();
rows.forEach(row => console.log('Inner html', row.innerHTML));
expect(rows.length).toEqual(expectedRowsCount);
return rows;
});
Expand Down Expand Up @@ -176,7 +181,6 @@ describe('DataExplorer', () => {
optionLabel: string
) => {
await openMenuFor(menuAriaLabel);
console.log('Lookig for option ', optionLabel, ' in menu ', menuAriaLabel);
const option = await getDropdownOption(optionLabel);
await userEvent.click(option, { pointerEventsCheck: 0 });
};
Expand Down Expand Up @@ -398,11 +402,11 @@ describe('DataExplorer', () => {
await expectRowCountToBe(3);

await selectOptionFromMenu(PathMenuLabel, 'author');
await selectOptionFromMenu(PredicateMenuLabel, 'Empty value');
await selectOptionFromMenu(PredicateMenuLabel, DOES_NOT_EXIST);
await expectRowCountToBe(1);

await selectOptionFromMenu(PathMenuLabel, 'edition');
await selectOptionFromMenu(PredicateMenuLabel, 'Empty value');
await selectOptionFromMenu(PredicateMenuLabel, DOES_NOT_EXIST);
await expectRowCountToBe(2);
});

Expand All @@ -419,7 +423,7 @@ describe('DataExplorer', () => {

await selectOptionFromMenu(PathMenuLabel, 'author');
await userEvent.click(container);
await selectOptionFromMenu(PredicateMenuLabel, 'Contains');
await selectOptionFromMenu(PredicateMenuLabel, CONTAINS);
const valueInput = await screen.getByPlaceholderText('type the value...');
await userEvent.type(valueInput, 'iggy');
await expectRowCountToBe(2);
Expand All @@ -443,7 +447,24 @@ describe('DataExplorer', () => {

await selectOptionFromMenu(PathMenuLabel, 'author');
await userEvent.click(container);
await selectOptionFromMenu(PredicateMenuLabel, 'Contains');
await selectOptionFromMenu(PredicateMenuLabel, CONTAINS);
await expectRowCountToBe(3);
});

it('shows resources that have a path when user selects exists predicate', async () => {
await expectRowCountToBe(10);
const mockResourcesForNextPage = [
getMockResource('self1', { author: 'piggy', edition: 1 }),
getMockResource('self2', { author: ['iggy', 'twinky'] }),
getMockResource('self3', { year: 2013 }),
];

await getRowsForNextPage(mockResourcesForNextPage);
await expectRowCountToBe(3);

await selectOptionFromMenu(PathMenuLabel, 'author');
await userEvent.click(container);
await selectOptionFromMenu(PredicateMenuLabel, EXISTS);
await expectRowCountToBe(2);
});
});
Loading

0 comments on commit 9d82891

Please sign in to comment.