mirror of
https://github.com/getredash/redash.git
synced 2025-12-19 17:37:19 -05:00
* DynamicComponent for QuerySourceAlerts * General Settings updates * Dynamic Date[Range] updates * EmptyState updates * Query and SchemaBrowser updates * Adjust page headers and add disablePublish * Policy updates * Separate Home FavoritesList component * Update FormatQuery * Autolimit frontend fixes * Misc updates * Keep registering of QuerySourceDropdown * Undo changes in DynamicComponent * Change sql-formatter package.json syntax * Allow opening help trigger in new tab * Don't run npm commands as root in Dockerfile * Cypress: Remove extra execute query
57 lines
2.3 KiB
JavaScript
57 lines
2.3 KiB
JavaScript
import { Query } from "@/services/query";
|
|
import * as queryFormat from "./queryFormat";
|
|
|
|
describe("QueryFormat.formatQuery", () => {
|
|
test("returns same query text when syntax is not supported", () => {
|
|
const unsupportedSyntax = "unsupported-syntax";
|
|
const queryText = "select * from example";
|
|
const isFormatQueryAvailable = queryFormat.isFormatQueryAvailable(unsupportedSyntax);
|
|
const formattedQuery = queryFormat.formatQuery(queryText, unsupportedSyntax);
|
|
|
|
expect(isFormatQueryAvailable).toBeFalsy();
|
|
expect(formattedQuery).toBe(queryText);
|
|
});
|
|
|
|
describe("sql", () => {
|
|
const syntax = "sql";
|
|
|
|
test("returns the formatted query text", () => {
|
|
const queryText = "select column1, column2 from example where column1 = 2";
|
|
const expectedFormattedQueryText = [
|
|
"select",
|
|
" column1,",
|
|
" column2",
|
|
"from",
|
|
" example",
|
|
"where",
|
|
" column1 = 2",
|
|
].join("\n");
|
|
const isFormatQueryAvailable = queryFormat.isFormatQueryAvailable(syntax);
|
|
const formattedQueryText = queryFormat.formatQuery(queryText, syntax);
|
|
expect(isFormatQueryAvailable).toBeTruthy();
|
|
expect(formattedQueryText).toBe(expectedFormattedQueryText);
|
|
});
|
|
|
|
test("still recognizes parameters after formatting", () => {
|
|
const queryText = "select {{param1}}, {{ param2 }}, {{ date-range.start }} from example";
|
|
const formattedQueryText = queryFormat.formatQuery(queryText, syntax);
|
|
const queryParameters = new Query({ query: queryText }).getParameters().parseQuery();
|
|
const formattedQueryParameters = new Query({ query: formattedQueryText }).getParameters().parseQuery();
|
|
expect(formattedQueryParameters.sort()).toEqual(queryParameters.sort());
|
|
});
|
|
});
|
|
|
|
describe("json", () => {
|
|
const syntax = "json";
|
|
|
|
test("returns the formatted query text", () => {
|
|
const queryText = '{"collection": "example","limit": 10}';
|
|
const expectedFormattedQueryText = '{\n "collection": "example",\n "limit": 10\n}';
|
|
const isFormatQueryAvailable = queryFormat.isFormatQueryAvailable(syntax);
|
|
const formattedQueryText = queryFormat.formatQuery(queryText, syntax);
|
|
expect(isFormatQueryAvailable).toBeTruthy();
|
|
expect(formattedQueryText).toBe(expectedFormattedQueryText);
|
|
});
|
|
});
|
|
});
|