Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { FilterAttribute } from '../filter-attribute';
import { FilterAttributeType } from '../filter-attribute-type';
import { tryParseStringForAttribute } from './parsed-filter';

describe('Filter Parsing utilities', () => {
const testStatusAttribute: FilterAttribute = {
name: 'status',
displayName: 'Status',
type: FilterAttributeType.String
};

const testStatusCodeAttribute: FilterAttribute = {
name: 'statusCode',
displayName: 'Status Code',
type: FilterAttributeType.String
};

test('should match if full name match', () => {
expect(tryParseStringForAttribute(testStatusAttribute, 'status', ['name'])).toEqual({
attribute: testStatusAttribute
});

expect(tryParseStringForAttribute(testStatusAttribute, 'status ', ['name'])).toEqual({
attribute: testStatusAttribute
});

expect(tryParseStringForAttribute(testStatusCodeAttribute, 'statusCode', ['name'])).toEqual({
attribute: testStatusCodeAttribute
});
});

test('should match if followed by beginning of operator', () => {
expect(tryParseStringForAttribute(testStatusAttribute, 'status !', ['name'])).toEqual({
attribute: testStatusAttribute
});
});

test('should not match if partial name match', () => {
expect(tryParseStringForAttribute(testStatusCodeAttribute, 'status', ['name'])).toBe(undefined);
});

test('should not match if text starts with attribute name and continues', () => {
expect(tryParseStringForAttribute(testStatusAttribute, 'statusCode', ['name'])).toBe(undefined);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export const tryParseStringForAttribute = (
// Now, we know that it does match. Remove the attribute name from the beginning and try to determine the subpath next.
const stringAfterAttributeName = text.slice(attributeToTest[matchingNameField].length).trim();

// If the string continues with more alphanumeric characters directly after this attribute name, it's no longer a match
if (stringAfterAttributeName.match(/^\w/)) {
return undefined;
}

if (stringAfterAttributeName.startsWith(MAP_LHS_DELIMITER)) {
if (attributeToTest.type !== FilterAttributeType.StringMap) {
// Can't have a subpath if not a map
Expand Down