mirror of
https://github.com/apache/superset.git
synced 2026-04-18 15:44:57 +00:00
fix(explore): improve filter translation (#12350)
* fix(explore): improve filter translation * address review comments
This commit is contained in:
@@ -301,28 +301,38 @@ describe('exploreUtils', () => {
|
||||
});
|
||||
|
||||
describe('getSimpleSQLExpression', () => {
|
||||
const subject = 'subject';
|
||||
const operator = '=';
|
||||
const comparator = 'comparator';
|
||||
it('returns empty string when subject is undefined', () => {
|
||||
expect(getSimpleSQLExpression(undefined, '=', 10)).toBe('');
|
||||
expect(getSimpleSQLExpression()).toBe('');
|
||||
});
|
||||
it('returns subject when its provided and operator is undefined', () => {
|
||||
expect(getSimpleSQLExpression(subject, undefined, 10)).toBe(subject);
|
||||
expect(getSimpleSQLExpression(subject)).toBe(subject);
|
||||
it("returns subject when it's provided and operator is undefined", () => {
|
||||
expect(getSimpleSQLExpression('col', undefined, 10)).toBe('col');
|
||||
expect(getSimpleSQLExpression('col')).toBe('col');
|
||||
});
|
||||
it('returns subject and operator when theyre provided and comparator is undefined', () => {
|
||||
expect(getSimpleSQLExpression(subject, operator)).toBe(
|
||||
`${subject} ${operator}`,
|
||||
);
|
||||
it("returns subject and operator when they're provided and comparator is undefined", () => {
|
||||
expect(getSimpleSQLExpression('col', '=')).toBe('col =');
|
||||
expect(getSimpleSQLExpression('col', 'IN')).toBe('col IN');
|
||||
expect(getSimpleSQLExpression('col', 'IN', [])).toBe('col IN');
|
||||
});
|
||||
it('returns full expression when subject, operator and comparator are provided', () => {
|
||||
expect(getSimpleSQLExpression(subject, operator, comparator)).toBe(
|
||||
`${subject} ${operator} ${comparator}`,
|
||||
expect(getSimpleSQLExpression('col', '=', 'comp')).toBe("col = 'comp'");
|
||||
expect(getSimpleSQLExpression('col', '=', "it's an apostrophe")).toBe(
|
||||
"col = 'it''s an apostrophe'",
|
||||
);
|
||||
expect(getSimpleSQLExpression(subject, operator, comparator, true)).toBe(
|
||||
`${subject} ${operator} ('${comparator}')`,
|
||||
expect(getSimpleSQLExpression('col', '=', 0)).toBe('col = 0');
|
||||
expect(getSimpleSQLExpression('col', '=', '0')).toBe('col = 0');
|
||||
expect(getSimpleSQLExpression('col', 'IN', 'foo')).toBe("col IN ('foo')");
|
||||
expect(getSimpleSQLExpression('col', 'NOT IN', ['foo'])).toBe(
|
||||
"col NOT IN ('foo')",
|
||||
);
|
||||
expect(getSimpleSQLExpression('col', 'IN', ['foo', 'bar'])).toBe(
|
||||
"col IN ('foo', 'bar')",
|
||||
);
|
||||
expect(getSimpleSQLExpression('col', 'IN', ['0', '1', '2'])).toBe(
|
||||
'col IN (0, 1, 2)',
|
||||
);
|
||||
expect(getSimpleSQLExpression('col', 'NOT IN', [0, 1, 2])).toBe(
|
||||
'col NOT IN (0, 1, 2)',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user