Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Add spaces to regex for relational operators. #612

Merged
merged 19 commits into from
Oct 8, 2019
Merged
Show file tree
Hide file tree
Changes from 7 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
16 changes: 8 additions & 8 deletions src/dash-table/syntax-tree/lexeme/relational.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const contains: IUnboundedLexeme = R.merge({
op.toString().indexOf(exp.toString()) !== -1
),
subType: RelationalOperator.Contains,
regexp: /^(contains)/i
regexp: /^(contains(\s|$))/i
}, LEXEME_BASE);

export const equal: IUnboundedLexeme = R.merge({
Expand All @@ -67,19 +67,19 @@ export const equal: IUnboundedLexeme = R.merge({
op === exp
),
subType: RelationalOperator.Equal,
regexp: /^(=|eq)/i
regexp: /^(=|eq\s)/i
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And the other ones :)

}, LEXEME_BASE);

export const greaterOrEqual: IUnboundedLexeme = R.merge({
evaluate: relationalEvaluator(([op, exp]) => op >= exp),
subType: RelationalOperator.GreaterOrEqual,
regexp: /^(>=|ge)/i
regexp: /^(>=|ge\s)/i
}, LEXEME_BASE);

export const greaterThan: IUnboundedLexeme = R.merge({
evaluate: relationalEvaluator(([op, exp]) => op > exp),
subType: RelationalOperator.GreaterThan,
regexp: /^(>|gt)/i
regexp: /^(>|gt\s)/i
}, LEXEME_BASE);

const DATE_OPTIONS: IDateValidation = {
Expand All @@ -100,23 +100,23 @@ export const dateStartsWith: IUnboundedLexeme = R.merge({
normalizedOp.indexOf(normalizedExp) === 0;
}),
subType: RelationalOperator.DateStartsWith,
regexp: /^(datestartswith)/i
regexp: /^(datestartswith\s)/i
}, LEXEME_BASE);

export const lessOrEqual: IUnboundedLexeme = R.merge({
evaluate: relationalEvaluator(([op, exp]) => op <= exp),
subType: RelationalOperator.LessOrEqual,
regexp: /^(<=|le)/i
regexp: /^(<=|le\s)/i
}, LEXEME_BASE);

export const lessThan: IUnboundedLexeme = R.merge({
evaluate: relationalEvaluator(([op, exp]) => op < exp),
subType: RelationalOperator.LessThan,
regexp: /^(<|lt)/i
regexp: /^(<|lt\s)/i
}, LEXEME_BASE);

export const notEqual: IUnboundedLexeme = R.merge({
evaluate: relationalEvaluator(([op, exp]) => op !== exp),
subType: RelationalOperator.NotEqual,
regexp: /^(!=|ne)/i
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ne should also have \s

}, LEXEME_BASE);
}, LEXEME_BASE);
37 changes: 31 additions & 6 deletions tests/cypress/tests/standalone/filtering_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ describe('filter', () => {
.within(() => cy.get('.dash-cell-value')
.then($el => cell_1 = $el[0].innerHTML));

DashTable.getFilterById('ccc').click();
DOM.focused.type(`gt`);
DashTable.getFilterById('ddd').click();
DOM.focused.type('"20 a000');
DashTable.getFilterById('eee').click();
Expand All @@ -85,12 +83,10 @@ describe('filter', () => {
DashTable.getCellById(1, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', cell_1));

DashTable.getFilterById('bbb').within(() => cy.get('input').should('have.value', '! !"'));
DashTable.getFilterById('ccc').within(() => cy.get('input').should('have.value', 'gt'));
DashTable.getFilterById('ddd').within(() => cy.get('input').should('have.value', '"20 a000'));
DashTable.getFilterById('eee').within(() => cy.get('input').should('have.value', 'is prime2'));

DashTable.getFilterById('bbb').should('have.class', 'invalid');
DashTable.getFilterById('ccc').should('have.class', 'invalid');
DashTable.getFilterById('ddd').should('have.class', 'invalid');
DashTable.getFilterById('eee').should('have.class', 'invalid');
});
Expand All @@ -113,14 +109,43 @@ describe('filter', () => {
DashTable.getCellById(0, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '100'));
});

it('does not use text-based relational operators unless they are followed by a space', () => {
DashTable.getCellById(2, 'ccc').click();
DOM.focused.type(`le5${Key.Enter}`);

DashTable.getFilterById('ccc').click();
DOM.focused.type(`le5${Key.Enter}`);
DashTable.getCellById(0, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', 'le5'));
DashTable.getCellById(0, 'rows').within(() => cy.get('.dash-cell-value').should('have.html', '3'));

cy.get('.clear-filters').click();

DashTable.getFilterById('ccc').click();
DOM.focused.type(`le 5${Key.Enter}`);
DashTable.getCellById(0, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '1'));
DashTable.getCellById(1, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '2'));
DashTable.getCellById(2, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '4'));
DashTable.getCellById(3, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '5'));
});

it('uses symbol relational operators that are not followed by a space', () => {
DashTable.getFilterById('ccc').click();
DOM.focused.type(`<=5${Key.Enter}`);
DashTable.getCellById(0, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '1'));
DashTable.getCellById(1, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '2'));
DashTable.getCellById(2, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '3'));
DashTable.getCellById(3, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '4'));
DashTable.getCellById(4, 'ccc').within(() => cy.get('.dash-cell-value').should('have.html', '5'));
});

it('typing invalid followed by valid query fragment does not reset invalid', () => {
DashTable.getFilterById('ccc').click();
DOM.focused.type(`gt`);
DOM.focused.type(`is prime2`);
DashTable.getFilterById('ddd').click();
DOM.focused.type('lt 20000');
DashTable.getFilterById('eee').click();

DashTable.getFilterById('ccc').within(() => cy.get('input').should('have.value', 'gt'));
DashTable.getFilterById('ccc').within(() => cy.get('input').should('have.value', 'is prime2'));
DashTable.getFilterById('ddd').within(() => cy.get('input').should('have.value', 'lt 20000'));
});

Expand Down