mirror of
https://github.com/getredash/redash.git
synced 2026-03-21 16:00:09 -04:00
* Migrate router and <app-view> to React: skeleton * Update layout on route change * Start moving page routes from angular to react * Move page routes to react except of public dashboard and visualization embed) * Move public dashboard and visualization embed routes to React * Replace $route/$routeParams usages * Some cleanup * Replace AngularJS $location service with implementation based on history library * Minor fix to how ApplicationView handles route change * Explicitly use global layout for each page instead of handling related stuff in ApplicationArea component * Error handling * Remove AngularJS and related dependencies * Move Parameter factory method to a separate file * Fix CSS (replace custom components with classes) * Fix: keep other url parts when updating location partially; refine code * Fix tests * Make router work in multi-org mode (respect <base> tag) * Optimzation: don't resolve route if path didn't change * Fix search input in header; error handling improvement (handle more errors in pages; global error handler for unhandled errors; dialog dismiss 'unhandled rejection' errors) * Fix page keys; fix navigateTo calls (third parameter not available) * Use relative links * Router: ignore location REPLACE events, resolve only on PUSH/POP * Fix tests * Remove unused jQuery reference * Show error from backend when creating Destination * Remove route.resolve where not necessary (used constant values) * New Query page: keep state on saving, reload when creating another new query * Use currentRoute.key instead of hard-coded keys for page components * Tidy up Router * Tidy up location service * Fix tests * Don't add parameters changes to browser's history * Fix test (improved fix) Co-authored-by: Gabriel Dutra <nesk.frz@gmail.com>
77 lines
2.8 KiB
JavaScript
77 lines
2.8 KiB
JavaScript
import { createParameter } from "..";
|
|
import { getDynamicDateRangeFromString } from "../DateRangeParameter";
|
|
import moment from "moment";
|
|
|
|
describe("DateRangeParameter", () => {
|
|
let type = "date-range";
|
|
let param;
|
|
|
|
beforeEach(() => {
|
|
param = createParameter({ name: "param", title: "Param", type });
|
|
});
|
|
|
|
describe("getExecutionValue", () => {
|
|
beforeEach(() => {
|
|
param.setValue({ start: "2019-10-05 10:00:00", end: "2019-10-06 09:59:59" });
|
|
});
|
|
|
|
test("formats value as a string date", () => {
|
|
const executionValue = param.getExecutionValue();
|
|
expect(executionValue).toEqual({ start: "2019-10-05", end: "2019-10-06" });
|
|
});
|
|
|
|
describe("type is datetime-range", () => {
|
|
beforeAll(() => {
|
|
type = "datetime-range";
|
|
});
|
|
|
|
test("formats value as a string datetime", () => {
|
|
const executionValue = param.getExecutionValue();
|
|
expect(executionValue).toEqual({ start: "2019-10-05 10:00", end: "2019-10-06 09:59" });
|
|
});
|
|
});
|
|
|
|
describe("type is datetime-range-with-seconds", () => {
|
|
beforeAll(() => {
|
|
type = "datetime-range-with-seconds";
|
|
});
|
|
|
|
test("formats value as a string datetime with seconds", () => {
|
|
const executionValue = param.getExecutionValue();
|
|
expect(executionValue).toEqual({ start: "2019-10-05 10:00:00", end: "2019-10-06 09:59:59" });
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("normalizeValue", () => {
|
|
test("recognizes dates from moment arrays", () => {
|
|
const normalizedValue = param.normalizeValue([moment("2019-10-05"), moment("2019-10-06")]);
|
|
expect(normalizedValue).toHaveLength(2);
|
|
expect(normalizedValue[0].format("YYYY-MM-DD")).toBe("2019-10-05");
|
|
expect(normalizedValue[1].format("YYYY-MM-DD")).toBe("2019-10-06");
|
|
});
|
|
|
|
test("recognizes dates from object", () => {
|
|
const normalizedValue = param.normalizeValue({ start: "2019-10-05", end: "2019-10-06" });
|
|
expect(normalizedValue).toHaveLength(2);
|
|
expect(normalizedValue[0].format("YYYY-MM-DD")).toBe("2019-10-05");
|
|
expect(normalizedValue[1].format("YYYY-MM-DD")).toBe("2019-10-06");
|
|
});
|
|
|
|
describe("Dynamic values", () => {
|
|
test("recognizes dynamic values from string index", () => {
|
|
const normalizedValue = param.normalizeValue("d_last_week");
|
|
expect(normalizedValue).not.toBeNull();
|
|
expect(normalizedValue).toEqual(getDynamicDateRangeFromString("d_last_week"));
|
|
});
|
|
|
|
test("recognizes dynamic values from a dynamic date range", () => {
|
|
const dynamicDateRange = getDynamicDateRangeFromString("d_last_week");
|
|
const normalizedValue = param.normalizeValue(dynamicDateRange);
|
|
expect(normalizedValue).not.toBeNull();
|
|
expect(normalizedValue).toEqual(dynamicDateRange);
|
|
});
|
|
});
|
|
});
|
|
});
|